/src/mozilla-central/layout/xul/nsDocElementBoxFrame.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "nsHTMLParts.h" |
7 | | #include "nsContainerFrame.h" |
8 | | #include "nsCSSRendering.h" |
9 | | #include "nsIDocument.h" |
10 | | #include "nsPageFrame.h" |
11 | | #include "nsStyleConsts.h" |
12 | | #include "nsGkAtoms.h" |
13 | | #include "nsIPresShell.h" |
14 | | #include "nsBoxFrame.h" |
15 | | #include "nsStackLayout.h" |
16 | | #include "nsIAnonymousContentCreator.h" |
17 | | #include "mozilla/dom/NodeInfo.h" |
18 | | #include "nsIServiceManager.h" |
19 | | #include "nsNodeInfoManager.h" |
20 | | #include "nsContentCreatorFunctions.h" |
21 | | #include "mozilla/dom/Element.h" |
22 | | #include "mozilla/dom/FromParser.h" |
23 | | |
24 | | //#define DEBUG_REFLOW |
25 | | |
26 | | using namespace mozilla::dom; |
27 | | |
28 | | class nsDocElementBoxFrame final : public nsBoxFrame |
29 | | , public nsIAnonymousContentCreator |
30 | | { |
31 | | public: |
32 | | virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override; |
33 | | |
34 | | friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, |
35 | | ComputedStyle* aStyle); |
36 | | |
37 | | explicit nsDocElementBoxFrame(ComputedStyle* aStyle) |
38 | 0 | :nsBoxFrame(aStyle, kClassID, true) {} |
39 | | |
40 | | NS_DECL_QUERYFRAME |
41 | | NS_DECL_FRAMEARENA_HELPERS(nsDocElementBoxFrame) |
42 | | |
43 | | // nsIAnonymousContentCreator |
44 | | virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override; |
45 | | virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, |
46 | | uint32_t aFilter) override; |
47 | | |
48 | | virtual bool IsFrameOfType(uint32_t aFlags) const override |
49 | 0 | { |
50 | 0 | // Override nsBoxFrame. |
51 | 0 | if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced)) |
52 | 0 | return false; |
53 | 0 | return nsBoxFrame::IsFrameOfType(aFlags); |
54 | 0 | } |
55 | | |
56 | | #ifdef DEBUG_FRAME_DUMP |
57 | | virtual nsresult GetFrameName(nsAString& aResult) const override; |
58 | | #endif |
59 | | private: |
60 | | nsCOMPtr<Element> mPopupgroupContent; |
61 | | nsCOMPtr<Element> mTooltipContent; |
62 | | }; |
63 | | |
64 | | //---------------------------------------------------------------------- |
65 | | |
66 | | nsContainerFrame* |
67 | | NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
68 | 0 | { |
69 | 0 | return new (aPresShell) nsDocElementBoxFrame(aStyle); |
70 | 0 | } |
71 | | |
72 | | NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame) |
73 | | |
74 | | void |
75 | | nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) |
76 | 0 | { |
77 | 0 | aPostDestroyData.AddAnonymousContent(mPopupgroupContent.forget()); |
78 | 0 | aPostDestroyData.AddAnonymousContent(mTooltipContent.forget()); |
79 | 0 | nsBoxFrame::DestroyFrom(aDestructRoot, aPostDestroyData); |
80 | 0 | } |
81 | | |
82 | | nsresult |
83 | | nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements) |
84 | 0 | { |
85 | 0 | nsIDocument* doc = mContent->GetComposedDoc(); |
86 | 0 | if (!doc) { |
87 | 0 | // The page is currently being torn down. Why bother. |
88 | 0 | return NS_ERROR_FAILURE; |
89 | 0 | } |
90 | 0 | nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager(); |
91 | 0 |
|
92 | 0 | // create the top-secret popupgroup node. shhhhh! |
93 | 0 | RefPtr<NodeInfo> nodeInfo; |
94 | 0 | nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup, |
95 | 0 | nullptr, kNameSpaceID_XUL, |
96 | 0 | nsINode::ELEMENT_NODE); |
97 | 0 | NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); |
98 | 0 |
|
99 | 0 | nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent), |
100 | 0 | nodeInfo.forget(), dom::NOT_FROM_PARSER); |
101 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
102 | 0 |
|
103 | 0 | if (!aElements.AppendElement(mPopupgroupContent)) |
104 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
105 | 0 | |
106 | 0 | // create the top-secret default tooltip node. shhhhh! |
107 | 0 | nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr, |
108 | 0 | kNameSpaceID_XUL, |
109 | 0 | nsINode::ELEMENT_NODE); |
110 | 0 | NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); |
111 | 0 |
|
112 | 0 | rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget(), |
113 | 0 | dom::NOT_FROM_PARSER); |
114 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
115 | 0 |
|
116 | 0 | mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default, |
117 | 0 | NS_LITERAL_STRING("true"), false); |
118 | 0 |
|
119 | 0 | if (!aElements.AppendElement(mTooltipContent)) |
120 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
121 | 0 | |
122 | 0 | return NS_OK; |
123 | 0 | } |
124 | | |
125 | | void |
126 | | nsDocElementBoxFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, |
127 | | uint32_t aFilter) |
128 | 0 | { |
129 | 0 | if (mPopupgroupContent) { |
130 | 0 | aElements.AppendElement(mPopupgroupContent); |
131 | 0 | } |
132 | 0 |
|
133 | 0 | if (mTooltipContent) { |
134 | 0 | aElements.AppendElement(mTooltipContent); |
135 | 0 | } |
136 | 0 | } |
137 | | |
138 | 0 | NS_QUERYFRAME_HEAD(nsDocElementBoxFrame) |
139 | 0 | NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator) |
140 | 0 | NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame) |
141 | | |
142 | | #ifdef DEBUG_FRAME_DUMP |
143 | | nsresult |
144 | | nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const |
145 | | { |
146 | | return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult); |
147 | | } |
148 | | #endif |