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