Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / layout / xul / nsDocElementBoxFrame.cpp
blob9d6de5de08ee82690a10857801fadcb9ee501478
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"
25 //#define DEBUG_REFLOW
27 using namespace mozilla::dom;
29 class nsDocElementBoxFrame : public nsBoxFrame,
30 public nsIAnonymousContentCreator
32 public:
33 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
35 friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell,
36 nsStyleContext* aContext);
38 explicit nsDocElementBoxFrame(nsStyleContext* aContext)
39 :nsBoxFrame(aContext, true) {}
41 NS_DECL_QUERYFRAME
42 NS_DECL_FRAMEARENA_HELPERS
44 // nsIAnonymousContentCreator
45 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
46 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
47 uint32_t aFilter) MOZ_OVERRIDE;
49 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
51 // Override nsBoxFrame.
52 if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
53 return false;
54 return nsBoxFrame::IsFrameOfType(aFlags);
57 #ifdef DEBUG_FRAME_DUMP
58 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
59 #endif
60 private:
61 nsCOMPtr<Element> mPopupgroupContent;
62 nsCOMPtr<Element> mTooltipContent;
65 //----------------------------------------------------------------------
67 nsContainerFrame*
68 NS_NewDocElementBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
70 return new (aPresShell) nsDocElementBoxFrame(aContext);
73 NS_IMPL_FRAMEARENA_HELPERS(nsDocElementBoxFrame)
75 void
76 nsDocElementBoxFrame::DestroyFrom(nsIFrame* aDestructRoot)
78 nsContentUtils::DestroyAnonymousContent(&mPopupgroupContent);
79 nsContentUtils::DestroyAnonymousContent(&mTooltipContent);
80 nsBoxFrame::DestroyFrom(aDestructRoot);
83 nsresult
84 nsDocElementBoxFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
86 nsIDocument* doc = mContent->GetComposedDoc();
87 if (!doc) {
88 // The page is currently being torn down. Why bother.
89 return NS_ERROR_FAILURE;
91 nsNodeInfoManager *nodeInfoManager = doc->NodeInfoManager();
93 // create the top-secret popupgroup node. shhhhh!
94 nsRefPtr<NodeInfo> nodeInfo;
95 nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::popupgroup,
96 nullptr, kNameSpaceID_XUL,
97 nsIDOMNode::ELEMENT_NODE);
98 NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
100 nsresult rv = NS_NewXULElement(getter_AddRefs(mPopupgroupContent),
101 nodeInfo.forget());
102 NS_ENSURE_SUCCESS(rv, rv);
104 if (!aElements.AppendElement(mPopupgroupContent))
105 return NS_ERROR_OUT_OF_MEMORY;
107 // create the top-secret default tooltip node. shhhhh!
108 nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::tooltip, nullptr,
109 kNameSpaceID_XUL,
110 nsIDOMNode::ELEMENT_NODE);
111 NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
113 rv = NS_NewXULElement(getter_AddRefs(mTooltipContent), nodeInfo.forget());
114 NS_ENSURE_SUCCESS(rv, rv);
116 mTooltipContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_default,
117 NS_LITERAL_STRING("true"), false);
119 if (!aElements.AppendElement(mTooltipContent))
120 return NS_ERROR_OUT_OF_MEMORY;
122 return NS_OK;
125 void
126 nsDocElementBoxFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
127 uint32_t aFilter)
129 if (mPopupgroupContent) {
130 aElements.AppendElement(mPopupgroupContent);
133 if (mTooltipContent) {
134 aElements.AppendElement(mTooltipContent);
138 NS_QUERYFRAME_HEAD(nsDocElementBoxFrame)
139 NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
140 NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
142 #ifdef DEBUG_FRAME_DUMP
143 nsresult
144 nsDocElementBoxFrame::GetFrameName(nsAString& aResult) const
146 return MakeFrameName(NS_LITERAL_STRING("DocElementBox"), aResult);
148 #endif