gecko/layout/inspector/inLayoutUtils.cpp
Carsten "Tomcat" Book 7bd597dc19 Backed out changeset 1dcb339812d1 (bug 945091) for mochitest-8 bustage on a CLOSED TREE
--HG--
rename : layout/inspector/inICSSValueSearch.idl => layout/inspector/public/inICSSValueSearch.idl
rename : layout/inspector/inIDOMUtils.idl => layout/inspector/public/inIDOMUtils.idl
rename : layout/inspector/inIDOMView.idl => layout/inspector/public/inIDOMView.idl
rename : layout/inspector/inIDeepTreeWalker.idl => layout/inspector/public/inIDeepTreeWalker.idl
rename : layout/inspector/inIFlasher.idl => layout/inspector/public/inIFlasher.idl
rename : layout/inspector/inISearchObserver.idl => layout/inspector/public/inISearchObserver.idl
rename : layout/inspector/inISearchProcess.idl => layout/inspector/public/inISearchProcess.idl
rename : layout/inspector/nsIDOMFontFace.idl => layout/inspector/public/nsIDOMFontFace.idl
rename : layout/inspector/nsIDOMFontFaceList.idl => layout/inspector/public/nsIDOMFontFaceList.idl
rename : layout/inspector/inCSSValueSearch.cpp => layout/inspector/src/inCSSValueSearch.cpp
rename : layout/inspector/inCSSValueSearch.h => layout/inspector/src/inCSSValueSearch.h
rename : layout/inspector/inDOMUtils.cpp => layout/inspector/src/inDOMUtils.cpp
rename : layout/inspector/inDOMUtils.h => layout/inspector/src/inDOMUtils.h
rename : layout/inspector/inDOMView.cpp => layout/inspector/src/inDOMView.cpp
rename : layout/inspector/inDOMView.h => layout/inspector/src/inDOMView.h
rename : layout/inspector/inDeepTreeWalker.cpp => layout/inspector/src/inDeepTreeWalker.cpp
rename : layout/inspector/inDeepTreeWalker.h => layout/inspector/src/inDeepTreeWalker.h
rename : layout/inspector/inFlasher.cpp => layout/inspector/src/inFlasher.cpp
rename : layout/inspector/inFlasher.h => layout/inspector/src/inFlasher.h
rename : layout/inspector/inLayoutUtils.cpp => layout/inspector/src/inLayoutUtils.cpp
rename : layout/inspector/inLayoutUtils.h => layout/inspector/src/inLayoutUtils.h
rename : layout/inspector/inSearchLoop.cpp => layout/inspector/src/inSearchLoop.cpp
rename : layout/inspector/inSearchLoop.h => layout/inspector/src/inSearchLoop.h
rename : layout/inspector/moz.build => layout/inspector/src/moz.build
rename : layout/inspector/nsFontFace.cpp => layout/inspector/src/nsFontFace.cpp
rename : layout/inspector/nsFontFace.h => layout/inspector/src/nsFontFace.h
rename : layout/inspector/nsFontFaceList.cpp => layout/inspector/src/nsFontFaceList.cpp
rename : layout/inspector/nsFontFaceList.h => layout/inspector/src/nsFontFaceList.h
2013-12-04 09:24:09 +01:00

101 lines
2.4 KiB
C++

/* -*- 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/dom/Element.h"
///////////////////////////////////////////////////////////////////////////////
nsIDOMWindow*
inLayoutUtils::GetWindowFor(nsIDOMNode* aNode)
{
nsCOMPtr<nsIDOMDocument> doc1;
aNode->GetOwnerDocument(getter_AddRefs(doc1));
return GetWindowFor(doc1.get());
}
nsIDOMWindow*
inLayoutUtils::GetWindowFor(nsIDOMDocument* aDoc)
{
nsCOMPtr<nsIDOMWindow> window;
aDoc->GetDefaultView(getter_AddRefs(window));
return window;
}
nsIPresShell*
inLayoutUtils::GetPresShellFor(nsISupports* aThing)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aThing);
return window->GetDocShell()->GetPresShell();
}
/*static*/
nsIFrame*
inLayoutUtils::GetFrameFor(nsIDOMElement* aElement)
{
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
return content->GetPrimaryFrame();
}
nsEventStateManager*
inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
{
NS_PRECONDITION(aElement, "Passing in a null element is bad");
nsCOMPtr<nsIDOMDocument> domDoc;
aElement->GetOwnerDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> 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<nsIContent> content = do_QueryInterface(aNode);
if (content) {
nsCOMPtr<nsIDocument> doc = content->GetDocument();
if (doc) {
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content)));
return domdoc;
}
}
return nullptr;
}
nsIDOMNode*
inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
{
nsPIDOMWindow* pwin = aDoc.GetWindow();
if (!pwin) {
return nullptr;
}
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
return node;
}