From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- layout/inspector/inLayoutUtils.cpp | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 layout/inspector/inLayoutUtils.cpp (limited to 'layout/inspector/inLayoutUtils.cpp') diff --git a/layout/inspector/inLayoutUtils.cpp b/layout/inspector/inLayoutUtils.cpp new file mode 100644 index 000000000..eb502f905 --- /dev/null +++ b/layout/inspector/inLayoutUtils.cpp @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "inLayoutUtils.h" + +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsIContent.h" +#include "nsIContentViewer.h" +#include "nsPIDOMWindow.h" +#include "nsIDocShell.h" +#include "nsIPresShell.h" +#include "nsPresContext.h" +#include "mozilla/EventStateManager.h" +#include "mozilla/dom/Element.h" + +using namespace mozilla; + +/////////////////////////////////////////////////////////////////////////////// + +EventStateManager* +inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) +{ + NS_PRECONDITION(aElement, "Passing in a null element is bad"); + + nsCOMPtr domDoc; + aElement->GetOwnerDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc = do_QueryInterface(domDoc); + + if (!doc) { + NS_WARNING("Could not get an nsIDocument!"); + return nullptr; + } + + nsIPresShell *shell = doc->GetShell(); + if (!shell) + return nullptr; + + return shell->GetPresContext()->EventStateManager(); +} + +nsIDOMDocument* +inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode) +{ + nsCOMPtr content = do_QueryInterface(aNode); + if (content) { + nsCOMPtr doc = content->GetComposedDoc(); + if (doc) { + nsCOMPtr domdoc(do_QueryInterface(doc->GetSubDocumentFor(content))); + + return domdoc; + } + } + + return nullptr; +} + +nsIDOMNode* +inLayoutUtils::GetContainerFor(const nsIDocument& aDoc) +{ + nsPIDOMWindowOuter* pwin = aDoc.GetWindow(); + if (!pwin) { + return nullptr; + } + + nsCOMPtr node = do_QueryInterface(pwin->GetFrameElementInternal()); + return node; +} + -- cgit v1.2.3