Source code

Revision control

Other Tools

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
7
/* base class #1 for rendering objects that have child lists */
8
9
#include "nsContainerFrame.h"
10
11
#include "mozilla/ComputedStyle.h"
12
#include "mozilla/PresShell.h"
13
#include "mozilla/dom/HTMLSummaryElement.h"
14
#include "nsAbsoluteContainingBlock.h"
15
#include "nsAttrValue.h"
16
#include "nsAttrValueInlines.h"
17
#include "nsFlexContainerFrame.h"
18
#include "mozilla/dom/Document.h"
19
#include "nsPresContext.h"
20
#include "nsRect.h"
21
#include "nsPoint.h"
22
#include "nsStyleConsts.h"
23
#include "nsView.h"
24
#include "nsCOMPtr.h"
25
#include "nsGkAtoms.h"
26
#include "nsViewManager.h"
27
#include "nsIWidget.h"
28
#include "nsCSSRendering.h"
29
#include "nsError.h"
30
#include "nsDisplayList.h"
31
#include "nsIBaseWindow.h"
32
#include "nsBoxLayoutState.h"
33
#include "nsCSSFrameConstructor.h"
34
#include "nsBlockFrame.h"
35
#include "nsBulletFrame.h"
36
#include "nsPlaceholderFrame.h"
37
#include "mozilla/AutoRestore.h"
38
#include "nsIFrameInlines.h"
39
#include "nsPrintfCString.h"
40
#include <algorithm>
41
42
using namespace mozilla;
43
using namespace mozilla::dom;
44
using namespace mozilla::layout;
45
46
nsContainerFrame::~nsContainerFrame() {}
47
48
NS_QUERYFRAME_HEAD(nsContainerFrame)
49
NS_QUERYFRAME_ENTRY(nsContainerFrame)
50
NS_QUERYFRAME_TAIL_INHERITING(nsSplittableFrame)
51
52
void nsContainerFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
53
nsIFrame* aPrevInFlow) {
54
nsSplittableFrame::Init(aContent, aParent, aPrevInFlow);
55
if (aPrevInFlow) {
56
// Make sure we copy bits from our prev-in-flow that will affect
57
// us. A continuation for a container frame needs to know if it
58
// has a child with a view so that we'll properly reposition it.
59
if (aPrevInFlow->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)
60
AddStateBits(NS_FRAME_HAS_CHILD_WITH_VIEW);
61
}
62
}
63
64
void nsContainerFrame::SetInitialChildList(ChildListID aListID,
65
nsFrameList& aChildList) {
66
#ifdef DEBUG
67
nsFrame::VerifyDirtyBitSet(aChildList);
68
for (nsIFrame* f : aChildList) {
69
MOZ_ASSERT(f->GetParent() == this, "Unexpected parent");
70
}
71
#endif
72
if (aListID == kPrincipalList) {
73
MOZ_ASSERT(mFrames.IsEmpty(),
74
"unexpected second call to SetInitialChildList");
75
mFrames.SetFrames(aChildList);
76
} else if (aListID == kBackdropList) {
77
MOZ_ASSERT(StyleDisplay()->mTopLayer != NS_STYLE_TOP_LAYER_NONE,
78
"Only top layer frames should have backdrop");
79
MOZ_ASSERT(GetStateBits() & NS_FRAME_OUT_OF_FLOW,
80
"Top layer frames should be out-of-flow");
81
MOZ_ASSERT(!GetProperty(BackdropProperty()),
82
"We shouldn't have setup backdrop frame list before");
83
#ifdef DEBUG
84
{
85
nsIFrame* placeholder = aChildList.FirstChild();
86
MOZ_ASSERT(aChildList.OnlyChild(), "Should have only one backdrop");
87
MOZ_ASSERT(placeholder->IsPlaceholderFrame(),
88
"The frame to be stored should be a placeholder");
89
MOZ_ASSERT(static_cast<nsPlaceholderFrame*>(placeholder)
90
->GetOutOfFlowFrame()
91
->IsBackdropFrame(),
92
"The placeholder should points to a backdrop frame");
93
}
94
#endif
95
nsFrameList* list = new (PresShell()) nsFrameList(aChildList);
96
SetProperty(BackdropProperty(), list);
97
} else {
98
MOZ_ASSERT_UNREACHABLE("Unexpected child list");
99
}
100
}
101
102
void nsContainerFrame::AppendFrames(ChildListID aListID,
103
nsFrameList& aFrameList) {
104
MOZ_ASSERT(aListID == kPrincipalList || aListID == kNoReflowPrincipalList,
105
"unexpected child list");
106
107
if (MOZ_UNLIKELY(aFrameList.IsEmpty())) {
108
return;
109
}
110
111
DrainSelfOverflowList(); // ensure the last frame is in mFrames
112
mFrames.AppendFrames(this, aFrameList);
113
114
if (aListID != kNoReflowPrincipalList) {
115
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange,
116
NS_FRAME_HAS_DIRTY_CHILDREN);
117
}
118
}
119
120
void nsContainerFrame::InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
121
const nsLineList::iterator* aPrevFrameLine,
122
nsFrameList& aFrameList) {
123
MOZ_ASSERT(aListID == kPrincipalList || aListID == kNoReflowPrincipalList,
124
"unexpected child list");
125
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this,
126
"inserting after sibling frame with different parent");
127
128
if (MOZ_UNLIKELY(aFrameList.IsEmpty())) {
129
return;
130
}
131
132
DrainSelfOverflowList(); // ensure aPrevFrame is in mFrames
133
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
134
135
if (aListID != kNoReflowPrincipalList) {
136
PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange,
137
NS_FRAME_HAS_DIRTY_CHILDREN);
138
}
139
}
140
141
void nsContainerFrame::RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) {
142
MOZ_ASSERT(aListID == kPrincipalList || aListID == kNoReflowPrincipalList,
143
"unexpected child list");
144
145
AutoTArray<nsIFrame*, 10> continuations;
146
{
147
nsIFrame* continuation = aOldFrame;
148
while (continuation) {
149
continuations.AppendElement(continuation);
150
continuation = continuation->GetNextContinuation();
151
}
152
}
153
154
mozilla::PresShell* presShell = PresShell();
155
nsContainerFrame* lastParent = nullptr;
156
157
// Loop and destroy aOldFrame and all of its continuations.
158
//
159
// Request a reflow on the parent frames involved unless we were explicitly
160
// told not to (kNoReflowPrincipalList).
161
const bool generateReflowCommand = (kNoReflowPrincipalList != aListID);
162
for (nsIFrame* continuation : Reversed(continuations)) {
163
nsContainerFrame* parent = continuation->GetParent();
164
165
// Please note that 'parent' may not actually be where 'continuation' lives.
166
// We really MUST use StealFrame() and nothing else here.
167
// @see nsInlineFrame::StealFrame for details.
168
parent->StealFrame(continuation);
169
continuation->Destroy();
170
if (generateReflowCommand && parent != lastParent) {
171
presShell->FrameNeedsReflow(parent, IntrinsicDirty::TreeChange,
172
NS_FRAME_HAS_DIRTY_CHILDREN);
173
lastParent = parent;
174
}
175
}
176
}
177
178
void nsContainerFrame::DestroyAbsoluteFrames(
179
nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) {
180
if (IsAbsoluteContainer()) {
181
GetAbsoluteContainingBlock()->DestroyFrames(this, aDestructRoot,
182
aPostDestroyData);
183
MarkAsNotAbsoluteContainingBlock();
184
}
185
}
186
187
void nsContainerFrame::SafelyDestroyFrameListProp(
188
nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData,
189
mozilla::PresShell* aPresShell, FrameListPropertyDescriptor aProp) {
190
// Note that the last frame can be removed through another route and thus
191
// delete the property -- that's why we fetch the property again before
192
// removing each frame rather than fetching it once and iterating the list.
193
while (nsFrameList* frameList = GetProperty(aProp)) {
194
nsIFrame* frame = frameList->RemoveFirstChild();
195
if (MOZ_LIKELY(frame)) {
196
frame->DestroyFrom(aDestructRoot, aPostDestroyData);
197
} else {
198
RemoveProperty(aProp);
199
frameList->Delete(aPresShell);
200
return;
201
}
202
}
203
}
204
205
void nsContainerFrame::DestroyFrom(nsIFrame* aDestructRoot,
206
PostDestroyData& aPostDestroyData) {
207
// Prevent event dispatch during destruction.
208
if (HasView()) {
209
GetView()->SetFrame(nullptr);
210
}
211
212
DestroyAbsoluteFrames(aDestructRoot, aPostDestroyData);
213
214
// Destroy frames on the principal child list.
215
mFrames.DestroyFramesFrom(aDestructRoot, aPostDestroyData);
216
217
// If we have any IB split siblings, clear their references to us.
218
if (HasAnyStateBits(NS_FRAME_PART_OF_IBSPLIT)) {
219
// Delete previous sibling's reference to me.
220
nsIFrame* prevSib = GetProperty(nsIFrame::IBSplitPrevSibling());
221
if (prevSib) {
222
NS_WARNING_ASSERTION(
223
this == prevSib->GetProperty(nsIFrame::IBSplitSibling()),
224
"IB sibling chain is inconsistent");
225
prevSib->DeleteProperty(nsIFrame::IBSplitSibling());
226
}
227
228
// Delete next sibling's reference to me.
229
nsIFrame* nextSib = GetProperty(nsIFrame::IBSplitSibling());
230
if (nextSib) {
231
NS_WARNING_ASSERTION(
232
this == nextSib->GetProperty(nsIFrame::IBSplitPrevSibling()),
233
"IB sibling chain is inconsistent");
234
nextSib->DeleteProperty(nsIFrame::IBSplitPrevSibling());
235
}
236
237
#ifdef DEBUG
238
// This is just so we can assert it's not set in nsFrame::DestroyFrom.
239
RemoveStateBits(NS_FRAME_PART_OF_IBSPLIT);
240
#endif
241
}
242
243
if (MOZ_UNLIKELY(!mProperties.IsEmpty())) {
244
using T = mozilla::FrameProperties::UntypedDescriptor;
245
bool hasO = false, hasOC = false, hasEOC = false, hasBackdrop = false;
246
mProperties.ForEach([&](const T& aProp, void*) {
247
if (aProp == OverflowProperty()) {
248
hasO = true;
249
} else if (aProp == OverflowContainersProperty()) {
250
hasOC = true;
251
} else if (aProp == ExcessOverflowContainersProperty()) {
252
hasEOC = true;
253
} else if (aProp == BackdropProperty()) {
254
hasBackdrop = true;
255
}
256
return true;
257
});
258
259
// Destroy frames on the auxiliary frame lists and delete the lists.
260
nsPresContext* pc = PresContext();
261
mozilla::PresShell* presShell = pc->PresShell();
262
if (hasO) {
263
SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
264
OverflowProperty());
265
}
266
267
MOZ_ASSERT(
268
IsFrameOfType(eCanContainOverflowContainers) || !(hasOC || hasEOC),
269
"this type of frame shouldn't have overflow containers");
270
if (hasOC) {
271
SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
272
OverflowContainersProperty());
273
}
274
if (hasEOC) {
275
SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
276
ExcessOverflowContainersProperty());
277
}
278
279
MOZ_ASSERT(!GetProperty(BackdropProperty()) ||
280
StyleDisplay()->mTopLayer != NS_STYLE_TOP_LAYER_NONE,
281
"only top layer frame may have backdrop");
282
if (hasBackdrop) {
283
SafelyDestroyFrameListProp(aDestructRoot, aPostDestroyData, presShell,
284
BackdropProperty());
285
}
286
}
287
288
nsSplittableFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
289
}
290
291
/////////////////////////////////////////////////////////////////////////////
292
// Child frame enumeration
293
294
const nsFrameList& nsContainerFrame::GetChildList(ChildListID aListID) const {
295
// We only know about the principal child list, the overflow lists,
296
// and the backdrop list.
297
switch (aListID) {
298
case kPrincipalList:
299
return mFrames;
300
case kOverflowList: {
301
nsFrameList* list = GetOverflowFrames();
302
return list ? *list : nsFrameList::EmptyList();
303
}
304
case kOverflowContainersList: {
305
nsFrameList* list = GetPropTableFrames(OverflowContainersProperty());
306
return list ? *list : nsFrameList::EmptyList();
307
}
308
case kExcessOverflowContainersList: {
309
nsFrameList* list =
310
GetPropTableFrames(ExcessOverflowContainersProperty());
311
return list ? *list : nsFrameList::EmptyList();
312
}
313
case kBackdropList: {
314
nsFrameList* list = GetPropTableFrames(BackdropProperty());
315
return list ? *list : nsFrameList::EmptyList();
316
}
317
default:
318
return nsSplittableFrame::GetChildList(aListID);
319
}
320
}
321
322
void nsContainerFrame::GetChildLists(nsTArray<ChildList>* aLists) const {
323
mFrames.AppendIfNonempty(aLists, kPrincipalList);
324
325
using T = mozilla::FrameProperties::UntypedDescriptor;
326
mProperties.ForEach([this, aLists](const T& aProp, void* aValue) {
327
typedef const nsFrameList* L;
328
if (aProp == OverflowProperty()) {
329
L(aValue)->AppendIfNonempty(aLists, kOverflowList);
330
} else if (aProp == OverflowContainersProperty()) {
331
MOZ_ASSERT(IsFrameOfType(nsIFrame::eCanContainOverflowContainers),
332
"found unexpected OverflowContainersProperty");
333
Unused << this; // silence clang -Wunused-lambda-capture in opt builds
334
L(aValue)->AppendIfNonempty(aLists, kOverflowContainersList);
335
} else if (aProp == ExcessOverflowContainersProperty()) {
336
MOZ_ASSERT(IsFrameOfType(nsIFrame::eCanContainOverflowContainers),
337
"found unexpected ExcessOverflowContainersProperty");
338
Unused << this; // silence clang -Wunused-lambda-capture in opt builds
339
L(aValue)->AppendIfNonempty(aLists, kExcessOverflowContainersList);
340
} else if (aProp == BackdropProperty()) {
341
L(aValue)->AppendIfNonempty(aLists, kBackdropList);
342
}
343
return true;
344
});
345
346
nsSplittableFrame::GetChildLists(aLists);
347
}
348
349
/////////////////////////////////////////////////////////////////////////////
350
// Painting/Events
351
352
void nsContainerFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
353
const nsDisplayListSet& aLists) {
354
DisplayBorderBackgroundOutline(aBuilder, aLists);
355
BuildDisplayListForNonBlockChildren(aBuilder, aLists);
356
}
357
358
void nsContainerFrame::BuildDisplayListForNonBlockChildren(
359
nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists,
360
uint32_t aFlags) {
361
nsIFrame* kid = mFrames.FirstChild();
362
// Put each child's background directly onto the content list
363
nsDisplayListSet set(aLists, aLists.Content());
364
// The children should be in content order
365
while (kid) {
366
BuildDisplayListForChild(aBuilder, kid, set, aFlags);
367
kid = kid->GetNextSibling();
368
}
369
}
370
371
/* virtual */
372
void nsContainerFrame::ChildIsDirty(nsIFrame* aChild) {
373
NS_ASSERTION(NS_SUBTREE_DIRTY(aChild), "child isn't actually dirty");
374
375
AddStateBits(NS_FRAME_HAS_DIRTY_CHILDREN);
376
}
377
378
nsIFrame::FrameSearchResult nsContainerFrame::PeekOffsetNoAmount(
379
bool aForward, int32_t* aOffset) {
380
NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range");
381
// Don't allow the caret to stay in an empty (leaf) container frame.
382
return CONTINUE_EMPTY;
383
}
384
385
nsIFrame::FrameSearchResult nsContainerFrame::PeekOffsetCharacter(
386
bool aForward, int32_t* aOffset, PeekOffsetCharacterOptions aOptions) {
387
NS_ASSERTION(aOffset && *aOffset <= 1, "aOffset out of range");
388
// Don't allow the caret to stay in an empty (leaf) container frame.
389
return CONTINUE_EMPTY;
390
}
391
392
/////////////////////////////////////////////////////////////////////////////
393
// Helper member functions
394
395
/**
396
* Position the view associated with |aKidFrame|, if there is one. A
397
* container frame should call this method after positioning a frame,
398
* but before |Reflow|.
399
*/
400
void nsContainerFrame::PositionFrameView(nsIFrame* aKidFrame) {
401
nsIFrame* parentFrame = aKidFrame->GetParent();
402
if (!aKidFrame->HasView() || !parentFrame) return;
403
404
nsView* view = aKidFrame->GetView();
405
nsViewManager* vm = view->GetViewManager();
406
nsPoint pt;
407
nsView* ancestorView = parentFrame->GetClosestView(&pt);
408
409
if (ancestorView != view->GetParent()) {
410
NS_ASSERTION(ancestorView == view->GetParent()->GetParent(),
411
"Allowed only one anonymous view between frames");
412
// parentFrame is responsible for positioning aKidFrame's view
413
// explicitly
414
return;
415
}
416
417
pt += aKidFrame->GetPosition();
418
vm->MoveViewTo(view, pt.x, pt.y);
419
}
420
421
nsresult nsContainerFrame::ReparentFrameView(nsIFrame* aChildFrame,
422
nsIFrame* aOldParentFrame,
423
nsIFrame* aNewParentFrame) {
424
MOZ_ASSERT(aChildFrame, "null child frame pointer");
425
MOZ_ASSERT(aOldParentFrame, "null old parent frame pointer");
426
MOZ_ASSERT(aNewParentFrame, "null new parent frame pointer");
427
MOZ_ASSERT(aOldParentFrame != aNewParentFrame,
428
"same old and new parent frame");
429
430
// See if either the old parent frame or the new parent frame have a view
431
while (!aOldParentFrame->HasView() && !aNewParentFrame->HasView()) {
432
// Walk up both the old parent frame and the new parent frame nodes
433
// stopping when we either find a common parent or views for one
434
// or both of the frames.
435
//
436
// This works well in the common case where we push/pull and the old parent
437
// frame and the new parent frame are part of the same flow. They will
438
// typically be the same distance (height wise) from the
439
aOldParentFrame = aOldParentFrame->GetParent();
440
aNewParentFrame = aNewParentFrame->GetParent();
441
442
// We should never walk all the way to the root frame without finding
443
// a view
444
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
445
446
// See if we reached a common ancestor
447
if (aOldParentFrame == aNewParentFrame) {
448
break;
449
}
450
}
451
452
// See if we found a common parent frame
453
if (aOldParentFrame == aNewParentFrame) {
454
// We found a common parent and there are no views between the old parent
455
// and the common parent or the new parent frame and the common parent.
456
// Because neither the old parent frame nor the new parent frame have views,
457
// then any child views don't need reparenting
458
return NS_OK;
459
}
460
461
// We found views for one or both of the ancestor frames before we
462
// found a common ancestor.
463
nsView* oldParentView = aOldParentFrame->GetClosestView();
464
nsView* newParentView = aNewParentFrame->GetClosestView();
465
466
// See if the old parent frame and the new parent frame are in the
467
// same view sub-hierarchy. If they are then we don't have to do
468
// anything
469
if (oldParentView != newParentView) {
470
// They're not so we need to reparent any child views
471
aChildFrame->ReparentFrameViewTo(oldParentView->GetViewManager(),
472
newParentView, oldParentView);
473
}
474
475
return NS_OK;
476
}
477
478
nsresult nsContainerFrame::ReparentFrameViewList(
479
const nsFrameList& aChildFrameList, nsIFrame* aOldParentFrame,
480
nsIFrame* aNewParentFrame) {
481
MOZ_ASSERT(aChildFrameList.NotEmpty(), "empty child frame list");
482
MOZ_ASSERT(aOldParentFrame, "null old parent frame pointer");
483
MOZ_ASSERT(aNewParentFrame, "null new parent frame pointer");
484
MOZ_ASSERT(aOldParentFrame != aNewParentFrame,
485
"same old and new parent frame");
486
487
// See if either the old parent frame or the new parent frame have a view
488
while (!aOldParentFrame->HasView() && !aNewParentFrame->HasView()) {
489
// Walk up both the old parent frame and the new parent frame nodes
490
// stopping when we either find a common parent or views for one
491
// or both of the frames.
492
//
493
// This works well in the common case where we push/pull and the old parent
494
// frame and the new parent frame are part of the same flow. They will
495
// typically be the same distance (height wise) from the
496
aOldParentFrame = aOldParentFrame->GetParent();
497
aNewParentFrame = aNewParentFrame->GetParent();
498
499
// We should never walk all the way to the root frame without finding
500
// a view
501
NS_ASSERTION(aOldParentFrame && aNewParentFrame, "didn't find view");
502
503
// See if we reached a common ancestor
504
if (aOldParentFrame == aNewParentFrame) {
505
break;
506
}
507
}
508
509
// See if we found a common parent frame
510
if (aOldParentFrame == aNewParentFrame) {
511
// We found a common parent and there are no views between the old parent
512
// and the common parent or the new parent frame and the common parent.
513
// Because neither the old parent frame nor the new parent frame have views,
514
// then any child views don't need reparenting
515
return NS_OK;
516
}
517
518
// We found views for one or both of the ancestor frames before we
519
// found a common ancestor.
520
nsView* oldParentView = aOldParentFrame->GetClosestView();
521
nsView* newParentView = aNewParentFrame->GetClosestView();
522
523
// See if the old parent frame and the new parent frame are in the
524
// same view sub-hierarchy. If they are then we don't have to do
525
// anything
526
if (oldParentView != newParentView) {
527
nsViewManager* viewManager = oldParentView->GetViewManager();
528
529
// They're not so we need to reparent any child views
530
for (nsFrameList::Enumerator e(aChildFrameList); !e.AtEnd(); e.Next()) {
531
e.get()->ReparentFrameViewTo(viewManager, newParentView, oldParentView);
532
}
533
}
534
535
return NS_OK;
536
}
537
538
static nsIWidget* GetPresContextContainerWidget(nsPresContext* aPresContext) {
539
nsCOMPtr<nsISupports> container = aPresContext->Document()->GetContainer();
540
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
541
if (!baseWindow) return nullptr;
542
543
nsCOMPtr<nsIWidget> mainWidget;
544
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
545
return mainWidget;
546
}
547
548
static bool IsTopLevelWidget(nsIWidget* aWidget) {
549
nsWindowType windowType = aWidget->WindowType();
550
return windowType == eWindowType_toplevel ||
551
windowType == eWindowType_dialog || windowType == eWindowType_popup ||
552
windowType == eWindowType_sheet;
553
}
554
555
void nsContainerFrame::SyncWindowProperties(nsPresContext* aPresContext,
556
nsIFrame* aFrame, nsView* aView,
557
gfxContext* aRC, uint32_t aFlags) {
558
#ifdef MOZ_XUL
559
if (!aView || !nsCSSRendering::IsCanvasFrame(aFrame) || !aView->HasWidget())
560
return;
561
562
nsCOMPtr<nsIWidget> windowWidget =
563
GetPresContextContainerWidget(aPresContext);
564
if (!windowWidget || !IsTopLevelWidget(windowWidget)) return;
565
566
nsViewManager* vm = aView->GetViewManager();
567
nsView* rootView = vm->GetRootView();
568
569
if (aView != rootView) return;
570
571
Element* rootElement = aPresContext->Document()->GetRootElement();
572
if (!rootElement) {
573
return;
574
}
575
576
nsIFrame* rootFrame =
577
aPresContext->PresShell()->FrameConstructor()->GetRootElementStyleFrame();
578
if (!rootFrame) return;
579
580
if (aFlags & SET_ASYNC) {
581
aView->SetNeedsWindowPropertiesSync();
582
return;
583
}
584
585
RefPtr<nsPresContext> kungFuDeathGrip(aPresContext);
586
AutoWeakFrame weak(rootFrame);
587
588
if (!aPresContext->PresShell()->GetRootScrollFrame()) {
589
// Scrollframes use native widgets which don't work well with
590
// translucent windows, at least in Windows XP. So if the document
591
// has a root scrollrame it's useless to try to make it transparent,
592
// we'll just get something broken.
593
// We can change this to allow translucent toplevel HTML documents
594
// (e.g. to do something like Dashboard widgets), once we
595
// have broad support for translucent scrolled documents, but be
596
// careful because apparently some Firefox extensions expect
597
// openDialog("something.html") to produce an opaque window
598
// even if the HTML doesn't have a background-color set.
599
nsTransparencyMode mode =
600
nsLayoutUtils::GetFrameTransparency(aFrame, rootFrame);
601
int32_t shadow = rootFrame->StyleUIReset()->mWindowShadow;
602
nsCOMPtr<nsIWidget> viewWidget = aView->GetWidget();
603
viewWidget->SetTransparencyMode(mode);
604
windowWidget->SetWindowShadowStyle(shadow);
605
}
606
607
if (!aRC) return;
608
609
if (!weak.IsAlive()) {
610
return;
611
}
612
613
nsSize minSize(0, 0);
614
nsSize maxSize(NS_UNCONSTRAINEDSIZE, NS_UNCONSTRAINEDSIZE);
615
if (rootElement->IsXULElement()) {
616
nsBoxLayoutState aState(aPresContext, aRC);
617
minSize = rootFrame->GetXULMinSize(aState);
618
maxSize = rootFrame->GetXULMaxSize(aState);
619
} else {
620
auto* pos = rootFrame->StylePosition();
621
if (pos->mMinWidth.ConvertsToLength()) {
622
minSize.width = pos->mMinWidth.ToLength();
623
}
624
if (pos->mMinHeight.ConvertsToLength()) {
625
minSize.height = pos->mMinHeight.ToLength();
626
}
627
if (pos->mMaxWidth.ConvertsToLength()) {
628
maxSize.width = pos->mMaxWidth.ToLength();
629
}
630
if (pos->mMaxHeight.ConvertsToLength()) {
631
maxSize.height = pos->mMaxHeight.ToLength();
632
}
633
}
634
SetSizeConstraints(aPresContext, windowWidget, minSize, maxSize);
635
#endif
636
}
637
638
void nsContainerFrame::SetSizeConstraints(nsPresContext* aPresContext,
639
nsIWidget* aWidget,
640
const nsSize& aMinSize,
641
const nsSize& aMaxSize) {
642
LayoutDeviceIntSize devMinSize(
643
aPresContext->AppUnitsToDevPixels(aMinSize.width),
644
aPresContext->AppUnitsToDevPixels(aMinSize.height));
645
LayoutDeviceIntSize devMaxSize(
646
aMaxSize.width == NS_UNCONSTRAINEDSIZE
647
? NS_MAXSIZE
648
: aPresContext->AppUnitsToDevPixels(aMaxSize.width),
649
aMaxSize.height == NS_UNCONSTRAINEDSIZE
650
? NS_MAXSIZE
651
: aPresContext->AppUnitsToDevPixels(aMaxSize.height));
652
653
// MinSize has a priority over MaxSize
654
if (devMinSize.width > devMaxSize.width) devMaxSize.width = devMinSize.width;
655
if (devMinSize.height > devMaxSize.height)
656
devMaxSize.height = devMinSize.height;
657
658
widget::SizeConstraints constraints(devMinSize, devMaxSize);
659
660
// The sizes are in inner window sizes, so convert them into outer window
661
// sizes. Use a size of (200, 200) as only the difference between the inner
662
// and outer size is needed.
663
LayoutDeviceIntSize windowSize =
664
aWidget->ClientToWindowSize(LayoutDeviceIntSize(200, 200));
665
if (constraints.mMinSize.width)
666
constraints.mMinSize.width += windowSize.width - 200;
667
if (constraints.mMinSize.height)
668
constraints.mMinSize.height += windowSize.height - 200;
669
if (constraints.mMaxSize.width != NS_MAXSIZE)
670
constraints.mMaxSize.width += windowSize.width - 200;
671
if (constraints.mMaxSize.height != NS_MAXSIZE)
672
constraints.mMaxSize.height += windowSize.height - 200;
673
674
aWidget->SetSizeConstraints(constraints);
675
}
676
677
void nsContainerFrame::SyncFrameViewAfterReflow(
678
nsPresContext* aPresContext, nsIFrame* aFrame, nsView* aView,
679
const nsRect& aVisualOverflowArea, ReflowChildFlags aFlags) {
680
if (!aView) {
681
return;
682
}
683
684
// Make sure the view is sized and positioned correctly
685
if (!(aFlags & ReflowChildFlags::NoMoveView)) {
686
PositionFrameView(aFrame);
687
}
688
689
if (!(aFlags & ReflowChildFlags::NoSizeView)) {
690
nsViewManager* vm = aView->GetViewManager();
691
692
vm->ResizeView(aView, aVisualOverflowArea, true);
693
}
694
}
695
696
static nscoord GetCoord(const LengthPercentage& aCoord, nscoord aIfNotCoord) {
697
if (aCoord.ConvertsToLength()) {
698
return aCoord.ToLength();
699
}
700
return aIfNotCoord;
701
}
702
703
static nscoord GetCoord(const LengthPercentageOrAuto& aCoord,
704
nscoord aIfNotCoord) {
705
if (aCoord.IsAuto()) {
706
return aIfNotCoord;
707
}
708
return GetCoord(aCoord.AsLengthPercentage(), aIfNotCoord);
709
}
710
711
void nsContainerFrame::DoInlineIntrinsicISize(
712
gfxContext* aRenderingContext, InlineIntrinsicISizeData* aData,
713
nsLayoutUtils::IntrinsicISizeType aType) {
714
if (GetPrevInFlow()) return; // Already added.
715
716
MOZ_ASSERT(
717
aType == nsLayoutUtils::MIN_ISIZE || aType == nsLayoutUtils::PREF_ISIZE,
718
"bad type");
719
720
WritingMode wm = GetWritingMode();
721
mozilla::Side startSide = wm.PhysicalSideForInlineAxis(eLogicalEdgeStart);
722
mozilla::Side endSide = wm.PhysicalSideForInlineAxis(eLogicalEdgeEnd);
723
724
const nsStylePadding* stylePadding = StylePadding();
725
const nsStyleBorder* styleBorder = StyleBorder();
726
const nsStyleMargin* styleMargin = StyleMargin();
727
728
// This goes at the beginning no matter how things are broken and how
729
// messy the bidi situations are, since per CSS2.1 section 8.6
730
// (implemented in bug 328168), the startSide border is always on the
731
// first line.
732
// This frame is a first-in-flow, but it might have a previous bidi
733
// continuation, in which case that continuation should handle the startSide
734
// border.
735
// For box-decoration-break:clone we setup clonePBM = startPBM + endPBM and
736
// add that to each line. For box-decoration-break:slice clonePBM is zero.
737
nscoord clonePBM = 0; // PBM = PaddingBorderMargin
738
const bool sliceBreak =
739
styleBorder->mBoxDecorationBreak == StyleBoxDecorationBreak::Slice;
740
if (!GetPrevContinuation() || MOZ_UNLIKELY(!sliceBreak)) {
741
nscoord startPBM =
742
// clamp negative calc() to 0
743
std::max(GetCoord(stylePadding->mPadding.Get(startSide), 0), 0) +
744
styleBorder->GetComputedBorderWidth(startSide) +
745
GetCoord(styleMargin->mMargin.Get(startSide), 0);
746
if (MOZ_LIKELY(sliceBreak)) {
747
aData->mCurrentLine += startPBM;
748
} else {
749
clonePBM = startPBM;
750
}
751
}
752
753
nscoord endPBM =
754
// clamp negative calc() to 0
755
std::max(GetCoord(stylePadding->mPadding.Get(endSide), 0), 0) +
756
styleBorder->GetComputedBorderWidth(endSide) +
757
GetCoord(styleMargin->mMargin.Get(endSide), 0);
758
if (MOZ_UNLIKELY(!sliceBreak)) {
759
clonePBM += endPBM;
760
aData->mCurrentLine += clonePBM;
761
}
762
763
const nsLineList_iterator* savedLine = aData->mLine;
764
nsIFrame* const savedLineContainer = aData->LineContainer();
765
766
nsContainerFrame* lastInFlow;
767
for (nsContainerFrame* nif = this; nif;
768
nif = static_cast<nsContainerFrame*>(nif->GetNextInFlow())) {
769
if (aData->mCurrentLine == 0) {
770
aData->mCurrentLine = clonePBM;
771
}
772
for (nsIFrame* kid : nif->mFrames) {
773
if (aType == nsLayoutUtils::MIN_ISIZE)
774
kid->AddInlineMinISize(aRenderingContext,
775
static_cast<InlineMinISizeData*>(aData));
776
else
777
kid->AddInlinePrefISize(aRenderingContext,
778
static_cast<InlinePrefISizeData*>(aData));
779
}
780
781
// After we advance to our next-in-flow, the stored line and line container
782
// may no longer be correct. Just forget them.
783
aData->mLine = nullptr;
784
aData->SetLineContainer(nullptr);
785
786
lastInFlow = nif;
787
}
788
789
aData->mLine = savedLine;
790
aData->SetLineContainer(savedLineContainer);
791
792
// This goes at the end no matter how things are broken and how
793
// messy the bidi situations are, since per CSS2.1 section 8.6
794
// (implemented in bug 328168), the endSide border is always on the
795
// last line.
796
// We reached the last-in-flow, but it might have a next bidi
797
// continuation, in which case that continuation should handle
798
// the endSide border.
799
if (MOZ_LIKELY(!lastInFlow->GetNextContinuation() && sliceBreak)) {
800
aData->mCurrentLine += endPBM;
801
}
802
}
803
804
/* virtual */
805
LogicalSize nsContainerFrame::ComputeAutoSize(
806
gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
807
nscoord aAvailableISize, const LogicalSize& aMargin,
808
const LogicalSize& aBorder, const LogicalSize& aPadding,
809
ComputeSizeFlags aFlags) {
810
LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE);
811
nscoord availBased = aAvailableISize - aMargin.ISize(aWM) -
812
aBorder.ISize(aWM) - aPadding.ISize(aWM);
813
// replaced elements always shrink-wrap
814
if ((aFlags & ComputeSizeFlags::eShrinkWrap) || IsFrameOfType(eReplaced)) {
815
// Only bother computing our 'auto' ISize if the result will be used.
816
// It'll be used under two scenarios:
817
// - If our ISize property is itself 'auto'.
818
// - If we're using flex-basis in place of our ISize property (i.e. we're a
819
// flex item with our inline axis being the main axis), AND we have
820
// flex-basis:content.
821
const nsStylePosition* pos = StylePosition();
822
if (pos->ISize(aWM).IsAuto() ||
823
(pos->mFlexBasis.IsContent() && IsFlexItem() &&
824
nsFlexContainerFrame::IsItemInlineAxisMainAxis(this))) {
825
result.ISize(aWM) =
826
ShrinkWidthToFit(aRenderingContext, availBased, aFlags);
827
}
828
} else {
829
result.ISize(aWM) = availBased;
830
}
831
832
if (IsTableCaption()) {
833
// If we're a container for font size inflation, then shrink
834
// wrapping inside of us should not apply font size inflation.
835
AutoMaybeDisableFontInflation an(this);
836
837
WritingMode tableWM = GetParent()->GetWritingMode();
838
uint8_t captionSide = StyleTableBorder()->mCaptionSide;
839
840
if (aWM.IsOrthogonalTo(tableWM)) {
841
if (captionSide == NS_STYLE_CAPTION_SIDE_TOP ||
842
captionSide == NS_STYLE_CAPTION_SIDE_TOP_OUTSIDE ||
843
captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM ||
844
captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM_OUTSIDE) {
845
// For an orthogonal caption on a block-dir side of the table,
846
// shrink-wrap to min-isize.
847
result.ISize(aWM) = GetMinISize(aRenderingContext);
848
} else {
849
// An orthogonal caption on an inline-dir side of the table
850
// is constrained to the containing block.
851
nscoord pref = GetPrefISize(aRenderingContext);
852
if (pref > aCBSize.ISize(aWM)) {
853
pref = aCBSize.ISize(aWM);
854
}
855
if (pref < result.ISize(aWM)) {
856
result.ISize(aWM) = pref;
857
}
858
}
859
} else {
860
if (captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
861
captionSide == NS_STYLE_CAPTION_SIDE_RIGHT) {
862
result.ISize(aWM) = GetMinISize(aRenderingContext);
863
} else if (captionSide == NS_STYLE_CAPTION_SIDE_TOP ||
864
captionSide == NS_STYLE_CAPTION_SIDE_BOTTOM) {
865
// The outer frame constrains our available isize to the isize of
866
// the table. Grow if our min-isize is bigger than that, but not
867
// larger than the containing block isize. (It would really be nice
868
// to transmit that information another way, so we could grow up to
869
// the table's available isize, but that's harder.)
870
nscoord min = GetMinISize(aRenderingContext);
871
if (min > aCBSize.ISize(aWM)) {
872
min = aCBSize.ISize(aWM);
873
}
874
if (min > result.ISize(aWM)) {
875
result.ISize(aWM) = min;
876
}
877
}
878
}
879
}
880
return result;
881
}
882
883
void nsContainerFrame::ReflowChild(
884
nsIFrame* aKidFrame, nsPresContext* aPresContext,
885
ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
886
const WritingMode& aWM, const LogicalPoint& aPos,
887
const nsSize& aContainerSize, ReflowChildFlags aFlags,
888
nsReflowStatus& aStatus, nsOverflowContinuationTracker* aTracker) {
889
MOZ_ASSERT(aReflowInput.mFrame == aKidFrame, "bad reflow input");
890
if (aWM.IsPhysicalRTL()) {
891
NS_ASSERTION(aContainerSize.width != NS_UNCONSTRAINEDSIZE,
892
"ReflowChild with unconstrained container width!");
893
}
894
MOZ_ASSERT(aDesiredSize.VisualOverflow() == nsRect(0, 0, 0, 0) &&
895
aDesiredSize.ScrollableOverflow() == nsRect(0, 0, 0, 0),
896
"please reset the overflow areas before calling ReflowChild");
897
898
// Position the child frame and its view if requested.
899
if (ReflowChildFlags::NoMoveFrame !=
900
(aFlags & ReflowChildFlags::NoMoveFrame)) {
901
aKidFrame->SetPosition(aWM, aPos, aContainerSize);
902
}
903
904
if (!(aFlags & ReflowChildFlags::NoMoveView)) {
905
PositionFrameView(aKidFrame);
906
PositionChildViews(aKidFrame);
907
}
908
909
// Reflow the child frame
910
aKidFrame->Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
911
912
// If the child frame is complete, delete any next-in-flows,
913
// but only if the NoDeleteNextInFlowChild flag isn't set.
914
if (!aStatus.IsInlineBreakBefore() && aStatus.IsFullyComplete() &&
915
!(aFlags & ReflowChildFlags::NoDeleteNextInFlowChild)) {
916
nsIFrame* kidNextInFlow = aKidFrame->GetNextInFlow();
917
if (kidNextInFlow) {
918
// Remove all of the childs next-in-flows. Make sure that we ask
919
// the right parent to do the removal (it's possible that the
920
// parent is not this because we are executing pullup code)
921
nsOverflowContinuationTracker::AutoFinish fini(aTracker, aKidFrame);
922
kidNextInFlow->GetParent()->DeleteNextInFlowChild(kidNextInFlow, true);
923
}
924
}
925
}
926
927
// XXX temporary: hold on to a copy of the old physical version of
928
// ReflowChild so that we can convert callers incrementally.
929
void nsContainerFrame::ReflowChild(nsIFrame* aKidFrame,
930
nsPresContext* aPresContext,
931
ReflowOutput& aDesiredSize,
932
const ReflowInput& aReflowInput, nscoord aX,
933
nscoord aY, ReflowChildFlags aFlags,
934
nsReflowStatus& aStatus,
935
nsOverflowContinuationTracker* aTracker) {
936
MOZ_ASSERT(aReflowInput.mFrame == aKidFrame, "bad reflow input");
937
938
// Position the child frame and its view if requested.
939
if (ReflowChildFlags::NoMoveFrame !=
940
(aFlags & ReflowChildFlags::NoMoveFrame)) {
941
aKidFrame->SetPosition(nsPoint(aX, aY));
942
}
943
944
if (!(aFlags & ReflowChildFlags::NoMoveView)) {
945
PositionFrameView(aKidFrame);
946
PositionChildViews(aKidFrame);
947
}
948
949
// Reflow the child frame
950
aKidFrame->Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
951
952
// If the child frame is complete, delete any next-in-flows,
953
// but only if the NoDeleteNextInFlowChild flag isn't set.
954
if (aStatus.IsFullyComplete() &&
955
!(aFlags & ReflowChildFlags::NoDeleteNextInFlowChild)) {
956
nsIFrame* kidNextInFlow = aKidFrame->GetNextInFlow();
957
if (kidNextInFlow) {
958
// Remove all of the childs next-in-flows. Make sure that we ask
959
// the right parent to do the removal (it's possible that the
960
// parent is not this because we are executing pullup code)
961
nsOverflowContinuationTracker::AutoFinish fini(aTracker, aKidFrame);
962
kidNextInFlow->GetParent()->DeleteNextInFlowChild(kidNextInFlow, true);
963
}
964
}
965
}
966
967
/**
968
* Position the views of |aFrame|'s descendants. A container frame
969
* should call this method if it moves a frame after |Reflow|.
970
*/
971
void nsContainerFrame::PositionChildViews(nsIFrame* aFrame) {
972
if (!(aFrame->GetStateBits() & NS_FRAME_HAS_CHILD_WITH_VIEW)) {
973
return;
974
}
975
976
// Recursively walk aFrame's child frames.
977
// Process the additional child lists, but skip the popup list as the
978
// view for popups is managed by the parent. Currently only nsMenuFrame
979
// and nsPopupSetFrame have a popupList and during layout will adjust the
980
// view manually to position the popup.
981
ChildListIterator lists(aFrame);
982
for (; !lists.IsDone(); lists.Next()) {
983
if (lists.CurrentID() == kPopupList) {
984
continue;
985
}
986
nsFrameList::Enumerator childFrames(lists.CurrentList());
987
for (; !childFrames.AtEnd(); childFrames.Next()) {
988
// Position the frame's view (if it has one) otherwise recursively
989
// process its children
990
nsIFrame* childFrame = childFrames.get();
991
if (childFrame->HasView()) {
992
PositionFrameView(childFrame);
993
} else {
994
PositionChildViews(childFrame);
995
}
996
}
997
}
998
}
999
1000
/**
1001
* The second half of frame reflow. Does the following:
1002
* - sets the frame's bounds
1003
* - sizes and positions (if requested) the frame's view. If the frame's final
1004
* position differs from the current position and the frame itself does not
1005
* have a view, then any child frames with views are positioned so they stay
1006
* in sync
1007
* - sets the view's visibility, opacity, content transparency, and clip
1008
* - invoked the DidReflow() function
1009
*
1010
* Flags:
1011
* ReflowChildFlags::NoMoveFrame - don't move the frame. aX and aY are ignored
1012
* in this case. Also implies ReflowChildFlags::NoMoveView
1013
* ReflowChildFlags::NoMoveView - don't position the frame's view. Set this if
1014
* you don't want to automatically sync the frame and view
1015
* ReflowChildFlags::NoSizeView - don't size the frame's view
1016
*/
1017
1018
/**
1019
* De-optimize function to work around a VC2017 15.5+ compiler bug:
1021
*/
1022
#if defined(_MSC_VER) && !defined(__clang__) && defined(_M_AMD64)
1023
# pragma optimize("g", off)
1024
#endif
1025
void nsContainerFrame::FinishReflowChild(
1026
nsIFrame* aKidFrame, nsPresContext* aPresContext,
1027
const ReflowOutput& aDesiredSize, const ReflowInput* aReflowInput,
1028
const WritingMode& aWM, const LogicalPoint& aPos,
1029
const nsSize& aContainerSize, nsIFrame::ReflowChildFlags aFlags) {
1030
MOZ_ASSERT(!aReflowInput || aReflowInput->mFrame == aKidFrame);
1031
MOZ_ASSERT(aReflowInput || aKidFrame->IsFrameOfType(eMathML) ||
1032
aKidFrame->IsTableCellFrame(),
1033
"aReflowInput should be passed in almost all cases");
1034
1035
if (aWM.IsPhysicalRTL()) {
1036
NS_ASSERTION(aContainerSize.width != NS_UNCONSTRAINEDSIZE,
1037
"FinishReflowChild with unconstrained container width!");
1038
}
1039
1040
nsPoint curOrigin = aKidFrame->GetPosition();
1041
WritingMode outerWM = aDesiredSize.GetWritingMode();
1042
LogicalSize convertedSize =
1043
aDesiredSize.Size(outerWM).ConvertTo(aWM, outerWM);
1044
LogicalPoint pos(aPos);
1045
1046
if (aFlags & ReflowChildFlags::ApplyRelativePositioning) {
1047
MOZ_ASSERT(aReflowInput, "caller must have passed reflow input");
1048
// ApplyRelativePositioning in right-to-left writing modes needs to know
1049
// the updated frame width to set the normal position correctly.
1050
aKidFrame->SetSize(aWM, convertedSize);
1051
aReflowInput->ApplyRelativePositioning(&pos, aContainerSize);
1052
}
1053
1054
if (ReflowChildFlags::NoMoveFrame !=
1055
(aFlags & ReflowChildFlags::NoMoveFrame)) {
1056
aKidFrame->SetRect(aWM, LogicalRect(aWM, pos, convertedSize),
1057
aContainerSize);
1058
} else {
1059
aKidFrame->SetSize(aWM, convertedSize);
1060
}
1061
1062
if (aKidFrame->HasView()) {
1063
nsView* view = aKidFrame->GetView();
1064
// Make sure the frame's view is properly sized and positioned and has
1065
// things like opacity correct
1066
SyncFrameViewAfterReflow(aPresContext, aKidFrame, view,
1067
aDesiredSize.VisualOverflow(), aFlags);
1068
}
1069
1070
nsPoint newOrigin = aKidFrame->GetPosition();
1071
if (!(aFlags & ReflowChildFlags::NoMoveView) && curOrigin != newOrigin) {
1072
if (!aKidFrame->HasView()) {
1073
// If the frame has moved, then we need to make sure any child views are
1074
// correctly positioned
1075
PositionChildViews(aKidFrame);
1076
}
1077
}
1078
1079
aKidFrame->DidReflow(aPresContext, aReflowInput);
1080
}
1081
#if defined(_MSC_VER) && !defined(__clang__) && defined(_M_AMD64)
1082
# pragma optimize("", on)
1083
#endif
1084
1085
// XXX temporary: hold on to a copy of the old physical version of
1086
// FinishReflowChild so that we can convert callers incrementally.
1087
void nsContainerFrame::FinishReflowChild(nsIFrame* aKidFrame,
1088
nsPresContext* aPresContext,
1089
const ReflowOutput& aDesiredSize,
1090
const ReflowInput* aReflowInput,
1091
nscoord aX, nscoord aY,
1092
ReflowChildFlags aFlags) {
1093
MOZ_ASSERT(!(aFlags & ReflowChildFlags::ApplyRelativePositioning),
1094
"only the logical version supports ApplyRelativePositioning "
1095
"since ApplyRelativePositioning requires the container size");
1096
1097
nsPoint curOrigin = aKidFrame->GetPosition();
1098
nsPoint pos(aX, aY);
1099
nsSize size(aDesiredSize.PhysicalSize());
1100
1101
if (ReflowChildFlags::NoMoveFrame !=
1102
(aFlags & ReflowChildFlags::NoMoveFrame)) {
1103
aKidFrame->SetRect(nsRect(pos, size));
1104
} else {
1105
aKidFrame->SetSize(size);
1106
}
1107
1108
if (aKidFrame->HasView()) {
1109
nsView* view = aKidFrame->GetView();
1110
// Make sure the frame's view is properly sized and positioned and has
1111
// things like opacity correct
1112
SyncFrameViewAfterReflow(aPresContext, aKidFrame, view,
1113
aDesiredSize.VisualOverflow(), aFlags);
1114
}
1115
1116
if (!(aFlags & ReflowChildFlags::NoMoveView) && curOrigin != pos) {
1117
if (!aKidFrame->HasView()) {
1118
// If the frame has moved, then we need to make sure any child views are
1119
// correctly positioned
1120
PositionChildViews(aKidFrame);
1121
}
1122
}
1123
1124
aKidFrame->DidReflow(aPresContext, aReflowInput);
1125
}
1126
1127
void nsContainerFrame::ReflowOverflowContainerChildren(
1128
nsPresContext* aPresContext, const ReflowInput& aReflowInput,
1129
nsOverflowAreas& aOverflowRects, ReflowChildFlags aFlags,
1130
nsReflowStatus& aStatus, ChildFrameMerger aMergeFunc) {
1131
MOZ_ASSERT(aPresContext, "null pointer");
1132
1133
nsFrameList* overflowContainers =
1134
DrainExcessOverflowContainersList(aMergeFunc);
1135
if (!overflowContainers) {
1136
return; // nothing to reflow
1137
}
1138
1139
nsOverflowContinuationTracker tracker(this, false, false);
1140
bool shouldReflowAllKids = aReflowInput.ShouldReflowAllKids();
1141
1142
for (nsIFrame* frame : *overflowContainers) {
1143
if (frame->GetPrevInFlow()->GetParent() != GetPrevInFlow()) {
1144
// frame's prevInFlow has moved, skip reflowing this frame;
1145
// it will get reflowed once it's been placed
1146
if (GetNextInFlow()) {
1147
// We report OverflowIncomplete status in this case to avoid our parent
1148
// deleting our next-in-flows which might destroy non-empty frames.
1149
nsReflowStatus status;
1150
status.SetOverflowIncomplete();
1151
aStatus.MergeCompletionStatusFrom(status);
1152
}
1153
continue;
1154
}
1155
// If the available vertical height has changed, we need to reflow
1156
// even if the frame isn't dirty.
1157
if (shouldReflowAllKids || NS_SUBTREE_DIRTY(frame)) {
1158
// Get prev-in-flow
1159
nsIFrame* prevInFlow = frame->GetPrevInFlow();
1160
NS_ASSERTION(prevInFlow,
1161
"overflow container frame must have a prev-in-flow");
1162
NS_ASSERTION(
1163
frame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER,
1164
"overflow container frame must have overflow container bit set");
1165
WritingMode wm = frame->GetWritingMode();
1166
nsSize containerSize = aReflowInput.AvailableSize(wm).GetPhysicalSize(wm);
1167
LogicalRect prevRect = prevInFlow->GetLogicalRect(wm, containerSize);
1168
1169
// Initialize reflow params
1170
LogicalSize availSpace(wm, prevRect.ISize(wm),
1171
aReflowInput.AvailableSize(wm).BSize(wm));
1172
ReflowOutput desiredSize(aReflowInput);
1173
ReflowInput frameState(aPresContext, aReflowInput, frame, availSpace);
1174
nsReflowStatus frameStatus;
1175
1176
// Reflow
1177
LogicalPoint pos(wm, prevRect.IStart(wm), 0);
1178
ReflowChild(frame, aPresContext, desiredSize, frameState, wm, pos,
1179
containerSize, aFlags, frameStatus, &tracker);
1180
// XXXfr Do we need to override any shrinkwrap effects here?
1181
// e.g. desiredSize.Width() = prevRect.width;
1182
FinishReflowChild(frame, aPresContext, desiredSize, &frameState, wm, pos,
1183
containerSize, aFlags);
1184
1185
// Handle continuations
1186
if (!frameStatus.IsFullyComplete()) {
1187
if (frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) {
1188
// Abspos frames can't cause their parent to be incomplete,
1189
// only overflow incomplete.
1190
frameStatus.SetOverflowIncomplete();
1191
} else {
1192
NS_ASSERTION(frameStatus.IsComplete(),
1193
"overflow container frames can't be incomplete, only "
1194
"overflow-incomplete");
1195
}
1196
1197
// Acquire a next-in-flow, creating it if necessary
1198
nsIFrame* nif = frame->GetNextInFlow();
1199
if (!nif) {
1200
NS_ASSERTION(frameStatus.NextInFlowNeedsReflow(),
1201
"Someone forgot a NextInFlowNeedsReflow flag");
1202
nif = aPresContext->PresShell()
1203
->FrameConstructor()
1204
->CreateContinuingFrame(aPresContext, frame, this);
1205
} else if (!(nif->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER)) {
1206
// used to be a normal next-in-flow; steal it from the child list
1207
nsresult rv = nif->GetParent()->StealFrame(nif);
1208
if (NS_FAILED(rv)) {
1209
return;
1210
}
1211
}
1212
1213
tracker.Insert(nif, frameStatus);
1214
}
1215
aStatus.MergeCompletionStatusFrom(frameStatus);
1216
// At this point it would be nice to assert
1217
// !frame->GetOverflowRect().IsEmpty(), but we have some unsplittable
1218
// frames that, when taller than availableHeight will push zero-height
1219
// content into a next-in-flow.
1220
} else {
1221
tracker.Skip(frame, aStatus);
1222
if (aReflowInput.mFloatManager) {
1223
nsBlockFrame::RecoverFloatsFor(frame, *aReflowInput.mFloatManager,
1224
aReflowInput.GetWritingMode(),
1225
aReflowInput.ComputedPhysicalSize());
1226
}
1227
}
1228
ConsiderChildOverflow(aOverflowRects, frame);
1229
}
1230
}
1231
1232
void nsContainerFrame::DisplayOverflowContainers(
1233
nsDisplayListBuilder* aBuilder, const nsDisplayListSet& aLists) {
1234
nsFrameList* overflowconts = GetPropTableFrames(OverflowContainersProperty());
1235
if (overflowconts) {
1236
for (nsIFrame* frame : *overflowconts) {
1237
BuildDisplayListForChild(aBuilder, frame, aLists);
1238
}
1239
}
1240
}
1241
1242
static bool TryRemoveFrame(nsIFrame* aFrame,
1243
nsContainerFrame::FrameListPropertyDescriptor aProp,
1244
nsIFrame* aChildToRemove) {
1245
nsFrameList* list = aFrame->GetProperty(aProp);
1246
if (list && list->StartRemoveFrame(aChildToRemove)) {
1247
// aChildToRemove *may* have been removed from this list.
1248
if (list->IsEmpty()) {
1249
aFrame->RemoveProperty(aProp);
1250
list->Delete(aFrame->PresShell());
1251
}
1252
return true;
1253
}
1254
return false;
1255
}
1256
1257
bool nsContainerFrame::MaybeStealOverflowContainerFrame(nsIFrame* aChild) {
1258
bool removed = false;
1259
if (MOZ_UNLIKELY(aChild->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER)) {
1260
// Try removing from the overflow container list.
1261
removed = ::TryRemoveFrame(this, OverflowContainersProperty(), aChild);
1262
if (!removed) {
1263
// It might be in the excess overflow container list.
1264
removed =
1265
::TryRemoveFrame(this, ExcessOverflowContainersProperty(), aChild);
1266
}
1267
}
1268
return removed;
1269
}
1270
1271
nsresult nsContainerFrame::StealFrame(nsIFrame* aChild) {
1272
#ifdef DEBUG
1273
if (!mFrames.ContainsFrame(aChild)) {
1274
nsFrameList* list = GetOverflowFrames();
1275
if (!list || !list->ContainsFrame(aChild)) {
1276
list = GetProperty(OverflowContainersProperty());
1277
if (!list || !list->ContainsFrame(aChild)) {
1278
list = GetProperty(ExcessOverflowContainersProperty());
1279
MOZ_ASSERT(list && list->ContainsFrame(aChild),
1280
"aChild isn't our child"
1281
" or on a frame list not supported by StealFrame");
1282
}
1283
}
1284
}
1285
#endif
1286
1287
bool removed = MaybeStealOverflowContainerFrame(aChild);
1288
if (!removed) {
1289
// NOTE nsColumnSetFrame and nsCanvasFrame have their overflow containers
1290
// on the normal lists so we might get here also if the frame bit
1291
// NS_FRAME_IS_OVERFLOW_CONTAINER is set.
1292
removed = mFrames.StartRemoveFrame(aChild);
1293
if (!removed) {
1294
// We didn't find the child in our principal child list.
1295
// Maybe it's on the overflow list?
1296
nsFrameList* frameList = GetOverflowFrames();
1297
if (frameList) {
1298
removed = frameList->ContinueRemoveFrame(aChild);
1299
if (frameList->IsEmpty()) {
1300
DestroyOverflowList();
1301
}
1302
}
1303
}
1304
}
1305
1306
MOZ_ASSERT(removed, "StealFrame: can't find aChild");
1307
return removed ? NS_OK : NS_ERROR_UNEXPECTED;
1308
}
1309
1310
nsFrameList nsContainerFrame::StealFramesAfter(nsIFrame* aChild) {
1311
NS_ASSERTION(
1312
!aChild || !(aChild->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER),
1313
"StealFramesAfter doesn't handle overflow containers");
1314
NS_ASSERTION(!IsBlockFrame(), "unexpected call");
1315
1316
if (!aChild) {
1317
nsFrameList copy(mFrames);
1318
mFrames.Clear();
1319
return copy;
1320
}
1321
1322
for (nsFrameList::FrameLinkEnumerator iter(mFrames); !iter.AtEnd();
1323
iter.Next()) {
1324
if (iter.PrevFrame() == aChild) {
1325
return mFrames.ExtractTail(iter);
1326
}
1327
}
1328
1329
// We didn't find the child in the principal child list.
1330
// Maybe it's on the overflow list?
1331
nsFrameList* overflowFrames = GetOverflowFrames();
1332
if (overflowFrames) {
1333
for (nsFrameList::FrameLinkEnumerator iter(*overflowFrames); !iter.AtEnd();
1334
iter.Next()) {
1335
if (iter.PrevFrame() == aChild) {
1336
return overflowFrames->ExtractTail(iter);
1337
}
1338
}
1339
}
1340
1341
NS_ERROR("StealFramesAfter: can't find aChild");
1342
return nsFrameList::EmptyList();
1343
}
1344
1345
/*
1346
* Create a next-in-flow for aFrame. Will return the newly created
1347
* frame <b>if and only if</b> a new frame is created; otherwise
1348
* nullptr is returned.
1349
*/
1350
nsIFrame* nsContainerFrame::CreateNextInFlow(nsIFrame* aFrame) {
1351
MOZ_ASSERT(
1352
!IsBlockFrame(),
1353
"you should have called nsBlockFrame::CreateContinuationFor instead");
1354
MOZ_ASSERT(mFrames.ContainsFrame(aFrame), "expected an in-flow child frame");
1355
1356
nsPresContext* pc = PresContext();
1357
nsIFrame* nextInFlow = aFrame->GetNextInFlow();
1358
if (nullptr == nextInFlow) {
1359
// Create a continuation frame for the child frame and insert it
1360
// into our child list.
1361
nextInFlow = pc->PresShell()->FrameConstructor()->CreateContinuingFrame(
1362
pc, aFrame, this);
1363
mFrames.InsertFrame(nullptr, aFrame, nextInFlow);
1364
1365
NS_FRAME_LOG(NS_FRAME_TRACE_NEW_FRAMES,
1366
("nsContainerFrame::CreateNextInFlow: frame=%p nextInFlow=%p",
1367
aFrame, nextInFlow));
1368
1369
return nextInFlow;
1370
}
1371
return nullptr;
1372
}
1373
1374
/**
1375
* Remove and delete aNextInFlow and its next-in-flows. Updates the sibling and
1376
* flow pointers
1377
*/
1378
void nsContainerFrame::DeleteNextInFlowChild(nsIFrame* aNextInFlow,
1379
bool aDeletingEmptyFrames) {
1380
#ifdef DEBUG
1381
nsIFrame* prevInFlow = aNextInFlow->GetPrevInFlow();
1382
#endif
1383
MOZ_ASSERT(prevInFlow, "bad prev-in-flow");
1384
1385
// If the next-in-flow has a next-in-flow then delete it, too (and
1386
// delete it first).
1387
// Do this in a loop so we don't overflow the stack for frames
1388
// with very many next-in-flows
1389
nsIFrame* nextNextInFlow = aNextInFlow->GetNextInFlow();
1390
if (nextNextInFlow) {
1391
AutoTArray<nsIFrame*, 8> frames;
1392
for (nsIFrame* f = nextNextInFlow; f; f = f->GetNextInFlow()) {
1393
frames.AppendElement(f);
1394
}
1395
for (nsIFrame* delFrame : Reversed(frames)) {
1396
delFrame->GetParent()->DeleteNextInFlowChild(delFrame,
1397
aDeletingEmptyFrames);
1398
}
1399
}
1400
1401
// Take the next-in-flow out of the parent's child list
1402
DebugOnly<nsresult> rv = StealFrame(aNextInFlow);
1403
NS_ASSERTION(NS_SUCCEEDED(rv), "StealFrame failure");
1404
1405
#ifdef DEBUG
1406
if (aDeletingEmptyFrames) {
1407
nsLayoutUtils::AssertTreeOnlyEmptyNextInFlows(aNextInFlow);
1408
}
1409
#endif
1410
1411
// Delete the next-in-flow frame and its descendants. This will also
1412
// remove it from its next-in-flow/prev-in-flow chain.
1413
aNextInFlow->Destroy();
1414
1415
MOZ_ASSERT(!prevInFlow->GetNextInFlow(), "non null next-in-flow");
1416
}
1417
1418
/**
1419
* Set the frames on the overflow list
1420
*/
1421
void nsContainerFrame::SetOverflowFrames(const nsFrameList& aOverflowFrames) {
1422
MOZ_ASSERT(aOverflowFrames.NotEmpty(), "Shouldn't be called");
1423
1424
nsPresContext* pc = PresContext();
1425
nsFrameList* newList = new (pc->PresShell()) nsFrameList(aOverflowFrames);
1426
1427
SetProperty(OverflowProperty(), newList);
1428
}
1429
1430
nsFrameList* nsContainerFrame::GetPropTableFrames(
1431
FrameListPropertyDescriptor aProperty) const {
1432
return GetProperty(aProperty);
1433
}
1434
1435
nsFrameList* nsContainerFrame::RemovePropTableFrames(
1436
FrameListPropertyDescriptor aProperty) {
1437
return RemoveProperty(aProperty);
1438
}
1439
1440
void nsContainerFrame::SetPropTableFrames(
1441
nsFrameList* aFrameList, FrameListPropertyDescriptor aProperty) {
1442
MOZ_ASSERT(aProperty && aFrameList, "null ptr");
1443
MOZ_ASSERT(
1444
(aProperty != nsContainerFrame::OverflowContainersProperty() &&
1445
aProperty != nsContainerFrame::ExcessOverflowContainersProperty()) ||
1446
IsFrameOfType(nsIFrame::eCanContainOverflowContainers),
1447
"this type of frame can't have overflow containers");
1448
MOZ_ASSERT(!GetPropTableFrames(aProperty));
1449
SetProperty(aProperty, aFrameList);
1450
}
1451
1452
void nsContainerFrame::PushChildrenToOverflow(nsIFrame* aFromChild,
1453
nsIFrame* aPrevSibling) {
1454
MOZ_ASSERT(aFromChild, "null pointer");
1455
MOZ_ASSERT(aPrevSibling, "pushing first child");
1456
MOZ_ASSERT(aPrevSibling->GetNextSibling() == aFromChild, "bad prev sibling");
1457
1458
// Add the frames to our overflow list (let our next in flow drain
1459
// our overflow list when it is ready)
1460
SetOverflowFrames(mFrames.RemoveFramesAfter(aPrevSibling));
1461
}
1462
1463
void nsContainerFrame::PushChildren(nsIFrame* aFromChild,
1464
nsIFrame* aPrevSibling) {
1465
MOZ_ASSERT(aFromChild, "null pointer");
1466
MOZ_ASSERT(aPrevSibling, "pushing first child");
1467
MOZ_ASSERT(aPrevSibling->GetNextSibling() == aFromChild, "bad prev sibling");
1468
1469
// Disconnect aFromChild from its previous sibling
1470
nsFrameList tail = mFrames.RemoveFramesAfter(aPrevSibling);
1471
1472
nsContainerFrame* nextInFlow =
1473
static_cast<nsContainerFrame*>(GetNextInFlow());
1474
if (nextInFlow) {
1475
// XXX This is not a very good thing to do. If it gets removed
1476
// then remove the copy of this routine that doesn't do this from
1477
// nsInlineFrame.
1478
// When pushing and pulling frames we need to check for whether any
1479
// views need to be reparented.
1480
for (nsIFrame* f = aFromChild; f; f = f->GetNextSibling()) {
1481
nsContainerFrame::ReparentFrameView(f, this, nextInFlow);
1482
}
1483
nextInFlow->mFrames.InsertFrames(nextInFlow, nullptr, tail);
1484
} else {
1485
// Add the frames to our overflow list
1486
SetOverflowFrames(tail);
1487
}
1488
}
1489
1490
bool nsContainerFrame::MoveOverflowToChildList() {
1491
bool result = false;
1492
1493
// Check for an overflow list with our prev-in-flow
1494
nsContainerFrame* prevInFlow = (nsContainerFrame*)GetPrevInFlow();
1495
if (nullptr != prevInFlow) {
1496
AutoFrameListPtr prevOverflowFrames(PresContext(),
1497
prevInFlow->StealOverflowFrames());
1498
if (prevOverflowFrames) {
1499
// Tables are special; they can have repeated header/footer
1500
// frames on mFrames at this point.
1501
NS_ASSERTION(mFrames.IsEmpty() || IsTableFrame(), "bad overflow list");
1502
// When pushing and pulling frames we need to check for whether any
1503
// views need to be reparented.
1504
nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow,
1505
this);
1506
mFrames.AppendFrames(this, *prevOverflowFrames);
1507
result = true;
1508
}
1509
}
1510
1511
// It's also possible that we have an overflow list for ourselves.
1512
return DrainSelfOverflowList() || result;
1513
}
1514
1515
bool nsContainerFrame::MoveInlineOverflowToChildList(nsIFrame* aLineContainer) {
1516
MOZ_ASSERT(aLineContainer,
1517
"Must have line container for moving inline overflows");
1518
1519
bool result = false;
1520
1521
// Check for an overflow list with our prev-in-flow
1522
if (auto prevInFlow = static_cast<nsContainerFrame*>(GetPrevInFlow())) {
1523
AutoFrameListPtr prevOverflowFrames(PresContext(),
1524
prevInFlow->StealOverflowFrames());
1525
if (prevOverflowFrames) {
1526
// We may need to reparent floats from prev-in-flow to our line
1527
// container if the container has prev continuation.
1528
if (aLineContainer->GetPrevContinuation()) {
1529
ReparentFloatsForInlineChild(aLineContainer,
1530
prevOverflowFrames->FirstChild(), true);
1531
}
1532
// When pushing and pulling frames we need to check for whether
1533
// any views need to be reparented.
1534
nsContainerFrame::ReparentFrameViewList(*prevOverflowFrames, prevInFlow,
1535
this);
1536
// Prepend overflow frames to the list.
1537
mFrames.InsertFrames(this, nullptr, *prevOverflowFrames);
1538
result = true;
1539
}
1540
}
1541
1542
// It's also possible that we have overflow list for ourselves.
1543
return DrainSelfOverflowList() || result;
1544
}
1545
1546
bool nsContainerFrame::DrainSelfOverflowList() {
1547
AutoFrameListPtr overflowFrames(PresContext(), StealOverflowFrames());
1548
if (overflowFrames) {
1549
mFrames.AppendFrames(nullptr, *overflowFrames);
1550
return true;
1551
}
1552
return false;
1553
}
1554
1555
nsFrameList* nsContainerFrame::DrainExcessOverflowContainersList(
1556
ChildFrameMerger aMergeFunc) {
1557
nsFrameList* overflowContainers =
1558
GetPropTableFrames(OverflowContainersProperty());
1559
1560
NS_ASSERTION(!(overflowContainers && GetPrevInFlow() &&
1561
static_cast<nsContainerFrame*>(GetPrevInFlow())
1562
->GetPropTableFrames(ExcessOverflowContainersProperty())),
1563
"conflicting overflow containers lists");
1564
1565
if (!overflowContainers) {
1566
// Drain excess from previnflow
1567
nsContainerFrame* prev = (nsContainerFrame*)GetPrevInFlow();
1568
if (prev) {
1569
nsFrameList* excessFrames =
1570
prev->RemovePropTableFrames(ExcessOverflowContainersProperty());
1571
if (excessFrames) {
1572
excessFrames->ApplySetParent(this);
1573
nsContainerFrame::ReparentFrameViewList(*excessFrames, prev, this);
1574
overflowContainers = excessFrames;
1575
SetPropTableFrames(overflowContainers, OverflowContainersProperty());
1576
}
1577
}
1578
}
1579
1580
// Our own excess overflow containers from a previous reflow can still be
1581
// present if our next-in-flow hasn't been reflown yet. Move any children
1582
// from it that don't have a continuation in this frame to the
1583
// OverflowContainers list.
1584
nsFrameList* selfExcessOCFrames =
1585
RemovePropTableFrames(ExcessOverflowContainersProperty());
1586
if (selfExcessOCFrames) {
1587
nsFrameList toMove;
1588
auto child = selfExcessOCFrames->FirstChild();
1589
while (child) {
1590
auto next = child->GetNextSibling();
1591
MOZ_ASSERT(child->GetPrevInFlow(),
1592
"ExcessOverflowContainers frames must be continuations");
1593
if (child->GetPrevInFlow()->GetParent() != this) {
1594
selfExcessOCFrames->RemoveFrame(child);
1595
toMove.AppendFrame(nullptr, child);
1596
}
1597
child = next;
1598
}
1599
if (toMove.IsEmpty()) {
1600
SetPropTableFrames(selfExcessOCFrames,
1601
ExcessOverflowContainersProperty());
1602
} else if (overflowContainers) {
1603
aMergeFunc(*overflowContainers, toMove, this);
1604
if (selfExcessOCFrames->IsEmpty()) {
1605
selfExcessOCFrames->Delete(PresShell());
1606
} else {
1607
SetPropTableFrames(selfExcessOCFrames,
1608
ExcessOverflowContainersProperty());
1609
}
1610
} else {
1611
if (selfExcessOCFrames->IsEmpty()) {
1612
*selfExcessOCFrames = toMove;
1613
overflowContainers = selfExcessOCFrames;
1614
} else {
1615
SetPropTableFrames(selfExcessOCFrames,
1616
ExcessOverflowContainersProperty());
1617
auto shell = PresShell();
1618
overflowContainers = new (shell) nsFrameList(toMove);
1619
}
1620
SetPropTableFrames(overflowContainers, OverflowContainersProperty());
1621
}
1622
}
1623
1624
return overflowContainers;
1625
}
1626
1627
nsIFrame* nsContainerFrame::GetNextInFlowChild(
1628
ContinuationTraversingState& aState, bool* aIsInOverflow) {
1629
nsContainerFrame*& nextInFlow = aState.mNextInFlow;
1630
while (nextInFlow) {
1631
// See if there is any frame in the container
1632
nsIFrame* frame = nextInFlow->mFrames.FirstChild();
1633
if (frame) {
1634
if (aIsInOverflow) {
1635
*aIsInOverflow = false;
1636
}
1637
return frame;
1638
}
1639
// No frames in the principal list, try its overflow list
1640
nsFrameList* overflowFrames = nextInFlow->GetOverflowFrames();
1641
if (overflowFrames) {
1642
if (aIsInOverflow) {
1643
*aIsInOverflow = true;
1644
}
1645
return overflowFrames->FirstChild();
1646
}
1647
nextInFlow = static_cast<nsContainerFrame*>(nextInFlow->GetNextInFlow());
1648
}
1649
return nullptr;
1650
}
1651
1652
nsIFrame* nsContainerFrame::PullNextInFlowChild(
1653
ContinuationTraversingState& aState) {
1654
bool isInOverflow;
1655
nsIFrame* frame = GetNextInFlowChild(aState, &isInOverflow);
1656
if (frame) {
1657
nsContainerFrame* nextInFlow = aState.mNextInFlow;
1658
if (isInOverflow) {
1659
nsFrameList* overflowFrames = nextInFlow->GetOverflowFrames();
1660
overflowFrames->RemoveFirstChild();
1661
if (overflowFrames->IsEmpty()) {
1662
nextInFlow->DestroyOverflowList();
1663
}
1664
} else {
1665
nextInFlow->mFrames.RemoveFirstChild();
1666
}
1667
1668
// Move the frame to the principal frame list of this container
1669
mFrames.AppendFrame(this, frame);
1670
// AppendFrame has reparented the frame, we need
1671
// to reparent the frame view then.
1672
nsContainerFrame::ReparentFrameView(frame, nextInFlow, this);
1673
}
1674
return frame;
1675
}
1676
1677
/* static */
1678
void nsContainerFrame::ReparentFloatsForInlineChild(nsIFrame* aOurLineContainer,
1679
nsIFrame* aFrame,
1680
bool aReparentSiblings) {
1681
// XXXbz this would be better if it took a nsFrameList or a frame
1682
// list slice....
1683
NS_ASSERTION(aOurLineContainer->GetNextContinuation() ||
1684
aOurLineContainer->GetPrevContinuation(),
1685
"Don't call this when we have no continuation, it's a waste");
1686
if (!aFrame) {
1687
NS_ASSERTION(aReparentSiblings, "Why did we get called?");
1688
return;
1689
}
1690
1691
nsBlockFrame* frameBlock = nsLayoutUtils::GetFloatContainingBlock(aFrame);
1692
if (!frameBlock || frameBlock == aOurLineContainer) {
1693
return;
1694
}
1695
1696
nsBlockFrame* ourBlock = do_QueryFrame(aOurLineContainer);
1697
NS_ASSERTION(ourBlock, "Not a block, but broke vertically?");
1698
1699
while (true) {
1700
ourBlock->ReparentFloats(aFrame, frameBlock, false);
1701
1702
if (!aReparentSiblings) return;
1703
nsIFrame* next = aFrame->GetNextSibling();
1704
if (!next) return;
1705
if (next->GetParent() == aFrame->GetParent()) {
1706
aFrame = next;
1707
continue;
1708
}
1709
// This is paranoid and will hardly ever get hit ... but we can't actually
1710
// trust that the frames in the sibling chain all have the same parent,
1711
// because lazy reparenting may be going on. If we find a different
1712
// parent we need to redo our analysis.
1713
ReparentFloatsForInlineChild(aOurLineContainer, next, aReparentSiblings);
1714
return;
1715
}
1716
}
1717
1718
bool nsContainerFrame::ResolvedOrientationIsVertical() {
1719
StyleOrient orient = StyleDisplay()->mOrient;
1720
switch (orient) {
1721
case StyleOrient::Horizontal:
1722
return false;
1723
case StyleOrient::Vertical:
1724
return true;
1725
case StyleOrient::Inline:
1726
return GetWritingMode().IsVertical();
1727
case StyleOrient::Block:
1728
return !GetWritingMode().IsVertical();
1729
}
1730
MOZ_ASSERT_UNREACHABLE("unexpected -moz-orient value");
1731
return false;
1732
}
1733
1734
uint16_t nsContainerFrame::CSSAlignmentForAbsPosChild(
1735
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const {
1736
MOZ_ASSERT(aChildRI.mFrame->IsAbsolutelyPositioned(),
1737
"This method should only be called for abspos children");
1738
NS_ERROR(
1739
"Child classes that use css box alignment for abspos children "
1740
"should provide their own implementation of this method!");
1741
1742
// In the unexpected/unlikely event that this implementation gets invoked,
1743
// just use "start" alignment.
1744
return NS_STYLE_ALIGN_START;
1745
}
1746
1747
#ifdef ACCESSIBILITY
1748
void nsContainerFrame::GetSpokenMarkerText(nsAString& aText) const {
1749
aText.Truncate();
1750
const nsStyleList* myList = StyleList();
1751
if (myList->GetListStyleImage()) {
1752
char16_t kDiscCharacter = 0x2022;
1753
aText.Assign(kDiscCharacter);
1754
aText.Append(' ');
1755
return;
1756
}
1757
if (nsIFrame* marker = nsLayoutUtils::GetMarkerFrame(GetContent())) {
1758
if (nsBulletFrame* bullet = do_QueryFrame(marker)) {
1759
bullet->GetSpokenText(aText);
1760
} else {
1761
marker->GetContent()->GetTextContent(aText, IgnoreErrors());
1762
}
1763
}
1764
}
1765
#endif
1766
1767
nsOverflowContinuationTracker::nsOverflowContinuationTracker(
1768
nsContainerFrame* aFrame, bool aWalkOOFFrames,
1769
bool aSkipOverflowContainerChildren)
1770
: mOverflowContList(nullptr),
1771
mPrevOverflowCont(nullptr),
1772
mSentry(nullptr),
1773
mParent(aFrame),
1774
mSkipOverflowContainerChildren(aSkipOverflowContainerChildren),
1775
mWalkOOFFrames(aWalkOOFFrames) {
1776
MOZ_ASSERT(aFrame, "null frame pointer");
1777
SetupOverflowContList();
1778
}
1779
1780
void nsOverflowContinuationTracker::SetupOverflowContList() {
1781
MOZ_ASSERT(mParent, "null frame pointer");
1782
MOZ_ASSERT(!mOverflowContList, "already have list");
1783
nsContainerFrame* nif =
1784
static_cast<nsContainerFrame*>(mParent->GetNextInFlow());
1785
if (nif) {
1786
mOverflowContList =
1787
nif->GetPropTableFrames(nsContainerFrame::OverflowContainersProperty());
1788
if (mOverflowContList) {
1789
mParent = nif;
1790
SetUpListWalker();
1791
}
1792
}
1793
if (!mOverflowContList) {
1794
mOverflowContList = mParent->GetPropTableFrames(
1795
nsContainerFrame::ExcessOverflowContainersProperty());
1796
if (mOverflowContList) {
1797
SetUpListWalker();
1798
}
1799
}
1800
}
1801
1802
/**
1803
* Helper function to walk past overflow continuations whose prev-in-flow
1804
* isn't a normal child and to set mSentry and mPrevOverflowCont correctly.
1805
*/
1806
void nsOverflowContinuationTracker::SetUpListWalker() {
1807
NS_ASSERTION(!mSentry && !mPrevOverflowCont,
1808
"forgot to reset mSentry or mPrevOverflowCont");
1809
if (mOverflowContList) {
1810
nsIFrame* cur = mOverflowContList->FirstChild();
1811
if (mSkipOverflowContainerChildren) {
1812
while (cur && (cur->GetPrevInFlow()->GetStateBits() &