Bug 1919083 - [ci] Enable os-integration variant for more suites, r=jmaher
[gecko.git] / layout / tables / nsTableFrame.h
blob512fc733be74d72d812fd2093ab881d9529b2154
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;
253 * Emplace our border and padding in aBorder and aPadding if we are
254 * border-collapsed. Otherwise, do nothing.
256 void GetCollapsedBorderPadding(
257 mozilla::Maybe<mozilla::LogicalMargin>& aBorder,
258 mozilla::Maybe<mozilla::LogicalMargin>& aPadding) const;
260 friend class nsDelayedCalcBCBorders;
262 void AddBCDamageArea(const mozilla::TableArea& aValue);
263 bool BCRecalcNeeded(ComputedStyle* aOldComputedStyle,
264 ComputedStyle* aNewComputedStyle);
265 void PaintBCBorders(DrawTarget& aDrawTarget, const nsRect& aDirtyRect);
266 void CreateWebRenderCommandsForBCBorders(
267 mozilla::wr::DisplayListBuilder& aBuilder,
268 const mozilla::layers::StackingContextHelper& aSc,
269 const nsRect& aVisibleRect, const nsPoint& aOffsetToReferenceFrame);
271 void MarkIntrinsicISizesDirty() override;
272 // For border-collapse tables, the caller must not add padding and
273 // border to the results of these functions.
274 nscoord IntrinsicISize(const mozilla::IntrinsicSizeInput& aInput,
275 mozilla::IntrinsicISizeType aType) override;
276 IntrinsicSizeOffsetData IntrinsicISizeOffsets(
277 nscoord aPercentageBasis = NS_UNCONSTRAINEDSIZE) override;
279 SizeComputationResult ComputeSize(
280 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
281 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
282 const mozilla::LogicalSize& aMargin,
283 const mozilla::LogicalSize& aBorderPadding,
284 const mozilla::StyleSizeOverrides& aSizeOverrides,
285 mozilla::ComputeSizeFlags aFlags) override;
287 mozilla::LogicalSize ComputeAutoSize(
288 gfxContext* aRenderingContext, mozilla::WritingMode aWM,
289 const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
290 const mozilla::LogicalSize& aMargin,
291 const mozilla::LogicalSize& aBorderPadding,
292 const mozilla::StyleSizeOverrides& aSizeOverrides,
293 mozilla::ComputeSizeFlags aFlags) override;
296 * A copy of nsIFrame::ShrinkISizeToFit that calls a different
297 * GetPrefISize, since tables have two different ones.
299 nscoord TableShrinkISizeToFit(gfxContext* aRenderingContext,
300 nscoord aWidthInCB);
302 // XXXldb REWRITE THIS COMMENT!
303 // clang-format off
305 * Inner tables are reflowed in two steps.
306 * <pre>
307 * if mFirstPassValid is false, this is our first time through since content was last changed
308 * set pass to 1
309 * do pass 1
310 * get min/max info for all cells in an infinite space
311 * do column balancing
312 * set mFirstPassValid to true
313 * do pass 2
314 * use column widths to Reflow cells
315 * </pre>
317 * @see nsIFrame::Reflow
319 // clang-format on
320 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
321 const ReflowInput& aReflowInput,
322 nsReflowStatus& aStatus) override;
324 void ReflowTable(ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
325 const LogicalMargin& aBorderPadding,
326 mozilla::TableReflowMode aReflowMode,
327 nsIFrame*& aLastChildReflowed, nsReflowStatus& aStatus);
329 nsFrameList& GetColGroups();
331 ComputedStyle* GetParentComputedStyle(
332 nsIFrame** aProviderFrame) const override;
334 #ifdef DEBUG_FRAME_DUMP
335 /** @see nsIFrame::GetFrameName */
336 nsresult GetFrameName(nsAString& aResult) const override;
337 #endif
339 /** Return the isize of the column at aColIndex.
340 * This may only be called on the table's first-in-flow.
342 nscoord GetColumnISizeFromFirstInFlow(int32_t aColIndex);
344 /** Helper to get the column spacing style value.
345 * The argument refers to the space between column aColIndex and column
346 * aColIndex + 1. An index of -1 indicates the padding between the table
347 * and the left border, an index equal to the number of columns indicates
348 * the padding between the table and the right border.
350 * Although in this class cell spacing does not depend on the index, it
351 * may be important for overriding classes.
353 virtual nscoord GetColSpacing(int32_t aColIndex);
355 /** Helper to find the sum of the cell spacing between arbitrary columns.
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 * This method is equivalent to
362 * nscoord result = 0;
363 * for (i = aStartColIndex; i < aEndColIndex; i++) {
364 * result += GetColSpacing(i);
366 * return result;
368 virtual nscoord GetColSpacing(int32_t aStartColIndex, int32_t aEndColIndex);
370 /** Helper to get the row spacing style value.
371 * The argument refers to the space between row aRowIndex and row
372 * aRowIndex + 1. An index of -1 indicates the padding between the table
373 * and the top border, an index equal to the number of rows indicates
374 * the padding between the table and the bottom border.
376 * Although in this class cell spacing does not depend on the index, it
377 * may be important for overriding classes.
379 virtual nscoord GetRowSpacing(int32_t aRowIndex);
381 /** Helper to find the sum of the cell spacing between arbitrary rows.
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 * This method is equivalent to
388 * nscoord result = 0;
389 * for (i = aStartRowIndex; i < aEndRowIndex; i++) {
390 * result += GetRowSpacing(i);
392 * return result;
394 virtual nscoord GetRowSpacing(int32_t aStartRowIndex, int32_t aEndRowIndex);
396 private:
397 /* For the base implementation of nsTableFrame, cell spacing does not depend
398 * on row/column indexing.
400 nscoord GetColSpacing();
401 nscoord GetRowSpacing();
403 public:
404 nscoord SynthesizeFallbackBaseline(
405 mozilla::WritingMode aWM,
406 BaselineSharingGroup aBaselineGroup) const override;
407 Maybe<nscoord> GetNaturalBaselineBOffset(
408 mozilla::WritingMode aWM, BaselineSharingGroup aBaselineGroup,
409 BaselineExportContext) const override;
411 /** return the row span of a cell, taking into account row span magic at the
412 * bottom of a table. The row span equals the number of rows spanned by aCell
413 * starting at aStartRowIndex, and can be smaller if aStartRowIndex is greater
414 * than the row index in which aCell originates.
416 * @param aStartRowIndex the cell
417 * @param aCell the cell
419 * @return the row span, correcting for row spans that extend beyond the
420 * bottom of the table.
422 int32_t GetEffectiveRowSpan(int32_t aStartRowIndex,
423 const nsTableCellFrame& aCell) const;
424 int32_t GetEffectiveRowSpan(const nsTableCellFrame& aCell,
425 nsCellMap* aCellMap = nullptr);
427 /** return the col span of a cell, taking into account col span magic at the
428 * edge of a table.
430 * @param aCell the cell
432 * @return the col span, correcting for col spans that extend beyond the edge
433 * of the table.
435 int32_t GetEffectiveColSpan(const nsTableCellFrame& aCell,
436 nsCellMap* aCellMap = nullptr) const;
438 /** indicate whether the row has more than one cell that either originates
439 * or is spanned from the rows above
441 bool HasMoreThanOneCell(int32_t aRowIndex) const;
443 /** return the column frame associated with aColIndex
444 * returns nullptr if the col frame has not yet been allocated, or if
445 * aColIndex is out of range
447 nsTableColFrame* GetColFrame(int32_t aColIndex) const;
449 /** Insert a col frame reference into the colframe cache and adapt the cellmap
450 * @param aColFrame - the column frame
451 * @param aColIndex - index where the column should be inserted into the
452 * colframe cache
454 void InsertCol(nsTableColFrame& aColFrame, int32_t aColIndex);
456 nsTableColGroupFrame* CreateSyntheticColGroupFrame();
458 int32_t DestroyAnonymousColFrames(int32_t aNumFrames);
460 // Append aNumColsToAdd anonymous col frames of type eColAnonymousCell to our
461 // last synthetic colgroup. If we have no such colgroup, then create one.
462 void AppendAnonymousColFrames(int32_t aNumColsToAdd);
464 // Append aNumColsToAdd anonymous col frames of type aColType to
465 // aColGroupFrame. If aAddToTable is true, also call AddColsToTable on the
466 // new cols.
467 void AppendAnonymousColFrames(nsTableColGroupFrame* aColGroupFrame,
468 int32_t aNumColsToAdd, nsTableColType aColType,
469 bool aAddToTable);
471 void MatchCellMapToColCache(nsTableCellMap* aCellMap);
473 void DidResizeColumns();
475 void AppendCell(nsTableCellFrame& aCellFrame, int32_t aRowIndex);
477 void InsertCells(nsTArray<nsTableCellFrame*>& aCellFrames, int32_t aRowIndex,
478 int32_t aColIndexBefore);
480 void RemoveCell(nsTableCellFrame* aCellFrame, int32_t aRowIndex);
482 void AppendRows(nsTableRowGroupFrame* aRowGroupFrame, int32_t aRowIndex,
483 nsTArray<nsTableRowFrame*>& aRowFrames);
485 int32_t InsertRows(nsTableRowGroupFrame* aRowGroupFrame,
486 nsTArray<nsTableRowFrame*>& aFrames, int32_t aRowIndex,
487 bool aConsiderSpans);
489 void RemoveRows(nsTableRowFrame& aFirstRowFrame, int32_t aNumRowsToRemove,
490 bool aConsiderSpans);
492 /** Insert multiple rowgroups into the table cellmap handling
493 * @param aRowGroups - iterator that iterates over the rowgroups to insert
495 void InsertRowGroups(const nsFrameList::Slice& aRowGroups);
497 void InsertColGroups(int32_t aStartColIndex,
498 const nsFrameList::Slice& aColgroups);
500 void RemoveCol(nsTableColGroupFrame* aColGroupFrame, int32_t aColIndex,
501 bool aRemoveFromCache, bool aRemoveFromCellMap);
503 bool ColumnHasCellSpacingBefore(int32_t aColIndex) const;
505 bool HasPctCol() const;
506 void SetHasPctCol(bool aValue);
508 bool HasCellSpanningPctCol() const;
509 void SetHasCellSpanningPctCol(bool aValue);
512 * To be called on a frame by its parent after setting its size/position and
513 * calling DidReflow (possibly via FinishReflowChild()). This can also be
514 * used for child frames which are not being reflowed but did have their size
515 * or position changed.
517 * @param aFrame The frame to invalidate
518 * @param aOrigRect The original rect of aFrame (before the change).
519 * @param aOrigInkOverflow The original overflow rect of aFrame.
520 * @param aIsFirstReflow True if the size/position change is due to the
521 * first reflow of aFrame.
523 static void InvalidateTableFrame(nsIFrame* aFrame, const nsRect& aOrigRect,
524 const nsRect& aOrigInkOverflow,
525 bool aIsFirstReflow);
527 bool ComputeCustomOverflow(mozilla::OverflowAreas& aOverflowAreas) override;
529 // Return our wrapper frame.
530 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
532 protected:
533 static void UpdateStyleOfOwnedAnonBoxesForTableWrapper(
534 nsIFrame* aOwningFrame, nsIFrame* aWrapperFrame,
535 mozilla::ServoRestyleState& aRestyleState);
537 /** protected constructor.
538 * @see NewFrame
540 explicit nsTableFrame(ComputedStyle* aStyle, nsPresContext* aPresContext,
541 ClassID aID = kClassID);
543 virtual ~nsTableFrame();
545 void InitChildReflowInput(ReflowInput& aReflowInput);
547 LogicalSides GetLogicalSkipSides() const override;
549 void IterateBCBorders(BCPaintBorderAction& aAction, const nsRect& aDirtyRect);
551 public:
552 bool IsRowInserted() const;
553 void SetRowInserted(bool aValue);
555 protected:
556 // A helper function to reflow a header or footer with unconstrained
557 // block-size to see if it should be made repeatable.
558 // @return the desired block-size for a header or footer.
559 nscoord SetupHeaderFooterChild(const mozilla::TableReflowInput& aReflowInput,
560 nsTableRowGroupFrame* aFrame);
562 void ReflowChildren(mozilla::TableReflowInput& aReflowInput,
563 nsReflowStatus& aStatus, nsIFrame*& aLastChildReflowed,
564 mozilla::OverflowAreas& aOverflowAreas);
566 // This calls the col group and column reflow methods, which do two things:
567 // (1) set all the dimensions to 0
568 // (2) notify the table about colgroups or columns with hidden visibility
569 void ReflowColGroups(gfxContext* aRenderingContext);
571 /** return the isize of the table taking into account visibility collapse
572 * on columns and colgroups
573 * @param aBorderPadding the border and padding of the table
575 nscoord GetCollapsedISize(const WritingMode aWM,
576 const LogicalMargin& aBorderPadding);
578 /** Adjust the table for visibility.collapse set on rowgroups, rows,
579 * colgroups and cols
580 * @param aDesiredSize the metrics of the table
581 * @param aBorderPadding the border and padding of the table
583 void AdjustForCollapsingRowsCols(ReflowOutput& aDesiredSize,
584 const WritingMode aWM,
585 const LogicalMargin& aBorderPadding);
587 /** FixupPositionedTableParts is called at the end of table reflow to reflow
588 * the absolutely positioned descendants of positioned table parts. This is
589 * necessary because the dimensions of table parts may change after they've
590 * been reflowed (e.g. in AdjustForCollapsingRowsCols).
592 void FixupPositionedTableParts(nsPresContext* aPresContext,
593 ReflowOutput& aDesiredSize,
594 const ReflowInput& aReflowInput);
596 // Clears the list of positioned table parts.
597 void ClearAllPositionedTableParts();
599 nsITableLayoutStrategy* LayoutStrategy() const {
600 return static_cast<nsTableFrame*>(FirstInFlow())
601 ->mTableLayoutStrategy.get();
604 // Helper for InsertFrames.
605 void HomogenousInsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
606 nsFrameList& aFrameList);
608 private:
609 /* Handle a row that got inserted during reflow. aNewHeight is the
610 new height of the table after reflow. */
611 void ProcessRowInserted(nscoord aNewHeight);
613 protected:
614 // Calculate the border-box block-size of this table, with the min-block-size,
615 // max-block-size, and intrinsic border-box block considered.
616 nscoord CalcBorderBoxBSize(const ReflowInput& aReflowInput,
617 const LogicalMargin& aBorderPadding,
618 nscoord aIntrinsicBorderBoxBSize);
620 // Calculate the desired block-size of this table.
622 // Note: this method is accurate after the children are reflowed. It might
623 // distribute extra block-size to table rows if the table has a specified
624 // block-size larger than the intrinsic block-size.
625 nscoord CalcDesiredBSize(const ReflowInput& aReflowInput,
626 const LogicalMargin& aBorderPadding,
627 const nsReflowStatus& aStatus);
629 // The following is a helper for CalcDesiredBSize
630 void DistributeBSizeToRows(const ReflowInput& aReflowInput, nscoord aAmount);
632 void PlaceChild(mozilla::TableReflowInput& aReflowInput, nsIFrame* aKidFrame,
633 const ReflowInput& aKidReflowInput,
634 const mozilla::LogicalPoint& aKidPosition,
635 const nsSize& aContainerSize, ReflowOutput& aKidDesiredSize,
636 const nsRect& aOriginalKidRect,
637 const nsRect& aOriginalKidInkOverflow);
638 void PlaceRepeatedFooter(mozilla::TableReflowInput& aReflowInput,
639 nsTableRowGroupFrame* aTfoot, nscoord aFooterBSize);
641 public:
642 using RowGroupArray = AutoTArray<nsTableRowGroupFrame*, 8>;
644 protected:
645 // Push all our non-repeatable child frames from the aRowGroups array, in
646 // order, starting from the frame at aPushFrom to the end of the array. The
647 // pushed frames are put on our overflow list. This is a table specific
648 // version that takes into account repeated header and footer frames when
649 // continuing table frames.
650 void PushChildrenToOverflow(const RowGroupArray& aRowGroups,
651 size_t aPushFrom);
653 public:
654 // Return the children frames in the display order (e.g. thead before tbodies
655 // before tfoot). If there are multiple theads or tfoots, all but the first
656 // one are treated as tbodies instead.
658 // @param aHead Outparam for the first thead if there is any.
659 // @param aFoot Outparam for the first tfoot if there is any.
660 RowGroupArray OrderedRowGroups(nsTableRowGroupFrame** aHead = nullptr,
661 nsTableRowGroupFrame** aFoot = nullptr) const;
663 // Returns true if there are any cells above the row at
664 // aRowIndex and spanning into the row at aRowIndex, the number of
665 // effective columns limits the search up to that column
666 bool RowIsSpannedInto(int32_t aRowIndex, int32_t aNumEffCols);
668 // Returns true if there is a cell originating in aRowIndex
669 // which spans into the next row, the number of effective
670 // columns limits the search up to that column
671 bool RowHasSpanningCells(int32_t aRowIndex, int32_t aNumEffCols);
673 protected:
674 bool HaveReflowedColGroups() const;
675 void SetHaveReflowedColGroups(bool aValue);
677 public:
678 bool IsBorderCollapse() const;
680 bool NeedToCalcBCBorders() const;
681 void SetNeedToCalcBCBorders(bool aValue);
683 bool NeedToCollapse() const;
684 void SetNeedToCollapse(bool aValue);
686 bool NeedToCalcHasBCBorders() const;
687 void SetNeedToCalcHasBCBorders(bool aValue);
689 void CalcHasBCBorders();
690 bool HasBCBorders();
691 void SetHasBCBorders(bool aValue);
693 /** The GeometryDirty bit is similar to the NS_FRAME_IS_DIRTY frame
694 * state bit, which implies that all descendants are dirty. The
695 * GeometryDirty still implies that all the parts of the table are
696 * dirty, but resizing optimizations should still apply to the
697 * contents of the individual cells.
699 void SetGeometryDirty() { mBits.mGeometryDirty = true; }
700 void ClearGeometryDirty() { mBits.mGeometryDirty = false; }
701 bool IsGeometryDirty() const { return mBits.mGeometryDirty; }
703 /** Get the cell map for this table frame. It is not always mCellMap.
704 * Only the firstInFlow has a legit cell map
706 nsTableCellMap* GetCellMap() const;
708 /** Iterate over the row groups and adjust the row indices of all rows
709 * whose index is >= aRowIndex.
710 * @param aRowIndex - start adjusting with this index
711 * @param aAdjustment - shift the row index by this amount
713 void AdjustRowIndices(int32_t aRowIndex, int32_t aAdjustment);
715 /** Reset the rowindices of all rows as they might have changed due to
716 * rowgroup reordering, exclude new row group frames that show in the
717 * reordering but are not yet inserted into the cellmap
718 * @param aRowGroupsToExclude - an iterator that will produce the row groups
719 * to exclude.
721 void ResetRowIndices(const nsFrameList::Slice& aRowGroupsToExclude);
723 nsTArray<nsTableColFrame*>& GetColCache();
725 mozilla::TableBCData* GetTableBCData() const;
727 protected:
728 void SetBorderCollapse(bool aValue);
730 mozilla::TableBCData* GetOrCreateTableBCData();
731 void SetFullBCDamageArea();
732 void CalcBCBorders();
734 void ExpandBCDamageArea(mozilla::TableArea& aRect) const;
736 void SetColumnDimensions(nscoord aHeight, WritingMode aWM,
737 const LogicalMargin& aBorderPadding,
738 const nsSize& aContainerSize);
740 int32_t CollectRows(nsIFrame* aFrame,
741 nsTArray<nsTableRowFrame*>& aCollection);
743 public: /* ----- Cell Map public methods ----- */
744 int32_t GetStartRowIndex(const nsTableRowGroupFrame* aRowGroupFrame) const;
746 /** returns the number of rows in this table.
748 int32_t GetRowCount() const { return GetCellMap()->GetRowCount(); }
750 /** returns the number of columns in this table after redundant columns have
751 * been removed
753 int32_t GetEffectiveColCount() const;
755 /* return the col count including dead cols */
756 int32_t GetColCount() const { return GetCellMap()->GetColCount(); }
758 // return the last col index which isn't of type eColAnonymousCell
759 int32_t GetIndexOfLastRealCol();
761 /** returns true if table-layout:auto */
762 bool IsAutoLayout();
764 public:
765 /* ---------- Row index management methods ------------ */
767 /** Add the given index to the existing ranges of
768 * deleted row indices and merge ranges if, with the addition of the new
769 * index, they become consecutive.
770 * @param aDeletedRowStoredIndex - index of the row that was deleted
771 * Note - 'stored' index here refers to the index that was assigned to
772 * the row before any remove row operations were performed i.e. the
773 * value of mRowIndex and not the value returned by GetRowIndex()
775 void AddDeletedRowIndex(int32_t aDeletedRowStoredIndex);
777 /** Calculate the change that aStoredIndex must be increased/decreased by
778 * to get new index.
779 * Note that aStoredIndex is always the index of an undeleted row (since
780 * rows that have already been deleted can never call this method).
781 * @param aStoredIndex - The stored index value that must be adjusted
782 * Note - 'stored' index here refers to the index that was assigned to
783 * the row before any remove row operations were performed i.e. the
784 * value of mRowIndex and not the value returned by GetRowIndex()
786 int32_t GetAdjustmentForStoredIndex(int32_t aStoredIndex);
788 /** Returns whether mDeletedRowIndexRanges is empty
790 bool IsDeletedRowIndexRangesEmpty() const {
791 return mDeletedRowIndexRanges.empty();
794 bool IsDestroying() const { return mBits.mIsDestroying; }
796 public:
797 #ifdef DEBUG
798 void Dump(bool aDumpRows, bool aDumpCols, bool aDumpCellMap);
799 #endif
801 protected:
803 * Helper method for RemoveFrame.
805 void DoRemoveFrame(DestroyContext&, ChildListID, nsIFrame*);
806 #ifdef DEBUG
807 void DumpRowGroup(nsIFrame* aChildFrame);
808 #endif
809 // DATA MEMBERS
810 AutoTArray<nsTableColFrame*, 8> mColFrames;
812 struct TableBits {
813 uint32_t mHaveReflowedColGroups : 1; // have the col groups gotten their
814 // initial reflow
815 uint32_t mHasPctCol : 1; // does any cell or col have a pct width
816 uint32_t mCellSpansPctCol : 1; // does any cell span a col with a pct width
817 // (or containing a cell with a pct width)
818 uint32_t mIsBorderCollapse : 1; // border collapsing model vs. separate
819 // model
820 uint32_t mRowInserted : 1;
821 uint32_t mNeedToCalcBCBorders : 1;
822 uint32_t mGeometryDirty : 1;
823 uint32_t mNeedToCollapse : 1; // rows, cols that have visibility:collapse
824 // need to be collapsed
825 uint32_t mResizedColumns : 1; // have we resized columns since last reflow?
826 uint32_t mNeedToCalcHasBCBorders : 1;
827 uint32_t mHasBCBorders : 1;
828 uint32_t mIsDestroying : 1; // Whether we're in the process of destroying
829 // this table frame.
830 } mBits;
832 std::map<int32_t, int32_t> mDeletedRowIndexRanges; // maintains ranges of row
833 // indices of deleted rows
834 mozilla::UniquePtr<nsTableCellMap> mCellMap; // maintains the relationships
835 // between rows, cols, and cells
836 // the layout strategy for this frame
837 mozilla::UniquePtr<nsITableLayoutStrategy> mTableLayoutStrategy;
838 nsFrameList mColGroups; // the list of colgroup frames
841 inline bool nsTableFrame::IsRowGroup(mozilla::StyleDisplay aDisplayType) const {
842 return mozilla::StyleDisplay::TableHeaderGroup == aDisplayType ||
843 mozilla::StyleDisplay::TableFooterGroup == aDisplayType ||
844 mozilla::StyleDisplay::TableRowGroup == aDisplayType;
847 inline void nsTableFrame::SetHaveReflowedColGroups(bool aValue) {
848 mBits.mHaveReflowedColGroups = aValue;
851 inline bool nsTableFrame::HaveReflowedColGroups() const {
852 return (bool)mBits.mHaveReflowedColGroups;
855 inline bool nsTableFrame::HasPctCol() const { return (bool)mBits.mHasPctCol; }
857 inline void nsTableFrame::SetHasPctCol(bool aValue) {
858 mBits.mHasPctCol = (unsigned)aValue;
861 inline bool nsTableFrame::HasCellSpanningPctCol() const {
862 return (bool)mBits.mCellSpansPctCol;
865 inline void nsTableFrame::SetHasCellSpanningPctCol(bool aValue) {
866 mBits.mCellSpansPctCol = (unsigned)aValue;
869 inline bool nsTableFrame::IsRowInserted() const {
870 return (bool)mBits.mRowInserted;
873 inline void nsTableFrame::SetRowInserted(bool aValue) {
874 mBits.mRowInserted = (unsigned)aValue;
877 inline void nsTableFrame::SetNeedToCollapse(bool aValue) {
878 static_cast<nsTableFrame*>(FirstInFlow())->mBits.mNeedToCollapse =
879 (unsigned)aValue;
882 inline bool nsTableFrame::NeedToCollapse() const {
883 return (bool)static_cast<nsTableFrame*>(FirstInFlow())->mBits.mNeedToCollapse;
886 inline nsFrameList& nsTableFrame::GetColGroups() {
887 return static_cast<nsTableFrame*>(FirstInFlow())->mColGroups;
890 inline nsTArray<nsTableColFrame*>& nsTableFrame::GetColCache() {
891 return mColFrames;
894 inline bool nsTableFrame::IsBorderCollapse() const {
895 return (bool)mBits.mIsBorderCollapse;
898 inline void nsTableFrame::SetBorderCollapse(bool aValue) {
899 mBits.mIsBorderCollapse = aValue;
902 inline bool nsTableFrame::NeedToCalcBCBorders() const {
903 return (bool)mBits.mNeedToCalcBCBorders;
906 inline void nsTableFrame::SetNeedToCalcBCBorders(bool aValue) {
907 mBits.mNeedToCalcBCBorders = (unsigned)aValue;
910 inline bool nsTableFrame::NeedToCalcHasBCBorders() const {
911 return (bool)mBits.mNeedToCalcHasBCBorders;
914 inline void nsTableFrame::SetNeedToCalcHasBCBorders(bool aValue) {
915 mBits.mNeedToCalcHasBCBorders = (unsigned)aValue;
918 inline bool nsTableFrame::HasBCBorders() {
919 if (NeedToCalcHasBCBorders()) {
920 CalcHasBCBorders();
921 SetNeedToCalcHasBCBorders(false);
923 return (bool)mBits.mHasBCBorders;
926 inline void nsTableFrame::SetHasBCBorders(bool aValue) {
927 mBits.mHasBCBorders = (unsigned)aValue;
930 #define ABORT0() \
932 NS_ASSERTION(false, "CellIterator program error"); \
933 return; \
936 #define ABORT1(aReturn) \
938 NS_ASSERTION(false, "CellIterator program error"); \
939 return aReturn; \
942 #endif