forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nsRootBoxFrame.cpp
308 lines (256 loc) · 8.47 KB
/
nsRootBoxFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHTMLParts.h"
#include "nsGUIEvent.h"
#include "nsStyleConsts.h"
#include "nsGkAtoms.h"
#include "nsIPresShell.h"
#include "nsBoxFrame.h"
#include "nsStackLayout.h"
#include "nsIRootBox.h"
#include "nsIContent.h"
#include "nsXULTooltipListener.h"
#include "nsFrameManager.h"
// Interface IDs
//#define DEBUG_REFLOW
// static
nsIRootBox*
nsIRootBox::GetRootBox(nsIPresShell* aShell)
{
if (!aShell) {
return nullptr;
}
nsIFrame* rootFrame = aShell->FrameManager()->GetRootFrame();
if (!rootFrame) {
return nullptr;
}
if (rootFrame) {
rootFrame = rootFrame->GetFirstPrincipalChild();
}
nsIRootBox* rootBox = do_QueryFrame(rootFrame);
return rootBox;
}
class nsRootBoxFrame : public nsBoxFrame, public nsIRootBox {
public:
friend nsIFrame* NS_NewBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext *aContext);
NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS
virtual nsPopupSetFrame* GetPopupSetFrame();
virtual void SetPopupSetFrame(nsPopupSetFrame* aPopupSet);
virtual nsIContent* GetDefaultTooltip();
virtual void SetDefaultTooltip(nsIContent* aTooltip);
virtual nsresult AddTooltipSupport(nsIContent* aNode);
virtual nsresult RemoveTooltipSupport(nsIContent* aNode);
NS_IMETHOD AppendFrames(ChildListID aListID,
nsFrameList& aFrameList);
NS_IMETHOD InsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList);
NS_IMETHOD RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame);
NS_IMETHOD Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
NS_IMETHOD HandleEvent(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus);
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
/**
* Get the "type" of the frame
*
* @see nsGkAtoms::rootFrame
*/
virtual nsIAtom* GetType() const;
virtual bool IsFrameOfType(uint32_t aFlags) const
{
// Override bogus IsFrameOfType in nsBoxFrame.
if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
return false;
return nsBoxFrame::IsFrameOfType(aFlags);
}
#ifdef DEBUG
NS_IMETHOD GetFrameName(nsAString& aResult) const;
#endif
nsPopupSetFrame* mPopupSetFrame;
protected:
nsIContent* mDefaultTooltip;
};
//----------------------------------------------------------------------
nsIFrame*
NS_NewRootBoxFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) nsRootBoxFrame (aPresShell, aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsRootBoxFrame)
nsRootBoxFrame::nsRootBoxFrame(nsIPresShell* aShell, nsStyleContext* aContext):
nsBoxFrame(aShell, aContext, true)
{
mPopupSetFrame = nullptr;
nsCOMPtr<nsBoxLayout> layout;
NS_NewStackLayout(aShell, layout);
SetLayoutManager(layout);
}
NS_IMETHODIMP
nsRootBoxFrame::AppendFrames(ChildListID aListID,
nsFrameList& aFrameList)
{
nsresult rv;
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
NS_PRECONDITION(mFrames.IsEmpty(), "already have a child frame");
if (aListID != kPrincipalList) {
// We only support the principal child list.
rv = NS_ERROR_INVALID_ARG;
} else if (!mFrames.IsEmpty()) {
// We only allow a single child frame.
rv = NS_ERROR_FAILURE;
} else {
rv = nsBoxFrame::AppendFrames(aListID, aFrameList);
}
return rv;
}
NS_IMETHODIMP
nsRootBoxFrame::InsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList)
{
nsresult rv;
// Because we only support a single child frame inserting is the same
// as appending.
NS_PRECONDITION(!aPrevFrame, "unexpected previous sibling frame");
if (aPrevFrame) {
rv = NS_ERROR_UNEXPECTED;
} else {
rv = AppendFrames(aListID, aFrameList);
}
return rv;
}
NS_IMETHODIMP
nsRootBoxFrame::RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame)
{
nsresult rv;
NS_ASSERTION(aListID == kPrincipalList, "unexpected child list ID");
if (aListID != kPrincipalList) {
// We only support the principal child list.
rv = NS_ERROR_INVALID_ARG;
} else if (aOldFrame == mFrames.FirstChild()) {
rv = nsBoxFrame::RemoveFrame(aListID, aOldFrame);
} else {
rv = NS_ERROR_FAILURE;
}
return rv;
}
#ifdef DEBUG_REFLOW
int32_t gReflows = 0;
#endif
NS_IMETHODIMP
nsRootBoxFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
DO_GLOBAL_REFLOW_COUNT("nsRootBoxFrame");
#ifdef DEBUG_REFLOW
gReflows++;
printf("----Reflow %d----\n", gReflows);
#endif
return nsBoxFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
}
void
nsRootBoxFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists)
{
// root boxes don't need a debug border/outline or a selection overlay...
// They *may* have a background propagated to them, so force creation
// of a background display list element.
DisplayBorderBackgroundOutline(aBuilder, aLists, true);
BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
}
NS_IMETHODIMP
nsRootBoxFrame::HandleEvent(nsPresContext* aPresContext,
nsGUIEvent* aEvent,
nsEventStatus* aEventStatus)
{
NS_ENSURE_ARG_POINTER(aEventStatus);
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
return NS_OK;
}
if (aEvent->message == NS_MOUSE_BUTTON_UP) {
nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
}
return NS_OK;
}
// REVIEW: The override here was doing nothing since nsBoxFrame is our
// parent class
nsIAtom*
nsRootBoxFrame::GetType() const
{
return nsGkAtoms::rootFrame;
}
nsPopupSetFrame*
nsRootBoxFrame::GetPopupSetFrame()
{
return mPopupSetFrame;
}
void
nsRootBoxFrame::SetPopupSetFrame(nsPopupSetFrame* aPopupSet)
{
// Under normal conditions this should only be called once. However,
// if something triggers ReconstructDocElementHierarchy, we will
// destroy this frame's child (the nsDocElementBoxFrame), but not this
// frame. This will cause the popupset to remove itself by calling
// |SetPopupSetFrame(nullptr)|, and then we'll be able to accept a new
// popupset. Since the anonymous content is associated with the
// nsDocElementBoxFrame, we'll get a new popupset when the new doc
// element box frame is created.
if (!mPopupSetFrame || !aPopupSet) {
mPopupSetFrame = aPopupSet;
} else {
NS_NOTREACHED("Popup set is already defined! Only 1 allowed.");
}
}
nsIContent*
nsRootBoxFrame::GetDefaultTooltip()
{
return mDefaultTooltip;
}
void
nsRootBoxFrame::SetDefaultTooltip(nsIContent* aTooltip)
{
mDefaultTooltip = aTooltip;
}
nsresult
nsRootBoxFrame::AddTooltipSupport(nsIContent* aNode)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
nsXULTooltipListener *listener = nsXULTooltipListener::GetInstance();
if (!listener)
return NS_ERROR_OUT_OF_MEMORY;
return listener->AddTooltipSupport(aNode);
}
nsresult
nsRootBoxFrame::RemoveTooltipSupport(nsIContent* aNode)
{
// XXjh yuck, I'll have to implement a way to get at
// the tooltip listener for a given node to make
// this work. Not crucial, we aren't removing
// tooltips from any nodes in the app just yet.
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_QUERYFRAME_HEAD(nsRootBoxFrame)
NS_QUERYFRAME_ENTRY(nsIRootBox)
NS_QUERYFRAME_TAIL_INHERITING(nsBoxFrame)
#ifdef DEBUG
NS_IMETHODIMP
nsRootBoxFrame::GetFrameName(nsAString& aResult) const
{
return MakeFrameName(NS_LITERAL_STRING("RootBox"), aResult);
}
#endif