Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "inLayoutUtils.h"
7 :
8 : #include "nsIDocument.h"
9 : #include "nsIDOMDocument.h"
10 : #include "nsIContent.h"
11 : #include "nsIContentViewer.h"
12 : #include "nsPIDOMWindow.h"
13 : #include "nsIDocShell.h"
14 : #include "nsIPresShell.h"
15 : #include "nsPresContext.h"
16 : #include "mozilla/EventStateManager.h"
17 : #include "mozilla/dom/Element.h"
18 :
19 : using namespace mozilla;
20 :
21 : ///////////////////////////////////////////////////////////////////////////////
22 :
23 : EventStateManager*
24 0 : inLayoutUtils::GetEventStateManagerFor(nsIDOMElement *aElement)
25 : {
26 0 : NS_PRECONDITION(aElement, "Passing in a null element is bad");
27 :
28 0 : nsCOMPtr<nsIDOMDocument> domDoc;
29 0 : aElement->GetOwnerDocument(getter_AddRefs(domDoc));
30 0 : nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
31 :
32 0 : if (!doc) {
33 0 : NS_WARNING("Could not get an nsIDocument!");
34 0 : return nullptr;
35 : }
36 :
37 0 : nsIPresShell *shell = doc->GetShell();
38 0 : if (!shell)
39 0 : return nullptr;
40 :
41 0 : return shell->GetPresContext()->EventStateManager();
42 : }
43 :
44 : nsIDOMDocument*
45 0 : inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
46 : {
47 0 : nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
48 0 : if (content) {
49 0 : nsCOMPtr<nsIDocument> doc = content->GetComposedDoc();
50 0 : if (doc) {
51 0 : nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(doc->GetSubDocumentFor(content)));
52 :
53 0 : return domdoc;
54 : }
55 : }
56 :
57 0 : return nullptr;
58 : }
59 :
60 : nsIDOMNode*
61 0 : inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
62 : {
63 0 : nsPIDOMWindowOuter* pwin = aDoc.GetWindow();
64 0 : if (!pwin) {
65 0 : return nullptr;
66 : }
67 :
68 0 : nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
69 0 : return node;
70 : }
71 :
|