|
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 "nsCOMPtr.h" |
|
7 #include "nsIContainerBoxObject.h" |
|
8 #include "nsIBrowserBoxObject.h" |
|
9 #include "nsIEditorBoxObject.h" |
|
10 #include "nsIIFrameBoxObject.h" |
|
11 #include "nsBoxObject.h" |
|
12 #include "nsIDocShell.h" |
|
13 #include "nsIContent.h" |
|
14 #include "nsIDocument.h" |
|
15 #include "nsIFrame.h" |
|
16 #include "nsSubDocumentFrame.h" |
|
17 |
|
18 /** |
|
19 * nsContainerBoxObject implements deprecated nsIBrowserBoxObject, |
|
20 * nsIEditorBoxObject and nsIIFrameBoxObject interfaces only because of the |
|
21 * backward compatibility. |
|
22 */ |
|
23 |
|
24 class nsContainerBoxObject : public nsBoxObject, |
|
25 public nsIBrowserBoxObject, |
|
26 public nsIEditorBoxObject, |
|
27 public nsIIFrameBoxObject |
|
28 { |
|
29 public: |
|
30 NS_DECL_ISUPPORTS_INHERITED |
|
31 NS_DECL_NSICONTAINERBOXOBJECT |
|
32 NS_DECL_NSIBROWSERBOXOBJECT |
|
33 NS_DECL_NSIEDITORBOXOBJECT |
|
34 NS_DECL_NSIIFRAMEBOXOBJECT |
|
35 }; |
|
36 |
|
37 NS_INTERFACE_MAP_BEGIN(nsContainerBoxObject) |
|
38 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIContainerBoxObject, nsIBrowserBoxObject) |
|
39 NS_INTERFACE_MAP_ENTRY(nsIBrowserBoxObject) |
|
40 NS_INTERFACE_MAP_ENTRY(nsIEditorBoxObject) |
|
41 NS_INTERFACE_MAP_ENTRY(nsIIFrameBoxObject) |
|
42 NS_INTERFACE_MAP_END_INHERITING(nsBoxObject) |
|
43 |
|
44 NS_IMPL_ADDREF_INHERITED(nsContainerBoxObject, nsBoxObject) |
|
45 NS_IMPL_RELEASE_INHERITED(nsContainerBoxObject, nsBoxObject) |
|
46 |
|
47 NS_IMETHODIMP nsContainerBoxObject::GetDocShell(nsIDocShell** aResult) |
|
48 { |
|
49 *aResult = nullptr; |
|
50 |
|
51 nsSubDocumentFrame *subDocFrame = do_QueryFrame(GetFrame(false)); |
|
52 if (subDocFrame) { |
|
53 // Ok, the frame for mContent is an nsSubDocumentFrame, it knows how |
|
54 // to reach the docshell, so ask it... |
|
55 |
|
56 return subDocFrame->GetDocShell(aResult); |
|
57 } |
|
58 |
|
59 if (!mContent) { |
|
60 return NS_OK; |
|
61 } |
|
62 |
|
63 // No nsSubDocumentFrame available for mContent, try if there's a mapping |
|
64 // between mContent's document to mContent's subdocument. |
|
65 |
|
66 // XXXbz sXBL/XBL2 issue -- ownerDocument or currentDocument? |
|
67 nsIDocument *doc = mContent->GetDocument(); |
|
68 |
|
69 if (!doc) { |
|
70 return NS_OK; |
|
71 } |
|
72 |
|
73 nsIDocument *sub_doc = doc->GetSubDocumentFor(mContent); |
|
74 |
|
75 if (!sub_doc) { |
|
76 return NS_OK; |
|
77 } |
|
78 |
|
79 NS_IF_ADDREF(*aResult = sub_doc->GetDocShell()); |
|
80 return NS_OK; |
|
81 } |
|
82 |
|
83 nsresult |
|
84 NS_NewContainerBoxObject(nsIBoxObject** aResult) |
|
85 { |
|
86 *aResult = new nsContainerBoxObject(); |
|
87 if (!*aResult) |
|
88 return NS_ERROR_OUT_OF_MEMORY; |
|
89 NS_ADDREF(*aResult); |
|
90 return NS_OK; |
|
91 } |
|
92 |