Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "inLayoutUtils.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIDocument.h" |
michael@0 | 9 | #include "nsIDOMDocument.h" |
michael@0 | 10 | #include "nsIContent.h" |
michael@0 | 11 | #include "nsIContentViewer.h" |
michael@0 | 12 | #include "nsPIDOMWindow.h" |
michael@0 | 13 | #include "nsIDocShell.h" |
michael@0 | 14 | #include "nsIPresShell.h" |
michael@0 | 15 | #include "nsPresContext.h" |
michael@0 | 16 | #include "mozilla/EventStateManager.h" |
michael@0 | 17 | #include "mozilla/dom/Element.h" |
michael@0 | 18 | |
michael@0 | 19 | using namespace mozilla; |
michael@0 | 20 | |
michael@0 | 21 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 22 | |
michael@0 | 23 | nsIDOMWindow* |
michael@0 | 24 | inLayoutUtils::GetWindowFor(nsIDOMNode* aNode) |
michael@0 | 25 | { |
michael@0 | 26 | nsCOMPtr<nsIDOMDocument> doc1; |
michael@0 | 27 | aNode->GetOwnerDocument(getter_AddRefs(doc1)); |
michael@0 | 28 | return GetWindowFor(doc1.get()); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | nsIDOMWindow* |
michael@0 | 32 | inLayoutUtils::GetWindowFor(nsIDOMDocument* aDoc) |
michael@0 | 33 | { |
michael@0 | 34 | nsCOMPtr<nsIDOMWindow> window; |
michael@0 | 35 | aDoc->GetDefaultView(getter_AddRefs(window)); |
michael@0 | 36 | return window; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | nsIPresShell* |
michael@0 | 40 | inLayoutUtils::GetPresShellFor(nsISupports* aThing) |
michael@0 | 41 | { |
michael@0 | 42 | nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aThing); |
michael@0 | 43 | |
michael@0 | 44 | return window->GetDocShell()->GetPresShell(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | /*static*/ |
michael@0 | 48 | nsIFrame* |
michael@0 | 49 | inLayoutUtils::GetFrameFor(nsIDOMElement* aElement) |
michael@0 | 50 | { |
michael@0 | 51 | nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); |
michael@0 | 52 | return content->GetPrimaryFrame(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | EventStateManager* |
michael@0 | 56 | inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement) |
michael@0 | 57 | { |
michael@0 | 58 | NS_PRECONDITION(aElement, "Passing in a null element is bad"); |
michael@0 | 59 | |
michael@0 | 60 | nsCOMPtr<nsIDOMDocument> domDoc; |
michael@0 | 61 | aElement->GetOwnerDocument(getter_AddRefs(domDoc)); |
michael@0 | 62 | nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc); |
michael@0 | 63 | |
michael@0 | 64 | if (!doc) { |
michael@0 | 65 | NS_WARNING("Could not get an nsIDocument!"); |
michael@0 | 66 | return nullptr; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | nsIPresShell *shell = doc->GetShell(); |
michael@0 | 70 | if (!shell) |
michael@0 | 71 | return nullptr; |
michael@0 | 72 | |
michael@0 | 73 | return shell->GetPresContext()->EventStateManager(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | nsIDOMDocument* |
michael@0 | 77 | inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode) |
michael@0 | 78 | { |
michael@0 | 79 | nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); |
michael@0 | 80 | if (content) { |
michael@0 | 81 | nsCOMPtr<nsIDocument> doc = content->GetDocument(); |
michael@0 | 82 | if (doc) { |
michael@0 | 83 | nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content))); |
michael@0 | 84 | |
michael@0 | 85 | return domdoc; |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | return nullptr; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | nsIDOMNode* |
michael@0 | 93 | inLayoutUtils::GetContainerFor(const nsIDocument& aDoc) |
michael@0 | 94 | { |
michael@0 | 95 | nsPIDOMWindow* pwin = aDoc.GetWindow(); |
michael@0 | 96 | if (!pwin) { |
michael@0 | 97 | return nullptr; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal()); |
michael@0 | 101 | return node; |
michael@0 | 102 | } |
michael@0 | 103 |