Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / layout / tables / nsTableFrame.h
blob0204af983450a3c0c2b3ee3f6fb9b1ebebee4556
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsTableFrame_h__
6 #define nsTableFrame_h__
8 #include "mozilla/Attributes.h"
9 #include "celldata.h"
10 #include "nscore.h"
11 #include "nsContainerFrame.h"
12 #include "nsStyleConsts.h"
13 #include "nsCellMap.h"
14 #include "nsGkAtoms.h"
15 #include "nsDisplayList.h"
16 #include "TableArea.h"
18 struct BCPaintBorderAction;
19 class nsTableCellFrame;
20 class nsTableCellMap;
21 class nsTableColFrame;
22 class nsTableRowGroupFrame;
23 class nsTableRowFrame;
24 class nsTableColGroupFrame;
25 class nsITableLayoutStrategy;
27 namespace mozilla {
28 class LogicalMargin;
29 class PresShell;
30 class WritingMode;
31 struct TableBCData;
32 struct TableReflowInput;
34 namespace layers {
35 class StackingContextHelper;
38 // An input to nsTableFrame::ReflowTable() and TableReflowInput.
39 enum class TableReflowMode : uint8_t {
40 // A reflow to measure the block-size of the table. We use this value to
41 // request an unconstrained available block in the first reflow if a second
42 // special block-size reflow is needed later.
43 Measuring,
45 // A final reflow with the available block-size in the table frame's
46 // ReflowInput.
47 Final,
50 class nsDisplayTableItem : public nsPaintedDisplayItem {
51 public:
52 nsDisplayTableItem(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
53 : nsPaintedDisplayItem(aBuilder, aFrame) {}
55 // With collapsed borders, parts of the collapsed border can extend outside
56 // the table part frames, so allow this display element to blow out to our
57 // overflow rect. This is also useful for row frames that have spanning
58 // cells extending outside them.
59 nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override;
62 class nsDisplayTableBackgroundSet {
63 public:
64 nsDisplayList* ColGroupBackgrounds() { return &mColGroupBackgrounds; }
66 nsDisplayList* ColBackgrounds() { return &mColBackgrounds; }
68 nsDisplayTableBackgroundSet(nsDisplayListBuilder* aBuilder, nsIFrame* aTable);
70 ~nsDisplayTableBackgroundSet() {
71 mozilla::DebugOnly<nsDisplayTableBackgroundSet*> result =
72 mBuilder->SetTableBackgroundSet(mPrevTableBackgroundSet);
73 MOZ_ASSERT(result == this);
76 /**
77 * Move all display items in our lists to top of the corresponding lists in
78 * the destination.
80 void MoveTo(const nsDisplayListSet& aDestination) {
81 aDestination.BorderBackground()->AppendToTop(ColGroupBackgrounds());
82 aDestination.BorderBackground()->AppendToTop(ColBackgrounds());
85 void AddColumn(nsTableColFrame* aFrame) { mColumns.AppendElement(aFrame); }
87 nsTableColFrame* GetColForIndex(int32_t aIndex) { return mColumns[aIndex]; }
89 const nsPoint& TableToReferenceFrame() { return mToReferenceFrame; }
91 const nsRect& GetDirtyRect() { return mDirtyRect; }
93 const DisplayItemClipChain* GetTableClipChain() {
94 return mCombinedTableClipChain;
97 const ActiveScrolledRoot* GetTableASR() { return mTableASR; }
98 layers::ScrollableLayerGuid::ViewID GetScrollParentId() {
99 return mCurrentScrollParentId;
102 private:
103 // This class is only used on stack, so we don't have to worry about leaking
104 // it. Don't let us be heap-allocated!
105 void* operator new(size_t sz) noexcept(true);
107 protected:
108 nsDisplayListBuilder* mBuilder;
109 nsDisplayTableBackgroundSet* mPrevTableBackgroundSet;
111 nsDisplayList mColGroupBackgrounds;
112 nsDisplayList mColBackgrounds;
114 nsTArray<nsTableColFrame*> mColumns;
115 nsPoint mToReferenceFrame;
116 nsRect mDirtyRect;
117 layers::ScrollableLayerGuid::ViewID mCurrentScrollParentId;
119 const DisplayItemClipChain* mCombinedTableClipChain;
120 const ActiveScrolledRoot* mTableASR;
123 } // namespace mozilla
125 /* ========================================================================== */
127 enum nsTableColType {
128 eColContent = 0, // there is real col content associated
129 eColAnonymousCol = 1, // the result of a span on a col
130 eColAnonymousColGroup = 2, // the result of a span on a col group
131 eColAnonymousCell = 3 // the result of a cell alone
135 * nsTableFrame maps the inner portion of a table (everything except captions.)
136 * Used as a pseudo-frame within nsTableWrapperFrame, it may also be used
137 * stand-alone as the top-level frame.
139 * The principal child list contains row group frames. There is also an
140 * additional child list, FrameChildListID::ColGroup, which contains the col
141 * group frames.
143 class nsTableFrame : public nsContainerFrame {
144 typedef mozilla::image::ImgDrawResult ImgDrawResult;
145 typedef mozilla::WritingMode WritingMode;
146 typedef mozilla::LogicalMargin LogicalMargin;
148 public:
149 NS_DECL_FRAMEARENA_HELPERS(nsTableFrame)
151 typedef nsTArray<nsIFrame*> FrameTArray;
152 NS_DECLARE_FRAME_PROPERTY_DELETABLE(PositionedTablePartArray, FrameTArray)
154 /** nsTableWrapperFrame has intimate knowledge of the inner table frame */
155 friend class nsTableWrapperFrame;
158 * instantiate a new instance of nsTableRowFrame.
160 * @param aPresShell the pres shell for this frame
162 * @return the frame that was created
164 friend nsTableFrame* NS_NewTableFrame(mozilla::PresShell* aPresShell,
165 ComputedStyle* aStyle);
167 /** sets defaults for table-specific style.
168 * @see nsIFrame::Init
170 void Init(nsIContent* aContent, nsContainerFrame* aParent,
171 nsIFrame* aPrevInFlow) override;
173 // Return true if aParentReflowInput.frame or any of its ancestors within
174 // the containing table have non-auto bsize. (e.g. pct or fixed bsize)
175 static bool AncestorsHaveStyleBSize(const ReflowInput& aParentReflowInput);
177 // See if a special bsize reflow will occur due to having a pct bsize when
178 // the pct bsize basis may not yet be valid.
179 static void CheckRequestSpecialBSizeReflow(const ReflowInput& aReflowInput);
181 // Notify the frame and its ancestors (up to the containing table) that a
182 // special height reflow will occur.
183 static void RequestSpecialBSizeReflow(const ReflowInput& aReflowInput);
185 static void RePositionViews(nsIFrame* aFrame);
187 static bool PageBreakAfter(nsIFrame* aSourceFrame, nsIFrame* aNextFrame);
189 // Register or deregister a positioned table part with its nsTableFrame.
190 // These objects will be visited by FixupPositionedTableParts after reflow is
191 // complete. (See that function for more explanation.) Should be called
192 // during frame construction or style recalculation.
194 // @return true if the frame is a registered positioned table part.
195 static void PositionedTablePartMaybeChanged(
196 nsIFrame*, mozilla::ComputedStyle* aOldStyle);
198 // Unregister a positioned table part with its nsTableFrame, if needed.
199 static void MaybeUnregisterPositionedTablePart(nsIFrame* aFrame);
202 * Notification that rowspan or colspan has changed for content inside a
203 * table cell
205 void RowOrColSpanChanged(nsTableCellFrame* aCellFrame);
207 /** @see nsIFrame::DestroyFrom */
208 void Destroy(DestroyContext&) override;
210 /** @see nsIFrame::DidSetComputedStyle */
211 void DidSetComputedStyle(ComputedStyle* aOldComputedStyle) override;
213 void SetInitialChildList(ChildListID aListID,
214 nsFrameList&& aChildList) override;
215 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
216 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
217 const nsLineList::iterator* aPrevFrameLine,
218 nsFrameList&& aFrameList) override;
219 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
221 nsMargin GetUsedBorder() const override;
222 nsMargin GetUsedPadding() const override;
223 nsMargin GetUsedMargin() const override;
225 /** helper method to find the table parent of any table frame object */
226 static nsTableFrame* GetTableFrame(nsIFrame* aSourceFrame);
228 // Return the closest sibling of aPriorChildFrame (including aPriroChildFrame)
229 // of type aChildType.
230 static nsIFrame* GetFrameAtOrBefore(nsIFrame* aParentFrame,
231 nsIFrame* aPriorChildFrame,
232 mozilla::LayoutFrameType aChildType);
233 bool IsAutoBSize(mozilla::WritingMode aWM);
235 /** @return true if aDisplayType represents a rowgroup of any sort
236 * (header, footer, or body)
238 bool IsRowGroup(mozilla::StyleDisplay aDisplayType) const;
240 const nsFrameList& GetChildList(ChildListID aListID) const override;
241 void GetChildLists(nsTArray<ChildList>* aLists) const override;
243 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
244 const nsDisplayListSet& aLists) override;
246 /** Get the outer half (i.e., the part outside the height and width of
247 * the table) of the largest segment (?) of border-collapsed border on
248 * the table on each side, or 0 for non border-collapsed tables.
250 LogicalMargin GetOuterBCBorder(const WritingMode aWM) const;
252 /** Same as above, but only if it's included from the border-box width
253 * of the table.
255 LogicalMargin GetIncludedOuterBCBorder(const WritingMode aWM) const;
257 /** Same as above, but only if it's excluded from the border-box width
258 * of the table. This is the area that leaks out into the margin
259 * (or potentially past it, if there is no margin).
261 LogicalMargin GetExcludedOuterBCBorder(const WritingMode aWM) const;
264 * Emplace our border and padding in aBorder and aPadding if we are
265 * border-collapsed. Otherwise, do nothing.
267 void GetCollapsedBorderPadding(
268 mozilla::Maybe<mozilla::LogicalMargin>& aBorder,
269 mozilla::Maybe<mozilla::LogicalMargin>& aPadding) const;
271 friend class nsDelayedCalcBCBorders;
273 void AddBCDamageArea(const mozilla::TableArea& aValue);
274 bool BCRecalcNeeded(ComputedStyle* aOldComputedStyle,
275 ComputedStyle* aNewComputedStyle);
276 void PaintBCBorders(DrawTarget& aDrawTarget, const nsRect& aDirtyRect);
277 void CreateWebRenderCommandsForBCBorders(
278 mozilla::wr::DisplayListBuilder& aBuilder,
279 const mozilla::layers::StackingContextHelper& aSc,
280 const nsRect& aVisibleRect, const nsPoint& aOffsetToReferenceFrame);
282 void MarkIntrinsicISizesDirty() override;
283 // For border-collapse tables, the caller must not add padding and
284 // border to the results of these functions.
285 nscoord GetMinISize(gfxContext* aRenderingContext) override;
286 nscoord GetPrefISize(gfxContext* aRenderingContext) override;
287 IntrinsicSizeOffsetData IntrinsicISizeOffsets(
288 nscoord aPercentageBasis = NS_UNCONSTRAINEDSIZE) override;
290 SizeComputationResult ComputeSize(
291 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
292 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
293 const mozilla::LogicalSize& aMargin,
294 const mozilla::LogicalSize& aBorderPadding,
295 const mozilla::StyleSizeOverrides& aSizeOverrides,
296 mozilla::ComputeSizeFlags aFlags) override;
298 mozilla::LogicalSize ComputeAutoSize(
299 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
300 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
301 const mozilla::LogicalSize& aMargin,
302 const mozilla::LogicalSize& aBorderPadding,
303 const mozilla::StyleSizeOverrides& aSizeOverrides,
304 mozilla::ComputeSizeFlags aFlags) override;
307 * A copy of nsIFrame::ShrinkISizeToFit that calls a different
308 * GetPrefISize, since tables have two different ones.
310 nscoord TableShrinkISizeToFit(gfxContext* aRenderingContext,
311 nscoord aWidthInCB);
313 // XXXldb REWRITE THIS COMMENT!
314 // clang-format off
316 * Inner tables are reflowed in two steps.
317 * <pre>
318 * if mFirstPassValid is false, this is our first time through since content was last changed
319 * set pass to 1
320 * do pass 1
321 * get min/max info for all cells in an infinite space
322 * do column balancing
323 * set mFirstPassValid to true
324 * do pass 2
325 * use column widths to Reflow cells
326 * </pre>
328 * @see nsIFrame::Reflow
330 // clang-format on
331 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
332 const ReflowInput& aReflowInput,
333 nsReflowStatus& aStatus) override;
335 void ReflowTable(ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
336 const LogicalMargin& aBorderPadding,
337 mozilla::TableReflowMode aReflowMode,
338 nsIFrame*& aLastChildReflowed, nsReflowStatus& aStatus);
340 nsFrameList& GetColGroups();
342 ComputedStyle* GetParentComputedStyle(
343 nsIFrame** aProviderFrame) const override;
345 #ifdef DEBUG_FRAME_DUMP
346 /** @see nsIFrame::GetFrameName */
347 nsresult GetFrameName(nsAString& aResult) const override;
348 #endif
350 /** Return the isize of the column at aColIndex.
351 * This may only be called on the table's first-in-flow.
353 nscoord GetColumnISizeFromFirstInFlow(int32_t aColIndex);
355 /** Helper to get the column spacing style value.
356 * The argument refers to the space between column aColIndex and column
357 * aColIndex + 1. An index of -1 indicates the padding between the table
358 * and the left border, an index equal to the number of columns indicates
359 * the padding between the table and the right border.
361 * Although in this class cell spacing does not depend on the index, it
362 * may be important for overriding classes.
364 virtual nscoord GetColSpacing(int32_t aColIndex);
366 /** Helper to find the sum of the cell spacing between arbitrary columns.
367 * The argument refers to the space between column aColIndex and column
368 * aColIndex + 1. An index of -1 indicates the padding between the table
369 * and the left border, an index equal to the number of columns indicates
370 * the padding between the table and the right border.
372 * This method is equivalent to
373 * nscoord result = 0;
374 * for (i = aStartColIndex; i < aEndColIndex; i++) {
375 * result += GetColSpacing(i);
377 * return result;
379 virtual nscoord GetColSpacing(int32_t aStartColIndex, int32_t aEndColIndex);
381 /** Helper to get the row spacing style value.
382 * The argument refers to the space between row aRowIndex and row
383 * aRowIndex + 1. An index of -1 indicates the padding between the table
384 * and the top border, an index equal to the number of rows indicates
385 * the padding between the table and the bottom border.
387 * Although in this class cell spacing does not depend on the index, it
388 * may be important for overriding classes.
390 virtual nscoord GetRowSpacing(int32_t aRowIndex);
392 /** Helper to find the sum of the cell spacing between arbitrary rows.
393 * The argument refers to the space between row aRowIndex and row
394 * aRowIndex + 1. An index of -1 indicates the padding between the table
395 * and the top border, an index equal to the number of rows indicates
396 * the padding between the table and the bottom border.
398 * This method is equivalent to
399 * nscoord result = 0;
400 * for (i = aStartRowIndex; i < aEndRowIndex; i++) {
401 * result += GetRowSpacing(i);
403 * return result;
405 virtual nscoord GetRowSpacing(int32_t aStartRowIndex, int32_t aEndRowIndex);
407 private:
408 /* For the base implementation of nsTableFrame, cell spacing does not depend
409 * on row/column indexing.
411 nscoord GetColSpacing();
412 nscoord GetRowSpacing();
414 public:
415 nscoord SynthesizeFallbackBaseline(
416 mozilla::WritingMode aWM,
417 BaselineSharingGroup aBaselineGroup) const override;
418 Maybe<nscoord> GetNaturalBaselineBOffset(
419 mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
420 BaselineExportContext) const override;
422 /** return the row span of a cell, taking into account row span magic at the
423 * bottom of a table. The row span equals the number of rows spanned by aCell
424 * starting at aStartRowIndex, and can be smaller if aStartRowIndex is greater
425 * than the row index in which aCell originates.
427 * @param aStartRowIndex the cell
428 * @param aCell the cell
430 * @return the row span, correcting for row spans that extend beyond the
431 * bottom of the table.
433 int32_t GetEffectiveRowSpan(int32_t aStartRowIndex,
434 const nsTableCellFrame& aCell) const;
435 int32_t GetEffectiveRowSpan(const nsTableCellFrame& aCell,
436 nsCellMap* aCellMap = nullptr);
438 /** return the col span of a cell, taking into account col span magic at the
439 * edge of a table.
441 * @param aCell the cell
443 * @return the col span, correcting for col spans that extend beyond the edge
444 * of the table.
446 int32_t GetEffectiveColSpan(const nsTableCellFrame& aCell,
447 nsCellMap* aCellMap = nullptr) const;
449 /** indicate whether the row has more than one cell that either originates
450 * or is spanned from the rows above
452 bool HasMoreThanOneCell(int32_t aRowIndex) const;
454 /** return the column frame associated with aColIndex
455 * returns nullptr if the col frame has not yet been allocated, or if
456 * aColIndex is out of range
458 nsTableColFrame* GetColFrame(int32_t aColIndex) const;
460 /** Insert a col frame reference into the colframe cache and adapt the cellmap
461 * @param aColFrame - the column frame
462 * @param aColIndex - index where the column should be inserted into the
463 * colframe cache
465 void InsertCol(nsTableColFrame& aColFrame, int32_t aColIndex);
467 nsTableColGroupFrame* CreateSyntheticColGroupFrame();
469 int32_t DestroyAnonymousColFrames(int32_t aNumFrames);
471 // Append aNumColsToAdd anonymous col frames of type eColAnonymousCell to our
472 // last synthetic colgroup. If we have no such colgroup, then create one.
473 void AppendAnonymousColFrames(int32_t aNumColsToAdd);
475 // Append aNumColsToAdd anonymous col frames of type aColType to
476 // aColGroupFrame. If aAddToTable is true, also call AddColsToTable on the
477 // new cols.
478 void AppendAnonymousColFrames(nsTableColGroupFrame* aColGroupFrame,
479 int32_t aNumColsToAdd, nsTableColType aColType,
480 bool aAddToTable);
482 void MatchCellMapToColCache(nsTableCellMap* aCellMap);
484 void DidResizeColumns();
486 void AppendCell(nsTableCellFrame& aCellFrame, int32_t aRowIndex);
488 void InsertCells(nsTArray<nsTableCellFrame*>& aCellFrames, int32_t aRowIndex,
489 int32_t aColIndexBefore);
491 void RemoveCell(nsTableCellFrame* aCellFrame, int32_t aRowIndex);
493 void AppendRows(nsTableRowGroupFrame* aRowGroupFrame, int32_t aRowIndex,
494 nsTArray<nsTableRowFrame*>& aRowFrames);
496 int32_t InsertRows(nsTableRowGroupFrame* aRowGroupFrame,
497 nsTArray<nsTableRowFrame*>& aFrames, int32_t aRowIndex,
498 bool aConsiderSpans);
500 void RemoveRows(nsTableRowFrame& aFirstRowFrame, int32_t aNumRowsToRemove,
501 bool aConsiderSpans);
503 /** Insert multiple rowgroups into the table cellmap handling
504 * @param aRowGroups - iterator that iterates over the rowgroups to insert
506 void InsertRowGroups(const nsFrameList::Slice& aRowGroups);
508 void InsertColGroups(int32_t aStartColIndex,
509 const nsFrameList::Slice& aColgroups);
511 void RemoveCol(nsTableColGroupFrame* aColGroupFrame, int32_t aColIndex,
512 bool aRemoveFromCache, bool aRemoveFromCellMap);
514 bool ColumnHasCellSpacingBefore(int32_t aColIndex) const;
516 bool HasPctCol() const;
517 void SetHasPctCol(bool aValue);
519 bool HasCellSpanningPctCol() const;
520 void SetHasCellSpanningPctCol(bool aValue);
523 * To be called on a frame by its parent after setting its size/position and
524 * calling DidReflow (possibly via FinishReflowChild()). This can also be
525 * used for child frames which are not being reflowed but did have their size
526 * or position changed.
528 * @param aFrame The frame to invalidate
529 * @param aOrigRect The original rect of aFrame (before the change).
530 * @param aOrigInkOverflow The original overflow rect of aFrame.
531 * @param aIsFirstReflow True if the size/position change is due to the
532 * first reflow of aFrame.
534 static void InvalidateTableFrame(nsIFrame* aFrame, const nsRect& aOrigRect,
535 const nsRect& aOrigInkOverflow,
536 bool aIsFirstReflow);
538 bool ComputeCustomOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
540 // Return our wrapper frame.
541 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
543 protected:
544 static void UpdateStyleOfOwnedAnonBoxesForTableWrapper(
545 nsIFrame* aOwningFrame, nsIFrame* aWrapperFrame,
546 mozilla::ServoRestyleState& aRestyleState);
548 /** protected constructor.
549 * @see NewFrame
551 explicit nsTableFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
552 ClassID aID = kClassID);
554 virtual ~nsTableFrame();
556 void InitChildReflowInput(ReflowInput& aReflowInput);
558 LogicalSides GetLogicalSkipSides() const override;
560 void IterateBCBorders(BCPaintBorderAction& aAction, const nsRect& aDirtyRect);
562 public:
563 bool IsRowInserted() const;
564 void SetRowInserted(bool aValue);
566 protected:
567 // A helper function to reflow a header or footer with unconstrained
568 // block-size to see if it should be made repeatable.
569 // @return the desired block-size for a header or footer.
570 nscoord SetupHeaderFooterChild(const mozilla::TableReflowInput& aReflowInput,
571 nsTableRowGroupFrame* aFrame);
573 void ReflowChildren(mozilla::TableReflowInput& aReflowInput,
574 nsReflowStatus& aStatus, nsIFrame*& aLastChildReflowed,
575 mozilla::OverflowAreas& aOverflowAreas);
577 // This calls the col group and column reflow methods, which do two things:
578 // (1) set all the dimensions to 0
579 // (2) notify the table about colgroups or columns with hidden visibility
580 void ReflowColGroups(gfxContext* aRenderingContext);
582 /** return the isize of the table taking into account visibility collapse
583 * on columns and colgroups
584 * @param aBorderPadding the border and padding of the table
586 nscoord GetCollapsedISize(const WritingMode aWM,
587 const LogicalMargin& aBorderPadding);
589 /** Adjust the table for visibility.collapse set on rowgroups, rows,
590 * colgroups and cols
591 * @param aDesiredSize the metrics of the table
592 * @param aBorderPadding the border and padding of the table
594 void AdjustForCollapsingRowsCols(ReflowOutput& aDesiredSize,
595 const WritingMode aWM,
596 const LogicalMargin& aBorderPadding);
598 /** FixupPositionedTableParts is called at the end of table reflow to reflow
599 * the absolutely positioned descendants of positioned table parts. This is
600 * necessary because the dimensions of table parts may change after they've
601 * been reflowed (e.g. in AdjustForCollapsingRowsCols).
603 void FixupPositionedTableParts(nsPresContext* aPresContext,
604 ReflowOutput& aDesiredSize,
605 const ReflowInput& aReflowInput);
607 // Clears the list of positioned table parts.
608 void ClearAllPositionedTableParts();
610 nsITableLayoutStrategy* LayoutStrategy() const {
611 return static_cast<nsTableFrame*>(FirstInFlow())
612 ->mTableLayoutStrategy.get();
615 // Helper for InsertFrames.
616 void HomogenousInsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
617 nsFrameList& aFrameList);
619 private:
620 /* Handle a row that got inserted during reflow. aNewHeight is the
621 new height of the table after reflow. */
622 void ProcessRowInserted(nscoord aNewHeight);
624 protected:
625 // Calculate the border-box block-size of this table, with the min-block-size,
626 // max-block-size, and intrinsic border-box block considered.
627 nscoord CalcBorderBoxBSize(const ReflowInput& aReflowInput,
628 const LogicalMargin& aBorderPadding,
629 nscoord aIntrinsicBorderBoxBSize);
631 // Calculate the desired block-size of this table.
633 // Note: this method is accurate after the children are reflowed. It might
634 // distribute extra block-size to table rows if the table has a specified
635 // block-size larger than the intrinsic block-size.
636 nscoord CalcDesiredBSize(const ReflowInput& aReflowInput,
637 const LogicalMargin& aBorderPadding);
639 // The following is a helper for CalcDesiredBSize
640 void DistributeBSizeToRows(const ReflowInput& aReflowInput, nscoord aAmount);
642 void PlaceChild(mozilla::TableReflowInput& aReflowInput, nsIFrame* aKidFrame,
643 const ReflowInput& aKidReflowInput,
644 const mozilla::LogicalPoint& aKidPosition,
645 const nsSize& aContainerSize, ReflowOutput& aKidDesiredSize,
646 const nsRect& aOriginalKidRect,
647 const nsRect& aOriginalKidInkOverflow);
648 void PlaceRepeatedFooter(mozilla::TableReflowInput& aReflowInput,
649 nsTableRowGroupFrame* aTfoot, nscoord aFooterBSize);
651 public:
652 using RowGroupArray = AutoTArray<nsTableRowGroupFrame*, 8>;
654 protected:
655 // Push all our non-repeatable child frames from the aRowGroups array, in
656 // order, starting from the frame at aPushFrom to the end of the array. The
657 // pushed frames are put on our overflow list. This is a table specific
658 // version that takes into account repeated header and footer frames when
659 // continuing table frames.
660 void PushChildrenToOverflow(const RowGroupArray& aRowGroups,
661 size_t aPushFrom);
663 public:
664 // Return the children frames in the display order (e.g. thead before tbodies
665 // before tfoot). If there are multiple theads or tfoots, all but the first
666 // one are treated as tbodies instead.
668 // @param aHead Outparam for the first thead if there is any.
669 // @param aFoot Outparam for the first tfoot if there is any.
670 RowGroupArray OrderedRowGroups(nsTableRowGroupFrame** aHead = nullptr,
671 nsTableRowGroupFrame** aFoot = nullptr) const;
673 // Returns true if there are any cells above the row at
674 // aRowIndex and spanning into the row at aRowIndex, the number of
675 // effective columns limits the search up to that column
676 bool RowIsSpannedInto(int32_t aRowIndex, int32_t aNumEffCols);
678 // Returns true if there is a cell originating in aRowIndex
679 // which spans into the next row, the number of effective
680 // columns limits the search up to that column
681 bool RowHasSpanningCells(int32_t aRowIndex, int32_t aNumEffCols);
683 protected:
684 bool HaveReflowedColGroups() const;
685 void SetHaveReflowedColGroups(bool aValue);
687 public:
688 bool IsBorderCollapse() const;
690 bool NeedToCalcBCBorders() const;
691 void SetNeedToCalcBCBorders(bool aValue);
693 bool NeedToCollapse() const;
694 void SetNeedToCollapse(bool aValue);
696 bool NeedToCalcHasBCBorders() const;
697 void SetNeedToCalcHasBCBorders(bool aValue);
699 void CalcHasBCBorders();
700 bool HasBCBorders();
701 void SetHasBCBorders(bool aValue);
703 /** The GeometryDirty bit is similar to the NS_FRAME_IS_DIRTY frame
704 * state bit, which implies that all descendants are dirty. The
705 * GeometryDirty still implies that all the parts of the table are
706 * dirty, but resizing optimizations should still apply to the
707 * contents of the individual cells.
709 void SetGeometryDirty() { mBits.mGeometryDirty = true; }
710 void ClearGeometryDirty() { mBits.mGeometryDirty = false; }
711 bool IsGeometryDirty() const { return mBits.mGeometryDirty; }
713 /** Get the cell map for this table frame. It is not always mCellMap.
714 * Only the firstInFlow has a legit cell map
716 nsTableCellMap* GetCellMap() const;
718 /** Iterate over the row groups and adjust the row indices of all rows
719 * whose index is >= aRowIndex.
720 * @param aRowIndex - start adjusting with this index
721 * @param aAdjustment - shift the row index by this amount
723 void AdjustRowIndices(int32_t aRowIndex, int32_t aAdjustment);
725 /** Reset the rowindices of all rows as they might have changed due to
726 * rowgroup reordering, exclude new row group frames that show in the
727 * reordering but are not yet inserted into the cellmap
728 * @param aRowGroupsToExclude - an iterator that will produce the row groups
729 * to exclude.
731 void ResetRowIndices(const nsFrameList::Slice& aRowGroupsToExclude);
733 nsTArray<nsTableColFrame*>& GetColCache();
735 mozilla::TableBCData* GetTableBCData() const;
737 protected:
738 void SetBorderCollapse(bool aValue);
740 mozilla::TableBCData* GetOrCreateTableBCData();
741 void SetFullBCDamageArea();
742 void CalcBCBorders();
744 void ExpandBCDamageArea(mozilla::TableArea& aRect) const;
746 void SetColumnDimensions(nscoord aHeight, WritingMode aWM,
747 const LogicalMargin& aBorderPadding,
748 const nsSize& aContainerSize);
750 int32_t CollectRows(nsIFrame* aFrame,
751 nsTArray<nsTableRowFrame*>& aCollection);
753 public: /* ----- Cell Map public methods ----- */
754 int32_t GetStartRowIndex(const nsTableRowGroupFrame* aRowGroupFrame) const;
756 /** returns the number of rows in this table.
758 int32_t GetRowCount() const { return GetCellMap()->GetRowCount(); }
760 /** returns the number of columns in this table after redundant columns have
761 * been removed
763 int32_t GetEffectiveColCount() const;
765 /* return the col count including dead cols */
766 int32_t GetColCount() const { return GetCellMap()->GetColCount(); }
768 // return the last col index which isn't of type eColAnonymousCell
769 int32_t GetIndexOfLastRealCol();
771 /** returns true if table-layout:auto */
772 bool IsAutoLayout();
774 public:
775 /* ---------- Row index management methods ------------ */
777 /** Add the given index to the existing ranges of
778 * deleted row indices and merge ranges if, with the addition of the new
779 * index, they become consecutive.
780 * @param aDeletedRowStoredIndex - index of the row that was deleted
781 * Note - 'stored' index here refers to the index that was assigned to
782 * the row before any remove row operations were performed i.e. the
783 * value of mRowIndex and not the value returned by GetRowIndex()
785 void AddDeletedRowIndex(int32_t aDeletedRowStoredIndex);
787 /** Calculate the change that aStoredIndex must be increased/decreased by
788 * to get new index.
789 * Note that aStoredIndex is always the index of an undeleted row (since
790 * rows that have already been deleted can never call this method).
791 * @param aStoredIndex - The stored index value that must be adjusted
792 * Note - 'stored' index here refers to the index that was assigned to
793 * the row before any remove row operations were performed i.e. the
794 * value of mRowIndex and not the value returned by GetRowIndex()
796 int32_t GetAdjustmentForStoredIndex(int32_t aStoredIndex);
798 /** Returns whether mDeletedRowIndexRanges is empty
800 bool IsDeletedRowIndexRangesEmpty() const {
801 return mDeletedRowIndexRanges.empty();
804 bool IsDestroying() const { return mBits.mIsDestroying; }
806 public:
807 #ifdef DEBUG
808 void Dump(bool aDumpRows, bool aDumpCols, bool aDumpCellMap);
809 #endif
811 protected:
813 * Helper method for RemoveFrame.
815 void DoRemoveFrame(DestroyContext&, ChildListID, nsIFrame*);
816 #ifdef DEBUG
817 void DumpRowGroup(nsIFrame* aChildFrame);
818 #endif
819 // DATA MEMBERS
820 AutoTArray<nsTableColFrame*, 8> mColFrames;
822 struct TableBits {
823 uint32_t mHaveReflowedColGroups : 1; // have the col groups gotten their
824 // initial reflow
825 uint32_t mHasPctCol : 1; // does any cell or col have a pct width
826 uint32_t mCellSpansPctCol : 1; // does any cell span a col with a pct width
827 // (or containing a cell with a pct width)
828 uint32_t mIsBorderCollapse : 1; // border collapsing model vs. separate
829 // model
830 uint32_t mRowInserted : 1;
831 uint32_t mNeedToCalcBCBorders : 1;
832 uint32_t mGeometryDirty : 1;
833 uint32_t mNeedToCollapse : 1; // rows, cols that have visibility:collapse
834 // need to be collapsed
835 uint32_t mResizedColumns : 1; // have we resized columns since last reflow?
836 uint32_t mNeedToCalcHasBCBorders : 1;
837 uint32_t mHasBCBorders : 1;
838 uint32_t mIsDestroying : 1; // Whether we're in the process of destroying
839 // this table frame.
840 } mBits;
842 std::map<int32_t, int32_t> mDeletedRowIndexRanges; // maintains ranges of row
843 // indices of deleted rows
844 mozilla::UniquePtr<nsTableCellMap> mCellMap; // maintains the relationships
845 // between rows, cols, and cells
846 // the layout strategy for this frame
847 mozilla::UniquePtr<nsITableLayoutStrategy> mTableLayoutStrategy;
848 nsFrameList mColGroups; // the list of colgroup frames
851 inline bool nsTableFrame::IsRowGroup(mozilla::StyleDisplay aDisplayType) const {
852 return mozilla::StyleDisplay::TableHeaderGroup == aDisplayType ||
853 mozilla::StyleDisplay::TableFooterGroup == aDisplayType ||
854 mozilla::StyleDisplay::TableRowGroup == aDisplayType;
857 inline void nsTableFrame::SetHaveReflowedColGroups(bool aValue) {
858 mBits.mHaveReflowedColGroups = aValue;
861 inline bool nsTableFrame::HaveReflowedColGroups() const {
862 return (bool)mBits.mHaveReflowedColGroups;
865 inline bool nsTableFrame::HasPctCol() const { return (bool)mBits.mHasPctCol; }
867 inline void nsTableFrame::SetHasPctCol(bool aValue) {
868 mBits.mHasPctCol = (unsigned)aValue;
871 inline bool nsTableFrame::HasCellSpanningPctCol() const {
872 return (bool)mBits.mCellSpansPctCol;
875 inline void nsTableFrame::SetHasCellSpanningPctCol(bool aValue) {
876 mBits.mCellSpansPctCol = (unsigned)aValue;
879 inline bool nsTableFrame::IsRowInserted() const {
880 return (bool)mBits.mRowInserted;
883 inline void nsTableFrame::SetRowInserted(bool aValue) {
884 mBits.mRowInserted = (unsigned)aValue;
887 inline void nsTableFrame::SetNeedToCollapse(bool aValue) {
888 static_cast<nsTableFrame*>(FirstInFlow())->mBits.mNeedToCollapse =
889 (unsigned)aValue;
892 inline bool nsTableFrame::NeedToCollapse() const {
893 return (bool)static_cast<nsTableFrame*>(FirstInFlow())->mBits.mNeedToCollapse;
896 inline nsFrameList& nsTableFrame::GetColGroups() {
897 return static_cast<nsTableFrame*>(FirstInFlow())->mColGroups;
900 inline nsTArray<nsTableColFrame*>& nsTableFrame::GetColCache() {
901 return mColFrames;
904 inline bool nsTableFrame::IsBorderCollapse() const {
905 return (bool)mBits.mIsBorderCollapse;
908 inline void nsTableFrame::SetBorderCollapse(bool aValue) {
909 mBits.mIsBorderCollapse = aValue;
912 inline bool nsTableFrame::NeedToCalcBCBorders() const {
913 return (bool)mBits.mNeedToCalcBCBorders;
916 inline void nsTableFrame::SetNeedToCalcBCBorders(bool aValue) {
917 mBits.mNeedToCalcBCBorders = (unsigned)aValue;
920 inline bool nsTableFrame::NeedToCalcHasBCBorders() const {
921 return (bool)mBits.mNeedToCalcHasBCBorders;
924 inline void nsTableFrame::SetNeedToCalcHasBCBorders(bool aValue) {
925 mBits.mNeedToCalcHasBCBorders = (unsigned)aValue;
928 inline bool nsTableFrame::HasBCBorders() {
929 if (NeedToCalcHasBCBorders()) {
930 CalcHasBCBorders();
931 SetNeedToCalcHasBCBorders(false);
933 return (bool)mBits.mHasBCBorders;
936 inline void nsTableFrame::SetHasBCBorders(bool aValue) {
937 mBits.mHasBCBorders = (unsigned)aValue;
940 #define ABORT0() \
942 NS_ASSERTION(false, "CellIterator program error"); \
943 return; \
946 #define ABORT1(aReturn) \
948 NS_ASSERTION(false, "CellIterator program error"); \
949 return aReturn; \
952 #endif