1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/inspector/inLayoutUtils.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "inLayoutUtils.h" 1.10 + 1.11 +#include "nsIDocument.h" 1.12 +#include "nsIDOMDocument.h" 1.13 +#include "nsIContent.h" 1.14 +#include "nsIContentViewer.h" 1.15 +#include "nsPIDOMWindow.h" 1.16 +#include "nsIDocShell.h" 1.17 +#include "nsIPresShell.h" 1.18 +#include "nsPresContext.h" 1.19 +#include "mozilla/EventStateManager.h" 1.20 +#include "mozilla/dom/Element.h" 1.21 + 1.22 +using namespace mozilla; 1.23 + 1.24 +/////////////////////////////////////////////////////////////////////////////// 1.25 + 1.26 +nsIDOMWindow* 1.27 +inLayoutUtils::GetWindowFor(nsIDOMNode* aNode) 1.28 +{ 1.29 + nsCOMPtr<nsIDOMDocument> doc1; 1.30 + aNode->GetOwnerDocument(getter_AddRefs(doc1)); 1.31 + return GetWindowFor(doc1.get()); 1.32 +} 1.33 + 1.34 +nsIDOMWindow* 1.35 +inLayoutUtils::GetWindowFor(nsIDOMDocument* aDoc) 1.36 +{ 1.37 + nsCOMPtr<nsIDOMWindow> window; 1.38 + aDoc->GetDefaultView(getter_AddRefs(window)); 1.39 + return window; 1.40 +} 1.41 + 1.42 +nsIPresShell* 1.43 +inLayoutUtils::GetPresShellFor(nsISupports* aThing) 1.44 +{ 1.45 + nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aThing); 1.46 + 1.47 + return window->GetDocShell()->GetPresShell(); 1.48 +} 1.49 + 1.50 +/*static*/ 1.51 +nsIFrame* 1.52 +inLayoutUtils::GetFrameFor(nsIDOMElement* aElement) 1.53 +{ 1.54 + nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); 1.55 + return content->GetPrimaryFrame(); 1.56 +} 1.57 + 1.58 +EventStateManager* 1.59 +inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) 1.60 +{ 1.61 + NS_PRECONDITION(aElement, "Passing in a null element is bad"); 1.62 + 1.63 + nsCOMPtr<nsIDOMDocument> domDoc; 1.64 + aElement->GetOwnerDocument(getter_AddRefs(domDoc)); 1.65 + nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); 1.66 + 1.67 + if (!doc) { 1.68 + NS_WARNING("Could not get an nsIDocument!"); 1.69 + return nullptr; 1.70 + } 1.71 + 1.72 + nsIPresShell *shell = doc->GetShell(); 1.73 + if (!shell) 1.74 + return nullptr; 1.75 + 1.76 + return shell->GetPresContext()->EventStateManager(); 1.77 +} 1.78 + 1.79 +nsIDOMDocument* 1.80 +inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode) 1.81 +{ 1.82 + nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); 1.83 + if (content) { 1.84 + nsCOMPtr<nsIDocument> doc = content->GetDocument(); 1.85 + if (doc) { 1.86 + nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content))); 1.87 + 1.88 + return domdoc; 1.89 + } 1.90 + } 1.91 + 1.92 + return nullptr; 1.93 +} 1.94 + 1.95 +nsIDOMNode* 1.96 +inLayoutUtils::GetContainerFor(const nsIDocument& aDoc) 1.97 +{ 1.98 + nsPIDOMWindow* pwin = aDoc.GetWindow(); 1.99 + if (!pwin) { 1.100 + return nullptr; 1.101 + } 1.102 + 1.103 + nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal()); 1.104 + return node; 1.105 +} 1.106 +