1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "inLayoutUtils.h"
8 
9 #include "nsIDocument.h"
10 #include "nsIDOMDocument.h"
11 #include "nsIContent.h"
12 #include "nsIContentViewer.h"
13 #include "nsPIDOMWindow.h"
14 #include "nsIDocShell.h"
15 #include "nsIPresShell.h"
16 #include "nsPresContext.h"
17 #include "mozilla/EventStateManager.h"
18 #include "mozilla/dom/Element.h"
19 
20 using namespace mozilla;
21 
22 ///////////////////////////////////////////////////////////////////////////////
23 
GetEventStateManagerFor(Element & aElement)24 EventStateManager* inLayoutUtils::GetEventStateManagerFor(Element& aElement) {
25   nsIDocument* doc = aElement.OwnerDoc();
26   nsPresContext* presContext = doc->GetPresContext();
27   if (!presContext) return nullptr;
28 
29   return presContext->EventStateManager();
30 }
31 
GetSubDocumentFor(nsIDOMNode * aNode)32 nsIDOMDocument* inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode) {
33   nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
34   if (content) {
35     nsCOMPtr<nsIDocument> doc = content->GetComposedDoc();
36     if (doc) {
37       nsCOMPtr<nsIDOMDocument> domdoc(
38           do_QueryInterface(doc->GetSubDocumentFor(content)));
39 
40       return domdoc;
41     }
42   }
43 
44   return nullptr;
45 }
46 
GetContainerFor(const nsIDocument & aDoc)47 nsINode* inLayoutUtils::GetContainerFor(const nsIDocument& aDoc) {
48   nsPIDOMWindowOuter* pwin = aDoc.GetWindow();
49   if (!pwin) {
50     return nullptr;
51   }
52 
53   return pwin->GetFrameElementInternal();
54 }
55