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
#ifndef nsContainerFrame_h___
10
#define nsContainerFrame_h___
11
12
#include "mozilla/Attributes.h"
13
#include "nsSplittableFrame.h"
14
#include "nsFrameList.h"
15
#include "nsLayoutUtils.h"
16
#include "nsLineBox.h"
17
18
class nsOverflowContinuationTracker;
19
20
namespace mozilla {
21
class PresShell;
22
} // namespace mozilla
23
24
// Some macros for container classes to do sanity checking on
25
// width/height/x/y values computed during reflow.
26
// NOTE: AppUnitsPerCSSPixel value hardwired here to remove the
27
// dependency on nsDeviceContext.h. It doesn't matter if it's a
28
// little off.
29
#ifdef DEBUG
30
// 10 million pixels, converted to app units. Note that this a bit larger
31
// than 1/4 of nscoord_MAX. So, if any content gets to be this large, we're
32
// definitely in danger of grazing up against nscoord_MAX; hence, it's CRAZY.
33
# define CRAZY_COORD (10000000 * 60)
34
# define CRAZY_SIZE(_x) (((_x) < -CRAZY_COORD) || ((_x) > CRAZY_COORD))
35
#endif
36
37
/**
38
* Implementation of a container frame.
39
*/
40
class nsContainerFrame : public nsSplittableFrame {
41
public:
42
NS_DECL_ABSTRACT_FRAME(nsContainerFrame)
43
NS_DECL_QUERYFRAME_TARGET(nsContainerFrame)
44
NS_DECL_QUERYFRAME
45
46
// nsIFrame overrides
47
virtual void Init(nsIContent* aContent, nsContainerFrame* aParent,
48
nsIFrame* aPrevInFlow) override;
49
virtual nsContainerFrame* GetContentInsertionFrame() override { return this; }
50
51
virtual const nsFrameList& GetChildList(ChildListID aList) const override;
52
virtual void GetChildLists(nsTArray<ChildList>* aLists) const override;
53
virtual void DestroyFrom(nsIFrame* aDestructRoot,
54
PostDestroyData& aPostDestroyData) override;
55
virtual void ChildIsDirty(nsIFrame* aChild) override;
56
57
virtual FrameSearchResult PeekOffsetNoAmount(bool aForward,
58
int32_t* aOffset) override;
59
virtual FrameSearchResult PeekOffsetCharacter(
60
bool aForward, int32_t* aOffset,
61
PeekOffsetCharacterOptions aOptions =
62
PeekOffsetCharacterOptions()) override;
63
64
#ifdef DEBUG_FRAME_DUMP
65
void List(FILE* out = stderr, const char* aPrefix = "",
66
uint32_t aFlags = 0) const override;
67
void ListWithMatchedRules(FILE* out = stderr,
68
const char* aPrefix = "") const override;
69
#endif
70
71
// nsContainerFrame methods
72
73
/**
74
* Called to set the initial list of frames. This happens after the frame
75
* has been initialized.
76
*
77
* This is only called once for a given child list, and won't be called
78
* at all for child lists with no initial list of frames.
79
*
80
* @param aListID the child list identifier.
81
* @param aChildList list of child frames. Each of the frames has its
82
* NS_FRAME_IS_DIRTY bit set. Must not be empty.
83
* This method cannot handle the child list returned by
84
* GetAbsoluteListID().
85
* @see #Init()
86
*/
87
virtual void SetInitialChildList(ChildListID aListID,
88
nsFrameList& aChildList);
89
90
/**
91
* This method is responsible for appending frames to the frame
92
* list. The implementation should append the frames to the specified
93
* child list and then generate a reflow command.
94
*
95
* @param aListID the child list identifier.
96
* @param aFrameList list of child frames to append. Each of the frames has
97
* its NS_FRAME_IS_DIRTY bit set. Must not be empty.
98
*/
99
virtual void AppendFrames(ChildListID aListID, nsFrameList& aFrameList);
100
101
/**
102
* This method is responsible for inserting frames into the frame
103
* list. The implementation should insert the new frames into the specified
104
* child list and then generate a reflow command.
105
*
106
* @param aListID the child list identifier.
107
* @param aPrevFrame the frame to insert frames <b>after</b>
108
* @param aPrevFrameLine (optional) if present (i.e., not null), the line
109
* box that aPrevFrame is part of.
110
* @param aFrameList list of child frames to insert <b>after</b> aPrevFrame.
111
* Each of the frames has its NS_FRAME_IS_DIRTY bit set
112
*/
113
virtual void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
114
const nsLineList::iterator* aPrevFrameLine,
115
nsFrameList& aFrameList);
116
117
/**
118
* This method is responsible for removing a frame in the frame
119
* list. The implementation should do something with the removed frame
120
* and then generate a reflow command. The implementation is responsible
121
* for destroying aOldFrame (the caller mustn't destroy aOldFrame).
122
*
123
* @param aListID the child list identifier.
124
* @param aOldFrame the frame to remove
125
*/
126
virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame);
127
128
/**
129
* Helper method to create next-in-flows if necessary. If aFrame
130
* already has a next-in-flow then this method does
131
* nothing. Otherwise, a new continuation frame is created and
132
* linked into the flow. In addition, the new frame is inserted
133
* into the principal child list after aFrame.
134
* @note calling this method on a block frame is illegal. Use
135
* nsBlockFrame::CreateContinuationFor() instead.
136
* @return the next-in-flow <b>if and only if</b> one is created. If
137
* a next-in-flow already exists, nullptr will be returned.
138
*/
139
nsIFrame* CreateNextInFlow(nsIFrame* aFrame);
140
141
/**
142
* Delete aNextInFlow and its next-in-flows.
143
* @param aDeletingEmptyFrames if set, then the reflow for aNextInFlow's
144
* content was complete before aNextInFlow, so aNextInFlow and its
145
* next-in-flows no longer map any real content.
146
*/
147
virtual void DeleteNextInFlowChild(nsIFrame* aNextInFlow,
148
bool aDeletingEmptyFrames);
149
150
// Positions the frame's view based on the frame's origin
151
static void PositionFrameView(nsIFrame* aKidFrame);
152
153
static nsresult ReparentFrameView(nsIFrame* aChildFrame,
154
nsIFrame* aOldParentFrame,
155
nsIFrame* aNewParentFrame);
156
157
static nsresult ReparentFrameViewList(const nsFrameList& aChildFrameList,
158
nsIFrame* aOldParentFrame,
159
nsIFrame* aNewParentFrame);
160
161
// Set the view's size and position after its frame has been reflowed.
162
//
163
// Flags:
164
// NoMoveView - don't position the frame's view. Set this if you
165
// don't want to automatically sync the frame and view
166
// NoSizeView - don't size the view
167
static void SyncFrameViewAfterReflow(
168
nsPresContext* aPresContext, nsIFrame* aFrame, nsView* aView,
169
const nsRect& aVisualOverflowArea,
170
ReflowChildFlags aFlags = ReflowChildFlags::Default);
171
172
// Syncs properties to the top level view and window, like transparency and
173
// shadow.
174
// The SET_ASYNC indicates that the actual nsIWidget calls to sync the window
175
// properties should be done async.
176
enum {
177
SET_ASYNC = 0x01,
178
};
179
static void SyncWindowProperties(nsPresContext* aPresContext,
180
nsIFrame* aFrame, nsView* aView,
181
gfxContext* aRC, uint32_t aFlags);
182
183
/**
184
* Converts the minimum and maximum sizes given in inner window app units to
185
* outer window device pixel sizes and assigns these constraints to the
186
* widget.
187
*
188
* @param aPresContext pres context
189
* @param aWidget widget for this frame
190
* @param minimum size of the window in app units
191
* @param maxmimum size of the window in app units
192
*/
193
static void SetSizeConstraints(nsPresContext* aPresContext,
194
nsIWidget* aWidget, const nsSize& aMinSize,
195
const nsSize& aMaxSize);
196
197
// Used by both nsInlineFrame and nsFirstLetterFrame.
198
void DoInlineIntrinsicISize(gfxContext* aRenderingContext,
199
InlineIntrinsicISizeData* aData,
200
nsLayoutUtils::IntrinsicISizeType aType);
201
202
/**
203
* This is the CSS block concept of computing 'auto' widths, which most
204
* classes derived from nsContainerFrame want.
205
*/
206
virtual mozilla::LogicalSize ComputeAutoSize(
207
gfxContext* aRenderingContext, mozilla::WritingMode aWM,
208
const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
209
const mozilla::LogicalSize& aMargin, const mozilla::LogicalSize& aBorder,
210
const mozilla::LogicalSize& aPadding, ComputeSizeFlags aFlags) override;
211
212
/**
213
* Positions aChildFrame and its view (if requested), and then calls Reflow().
214
* If the reflow status after reflowing the child is FULLY_COMPLETE then any
215
* next-in-flows are deleted using DeleteNextInFlowChild().
216
*
217
* @param aContainerSize size of the border-box of the containing frame
218
*
219
* Flags:
220
* NoMoveView - don't position the frame's view. Set this if you
221
* don't want to automatically sync the frame and view
222
* NoMoveFrame - don't move the frame. aPos is ignored in this
223
* case. Also implies NoMoveView
224
*/
225
void ReflowChild(nsIFrame* aChildFrame, nsPresContext* aPresContext,
226
ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
227
const mozilla::WritingMode& aWM,
228
const mozilla::LogicalPoint& aPos,
229
const nsSize& aContainerSize, ReflowChildFlags aFlags,
230
nsReflowStatus& aStatus,
231
nsOverflowContinuationTracker* aTracker = nullptr);
232
233
/**
234
* The second half of frame reflow. Does the following:
235
* - sets the frame's bounds
236
* - sizes and positions (if requested) the frame's view. If the frame's final
237
* position differs from the current position and the frame itself does not
238
* have a view, then any child frames with views are positioned so they stay
239
* in sync
240
* - sets the view's visibility, opacity, content transparency, and clip
241
* - invoked the DidReflow() function
242
*
243
* @param aContainerSize size of the border-box of the containing frame
244
*
245
* Flags:
246
* NoMoveFrame - don't move the frame. aPos is ignored in this
247
* case. Also implies NoMoveView
248
* NoMoveView - don't position the frame's view. Set this if you
249
* don't want to automatically sync the frame and view
250
* NoSizeView - don't size the frame's view
251
*/
252
static void FinishReflowChild(
253
nsIFrame* aKidFrame, nsPresContext* aPresContext,
254
const ReflowOutput& aDesiredSize, const ReflowInput* aReflowInput,
255
const mozilla::WritingMode& aWM, const mozilla::LogicalPoint& aPos,
256
const nsSize& aContainerSize, ReflowChildFlags aFlags);
257
258
// XXX temporary: hold on to a copy of the old physical versions of
259
// ReflowChild and FinishReflowChild so that we can convert callers
260
// incrementally.
261
void ReflowChild(nsIFrame* aKidFrame, nsPresContext* aPresContext,
262
ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
263
nscoord aX, nscoord aY, ReflowChildFlags aFlags,
264
nsReflowStatus& aStatus,
265
nsOverflowContinuationTracker* aTracker = nullptr);
266
267
static void FinishReflowChild(nsIFrame* aKidFrame,
268
nsPresContext* aPresContext,
269
const ReflowOutput& aDesiredSize,
270
const ReflowInput* aReflowInput, nscoord aX,
271
nscoord aY, ReflowChildFlags aFlags);
272
273
static void PositionChildViews(nsIFrame* aFrame);
274
275
// ==========================================================================
276
/* Overflow containers are continuation frames that hold overflow. They
277
* are created when the frame runs out of computed height, but still has
278
* too much content to fit in the availableHeight. The parent creates a
279
* continuation as usual, but marks it as NS_FRAME_IS_OVERFLOW_CONTAINER
280
* and adds it to its next-in-flow's overflow container list, either by
281
* adding it directly or by putting it in its own excess overflow containers
282
* list (to be drained by the next-in-flow when it calls
283
* ReflowOverflowContainerChildren). The parent continues reflow as if
284
* the frame was complete once it ran out of computed height, but returns a
285
* reflow status with either IsIncomplete() or IsOverflowIncomplete() equal
286
* to true to request a next-in-flow. The parent's next-in-flow is then
287
* responsible for calling ReflowOverflowContainerChildren to (drain and)
288
* reflow these overflow continuations. Overflow containers do not affect
289
* other frames' size or position during reflow (but do affect their
290
* parent's overflow area).
291
*
292
* Overflow container continuations are different from normal continuations
293
* in that
294
* - more than one child of the frame can have its next-in-flow broken
295
* off and pushed into the frame's next-in-flow
296
* - new continuations may need to be spliced into the middle of the list
297
* or deleted continuations slipped out
298
* e.g. A, B, C are all fixed-size containers on one page, all have
299
* overflow beyond availableHeight, and content is dynamically added
300
* and removed from B
301
* As a result, it is not possible to simply prepend the new continuations
302
* to the old list as with the overflowProperty mechanism. To avoid
303
* complicated list splicing, the code assumes only one overflow containers
304
* list exists for a given frame: either its own overflowContainersProperty
305
* or its prev-in-flow's excessOverflowContainersProperty, not both.
306
*
307
* The nsOverflowContinuationTracker helper class should be used for tracking
308
* overflow containers and adding them to the appropriate list.
309
* See nsBlockFrame::Reflow for a sample implementation.
310
*/
311
312
friend class nsOverflowContinuationTracker;
313
314
typedef void (*ChildFrameMerger)(nsFrameList& aDest, nsFrameList& aSrc,
315
nsContainerFrame* aParent);
316
static inline void DefaultChildFrameMerge(nsFrameList& aDest,
317
nsFrameList& aSrc,
318
nsContainerFrame* aParent) {
319
aDest.AppendFrames(nullptr, aSrc);
320
}
321
322
/**
323
* Reflow overflow container children. They are invisible to normal reflow
324
* (i.e. don't affect sizing or placement of other children) and inherit
325
* width and horizontal position from their prev-in-flow.
326
*
327
* This method
328
* 1. Pulls excess overflow containers from the prev-in-flow and adds
329
* them to our overflow container list
330
* 2. Reflows all our overflow container kids
331
* 3. Expands aOverflowRect as necessary to accomodate these children.
332
* 4. Sets aStatus's mOverflowIncomplete flag (along with
333
* mNextInFlowNeedsReflow as necessary) if any overflow children
334
* are incomplete and
335
* 5. Prepends a list of their continuations to our excess overflow
336
* container list, to be drained into our next-in-flow when it is
337
* reflowed.
338
*
339
* The caller is responsible for tracking any new overflow container
340
* continuations it makes, removing them from its child list, and
341
* making sure they are stored properly in the overflow container lists.
342
* The nsOverflowContinuationTracker helper class should be used for this.
343
*
344
* @param aFlags is passed through to ReflowChild
345
* @param aMergeFunc is passed to DrainExcessOverflowContainersList
346
*/
347
void ReflowOverflowContainerChildren(
348
nsPresContext* aPresContext, const ReflowInput& aReflowInput,
349
nsOverflowAreas& aOverflowRects, ReflowChildFlags aFlags,
350
nsReflowStatus& aStatus,
351
ChildFrameMerger aMergeFunc = DefaultChildFrameMerge);
352
353
/**
354
* Move any frames on our overflow list to the end of our principal list.
355
* @return true if there were any overflow frames
356
*/
357
virtual bool DrainSelfOverflowList() override;
358
359
/**
360
* Move all frames on our prev-in-flow's and our own ExcessOverflowContainers
361
* lists to our OverflowContainers list. If there are frames on multiple
362
* lists they are merged using aMergeFunc.
363
* @return a pointer to our OverflowContainers list, if any
364
*/
365
nsFrameList* DrainExcessOverflowContainersList(
366
ChildFrameMerger aMergeFunc = DefaultChildFrameMerge);
367
368
/**
369
* Removes aChild without destroying it and without requesting reflow.
370
* Continuations are not affected. Checks the principal and overflow lists,
371
* and also the [excess] overflow containers lists if the frame bit
372
* NS_FRAME_IS_OVERFLOW_CONTAINER is set. It does not check any other lists.
373
* Returns NS_ERROR_UNEXPECTED if aChild wasn't found on any of the lists
374
* mentioned above.
375
*/
376
virtual nsresult StealFrame(nsIFrame* aChild);
377
378
/**
379
* Removes the next-siblings of aChild without destroying them and without
380
* requesting reflow. Checks the principal and overflow lists (not
381
* overflow containers / excess overflow containers). Does not check any
382
* other auxiliary lists.
383
* @param aChild a child frame or nullptr
384
* @return If aChild is non-null, the next-siblings of aChild, if any.
385
* If aChild is null, all child frames on the principal list, if any.
386
*/
387
nsFrameList StealFramesAfter(nsIFrame* aChild);
388
389
/**
390
* Add overflow containers to the display list
391
*/
392
void DisplayOverflowContainers(nsDisplayListBuilder* aBuilder,
393
const nsDisplayListSet& aLists);
394
395
/**
396
* Builds display lists for the children. The background
397
* of each child is placed in the Content() list (suitable for inline
398
* children and other elements that behave like inlines,
399
* but not for in-flow block children of blocks). DOES NOT
400
* paint the background/borders/outline of this frame. This should
401
* probably be avoided and eventually removed. It's currently here
402
* to emulate what nsContainerFrame::Paint did.
403
*/
404
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
405
const nsDisplayListSet& aLists) override;
406
407
static void PlaceFrameView(nsIFrame* aFrame) {
408
if (aFrame->HasView())
409
nsContainerFrame::PositionFrameView(aFrame);
410
else
411
nsContainerFrame::PositionChildViews(aFrame);
412
}
413
414
/**
415
* Returns a CSS Box Alignment constant which the caller can use to align
416
* the absolutely-positioned child (whose ReflowInput is aChildRI) within
417
* a CSS Box Alignment area associated with this container.
418
*
419
* The lower 8 bits of the returned value are guaranteed to form a valid
420
* argument for CSSAlignUtils::AlignJustifySelf(). (The upper 8 bits may
421
* encode an <overflow-position>.)
422
*
423
* NOTE: This default nsContainerFrame implementation is a stub, and isn't
424
* meant to be called. Subclasses must provide their own implementations, if
425
* they use CSS Box Alignment to determine the static position of their
426
* absolutely-positioned children. (Though: if subclasses share enough code,
427
* maybe this nsContainerFrame impl should include some shared code.)
428
*
429
* @param aChildRI A ReflowInput for the positioned child frame that's being
430
* aligned.
431
* @param aLogicalAxis The axis (of this container frame) in which the caller
432
* would like to align the child frame.
433
*/
434
virtual uint16_t CSSAlignmentForAbsPosChild(
435
const ReflowInput& aChildRI, mozilla::LogicalAxis aLogicalAxis) const;
436
437
#ifdef ACCESSIBILITY
438
/**
439
* Return the ::marker text equivalent, without flushing.
440
*/
441
void GetSpokenMarkerText(nsAString& aText) const;
442
#endif
443
444
#define NS_DECLARE_FRAME_PROPERTY_FRAMELIST(prop) \
445
NS_DECLARE_FRAME_PROPERTY_WITH_DTOR_NEVER_CALLED(prop, nsFrameList)
446
447
typedef PropertyDescriptor<nsFrameList> FrameListPropertyDescriptor;
448
449
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OverflowProperty)
450
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(OverflowContainersProperty)
451
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(ExcessOverflowContainersProperty)
452
NS_DECLARE_FRAME_PROPERTY_FRAMELIST(BackdropProperty)
453
454
// Only really used on nsBlockFrame instances, but the caller thinks it could
455
// have arbitrary nsContainerFrames.
456
NS_DECLARE_FRAME_PROPERTY_WITHOUT_DTOR(FirstLetterProperty, nsIFrame)
457
458
void SetHasFirstLetterChild() { mHasFirstLetterChild = true; }
459
460
void ClearHasFirstLetterChild() { mHasFirstLetterChild = false; }
461
462
#ifdef DEBUG
463
// Use this to suppress the CRAZY_SIZE assertions.
464
NS_DECLARE_FRAME_PROPERTY_SMALL_VALUE(DebugReflowingWithInfiniteISize, bool)
465
bool IsCrazySizeAssertSuppressed() const {
466
return GetProperty(DebugReflowingWithInfiniteISize());
467
}
468
#endif
469
470
protected:
471
nsContainerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
472
ClassID aID)
473
: nsSplittableFrame(aStyle, aPresContext, aID) {}
474
475
~nsContainerFrame();
476
477
/**
478
* Helper for DestroyFrom. DestroyAbsoluteFrames is called before
479
* destroying frames on lists that can contain placeholders.
480
* Derived classes must do that too, if they destroy such frame lists.
481
* See nsBlockFrame::DestroyFrom for an example.
482
*/
483
void DestroyAbsoluteFrames(nsIFrame* aDestructRoot,
484
PostDestroyData& aPostDestroyData);
485
486
/**
487
* Helper for StealFrame. Returns true if aChild was removed from its list.
488
*/
489
bool MaybeStealOverflowContainerFrame(nsIFrame* aChild);
490
491
/**
492
* Builds a display list for non-block children that behave like
493
* inlines. This puts the background of each child into the
494
* Content() list (suitable for inline children but not for
495
* in-flow block children of blocks).
496
* @param aForcePseudoStack forces each child into a pseudo-stacking-context
497
* so its background and all other display items (except for positioned
498
* display items) go into the Content() list.
499
*/
500
void BuildDisplayListForNonBlockChildren(nsDisplayListBuilder* aBuilder,
501
const nsDisplayListSet& aLists,
502
uint32_t aFlags = 0);
503
504
/**
505
* A version of BuildDisplayList that use DISPLAY_CHILD_INLINE.
506
* Intended as a convenience for derived classes.
507
*/
508
void BuildDisplayListForInline(nsDisplayListBuilder* aBuilder,
509
const nsDisplayListSet& aLists) {
510
DisplayBorderBackgroundOutline(aBuilder, aLists);
511
BuildDisplayListForNonBlockChildren(aBuilder, aLists, DISPLAY_CHILD_INLINE);
512
}
513
514
// ==========================================================================
515
/* Overflow Frames are frames that did not fit and must be pulled by
516
* our next-in-flow during its reflow. (The same concept for overflow
517
* containers is called "excess frames". We should probably make the
518
* names match.)
519
*/
520
521
/**
522
* Get the frames on the overflow list. Can return null if there are no
523
* overflow frames. The caller does NOT take ownership of the list; it's
524
* still owned by this frame. A non-null return value indicates that the
525
* list is nonempty.
526
*/
527
inline nsFrameList* GetOverflowFrames() const;
528
529
/**
530
* As GetOverflowFrames, but removes the overflow frames property. The
531
* caller is responsible for deleting nsFrameList and either passing
532
* ownership of the frames to someone else or destroying the frames.
533
* A non-null return value indicates that the list is nonempty. The
534
* recommended way to use this function it to assign its return value
535
* into an AutoFrameListPtr.
536
*/
537
inline nsFrameList* StealOverflowFrames();
538
539
/**
540
* Set the overflow list. aOverflowFrames must not be an empty list.
541
*/
542
void SetOverflowFrames(const nsFrameList& aOverflowFrames);
543
544
/**
545
* Destroy the overflow list, which must be empty.
546
*/
547
inline void DestroyOverflowList();
548
549
/**
550
* Moves any frames on both the prev-in-flow's overflow list and the
551
* receiver's overflow to the receiver's child list.
552
*
553
* Resets the overlist pointers to nullptr, and updates the receiver's child
554
* count and content mapping.
555
*
556
* @return true if any frames were moved and false otherwise
557
*/
558
bool MoveOverflowToChildList();
559
560
/**
561
* Basically same as MoveOverflowToChildList, except that this is for
562
* handling inline children where children of prev-in-flow can be
563
* pushed to overflow list even if a next-in-flow exists.
564
*
565
* @param aLineContainer the line container of the current frame.
566
*
567
* @return true if any frames were moved and false otherwise
568
*/
569
bool MoveInlineOverflowToChildList(nsIFrame* aLineContainer);
570
571
/**
572
* Push aFromChild and its next siblings to the overflow list.
573
*
574
* @param aFromChild the first child frame to push. It is disconnected
575
* from aPrevSibling
576
* @param aPrevSibling aFrameChild's previous sibling. Must not be null.
577
* It's an error to push a parent's first child frame.
578
*/
579
void PushChildrenToOverflow(nsIFrame* aFromChild, nsIFrame* aPrevSibling);
580
581
/**
582
* Same as above, except that this pushes frames to the next-in-flow
583
* frame and changes the geometric parent of the pushed frames when
584
* there is a next-in-flow frame.
585
*
586
* Updates the next-in-flow's child count. Does <b>not</b> update the
587
* pusher's child count.
588
*/
589
void PushChildren(nsIFrame* aFromChild, nsIFrame* aPrevSibling);
590
591
/**
592
* Reparent floats whose placeholders are inline descendants of aFrame from
593
* whatever block they're currently parented by to aOurBlock.
594
* @param aReparentSiblings if this is true, we follow aFrame's
595
* GetNextSibling chain reparenting them all
596
*/
597
static void ReparentFloatsForInlineChild(nsIFrame* aOurBlock,
598
nsIFrame* aFrame,
599
bool aReparentSiblings);
600
601
// ==========================================================================
602
/*
603
* Convenience methods for traversing continuations
604
*/
605
606
struct ContinuationTraversingState {
607
nsContainerFrame* mNextInFlow;
608
explicit ContinuationTraversingState(nsContainerFrame* aFrame)
609
: mNextInFlow(static_cast<nsContainerFrame*>(aFrame->GetNextInFlow())) {
610
}
611
};
612
613
/**
614
* Find the first frame that is a child of this frame's next-in-flows,
615
* considering both their principal child lists and overflow lists.
616
*/
617
nsIFrame* GetNextInFlowChild(ContinuationTraversingState& aState,
618
bool* aIsInOverflow = nullptr);
619
620
/**
621
* Remove the result of GetNextInFlowChild from its current parent and
622
* append it to this frame's principal child list.
623
*/
624
nsIFrame* PullNextInFlowChild(ContinuationTraversingState& aState);
625
626
// ==========================================================================
627
/*
628
* Convenience methods for nsFrameLists stored in the
629
* PresContext's proptable
630
*/
631
632
/**
633
* Get the PresContext-stored nsFrameList named aPropID for this frame.
634
* May return null.
635
*/
636
nsFrameList* GetPropTableFrames(FrameListPropertyDescriptor aProperty) const;
637
638
/**
639
* Remove and return the PresContext-stored nsFrameList named aPropID for
640
* this frame. May return null.
641
*/
642
nsFrameList* RemovePropTableFrames(FrameListPropertyDescriptor aProperty);
643
644
/**
645
* Set the PresContext-stored nsFrameList named aPropID for this frame
646
* to the given aFrameList, which must not be null.
647
*/
648
void SetPropTableFrames(nsFrameList* aFrameList,
649
FrameListPropertyDescriptor aProperty);
650
651
/**
652
* Safely destroy the frames on the nsFrameList stored on aProp for this
653
* frame then remove the property and delete the frame list.
654
* Nothing happens if the property doesn't exist.
655
*/
656
void SafelyDestroyFrameListProp(nsIFrame* aDestructRoot,
657
PostDestroyData& aPostDestroyData,
658
mozilla::PresShell* aPresShell,
659
FrameListPropertyDescriptor aProp);
660
661
// ==========================================================================
662
663
// Helper used by Progress and Meter frames. Returns true if the bar should
664
// be rendered vertically, based on writing-mode and -moz-orient properties.
665
bool ResolvedOrientationIsVertical();
666
667
// ==========================================================================
668
669
nsFrameList mFrames;
670
};
671
672
// ==========================================================================
673
/* The out-of-flow-related code below is for a hacky way of splitting
674
* absolutely-positioned frames. Basically what we do is split the frame
675
* in nsAbsoluteContainingBlock and pretend the continuation is an overflow
676
* container. This isn't an ideal solution, but it lets us print the content
677
* at least. See bug 154892.
678
*/
679
680
#define IS_TRUE_OVERFLOW_CONTAINER(frame) \
681
((frame->GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) && \
682
!((frame->GetStateBits() & NS_FRAME_OUT_OF_FLOW) && \
683
frame->IsAbsolutelyPositioned()))
684
// XXXfr This check isn't quite correct, because it doesn't handle cases
685
// where the out-of-flow has overflow.. but that's rare.
686
// We'll need to revisit the way abspos continuations are handled later
687
// for various reasons, this detail is one of them. See bug 154892
688
689
/**
690
* Helper class for tracking overflow container continuations during reflow.
691
*
692
* A frame is related to two sets of overflow containers: those that /are/
693
* its own children, and those that are /continuations/ of its children.
694
* This tracker walks through those continuations (the frame's NIF's children)
695
* and their prev-in-flows (a subset of the frame's normal and overflow
696
* container children) in parallel. It allows the reflower to synchronously
697
* walk its overflow continuations while it loops through and reflows its
698
* children. This makes it possible to insert new continuations at the correct
699
* place in the overflow containers list.
700
*
701
* The reflower is expected to loop through its children in the same order it
702
* looped through them the last time (if there was a last time).
703
* For each child, the reflower should either
704
* - call Skip for the child if was not reflowed in this pass
705
* - call Insert for the overflow continuation if the child was reflowed
706
* but has incomplete overflow
707
* - call Finished for the child if it was reflowed in this pass but
708
* is either complete or has a normal next-in-flow. This call can
709
* be skipped if the child did not previously have an overflow
710
* continuation.
711
*/
712
class nsOverflowContinuationTracker {
713
public:
714
/**
715
* Initializes an nsOverflowContinuationTracker to help track overflow
716
* continuations of aFrame's children. Typically invoked on 'this'.
717
*
718
* aWalkOOFFrames determines whether the walker skips out-of-flow frames
719
* or skips non-out-of-flow frames.
720
*
721
* Don't set aSkipOverflowContainerChildren to false unless you plan
722
* to walk your own overflow container children. (Usually they are handled
723
* by calling ReflowOverflowContainerChildren.) aWalkOOFFrames is ignored
724
* if aSkipOverflowContainerChildren is false.
725
*/
726
nsOverflowContinuationTracker(nsContainerFrame* aFrame, bool aWalkOOFFrames,
727
bool aSkipOverflowContainerChildren = true);
728
/**
729
* This function adds an overflow continuation to our running list and
730
* sets its NS_FRAME_IS_OVERFLOW_CONTAINER flag.
731
*
732
* aReflowStatus should preferably be specific to the recently-reflowed
733
* child and not influenced by any of its siblings' statuses. This
734
* function sets the NS_FRAME_IS_DIRTY bit on aOverflowCont if it needs
735
* to be reflowed. (Its need for reflow depends on changes to its
736
* prev-in-flow, not to its parent--for whom it is invisible, reflow-wise.)
737
*
738
* The caller MUST disconnect the frame from its parent's child list
739
* if it was not previously an NS_FRAME_IS_OVERFLOW_CONTAINER (because
740
* StealFrame is much more inefficient than disconnecting in place
741
* during Reflow, which the caller is able to do but we are not).
742
*
743
* The caller MUST NOT disconnect the frame from its parent's
744
* child list if it is already an NS_FRAME_IS_OVERFLOW_CONTAINER.
745
* (In this case we will disconnect and reconnect it ourselves.)
746
*/
747
nsresult Insert(nsIFrame* aOverflowCont, nsReflowStatus& aReflowStatus);
748
/**
749
* Begin/EndFinish() must be called for each child that is reflowed
750
* but no longer has an overflow continuation. (It may be called for
751
* other children, but in that case has no effect.) It increments our
752
* walker and makes sure we drop any dangling pointers to its
753
* next-in-flow. This function MUST be called before stealing or
754
* deleting aChild's next-in-flow.
755
* The AutoFinish helper object does that for you. Use it like so:
756
* if (kidNextInFlow) {
757
* nsOverflowContinuationTracker::AutoFinish fini(tracker, kid);
758
* ... DeleteNextInFlowChild/StealFrame(kidNextInFlow) here ...
759
* }
760
*/
761
class MOZ_RAII AutoFinish {
762
public:
763
AutoFinish(nsOverflowContinuationTracker* aTracker, nsIFrame* aChild)
764
: mTracker(aTracker), mChild(aChild) {
765
if (mTracker) mTracker->BeginFinish(mChild);
766
}
767
~AutoFinish() {
768
if (mTracker) mTracker->EndFinish(mChild);
769
}
770
771
private:
772
nsOverflowContinuationTracker* mTracker;
773
nsIFrame* mChild;
774
};
775
776
/**
777
* This function should be called for each child that isn't reflowed.
778
* It increments our walker and sets the mOverflowIncomplete
779
* reflow flag if it encounters an overflow continuation so that our
780
* next-in-flow doesn't get prematurely deleted. It MUST be called on
781
* each unreflowed child that has an overflow container continuation;
782
* it MAY be called on other children, but it isn't necessary (doesn't
783
* do anything).
784
*/
785
void Skip(nsIFrame* aChild, nsReflowStatus& aReflowStatus) {
786
MOZ_ASSERT(aChild, "null ptr");
787
if (aChild == mSentry) {
788
StepForward();
789
if (aReflowStatus.IsComplete()) {
790
aReflowStatus.SetOverflowIncomplete();
791
}
792
}
793
}
794
795
private:
796
/**
797
* @see class AutoFinish
798
*/
799
void BeginFinish(nsIFrame* aChild);
800
void EndFinish(nsIFrame* aChild);
801
802
void SetupOverflowContList();
803
void SetUpListWalker();
804
void StepForward();
805
806
/* We hold a pointer to either the next-in-flow's overflow containers list
807
or, if that doesn't exist, our frame's excess overflow containers list.
808
We need to make sure that we drop that pointer if the list becomes
809
empty and is deleted elsewhere. */
810
nsFrameList* mOverflowContList;
811
/* We hold a pointer to the most recently-reflowed child that has an
812
overflow container next-in-flow. We do this because it's a known
813
good point; this pointer won't be deleted on us. We can use it to
814
recover our place in the list. */
815
nsIFrame* mPrevOverflowCont;
816
/* This is a pointer to the next overflow container's prev-in-flow, which
817
is (or should be) a child of our frame. When we hit this, we will need
818
to increment this walker to the next overflow container. */
819
nsIFrame* mSentry;
820
/* Parent of all frames in mOverflowContList. If our mOverflowContList
821
is an excessOverflowContainersProperty, or null, then this is our frame
822
(the frame that was passed in to our constructor). Otherwise this is
823
that frame's next-in-flow, and our mOverflowContList is mParent's
824
overflowContainersProperty */
825
nsContainerFrame* mParent;
826
/* Tells SetUpListWalker whether or not to walk us past any continuations
827
of overflow containers. aWalkOOFFrames is ignored when this is false. */
828
bool mSkipOverflowContainerChildren;
829
/* Tells us whether to pay attention to OOF frames or non-OOF frames */
830
bool mWalkOOFFrames;
831
};
832
833
inline nsFrameList* nsContainerFrame::GetOverflowFrames() const {
834
nsFrameList* list = GetProperty(OverflowProperty());
835
NS_ASSERTION(!list || !list->IsEmpty(), "Unexpected empty overflow list");
836
return list;
837
}
838
839
inline nsFrameList* nsContainerFrame::StealOverflowFrames() {
840
nsFrameList* list = RemoveProperty(OverflowProperty());
841
NS_ASSERTION(!list || !list->IsEmpty(), "Unexpected empty overflow list");
842
return list;
843
}
844
845
inline void nsContainerFrame::DestroyOverflowList() {
846
nsFrameList* list = RemovePropTableFrames(OverflowProperty());
847
MOZ_ASSERT(list && list->IsEmpty());
848
list->Delete(PresShell());
849
}
850
851
#endif /* nsContainerFrame_h___ */