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 #include "nsTableRowGroupFrame.h"
7 #include "mozilla/ComputedStyle.h"
8 #include "mozilla/PresShell.h"
11 #include "nsTableRowFrame.h"
12 #include "nsTableFrame.h"
13 #include "nsTableCellFrame.h"
14 #include "nsPresContext.h"
15 #include "nsStyleConsts.h"
16 #include "nsIContent.h"
18 #include "nsIFrameInlines.h"
19 #include "nsGkAtoms.h"
20 #include "nsCSSRendering.h"
21 #include "nsHTMLParts.h"
22 #include "nsCSSFrameConstructor.h"
23 #include "nsDisplayList.h"
25 #include "nsCellMap.h" //table cell navigation
28 using namespace mozilla
;
29 using namespace mozilla::layout
;
33 struct TableRowGroupReflowInput
{
34 const ReflowInput
& reflowInput
; // Our reflow input
36 nsTableFrame
* tableFrame
;
38 // The available size (computed from the parent)
39 mozilla::LogicalSize availSize
;
41 // Running block-offset
44 TableRowGroupReflowInput(const ReflowInput
& aReflowInput
,
45 nsTableFrame
* aTableFrame
)
46 : reflowInput(aReflowInput
),
47 tableFrame(aTableFrame
),
48 availSize(aReflowInput
.AvailableSize()),
51 ~TableRowGroupReflowInput() = default;
54 } // namespace mozilla
56 nsTableRowGroupFrame::nsTableRowGroupFrame(ComputedStyle
* aStyle
,
57 nsPresContext
* aPresContext
)
58 : nsContainerFrame(aStyle
, aPresContext
, kClassID
) {
62 nsTableRowGroupFrame::~nsTableRowGroupFrame() = default;
64 void nsTableRowGroupFrame::DestroyFrom(nsIFrame
* aDestructRoot
,
65 PostDestroyData
& aPostDestroyData
) {
66 if (HasAnyStateBits(NS_FRAME_CAN_HAVE_ABSPOS_CHILDREN
)) {
67 nsTableFrame::UnregisterPositionedTablePart(this, aDestructRoot
);
70 nsContainerFrame::DestroyFrom(aDestructRoot
, aPostDestroyData
);
73 NS_QUERYFRAME_HEAD(nsTableRowGroupFrame
)
74 NS_QUERYFRAME_ENTRY(nsTableRowGroupFrame
)
75 NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame
)
77 int32_t nsTableRowGroupFrame::GetRowCount() const {
79 for (nsFrameList::Enumerator
e(mFrames
); !e
.AtEnd(); e
.Next()) {
81 e
.get()->StyleDisplay()->mDisplay
== mozilla::StyleDisplay::TableRow
,
82 "Unexpected display");
83 NS_ASSERTION(e
.get()->IsTableRowFrame(), "Unexpected frame type");
87 return mFrames
.GetLength();
90 int32_t nsTableRowGroupFrame::GetStartRowIndex() const {
92 if (mFrames
.NotEmpty()) {
93 NS_ASSERTION(mFrames
.FirstChild()->IsTableRowFrame(),
94 "Unexpected frame type");
95 result
= static_cast<nsTableRowFrame
*>(mFrames
.FirstChild())->GetRowIndex();
97 // if the row group doesn't have any children, get it the hard way
99 return GetTableFrame()->GetStartRowIndex(this);
105 void nsTableRowGroupFrame::AdjustRowIndices(int32_t aRowIndex
,
106 int32_t anAdjustment
) {
107 for (nsIFrame
* rowFrame
: mFrames
) {
108 if (mozilla::StyleDisplay::TableRow
== rowFrame
->StyleDisplay()->mDisplay
) {
109 int32_t index
= ((nsTableRowFrame
*)rowFrame
)->GetRowIndex();
110 if (index
>= aRowIndex
)
111 ((nsTableRowFrame
*)rowFrame
)->SetRowIndex(index
+ anAdjustment
);
116 int32_t nsTableRowGroupFrame::GetAdjustmentForStoredIndex(
117 int32_t aStoredIndex
) {
118 nsTableFrame
* tableFrame
= GetTableFrame();
119 return tableFrame
->GetAdjustmentForStoredIndex(aStoredIndex
);
122 void nsTableRowGroupFrame::MarkRowsAsDeleted(nsTableRowFrame
& aStartRowFrame
,
123 int32_t aNumRowsToDelete
) {
124 nsTableRowFrame
* currentRowFrame
= &aStartRowFrame
;
126 // XXXneerja - Instead of calling AddDeletedRowIndex() per row frame
127 // it is possible to change AddDeleteRowIndex to instead take
128 // <start row index> and <num of rows to mark for deletion> as arguments.
129 // The problem that emerges here is mDeletedRowIndexRanges only stores
130 // disjoint index ranges and since AddDeletedRowIndex() must operate on
131 // the "stored" index, in some cases it is possible that the range
132 // of indices to delete becomes overlapping EG: Deleting rows 9 - 11 and
133 // then from the remaining rows deleting the *new* rows 7 to 20.
134 // Handling these overlapping ranges is much more complicated to
135 // implement and so I opted to add the deleted row index of one row at a
136 // time and maintain the invariant that the range of deleted row indices
137 // is always disjoint.
138 currentRowFrame
->AddDeletedRowIndex();
139 if (--aNumRowsToDelete
== 0) {
142 currentRowFrame
= do_QueryFrame(currentRowFrame
->GetNextSibling());
143 if (!currentRowFrame
) {
144 MOZ_ASSERT_UNREACHABLE("expected another row frame");
150 void nsTableRowGroupFrame::AddDeletedRowIndex(int32_t aDeletedRowStoredIndex
) {
151 nsTableFrame
* tableFrame
= GetTableFrame();
152 return tableFrame
->AddDeletedRowIndex(aDeletedRowStoredIndex
);
155 nsresult
nsTableRowGroupFrame::InitRepeatedFrame(
156 nsTableRowGroupFrame
* aHeaderFooterFrame
) {
157 nsTableRowFrame
* copyRowFrame
= GetFirstRow();
158 nsTableRowFrame
* originalRowFrame
= aHeaderFooterFrame
->GetFirstRow();
159 AddStateBits(NS_REPEATED_ROW_OR_ROWGROUP
);
160 while (copyRowFrame
&& originalRowFrame
) {
161 copyRowFrame
->AddStateBits(NS_REPEATED_ROW_OR_ROWGROUP
);
162 int rowIndex
= originalRowFrame
->GetRowIndex();
163 copyRowFrame
->SetRowIndex(rowIndex
);
165 // For each table cell frame set its column index
166 nsTableCellFrame
* originalCellFrame
= originalRowFrame
->GetFirstCell();
167 nsTableCellFrame
* copyCellFrame
= copyRowFrame
->GetFirstCell();
168 while (copyCellFrame
&& originalCellFrame
) {
170 originalCellFrame
->GetContent() == copyCellFrame
->GetContent(),
171 "cell frames have different content");
172 uint32_t colIndex
= originalCellFrame
->ColIndex();
173 copyCellFrame
->SetColIndex(colIndex
);
175 // Move to the next cell frame
176 copyCellFrame
= copyCellFrame
->GetNextCell();
177 originalCellFrame
= originalCellFrame
->GetNextCell();
180 // Move to the next row frame
181 originalRowFrame
= originalRowFrame
->GetNextRow();
182 copyRowFrame
= copyRowFrame
->GetNextRow();
188 // Handle the child-traversal part of DisplayGenericTablePart
189 static void DisplayRows(nsDisplayListBuilder
* aBuilder
, nsIFrame
* aFrame
,
190 const nsDisplayListSet
& aLists
) {
191 nscoord overflowAbove
;
192 nsTableRowGroupFrame
* f
= static_cast<nsTableRowGroupFrame
*>(aFrame
);
193 // Don't try to use the row cursor if we have to descend into placeholders;
194 // we might have rows containing placeholders, where the row's overflow
195 // area doesn't intersect the dirty rect but we need to descend into the row
196 // to see out of flows.
197 // Note that we really want to check ShouldDescendIntoFrame for all
198 // the rows in |f|, but that's exactly what we're trying to avoid, so we
199 // approximate it by checking it for |f|: if it's true for any row
200 // in |f| then it's true for |f| itself.
201 nsIFrame
* kid
= aBuilder
->ShouldDescendIntoFrame(f
, true)
203 : f
->GetFirstRowContaining(aBuilder
->GetVisibleRect().y
,
207 // have a cursor, use it
209 if (kid
->GetRect().y
- overflowAbove
>=
210 aBuilder
->GetVisibleRect().YMost()) {
213 f
->BuildDisplayListForChild(aBuilder
, kid
, aLists
);
214 kid
= kid
->GetNextSibling();
219 // No cursor. Traverse children the hard way and build a cursor while we're at
221 nsTableRowGroupFrame::FrameCursorData
* cursor
= f
->SetupRowCursor();
222 kid
= f
->PrincipalChildList().FirstChild();
224 f
->BuildDisplayListForChild(aBuilder
, kid
, aLists
);
227 if (!cursor
->AppendFrame(kid
)) {
233 kid
= kid
->GetNextSibling();
236 cursor
->FinishBuildingCursor();
240 void nsTableRowGroupFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
241 const nsDisplayListSet
& aLists
) {
242 DisplayOutsetBoxShadow(aBuilder
, aLists
.BorderBackground());
244 for (nsTableRowFrame
* row
= GetFirstRow(); row
; row
= row
->GetNextRow()) {
245 if (!aBuilder
->GetDirtyRect().Intersects(row
->InkOverflowRect() +
246 row
->GetNormalPosition())) {
249 row
->PaintCellBackgroundsForFrame(this, aBuilder
, aLists
,
250 row
->GetNormalPosition());
253 DisplayInsetBoxShadow(aBuilder
, aLists
.BorderBackground());
255 DisplayOutline(aBuilder
, aLists
);
257 DisplayRows(aBuilder
, this, aLists
);
260 LogicalSides
nsTableRowGroupFrame::GetLogicalSkipSides() const {
261 LogicalSides
skip(mWritingMode
);
262 if (MOZ_UNLIKELY(StyleBorder()->mBoxDecorationBreak
==
263 StyleBoxDecorationBreak::Clone
)) {
267 if (GetPrevInFlow()) {
268 skip
|= eLogicalSideBitsBStart
;
270 if (GetNextInFlow()) {
271 skip
|= eLogicalSideBitsBEnd
;
276 // Position and size aKidFrame and update our reflow input.
277 void nsTableRowGroupFrame::PlaceChild(
278 nsPresContext
* aPresContext
, TableRowGroupReflowInput
& aReflowInput
,
279 nsIFrame
* aKidFrame
, const ReflowInput
& aKidReflowInput
, WritingMode aWM
,
280 const LogicalPoint
& aKidPosition
, const nsSize
& aContainerSize
,
281 ReflowOutput
& aDesiredSize
, const nsRect
& aOriginalKidRect
,
282 const nsRect
& aOriginalKidInkOverflow
) {
283 bool isFirstReflow
= aKidFrame
->HasAnyStateBits(NS_FRAME_FIRST_REFLOW
);
285 // Place and size the child
286 FinishReflowChild(aKidFrame
, aPresContext
, aDesiredSize
, &aKidReflowInput
,
287 aWM
, aKidPosition
, aContainerSize
,
288 ReflowChildFlags::ApplyRelativePositioning
);
290 nsTableFrame
* tableFrame
= GetTableFrame();
291 if (tableFrame
->IsBorderCollapse()) {
292 nsTableFrame::InvalidateTableFrame(aKidFrame
, aOriginalKidRect
,
293 aOriginalKidInkOverflow
, isFirstReflow
);
296 // Adjust the running block-offset
297 aReflowInput
.bCoord
+= aDesiredSize
.BSize(aWM
);
299 // If our block-size is constrained then update the available bsize
300 if (NS_UNCONSTRAINEDSIZE
!= aReflowInput
.availSize
.BSize(aWM
)) {
301 aReflowInput
.availSize
.BSize(aWM
) -= aDesiredSize
.BSize(aWM
);
305 void nsTableRowGroupFrame::InitChildReflowInput(nsPresContext
& aPresContext
,
306 bool aBorderCollapse
,
307 ReflowInput
& aReflowInput
) {
308 const auto childWM
= aReflowInput
.GetWritingMode();
309 LogicalMargin
border(childWM
);
310 if (nsTableRowFrame
* rowFrame
= do_QueryFrame(aReflowInput
.mFrame
)) {
311 if (aBorderCollapse
) {
312 border
= rowFrame
->GetBCBorderWidth(childWM
);
315 const LogicalMargin
zeroPadding(childWM
);
316 aReflowInput
.Init(&aPresContext
, Nothing(), Some(border
), Some(zeroPadding
));
319 static void CacheRowBSizesForPrinting(nsPresContext
* aPresContext
,
320 nsTableRowFrame
* aFirstRow
,
322 for (nsTableRowFrame
* row
= aFirstRow
; row
; row
= row
->GetNextRow()) {
323 if (!row
->GetPrevInFlow()) {
324 row
->SetHasUnpaginatedBSize(true);
325 row
->SetUnpaginatedBSize(aPresContext
, row
->BSize(aWM
));
330 void nsTableRowGroupFrame::ReflowChildren(
331 nsPresContext
* aPresContext
, ReflowOutput
& aDesiredSize
,
332 TableRowGroupReflowInput
& aReflowInput
, nsReflowStatus
& aStatus
,
333 bool* aPageBreakBeforeEnd
) {
334 if (aPageBreakBeforeEnd
) {
335 *aPageBreakBeforeEnd
= false;
338 WritingMode wm
= aReflowInput
.reflowInput
.GetWritingMode();
339 nsTableFrame
* tableFrame
= GetTableFrame();
340 const bool borderCollapse
= tableFrame
->IsBorderCollapse();
342 // XXXldb Should we really be checking IsPaginated(),
343 // or should we *only* check available block-size?
344 // (Think about multi-column layout!)
345 bool isPaginated
= aPresContext
->IsPaginated() &&
346 NS_UNCONSTRAINEDSIZE
!= aReflowInput
.availSize
.BSize(wm
);
348 bool haveRow
= false;
349 bool reflowAllKids
= aReflowInput
.reflowInput
.ShouldReflowAllKids() ||
350 tableFrame
->IsGeometryDirty() ||
351 tableFrame
->NeedToCollapse();
353 // in vertical-rl mode, we always need the row bsizes in order to
354 // get the necessary containerSize for placing our kids
355 bool needToCalcRowBSizes
= reflowAllKids
|| wm
.IsVerticalRL();
357 nsSize containerSize
=
358 aReflowInput
.reflowInput
.ComputedSizeAsContainerIfConstrained();
360 nsIFrame
* prevKidFrame
= nullptr;
361 for (nsIFrame
* kidFrame
= mFrames
.FirstChild(); kidFrame
;
362 prevKidFrame
= kidFrame
, kidFrame
= kidFrame
->GetNextSibling()) {
363 nsTableRowFrame
* rowFrame
= do_QueryFrame(kidFrame
);
365 // XXXldb nsCSSFrameConstructor needs to enforce this!
366 MOZ_ASSERT_UNREACHABLE("yikes, a non-row child");
369 nscoord cellSpacingB
= tableFrame
->GetRowSpacing(rowFrame
->GetRowIndex());
372 // Reflow the row frame
373 if (reflowAllKids
|| kidFrame
->IsSubtreeDirty() ||
374 (aReflowInput
.reflowInput
.mFlags
.mSpecialBSizeReflow
&&
376 kidFrame
->HasAnyStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE
)))) {
377 LogicalRect oldKidRect
= kidFrame
->GetLogicalRect(wm
, containerSize
);
378 nsRect oldKidInkOverflow
= kidFrame
->InkOverflowRect();
380 ReflowOutput
desiredSize(aReflowInput
.reflowInput
);
381 desiredSize
.ClearSize();
383 // Reflow the child into the available space, giving it as much bsize as
384 // it wants. We'll deal with splitting later after we've computed the row
385 // bsizes, taking into account cells with row spans...
386 LogicalSize kidAvailSize
= aReflowInput
.availSize
;
387 kidAvailSize
.BSize(wm
) = NS_UNCONSTRAINEDSIZE
;
388 ReflowInput
kidReflowInput(aPresContext
, aReflowInput
.reflowInput
,
389 kidFrame
, kidAvailSize
, Nothing(),
390 ReflowInput::InitFlag::CallerWillInit
);
391 InitChildReflowInput(*aPresContext
, borderCollapse
, kidReflowInput
);
393 // This can indicate that columns were resized.
394 if (aReflowInput
.reflowInput
.IsIResize()) {
395 kidReflowInput
.SetIResize(true);
398 NS_ASSERTION(kidFrame
== mFrames
.FirstChild() || prevKidFrame
,
399 "If we're not on the first frame, we should have a "
400 "previous sibling...");
401 // If prev row has nonzero YMost, then we can't be at the top of the page
402 if (prevKidFrame
&& prevKidFrame
->GetNormalRect().YMost() > 0) {
403 kidReflowInput
.mFlags
.mIsTopOfPage
= false;
406 LogicalPoint
kidPosition(wm
, 0, aReflowInput
.bCoord
);
407 ReflowChild(kidFrame
, aPresContext
, desiredSize
, kidReflowInput
, wm
,
408 kidPosition
, containerSize
, ReflowChildFlags::Default
,
412 PlaceChild(aPresContext
, aReflowInput
, kidFrame
, kidReflowInput
, wm
,
413 kidPosition
, containerSize
, desiredSize
,
414 oldKidRect
.GetPhysicalRect(wm
, containerSize
),
416 aReflowInput
.bCoord
+= cellSpacingB
;
418 if (!reflowAllKids
) {
419 if (IsSimpleRowFrame(aReflowInput
.tableFrame
, rowFrame
)) {
420 // Inform the row of its new bsize.
421 rowFrame
->DidResize();
422 // the overflow area may have changed inflate the overflow area
423 const nsStylePosition
* stylePos
= StylePosition();
424 if (aReflowInput
.tableFrame
->IsAutoBSize(wm
) &&
425 !stylePos
->BSize(wm
).ConvertsToLength()) {
426 // Because other cells in the row may need to be aligned
427 // differently, repaint the entire row
429 } else if (oldKidRect
.BSize(wm
) != desiredSize
.BSize(wm
)) {
430 needToCalcRowBSizes
= true;
433 needToCalcRowBSizes
= true;
437 if (isPaginated
&& aPageBreakBeforeEnd
&& !*aPageBreakBeforeEnd
) {
438 nsTableRowFrame
* nextRow
= rowFrame
->GetNextRow();
440 *aPageBreakBeforeEnd
=
441 nsTableFrame::PageBreakAfter(kidFrame
, nextRow
);
445 SlideChild(aReflowInput
, kidFrame
);
447 // Adjust the running b-offset so we know where the next row should be
449 nscoord bSize
= kidFrame
->BSize(wm
) + cellSpacingB
;
450 aReflowInput
.bCoord
+= bSize
;
452 if (NS_UNCONSTRAINEDSIZE
!= aReflowInput
.availSize
.BSize(wm
)) {
453 aReflowInput
.availSize
.BSize(wm
) -= bSize
;
456 ConsiderChildOverflow(aDesiredSize
.mOverflowAreas
, kidFrame
);
460 aReflowInput
.bCoord
-=
461 tableFrame
->GetRowSpacing(GetStartRowIndex() + GetRowCount());
464 // Return our desired rect
465 aDesiredSize
.ISize(wm
) = aReflowInput
.reflowInput
.AvailableISize();
466 aDesiredSize
.BSize(wm
) = aReflowInput
.bCoord
;
468 if (aReflowInput
.reflowInput
.mFlags
.mSpecialBSizeReflow
) {
469 DidResizeRows(aDesiredSize
);
471 CacheRowBSizesForPrinting(aPresContext
, GetFirstRow(), wm
);
473 } else if (needToCalcRowBSizes
) {
474 CalculateRowBSizes(aPresContext
, aDesiredSize
, aReflowInput
.reflowInput
);
475 if (!reflowAllKids
) {
481 nsTableRowFrame
* nsTableRowGroupFrame::GetFirstRow() {
482 for (nsIFrame
* childFrame
: mFrames
) {
483 nsTableRowFrame
* rowFrame
= do_QueryFrame(childFrame
);
491 nsTableRowFrame
* nsTableRowGroupFrame::GetLastRow() {
492 for (auto iter
= mFrames
.rbegin(), end
= mFrames
.rend(); iter
!= end
;
494 nsTableRowFrame
* rowFrame
= do_QueryFrame(*iter
);
503 RowInfo() { bSize
= pctBSize
= hasStyleBSize
= hasPctBSize
= isSpecial
= 0; }
504 unsigned bSize
; // content bsize or fixed bsize, excluding pct bsize
505 unsigned pctBSize
: 29; // pct bsize
506 unsigned hasStyleBSize
: 1;
507 unsigned hasPctBSize
: 1;
508 unsigned isSpecial
: 1; // there is no cell originating in the row with
509 // rowspan=1 and there are at least 2 cells spanning
510 // the row and there is no style bsize on the row
513 static void UpdateBSizes(RowInfo
& aRowInfo
, nscoord aAdditionalBSize
,
514 nscoord
& aTotal
, nscoord
& aUnconstrainedTotal
) {
515 aRowInfo
.bSize
+= aAdditionalBSize
;
516 aTotal
+= aAdditionalBSize
;
517 if (!aRowInfo
.hasStyleBSize
) {
518 aUnconstrainedTotal
+= aAdditionalBSize
;
522 void nsTableRowGroupFrame::DidResizeRows(ReflowOutput
& aDesiredSize
) {
523 // Update the cells spanning rows with their new bsizes.
524 // This is the place where all of the cells in the row get set to the bsize
526 // Reset the overflow area.
527 aDesiredSize
.mOverflowAreas
.Clear();
528 for (nsTableRowFrame
* rowFrame
= GetFirstRow(); rowFrame
;
529 rowFrame
= rowFrame
->GetNextRow()) {
530 rowFrame
->DidResize();
531 ConsiderChildOverflow(aDesiredSize
.mOverflowAreas
, rowFrame
);
535 // This calculates the bsize of all the rows and takes into account
536 // style bsize on the row group, style bsizes on rows and cells, style bsizes on
537 // rowspans. Actual row bsizes will be adjusted later if the table has a style
538 // bsize. Even if rows don't change bsize, this method must be called to set the
539 // bsizes of each cell in the row to the bsize of its row.
540 void nsTableRowGroupFrame::CalculateRowBSizes(nsPresContext
* aPresContext
,
541 ReflowOutput
& aDesiredSize
,
542 const ReflowInput
& aReflowInput
) {
543 nsTableFrame
* tableFrame
= GetTableFrame();
544 const bool isPaginated
= aPresContext
->IsPaginated();
546 int32_t numEffCols
= tableFrame
->GetEffectiveColCount();
548 int32_t startRowIndex
= GetStartRowIndex();
549 // find the row corresponding to the row index we just found
550 nsTableRowFrame
* startRowFrame
= GetFirstRow();
552 if (!startRowFrame
) {
556 // The current row group block-size is the block-origin of the 1st row
557 // we are about to calculate a block-size for.
558 WritingMode wm
= aReflowInput
.GetWritingMode();
559 nsSize containerSize
; // actual value is unimportant as we're initially
560 // computing sizes, not physical positions
561 nscoord startRowGroupBSize
=
562 startRowFrame
->GetLogicalNormalPosition(wm
, containerSize
).B(wm
);
565 GetRowCount() - (startRowFrame
->GetRowIndex() - GetStartRowIndex());
566 // Collect the current bsize of each row.
567 if (numRows
<= 0) return;
569 AutoTArray
<RowInfo
, 32> rowInfo
;
570 // XXX(Bug 1631371) Check if this should use a fallible operation as it
571 // pretended earlier.
572 rowInfo
.AppendElements(numRows
);
574 bool hasRowSpanningCell
= false;
575 nscoord bSizeOfRows
= 0;
576 nscoord bSizeOfUnStyledRows
= 0;
577 // Get the bsize of each row without considering rowspans. This will be the
578 // max of the largest desired bsize of each cell, the largest style bsize of
579 // each cell, the style bsize of the row.
580 nscoord pctBSizeBasis
= GetBSizeBasis(aReflowInput
);
582 rowIndex
; // the index in rowInfo, not among the rows in the row group
583 nsTableRowFrame
* rowFrame
;
584 for (rowFrame
= startRowFrame
, rowIndex
= 0; rowFrame
;
585 rowFrame
= rowFrame
->GetNextRow(), rowIndex
++) {
586 nscoord nonPctBSize
= rowFrame
->GetContentBSize();
588 nonPctBSize
= std::max(nonPctBSize
, rowFrame
->BSize(wm
));
590 if (!rowFrame
->GetPrevInFlow()) {
591 if (rowFrame
->HasPctBSize()) {
592 rowInfo
[rowIndex
].hasPctBSize
= true;
593 rowInfo
[rowIndex
].pctBSize
= rowFrame
->GetInitialBSize(pctBSizeBasis
);
595 rowInfo
[rowIndex
].hasStyleBSize
= rowFrame
->HasStyleBSize();
596 nonPctBSize
= std::max(nonPctBSize
, rowFrame
->GetFixedBSize());
598 UpdateBSizes(rowInfo
[rowIndex
], nonPctBSize
, bSizeOfRows
,
599 bSizeOfUnStyledRows
);
601 if (!rowInfo
[rowIndex
].hasStyleBSize
) {
603 tableFrame
->HasMoreThanOneCell(rowIndex
+ startRowIndex
)) {
604 rowInfo
[rowIndex
].isSpecial
= true;
605 // iteratate the row's cell frames to see if any do not have rowspan > 1
606 nsTableCellFrame
* cellFrame
= rowFrame
->GetFirstCell();
608 int32_t rowSpan
= tableFrame
->GetEffectiveRowSpan(
609 rowIndex
+ startRowIndex
, *cellFrame
);
611 rowInfo
[rowIndex
].isSpecial
= false;
614 cellFrame
= cellFrame
->GetNextCell();
618 // See if a cell spans into the row. If so we'll have to do the next step
619 if (!hasRowSpanningCell
) {
620 if (tableFrame
->RowIsSpannedInto(rowIndex
+ startRowIndex
, numEffCols
)) {
621 hasRowSpanningCell
= true;
626 if (hasRowSpanningCell
) {
627 // Get the bsize of cells with rowspans and allocate any extra space to the
628 // rows they span iteratate the child frames and process the row frames
630 for (rowFrame
= startRowFrame
, rowIndex
= 0; rowFrame
;
631 rowFrame
= rowFrame
->GetNextRow(), rowIndex
++) {
632 // See if the row has an originating cell with rowspan > 1. We cannot
633 // determine this for a row in a continued row group by calling
634 // RowHasSpanningCells, because the row's fif may not have any originating
635 // cells yet the row may have a continued cell which originates in it.
636 if (GetPrevInFlow() || tableFrame
->RowHasSpanningCells(
637 startRowIndex
+ rowIndex
, numEffCols
)) {
638 nsTableCellFrame
* cellFrame
= rowFrame
->GetFirstCell();
639 // iteratate the row's cell frames
641 nscoord cellSpacingB
=
642 tableFrame
->GetRowSpacing(startRowIndex
+ rowIndex
);
643 int32_t rowSpan
= tableFrame
->GetEffectiveRowSpan(
644 rowIndex
+ startRowIndex
, *cellFrame
);
645 if ((rowIndex
+ rowSpan
) > numRows
) {
646 // there might be rows pushed already to the nextInFlow
647 rowSpan
= numRows
- rowIndex
;
649 if (rowSpan
> 1) { // a cell with rowspan > 1, determine the bsize of
651 nscoord bsizeOfRowsSpanned
= 0;
652 nscoord bsizeOfUnStyledRowsSpanned
= 0;
653 nscoord numSpecialRowsSpanned
= 0;
654 nscoord cellSpacingTotal
= 0;
656 for (spanX
= 0; spanX
< rowSpan
; spanX
++) {
657 bsizeOfRowsSpanned
+= rowInfo
[rowIndex
+ spanX
].bSize
;
658 if (!rowInfo
[rowIndex
+ spanX
].hasStyleBSize
) {
659 bsizeOfUnStyledRowsSpanned
+= rowInfo
[rowIndex
+ spanX
].bSize
;
662 cellSpacingTotal
+= cellSpacingB
;
664 if (rowInfo
[rowIndex
+ spanX
].isSpecial
) {
665 numSpecialRowsSpanned
++;
668 nscoord bsizeOfAreaSpanned
= bsizeOfRowsSpanned
+ cellSpacingTotal
;
669 // get the bsize of the cell
670 LogicalSize cellFrameSize
= cellFrame
->GetLogicalSize(wm
);
671 LogicalSize cellDesSize
= cellFrame
->GetDesiredSize();
672 rowFrame
->CalculateCellActualBSize(cellFrame
, cellDesSize
.BSize(wm
),
674 cellFrameSize
.BSize(wm
) = cellDesSize
.BSize(wm
);
675 if (cellFrame
->HasVerticalAlignBaseline()) {
676 // to ensure that a spanning cell with a long descender doesn't
677 // collide with the next row, we need to take into account the
678 // shift that will be done to align the cell on the baseline of
680 cellFrameSize
.BSize(wm
) +=
681 rowFrame
->GetMaxCellAscent() - cellFrame
->GetCellBaseline();
684 if (bsizeOfAreaSpanned
< cellFrameSize
.BSize(wm
)) {
685 // the cell's bsize is larger than the available space of the rows
686 // it spans so distribute the excess bsize to the rows affected
687 nscoord extra
= cellFrameSize
.BSize(wm
) - bsizeOfAreaSpanned
;
688 nscoord extraUsed
= 0;
689 if (0 == numSpecialRowsSpanned
) {
690 // NS_ASSERTION(bsizeOfRowsSpanned > 0, "invalid row span
692 bool haveUnStyledRowsSpanned
= (bsizeOfUnStyledRowsSpanned
> 0);
693 nscoord divisor
= (haveUnStyledRowsSpanned
)
694 ? bsizeOfUnStyledRowsSpanned
695 : bsizeOfRowsSpanned
;
697 for (spanX
= rowSpan
- 1; spanX
>= 0; spanX
--) {
698 if (!haveUnStyledRowsSpanned
||
699 !rowInfo
[rowIndex
+ spanX
].hasStyleBSize
) {
700 // The amount of additional space each row gets is
701 // proportional to its bsize
702 float percent
= ((float)rowInfo
[rowIndex
+ spanX
].bSize
) /
705 // give rows their percentage, except for the first row
706 // which gets the remainder
707 nscoord extraForRow
=
710 : NSToCoordRound(((float)(extra
)) * percent
);
711 extraForRow
= std::min(extraForRow
, extra
- extraUsed
);
712 // update the row bsize
713 UpdateBSizes(rowInfo
[rowIndex
+ spanX
], extraForRow
,
714 bSizeOfRows
, bSizeOfUnStyledRows
);
715 extraUsed
+= extraForRow
;
716 if (extraUsed
>= extra
) {
717 NS_ASSERTION((extraUsed
== extra
),
718 "invalid row bsize calculation");
724 // put everything in the last row
725 UpdateBSizes(rowInfo
[rowIndex
+ rowSpan
- 1], extra
,
726 bSizeOfRows
, bSizeOfUnStyledRows
);
729 // give the extra to the special rows
730 nscoord numSpecialRowsAllocated
= 0;
731 for (spanX
= rowSpan
- 1; spanX
>= 0; spanX
--) {
732 if (rowInfo
[rowIndex
+ spanX
].isSpecial
) {
733 // The amount of additional space each degenerate row gets
734 // is proportional to the number of them
735 float percent
= 1.0f
/ ((float)numSpecialRowsSpanned
);
737 // give rows their percentage, except for the first row
738 // which gets the remainder
739 nscoord extraForRow
=
740 (numSpecialRowsSpanned
- 1 == numSpecialRowsAllocated
)
742 : NSToCoordRound(((float)(extra
)) * percent
);
743 extraForRow
= std::min(extraForRow
, extra
- extraUsed
);
744 // update the row bsize
745 UpdateBSizes(rowInfo
[rowIndex
+ spanX
], extraForRow
,
746 bSizeOfRows
, bSizeOfUnStyledRows
);
747 extraUsed
+= extraForRow
;
748 if (extraUsed
>= extra
) {
749 NS_ASSERTION((extraUsed
== extra
),
750 "invalid row bsize calculation");
757 } // if (rowSpan > 1)
758 cellFrame
= cellFrame
->GetNextCell();
759 } // while (cellFrame)
760 } // if (tableFrame->RowHasSpanningCells(startRowIndex + rowIndex) {
761 } // while (rowFrame)
764 // pct bsize rows have already got their content bsizes.
765 // Give them their pct bsizes up to pctBSizeBasis
766 nscoord extra
= pctBSizeBasis
- bSizeOfRows
;
767 for (rowFrame
= startRowFrame
, rowIndex
= 0; rowFrame
&& (extra
> 0);
768 rowFrame
= rowFrame
->GetNextRow(), rowIndex
++) {
769 RowInfo
& rInfo
= rowInfo
[rowIndex
];
770 if (rInfo
.hasPctBSize
) {
772 (rInfo
.pctBSize
> rInfo
.bSize
) ? rInfo
.pctBSize
- rInfo
.bSize
: 0;
773 rowExtra
= std::min(rowExtra
, extra
);
774 UpdateBSizes(rInfo
, rowExtra
, bSizeOfRows
, bSizeOfUnStyledRows
);
779 bool styleBSizeAllocation
= false;
780 nscoord rowGroupBSize
= startRowGroupBSize
+ bSizeOfRows
+
781 tableFrame
->GetRowSpacing(0, numRows
- 1);
782 // if we have a style bsize, allocate the extra bsize to unconstrained rows
783 if ((aReflowInput
.ComputedBSize() > rowGroupBSize
) &&
784 (NS_UNCONSTRAINEDSIZE
!= aReflowInput
.ComputedBSize())) {
785 nscoord extraComputedBSize
= aReflowInput
.ComputedBSize() - rowGroupBSize
;
786 nscoord extraUsed
= 0;
787 bool haveUnStyledRows
= (bSizeOfUnStyledRows
> 0);
788 nscoord divisor
= (haveUnStyledRows
) ? bSizeOfUnStyledRows
: bSizeOfRows
;
790 styleBSizeAllocation
= true;
791 for (rowIndex
= 0; rowIndex
< numRows
; rowIndex
++) {
792 if (!haveUnStyledRows
|| !rowInfo
[rowIndex
].hasStyleBSize
) {
793 // The amount of additional space each row gets is based on the
794 // percentage of space it occupies
795 float percent
= ((float)rowInfo
[rowIndex
].bSize
) / ((float)divisor
);
796 // give rows their percentage, except for the last row which gets the
798 nscoord extraForRow
=
799 (numRows
- 1 == rowIndex
)
800 ? extraComputedBSize
- extraUsed
801 : NSToCoordRound(((float)extraComputedBSize
) * percent
);
802 extraForRow
= std::min(extraForRow
, extraComputedBSize
- extraUsed
);
803 // update the row bsize
804 UpdateBSizes(rowInfo
[rowIndex
], extraForRow
, bSizeOfRows
,
805 bSizeOfUnStyledRows
);
806 extraUsed
+= extraForRow
;
807 if (extraUsed
>= extraComputedBSize
) {
808 NS_ASSERTION((extraUsed
== extraComputedBSize
),
809 "invalid row bsize calculation");
815 rowGroupBSize
= aReflowInput
.ComputedBSize();
818 if (wm
.IsVertical()) {
819 // we need the correct containerSize below for block positioning in
820 // vertical-rl writing mode
821 containerSize
.width
= rowGroupBSize
;
824 nscoord bOrigin
= startRowGroupBSize
;
825 // update the rows with their (potentially) new bsizes
826 for (rowFrame
= startRowFrame
, rowIndex
= 0; rowFrame
;
827 rowFrame
= rowFrame
->GetNextRow(), rowIndex
++) {
828 nsRect rowBounds
= rowFrame
->GetRect();
829 LogicalSize
rowBoundsSize(wm
, rowBounds
.Size());
830 nsRect rowInkOverflow
= rowFrame
->InkOverflowRect();
832 bOrigin
- rowFrame
->GetLogicalNormalPosition(wm
, containerSize
).B(wm
);
835 (rowInfo
[rowIndex
].bSize
> 0) ? rowInfo
[rowIndex
].bSize
: 0;
837 if (deltaB
!= 0 || (rowBSize
!= rowBoundsSize
.BSize(wm
))) {
838 // Resize/move the row to its final size and position
840 rowFrame
->InvalidateFrameSubtree();
843 rowFrame
->MovePositionBy(wm
, LogicalPoint(wm
, 0, deltaB
));
844 rowFrame
->SetSize(LogicalSize(wm
, rowBoundsSize
.ISize(wm
), rowBSize
));
846 nsTableFrame::InvalidateTableFrame(rowFrame
, rowBounds
, rowInkOverflow
,
850 nsTableFrame::RePositionViews(rowFrame
);
851 // XXXbz we don't need to update our overflow area?
854 bOrigin
+= rowBSize
+ tableFrame
->GetRowSpacing(startRowIndex
+ rowIndex
);
857 if (isPaginated
&& styleBSizeAllocation
) {
858 // since the row group has a style bsize, cache the row bsizes,
859 // so next in flows can honor them
860 CacheRowBSizesForPrinting(aPresContext
, GetFirstRow(), wm
);
863 DidResizeRows(aDesiredSize
);
865 aDesiredSize
.BSize(wm
) = rowGroupBSize
; // Adjust our desired size
868 nscoord
nsTableRowGroupFrame::CollapseRowGroupIfNecessary(nscoord aBTotalOffset
,
871 nsTableFrame
* tableFrame
= GetTableFrame();
872 nsSize containerSize
= tableFrame
->GetSize();
873 const nsStyleVisibility
* groupVis
= StyleVisibility();
874 bool collapseGroup
= StyleVisibility::Collapse
== groupVis
->mVisible
;
876 tableFrame
->SetNeedToCollapse(true);
879 OverflowAreas overflow
;
881 nsTableRowFrame
* rowFrame
= GetFirstRow();
882 bool didCollapse
= false;
883 nscoord bGroupOffset
= 0;
885 bGroupOffset
+= rowFrame
->CollapseRowIfNecessary(
886 bGroupOffset
, aISize
, collapseGroup
, didCollapse
);
887 ConsiderChildOverflow(overflow
, rowFrame
);
888 rowFrame
= rowFrame
->GetNextRow();
891 LogicalRect groupRect
= GetLogicalRect(aWM
, containerSize
);
892 nsRect oldGroupRect
= GetRect();
893 nsRect oldGroupInkOverflow
= InkOverflowRect();
895 groupRect
.BSize(aWM
) -= bGroupOffset
;
897 // add back the cellspacing between rowgroups
898 groupRect
.BSize(aWM
) +=
899 tableFrame
->GetRowSpacing(GetStartRowIndex() + GetRowCount());
902 groupRect
.BStart(aWM
) -= aBTotalOffset
;
903 groupRect
.ISize(aWM
) = aISize
;
905 if (aBTotalOffset
!= 0) {
906 InvalidateFrameSubtree();
909 SetRect(aWM
, groupRect
, containerSize
);
910 overflow
.UnionAllWith(
911 nsRect(0, 0, groupRect
.Width(aWM
), groupRect
.Height(aWM
)));
912 FinishAndStoreOverflow(overflow
, groupRect
.Size(aWM
).GetPhysicalSize(aWM
));
913 nsTableFrame::RePositionViews(this);
914 nsTableFrame::InvalidateTableFrame(this, oldGroupRect
, oldGroupInkOverflow
,
920 // Move a child that was skipped during a reflow.
921 void nsTableRowGroupFrame::SlideChild(TableRowGroupReflowInput
& aReflowInput
,
922 nsIFrame
* aKidFrame
) {
923 // Move the frame if we need to.
924 WritingMode wm
= aReflowInput
.reflowInput
.GetWritingMode();
925 const nsSize containerSize
=
926 aReflowInput
.reflowInput
.ComputedSizeAsContainerIfConstrained();
927 LogicalPoint oldPosition
=
928 aKidFrame
->GetLogicalNormalPosition(wm
, containerSize
);
929 LogicalPoint newPosition
= oldPosition
;
930 newPosition
.B(wm
) = aReflowInput
.bCoord
;
931 if (oldPosition
.B(wm
) != newPosition
.B(wm
)) {
932 aKidFrame
->InvalidateFrameSubtree();
933 aReflowInput
.reflowInput
.ApplyRelativePositioning(&newPosition
,
935 aKidFrame
->SetPosition(wm
, newPosition
, containerSize
);
936 nsTableFrame::RePositionViews(aKidFrame
);
937 aKidFrame
->InvalidateFrameSubtree();
941 // Create a continuing frame, add it to the child list, and then push it
942 // and the frames that follow
943 void nsTableRowGroupFrame::CreateContinuingRowFrame(nsIFrame
& aRowFrame
,
944 nsIFrame
** aContRowFrame
) {
945 // XXX what is the row index?
946 if (!aContRowFrame
) {
947 NS_ASSERTION(false, "bad call");
950 // create the continuing frame which will create continuing cell frames
952 PresShell()->FrameConstructor()->CreateContinuingFrame(&aRowFrame
, this);
954 // Add the continuing row frame to the child list
955 mFrames
.InsertFrame(nullptr, &aRowFrame
, *aContRowFrame
);
957 // Push the continuing row frame and the frames that follow
958 PushChildren(*aContRowFrame
, &aRowFrame
);
961 // Reflow the cells with rowspan > 1 which originate between aFirstRow
962 // and end on or after aLastRow. aFirstTruncatedRow is the highest row on the
963 // page that contains a cell which cannot split on this page
964 void nsTableRowGroupFrame::SplitSpanningCells(
965 nsPresContext
& aPresContext
, const ReflowInput
& aReflowInput
,
966 nsTableFrame
& aTable
, nsTableRowFrame
& aFirstRow
, nsTableRowFrame
& aLastRow
,
967 bool aFirstRowIsTopOfPage
, nscoord aSpanningRowBEnd
,
968 nsTableRowFrame
*& aContRow
, nsTableRowFrame
*& aFirstTruncatedRow
,
969 nscoord
& aDesiredBSize
) {
970 NS_ASSERTION(aSpanningRowBEnd
>= 0, "Can't split negative bsizes");
971 aFirstTruncatedRow
= nullptr;
974 const bool borderCollapse
= aTable
.IsBorderCollapse();
975 int32_t lastRowIndex
= aLastRow
.GetRowIndex();
976 bool wasLast
= false;
977 bool haveRowSpan
= false;
978 // Iterate the rows between aFirstRow and aLastRow
979 for (nsTableRowFrame
* row
= &aFirstRow
; !wasLast
; row
= row
->GetNextRow()) {
980 wasLast
= (row
== &aLastRow
);
981 int32_t rowIndex
= row
->GetRowIndex();
982 nsPoint rowPos
= row
->GetNormalPosition();
983 // Iterate the cells looking for those that have rowspan > 1
984 for (nsTableCellFrame
* cell
= row
->GetFirstCell(); cell
;
985 cell
= cell
->GetNextCell()) {
986 int32_t rowSpan
= aTable
.GetEffectiveRowSpan(rowIndex
, *cell
);
987 // Only reflow rowspan > 1 cells which span aLastRow. Those which don't
988 // span aLastRow were reflowed correctly during the unconstrained bsize
990 if ((rowSpan
> 1) && (rowIndex
+ rowSpan
> lastRowIndex
)) {
992 nsReflowStatus status
;
993 // Ask the row to reflow the cell to the bsize of all the rows it spans
994 // up through aLastRow cellAvailBSize is the space between the row group
995 // start and the end of the page
996 nscoord cellAvailBSize
= aSpanningRowBEnd
- rowPos
.y
;
997 NS_ASSERTION(cellAvailBSize
>= 0, "No space for cell?");
998 bool isTopOfPage
= (row
== &aFirstRow
) && aFirstRowIsTopOfPage
;
1000 nsRect rowRect
= row
->GetNormalRect();
1001 nsSize
rowAvailSize(
1002 aReflowInput
.AvailableWidth(),
1003 std::max(aReflowInput
.AvailableHeight() - rowRect
.y
, 0));
1004 // don't let the available height exceed what
1005 // CalculateRowBSizes set for it
1006 rowAvailSize
.height
= std::min(rowAvailSize
.height
, rowRect
.height
);
1007 ReflowInput
rowReflowInput(
1008 &aPresContext
, aReflowInput
, row
,
1009 LogicalSize(row
->GetWritingMode(), rowAvailSize
), Nothing(),
1010 ReflowInput::InitFlag::CallerWillInit
);
1011 InitChildReflowInput(aPresContext
, borderCollapse
, rowReflowInput
);
1012 rowReflowInput
.mFlags
.mIsTopOfPage
= isTopOfPage
; // set top of page
1015 row
->ReflowCellFrame(&aPresContext
, rowReflowInput
, isTopOfPage
,
1016 cell
, cellAvailBSize
, status
);
1017 aDesiredBSize
= std::max(aDesiredBSize
, rowPos
.y
+ cellBSize
);
1018 if (status
.IsComplete()) {
1019 if (cellBSize
> cellAvailBSize
) {
1020 aFirstTruncatedRow
= row
;
1021 if ((row
!= &aFirstRow
) || !aFirstRowIsTopOfPage
) {
1022 // return now, since we will be getting another reflow after
1023 // either (1) row is moved to the next page or (2) the row group
1024 // is moved to the next page
1030 CreateContinuingRowFrame(aLastRow
, (nsIFrame
**)&aContRow
);
1033 if (row
!= &aLastRow
) {
1034 // aContRow needs a continuation for cell, since cell spanned into
1035 // aLastRow but does not originate there
1036 nsTableCellFrame
* contCell
= static_cast<nsTableCellFrame
*>(
1037 PresShell()->FrameConstructor()->CreateContinuingFrame(
1039 uint32_t colIndex
= cell
->ColIndex();
1040 aContRow
->InsertCellFrame(contCell
, colIndex
);
1048 aDesiredBSize
= aLastRow
.GetNormalRect().YMost();
1052 // Remove the next-in-flow of the row, its cells and their cell blocks. This
1053 // is necessary in case the row doesn't need a continuation later on or needs
1054 // a continuation which doesn't have the same number of cells that now exist.
1055 void nsTableRowGroupFrame::UndoContinuedRow(nsPresContext
* aPresContext
,
1056 nsTableRowFrame
* aRow
) {
1057 if (!aRow
) return; // allow null aRow to avoid callers doing null checks
1059 // rowBefore was the prev-sibling of aRow's next-sibling before aRow was
1061 nsTableRowFrame
* rowBefore
= (nsTableRowFrame
*)aRow
->GetPrevInFlow();
1062 MOZ_ASSERT(mFrames
.ContainsFrame(rowBefore
),
1063 "rowBefore not in our frame list?");
1065 AutoFrameListPtr
overflows(aPresContext
, StealOverflowFrames());
1066 if (!rowBefore
|| !overflows
|| overflows
->IsEmpty() ||
1067 overflows
->FirstChild() != aRow
) {
1068 NS_ERROR("invalid continued row");
1072 // Destroy aRow, its cells, and their cell blocks. Cell blocks that have split
1073 // will not have reflowed yet to pick up content from any overflow lines.
1074 overflows
->DestroyFrame(aRow
);
1076 // Put the overflow rows into our child list
1077 if (!overflows
->IsEmpty()) {
1078 mFrames
.InsertFrames(nullptr, rowBefore
, *overflows
);
1082 static nsTableRowFrame
* GetRowBefore(nsTableRowFrame
& aStartRow
,
1083 nsTableRowFrame
& aRow
) {
1084 nsTableRowFrame
* rowBefore
= nullptr;
1085 for (nsTableRowFrame
* sib
= &aStartRow
; sib
&& (sib
!= &aRow
);
1086 sib
= sib
->GetNextRow()) {
1092 nsresult
nsTableRowGroupFrame::SplitRowGroup(nsPresContext
* aPresContext
,
1093 ReflowOutput
& aDesiredSize
,
1094 const ReflowInput
& aReflowInput
,
1095 nsTableFrame
* aTableFrame
,
1096 nsReflowStatus
& aStatus
,
1097 bool aRowForcedPageBreak
) {
1098 MOZ_ASSERT(aPresContext
->IsPaginated(),
1099 "SplitRowGroup currently supports only paged media");
1101 nsTableRowFrame
* prevRowFrame
= nullptr;
1102 aDesiredSize
.Height() = 0;
1103 aDesiredSize
.SetOverflowAreasToDesiredBounds();
1105 const nscoord availWidth
= aReflowInput
.AvailableWidth();
1106 const nscoord availHeight
= aReflowInput
.AvailableHeight();
1108 const bool borderCollapse
= aTableFrame
->IsBorderCollapse();
1110 // get the page height
1111 nscoord pageHeight
= aPresContext
->GetPageSize().height
;
1112 NS_ASSERTION(pageHeight
!= NS_UNCONSTRAINEDSIZE
,
1113 "The table shouldn't be split when there should be space");
1115 bool isTopOfPage
= aReflowInput
.mFlags
.mIsTopOfPage
;
1116 nsTableRowFrame
* firstRowThisPage
= GetFirstRow();
1118 // Need to dirty the table's geometry, or else the row might skip
1119 // reflowing its cell as an optimization.
1120 aTableFrame
->SetGeometryDirty();
1122 // Walk each of the row frames looking for the first row frame that doesn't
1123 // fit in the available space
1124 for (nsTableRowFrame
* rowFrame
= firstRowThisPage
; rowFrame
;
1125 rowFrame
= rowFrame
->GetNextRow()) {
1126 bool rowIsOnPage
= true;
1127 nscoord cellSpacingB
= aTableFrame
->GetRowSpacing(rowFrame
->GetRowIndex());
1128 nsRect rowRect
= rowFrame
->GetNormalRect();
1129 // See if the row fits on this page
1130 if (rowRect
.YMost() > availHeight
) {
1131 nsTableRowFrame
* contRow
= nullptr;
1132 // Reflow the row in the availabe space and have it split if it is the 1st
1133 // row (on the page) or there is at least 5% of the current page available
1134 // XXX this 5% should be made a preference
1135 if (!prevRowFrame
||
1136 (availHeight
- aDesiredSize
.Height() > pageHeight
/ 20)) {
1137 nsSize
availSize(availWidth
, std::max(availHeight
- rowRect
.y
, 0));
1138 // don't let the available height exceed what CalculateRowHeights set
1140 availSize
.height
= std::min(availSize
.height
, rowRect
.height
);
1142 ReflowInput
rowReflowInput(
1143 aPresContext
, aReflowInput
, rowFrame
,
1144 LogicalSize(rowFrame
->GetWritingMode(), availSize
), Nothing(),
1145 ReflowInput::InitFlag::CallerWillInit
);
1147 InitChildReflowInput(*aPresContext
, borderCollapse
, rowReflowInput
);
1148 rowReflowInput
.mFlags
.mIsTopOfPage
= isTopOfPage
; // set top of page
1149 ReflowOutput
rowMetrics(aReflowInput
);
1151 // Get the old size before we reflow.
1152 nsRect oldRowRect
= rowFrame
->GetRect();
1153 nsRect oldRowInkOverflow
= rowFrame
->InkOverflowRect();
1155 // Reflow the cell with the constrained height. A cell with rowspan >1
1156 // will get this reflow later during SplitSpanningCells.
1157 ReflowChild(rowFrame
, aPresContext
, rowMetrics
, rowReflowInput
, 0, 0,
1158 ReflowChildFlags::NoMoveFrame
, aStatus
);
1159 rowFrame
->SetSize(nsSize(rowMetrics
.Width(), rowMetrics
.Height()));
1160 rowFrame
->DidReflow(aPresContext
, nullptr);
1161 rowFrame
->DidResize();
1163 if (!aRowForcedPageBreak
&& !aStatus
.IsFullyComplete() &&
1164 ShouldAvoidBreakInside(aReflowInput
)) {
1165 aStatus
.SetInlineLineBreakBeforeAndReset();
1169 nsTableFrame::InvalidateTableFrame(rowFrame
, oldRowRect
,
1170 oldRowInkOverflow
, false);
1172 if (aStatus
.IsIncomplete()) {
1173 // The row frame is incomplete and all of the rowspan 1 cells' block
1175 if ((rowMetrics
.Height() <= rowReflowInput
.AvailableHeight()) ||
1177 // The row stays on this page because either it split ok or we're on
1178 // the top of page. If top of page and the height exceeded the avail
1179 // height, then there will be data loss
1181 rowMetrics
.Height() <= rowReflowInput
.AvailableHeight(),
1182 "data loss - incomplete row needed more height than available, "
1184 CreateContinuingRowFrame(*rowFrame
, (nsIFrame
**)&contRow
);
1186 aDesiredSize
.Height() += rowMetrics
.Height();
1187 if (prevRowFrame
) aDesiredSize
.Height() += cellSpacingB
;
1189 return NS_ERROR_NULL_POINTER
;
1191 // Put the row on the next page to give it more height
1192 rowIsOnPage
= false;
1195 // The row frame is complete because either (1) its minimum height is
1196 // greater than the available height we gave it, or (2) it may have
1197 // been given a larger height through style than its content, or (3)
1198 // it contains a rowspan >1 cell which hasn't been reflowed with a
1199 // constrained height yet (we will find out when SplitSpanningCells is
1201 if (rowMetrics
.Height() > availSize
.height
||
1202 (aStatus
.IsInlineBreakBefore() && !aRowForcedPageBreak
)) {
1203 // cases (1) and (2)
1205 // We're on top of the page, so keep the row on this page. There
1206 // will be data loss. Push the row frame that follows
1207 nsTableRowFrame
* nextRowFrame
= rowFrame
->GetNextRow();
1210 aStatus
.SetIncomplete();
1212 aDesiredSize
.Height() += rowMetrics
.Height();
1213 if (prevRowFrame
) aDesiredSize
.Height() += cellSpacingB
;
1215 "data loss - complete row needed more height than available, "
1218 // We're not on top of the page, so put the row on the next page
1219 // to give it more height
1220 rowIsOnPage
= false;
1224 } // if (!prevRowFrame || (availHeight - aDesiredSize.Height() >
1225 // pageHeight / 20))
1227 // put the row on the next page to give it more height
1228 rowIsOnPage
= false;
1231 nsTableRowFrame
* lastRowThisPage
= rowFrame
;
1232 nscoord spanningRowBottom
= availHeight
;
1234 NS_ASSERTION(!contRow
,
1235 "We should not have created a continuation if none of "
1237 if (!prevRowFrame
||
1238 (!aRowForcedPageBreak
&& ShouldAvoidBreakInside(aReflowInput
))) {
1239 aStatus
.SetInlineLineBreakBeforeAndReset();
1242 spanningRowBottom
= prevRowFrame
->GetNormalRect().YMost();
1243 lastRowThisPage
= prevRowFrame
;
1245 aStatus
.SetIncomplete();
1247 // reflow the cells with rowspan >1 that occur on the page
1249 nsTableRowFrame
* firstTruncatedRow
;
1251 SplitSpanningCells(*aPresContext
, aReflowInput
, *aTableFrame
,
1252 *firstRowThisPage
, *lastRowThisPage
,
1253 aReflowInput
.mFlags
.mIsTopOfPage
, spanningRowBottom
,
1254 contRow
, firstTruncatedRow
, bMost
);
1255 if (firstTruncatedRow
) {
1256 // A rowspan >1 cell did not fit (and could not split) in the space we
1258 if (firstTruncatedRow
== firstRowThisPage
) {
1259 if (aReflowInput
.mFlags
.mIsTopOfPage
) {
1260 NS_WARNING("data loss in a row spanned cell");
1262 // We can't push children, so let our parent reflow us again with
1264 aDesiredSize
.Height() = rowRect
.YMost();
1266 UndoContinuedRow(aPresContext
, contRow
);
1269 } else { // (firstTruncatedRow != firstRowThisPage)
1270 // Try to put firstTruncateRow on the next page
1271 nsTableRowFrame
* rowBefore
=
1272 ::GetRowBefore(*firstRowThisPage
, *firstTruncatedRow
);
1273 nscoord oldSpanningRowBottom
= spanningRowBottom
;
1274 spanningRowBottom
= rowBefore
->GetNormalRect().YMost();
1276 UndoContinuedRow(aPresContext
, contRow
);
1278 nsTableRowFrame
* oldLastRowThisPage
= lastRowThisPage
;
1279 lastRowThisPage
= rowBefore
;
1281 aStatus
.SetIncomplete();
1283 // Call SplitSpanningCells again with rowBefore as the last row on the
1286 *aPresContext
, aReflowInput
, *aTableFrame
, *firstRowThisPage
,
1287 *rowBefore
, aReflowInput
.mFlags
.mIsTopOfPage
, spanningRowBottom
,
1288 contRow
, firstTruncatedRow
, aDesiredSize
.Height());
1289 if (firstTruncatedRow
) {
1290 if (aReflowInput
.mFlags
.mIsTopOfPage
) {
1291 // We were better off with the 1st call to SplitSpanningCells, do
1293 UndoContinuedRow(aPresContext
, contRow
);
1295 lastRowThisPage
= oldLastRowThisPage
;
1296 spanningRowBottom
= oldSpanningRowBottom
;
1297 SplitSpanningCells(*aPresContext
, aReflowInput
, *aTableFrame
,
1298 *firstRowThisPage
, *lastRowThisPage
,
1299 aReflowInput
.mFlags
.mIsTopOfPage
,
1300 spanningRowBottom
, contRow
, firstTruncatedRow
,
1301 aDesiredSize
.Height());
1302 NS_WARNING("data loss in a row spanned cell");
1304 // Let our parent reflow us again with more space
1305 aDesiredSize
.Height() = rowRect
.YMost();
1307 UndoContinuedRow(aPresContext
, contRow
);
1311 } // if (firstTruncatedRow == firstRowThisPage)
1312 } // if (firstTruncatedRow)
1314 aDesiredSize
.Height() = std::max(aDesiredSize
.Height(), bMost
);
1317 aStatus
.SetIncomplete();
1320 if (aStatus
.IsIncomplete() && !contRow
) {
1321 if (nsTableRowFrame
* nextRow
= lastRowThisPage
->GetNextRow()) {
1322 PushChildren(nextRow
, lastRowThisPage
);
1324 } else if (aStatus
.IsComplete() && lastRowThisPage
) {
1325 // Our size from the unconstrained reflow exceeded the constrained
1326 // available space but our size in the constrained reflow is Complete.
1327 // This can happen when a non-zero block-end margin is suppressed in
1328 // nsBlockFrame::ComputeFinalSize.
1329 if (nsTableRowFrame
* nextRow
= lastRowThisPage
->GetNextRow()) {
1331 aStatus
.SetIncomplete();
1332 PushChildren(nextRow
, lastRowThisPage
);
1336 } // if (rowRect.YMost() > availHeight)
1337 aDesiredSize
.Height() = rowRect
.YMost();
1338 prevRowFrame
= rowFrame
;
1339 // see if there is a page break after the row
1340 nsTableRowFrame
* nextRow
= rowFrame
->GetNextRow();
1341 if (nextRow
&& nsTableFrame::PageBreakAfter(rowFrame
, nextRow
)) {
1342 PushChildren(nextRow
, rowFrame
);
1344 aStatus
.SetIncomplete();
1347 // after the 1st row that has a height, we can't be on top
1348 // of the page anymore.
1349 isTopOfPage
= isTopOfPage
&& rowRect
.YMost() == 0;
1354 /** Layout the entire row group.
1355 * This method stacks rows vertically according to HTML 4.0 rules.
1356 * Rows are responsible for layout of their children.
1358 void nsTableRowGroupFrame::Reflow(nsPresContext
* aPresContext
,
1359 ReflowOutput
& aDesiredSize
,
1360 const ReflowInput
& aReflowInput
,
1361 nsReflowStatus
& aStatus
) {
1363 DO_GLOBAL_REFLOW_COUNT("nsTableRowGroupFrame");
1364 DISPLAY_REFLOW(aPresContext
, this, aReflowInput
, aDesiredSize
, aStatus
);
1365 MOZ_ASSERT(aStatus
.IsEmpty(), "Caller should pass a fresh reflow status!");
1367 // Row geometry may be going to change so we need to invalidate any row
1371 // see if a special bsize reflow needs to occur due to having a pct bsize
1372 nsTableFrame::CheckRequestSpecialBSizeReflow(aReflowInput
);
1374 nsTableFrame
* tableFrame
= GetTableFrame();
1375 TableRowGroupReflowInput
state(aReflowInput
, tableFrame
);
1376 const nsStyleVisibility
* groupVis
= StyleVisibility();
1377 bool collapseGroup
= StyleVisibility::Collapse
== groupVis
->mVisible
;
1378 if (collapseGroup
) {
1379 tableFrame
->SetNeedToCollapse(true);
1382 // Check for an overflow list
1383 MoveOverflowToChildList();
1385 // Reflow the existing frames.
1386 bool splitDueToPageBreak
= false;
1387 ReflowChildren(aPresContext
, aDesiredSize
, state
, aStatus
,
1388 &splitDueToPageBreak
);
1390 // See if all the frames fit. Do not try to split anything if we're
1391 // not paginated ... we can't split across columns yet.
1392 if (aReflowInput
.mFlags
.mTableIsSplittable
&&
1393 NS_UNCONSTRAINEDSIZE
!= aReflowInput
.AvailableHeight() &&
1394 (aStatus
.IsIncomplete() || splitDueToPageBreak
||
1395 aDesiredSize
.Height() > aReflowInput
.AvailableHeight())) {
1396 // Nope, find a place to split the row group
1397 auto& mutableRIFlags
= const_cast<ReflowInput::Flags
&>(aReflowInput
.mFlags
);
1398 const bool savedSpecialBSizeReflow
= mutableRIFlags
.mSpecialBSizeReflow
;
1399 mutableRIFlags
.mSpecialBSizeReflow
= false;
1401 SplitRowGroup(aPresContext
, aDesiredSize
, aReflowInput
, tableFrame
, aStatus
,
1402 splitDueToPageBreak
);
1404 mutableRIFlags
.mSpecialBSizeReflow
= savedSpecialBSizeReflow
;
1407 // XXXmats The following is just bogus. We leave it here for now because
1408 // ReflowChildren should pull up rows from our next-in-flow before returning
1409 // a Complete status, but doesn't (bug 804888).
1410 if (GetNextInFlow() && GetNextInFlow()->PrincipalChildList().FirstChild()) {
1411 aStatus
.SetIncomplete();
1414 SetHasStyleBSize((NS_UNCONSTRAINEDSIZE
!= aReflowInput
.ComputedBSize()) &&
1415 (aReflowInput
.ComputedBSize() > 0));
1417 // Just set our isize to what was available.
1418 // The table will calculate the isize and not use our value.
1419 WritingMode wm
= aReflowInput
.GetWritingMode();
1420 aDesiredSize
.ISize(wm
) = aReflowInput
.AvailableISize();
1422 aDesiredSize
.UnionOverflowAreasWithDesiredBounds();
1424 // If our parent is in initial reflow, it'll handle invalidating our
1425 // entire overflow rect.
1426 if (!GetParent()->HasAnyStateBits(NS_FRAME_FIRST_REFLOW
) &&
1427 nsSize(aDesiredSize
.Width(), aDesiredSize
.Height()) != mRect
.Size()) {
1431 FinishAndStoreOverflow(&aDesiredSize
);
1433 // Any absolutely-positioned children will get reflowed in
1434 // nsIFrame::FixupPositionedTableParts in another pass, so propagate our
1435 // dirtiness to them before our parent clears our dirty bits.
1436 PushDirtyBitToAbsoluteFrames();
1438 NS_FRAME_SET_TRUNCATION(aStatus
, aReflowInput
, aDesiredSize
);
1441 bool nsTableRowGroupFrame::ComputeCustomOverflow(
1442 OverflowAreas
& aOverflowAreas
) {
1443 // Row cursor invariants depend on the ink overflow area of the rows,
1444 // which may have changed, so we need to clear the cursor now.
1446 return nsContainerFrame::ComputeCustomOverflow(aOverflowAreas
);
1450 void nsTableRowGroupFrame::DidSetComputedStyle(
1451 ComputedStyle
* aOldComputedStyle
) {
1452 nsContainerFrame::DidSetComputedStyle(aOldComputedStyle
);
1454 if (!aOldComputedStyle
) // avoid this on init
1457 nsTableFrame
* tableFrame
= GetTableFrame();
1458 if (tableFrame
->IsBorderCollapse() &&
1459 tableFrame
->BCRecalcNeeded(aOldComputedStyle
, Style())) {
1460 TableArea
damageArea(0, GetStartRowIndex(), tableFrame
->GetColCount(),
1462 tableFrame
->AddBCDamageArea(damageArea
);
1466 void nsTableRowGroupFrame::AppendFrames(ChildListID aListID
,
1467 nsFrameList
& aFrameList
) {
1468 NS_ASSERTION(aListID
== kPrincipalList
, "unexpected child list");
1470 DrainSelfOverflowList(); // ensure the last frame is in mFrames
1473 // collect the new row frames in an array
1474 // XXXbz why are we doing the QI stuff? There shouldn't be any non-rows here.
1475 AutoTArray
<nsTableRowFrame
*, 8> rows
;
1476 for (nsFrameList::Enumerator
e(aFrameList
); !e
.AtEnd(); e
.Next()) {
1477 nsTableRowFrame
* rowFrame
= do_QueryFrame(e
.get());
1478 NS_ASSERTION(rowFrame
, "Unexpected frame; frame constructor screwed up");
1481 mozilla::StyleDisplay::TableRow
== e
.get()->StyleDisplay()->mDisplay
,
1482 "wrong display type on rowframe");
1483 rows
.AppendElement(rowFrame
);
1487 int32_t rowIndex
= GetRowCount();
1488 // Append the frames to the sibling chain
1489 mFrames
.AppendFrames(nullptr, aFrameList
);
1491 if (rows
.Length() > 0) {
1492 nsTableFrame
* tableFrame
= GetTableFrame();
1493 tableFrame
->AppendRows(this, rowIndex
, rows
);
1494 PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange
,
1495 NS_FRAME_HAS_DIRTY_CHILDREN
);
1496 tableFrame
->SetGeometryDirty();
1500 void nsTableRowGroupFrame::InsertFrames(
1501 ChildListID aListID
, nsIFrame
* aPrevFrame
,
1502 const nsLineList::iterator
* aPrevFrameLine
, nsFrameList
& aFrameList
) {
1503 NS_ASSERTION(aListID
== kPrincipalList
, "unexpected child list");
1504 NS_ASSERTION(!aPrevFrame
|| aPrevFrame
->GetParent() == this,
1505 "inserting after sibling frame with different parent");
1507 DrainSelfOverflowList(); // ensure aPrevFrame is in mFrames
1510 // collect the new row frames in an array
1511 // XXXbz why are we doing the QI stuff? There shouldn't be any non-rows here.
1512 nsTableFrame
* tableFrame
= GetTableFrame();
1513 nsTArray
<nsTableRowFrame
*> rows
;
1514 bool gotFirstRow
= false;
1515 for (nsFrameList::Enumerator
e(aFrameList
); !e
.AtEnd(); e
.Next()) {
1516 nsTableRowFrame
* rowFrame
= do_QueryFrame(e
.get());
1517 NS_ASSERTION(rowFrame
, "Unexpected frame; frame constructor screwed up");
1520 mozilla::StyleDisplay::TableRow
== e
.get()->StyleDisplay()->mDisplay
,
1521 "wrong display type on rowframe");
1522 rows
.AppendElement(rowFrame
);
1524 rowFrame
->SetFirstInserted(true);
1526 tableFrame
->SetRowInserted(true);
1531 int32_t startRowIndex
= GetStartRowIndex();
1532 // Insert the frames in the sibling chain
1533 mFrames
.InsertFrames(nullptr, aPrevFrame
, aFrameList
);
1535 int32_t numRows
= rows
.Length();
1537 nsTableRowFrame
* prevRow
=
1538 (nsTableRowFrame
*)nsTableFrame::GetFrameAtOrBefore(
1539 this, aPrevFrame
, LayoutFrameType::TableRow
);
1540 int32_t rowIndex
= (prevRow
) ? prevRow
->GetRowIndex() + 1 : startRowIndex
;
1541 tableFrame
->InsertRows(this, rows
, rowIndex
, true);
1543 PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange
,
1544 NS_FRAME_HAS_DIRTY_CHILDREN
);
1545 tableFrame
->SetGeometryDirty();
1549 void nsTableRowGroupFrame::RemoveFrame(ChildListID aListID
,
1550 nsIFrame
* aOldFrame
) {
1551 NS_ASSERTION(aListID
== kPrincipalList
, "unexpected child list");
1555 // XXX why are we doing the QI stuff? There shouldn't be any non-rows here.
1556 nsTableRowFrame
* rowFrame
= do_QueryFrame(aOldFrame
);
1558 nsTableFrame
* tableFrame
= GetTableFrame();
1559 // remove the rows from the table (and flag a rebalance)
1560 tableFrame
->RemoveRows(*rowFrame
, 1, true);
1562 PresShell()->FrameNeedsReflow(this, IntrinsicDirty::TreeChange
,
1563 NS_FRAME_HAS_DIRTY_CHILDREN
);
1564 tableFrame
->SetGeometryDirty();
1566 mFrames
.DestroyFrame(aOldFrame
);
1570 nsMargin
nsTableRowGroupFrame::GetUsedMargin() const {
1571 return nsMargin(0, 0, 0, 0);
1575 nsMargin
nsTableRowGroupFrame::GetUsedBorder() const {
1576 return nsMargin(0, 0, 0, 0);
1580 nsMargin
nsTableRowGroupFrame::GetUsedPadding() const {
1581 return nsMargin(0, 0, 0, 0);
1584 nscoord
nsTableRowGroupFrame::GetBSizeBasis(const ReflowInput
& aReflowInput
) {
1586 nsTableFrame
* tableFrame
= GetTableFrame();
1587 int32_t startRowIndex
= GetStartRowIndex();
1588 if ((aReflowInput
.ComputedBSize() > 0) &&
1589 (aReflowInput
.ComputedBSize() < NS_UNCONSTRAINEDSIZE
)) {
1590 nscoord cellSpacing
= tableFrame
->GetRowSpacing(
1592 std::max(startRowIndex
, startRowIndex
+ GetRowCount() - 1));
1593 result
= aReflowInput
.ComputedBSize() - cellSpacing
;
1595 const ReflowInput
* parentRI
= aReflowInput
.mParentReflowInput
;
1596 if (parentRI
&& (tableFrame
!= parentRI
->mFrame
)) {
1597 parentRI
= parentRI
->mParentReflowInput
;
1599 if (parentRI
&& (tableFrame
== parentRI
->mFrame
) &&
1600 (parentRI
->ComputedBSize() > 0) &&
1601 (parentRI
->ComputedBSize() < NS_UNCONSTRAINEDSIZE
)) {
1602 nscoord cellSpacing
=
1603 tableFrame
->GetRowSpacing(-1, tableFrame
->GetRowCount());
1604 result
= parentRI
->ComputedBSize() - cellSpacing
;
1611 bool nsTableRowGroupFrame::IsSimpleRowFrame(nsTableFrame
* aTableFrame
,
1612 nsTableRowFrame
* aRowFrame
) {
1613 int32_t rowIndex
= aRowFrame
->GetRowIndex();
1615 // It's a simple row frame if there are no cells that span into or
1617 int32_t numEffCols
= aTableFrame
->GetEffectiveColCount();
1618 if (!aTableFrame
->RowIsSpannedInto(rowIndex
, numEffCols
) &&
1619 !aTableFrame
->RowHasSpanningCells(rowIndex
, numEffCols
)) {
1626 /** find page break before the first row **/
1627 bool nsTableRowGroupFrame::HasInternalBreakBefore() const {
1628 nsIFrame
* firstChild
= mFrames
.FirstChild();
1629 if (!firstChild
) return false;
1630 return firstChild
->StyleDisplay()->BreakBefore();
1633 /** find page break after the last row **/
1634 bool nsTableRowGroupFrame::HasInternalBreakAfter() const {
1635 nsIFrame
* lastChild
= mFrames
.LastChild();
1636 if (!lastChild
) return false;
1637 return lastChild
->StyleDisplay()->BreakAfter();
1639 /* ----- global methods ----- */
1641 nsTableRowGroupFrame
* NS_NewTableRowGroupFrame(PresShell
* aPresShell
,
1642 ComputedStyle
* aStyle
) {
1643 return new (aPresShell
)
1644 nsTableRowGroupFrame(aStyle
, aPresShell
->GetPresContext());
1647 NS_IMPL_FRAMEARENA_HELPERS(nsTableRowGroupFrame
)
1649 #ifdef DEBUG_FRAME_DUMP
1650 nsresult
nsTableRowGroupFrame::GetFrameName(nsAString
& aResult
) const {
1651 return MakeFrameName(u
"TableRowGroup"_ns
, aResult
);
1655 LogicalMargin
nsTableRowGroupFrame::GetBCBorderWidth(WritingMode aWM
) {
1656 LogicalMargin
border(aWM
);
1657 nsTableRowFrame
* firstRowFrame
= GetFirstRow();
1658 if (!firstRowFrame
) {
1661 nsTableRowFrame
* lastRowFrame
= firstRowFrame
;
1662 for (nsTableRowFrame
* rowFrame
= firstRowFrame
->GetNextRow(); rowFrame
;
1663 rowFrame
= rowFrame
->GetNextRow()) {
1664 lastRowFrame
= rowFrame
;
1666 border
.BStart(aWM
) = PresContext()->DevPixelsToAppUnits(
1667 firstRowFrame
->GetBStartBCBorderWidth());
1669 PresContext()->DevPixelsToAppUnits(lastRowFrame
->GetBEndBCBorderWidth());
1673 void nsTableRowGroupFrame::SetContinuousBCBorderWidth(LogicalSide aForSide
,
1674 BCPixelSize aPixelValue
) {
1676 case eLogicalSideIEnd
:
1677 mIEndContBorderWidth
= aPixelValue
;
1679 case eLogicalSideBEnd
:
1680 mBEndContBorderWidth
= aPixelValue
;
1682 case eLogicalSideIStart
:
1683 mIStartContBorderWidth
= aPixelValue
;
1686 NS_ERROR("invalid LogicalSide argument");
1690 // nsILineIterator methods
1691 int32_t nsTableRowGroupFrame::GetNumLines() const { return GetRowCount(); }
1693 bool nsTableRowGroupFrame::GetDirection() {
1694 return (StyleDirection::Rtl
==
1695 GetTableFrame()->StyleVisibility()->mDirection
);
1698 Result
<nsILineIterator::LineInfo
, nsresult
> nsTableRowGroupFrame::GetLine(
1699 int32_t aLineNumber
) {
1700 if ((aLineNumber
< 0) || (aLineNumber
>= GetRowCount())) {
1701 return Err(NS_ERROR_FAILURE
);
1704 nsTableFrame
* table
= GetTableFrame();
1705 nsTableCellMap
* cellMap
= table
->GetCellMap();
1706 aLineNumber
+= GetStartRowIndex();
1708 structure
.mNumFramesOnLine
=
1709 cellMap
->GetNumCellsOriginatingInRow(aLineNumber
);
1710 if (structure
.mNumFramesOnLine
== 0) {
1713 int32_t colCount
= table
->GetColCount();
1714 for (int32_t i
= 0; i
< colCount
; i
++) {
1715 CellData
* data
= cellMap
->GetDataAt(aLineNumber
, i
);
1716 if (data
&& data
->IsOrig()) {
1717 structure
.mFirstFrameOnLine
= (nsIFrame
*)data
->GetCellFrame();
1718 nsIFrame
* parent
= structure
.mFirstFrameOnLine
->GetParent();
1719 structure
.mLineBounds
= parent
->GetRect();
1723 MOZ_ASSERT_UNREACHABLE("cellmap is lying");
1724 return Err(NS_ERROR_FAILURE
);
1727 int32_t nsTableRowGroupFrame::FindLineContaining(nsIFrame
* aFrame
,
1728 int32_t aStartLine
) {
1729 NS_ENSURE_TRUE(aFrame
, -1);
1731 nsTableRowFrame
* rowFrame
= do_QueryFrame(aFrame
);
1732 NS_ASSERTION(rowFrame
, "RowGroup contains a frame that is not a row");
1734 int32_t rowIndexInGroup
= rowFrame
->GetRowIndex() - GetStartRowIndex();
1736 return rowIndexInGroup
>= aStartLine
? rowIndexInGroup
: -1;
1740 nsTableRowGroupFrame::CheckLineOrder(int32_t aLine
, bool* aIsReordered
,
1741 nsIFrame
** aFirstVisual
,
1742 nsIFrame
** aLastVisual
) {
1743 *aIsReordered
= false;
1744 *aFirstVisual
= nullptr;
1745 *aLastVisual
= nullptr;
1750 nsTableRowGroupFrame::FindFrameAt(int32_t aLineNumber
, nsPoint aPos
,
1751 nsIFrame
** aFrameFound
,
1752 bool* aPosIsBeforeFirstFrame
,
1753 bool* aPosIsAfterLastFrame
) {
1754 nsTableFrame
* table
= GetTableFrame();
1755 nsTableCellMap
* cellMap
= table
->GetCellMap();
1757 WritingMode wm
= table
->GetWritingMode();
1758 nsSize containerSize
= table
->GetSize();
1759 LogicalPoint
pos(wm
, aPos
, containerSize
);
1761 *aFrameFound
= nullptr;
1762 *aPosIsBeforeFirstFrame
= true;
1763 *aPosIsAfterLastFrame
= false;
1765 aLineNumber
+= GetStartRowIndex();
1766 int32_t numCells
= cellMap
->GetNumCellsOriginatingInRow(aLineNumber
);
1767 if (numCells
== 0) {
1771 nsIFrame
* frame
= nullptr;
1772 int32_t colCount
= table
->GetColCount();
1773 for (int32_t i
= 0; i
< colCount
; i
++) {
1774 CellData
* data
= cellMap
->GetDataAt(aLineNumber
, i
);
1775 if (data
&& data
->IsOrig()) {
1776 frame
= (nsIFrame
*)data
->GetCellFrame();
1780 NS_ASSERTION(frame
, "cellmap is lying");
1781 bool isRTL
= (StyleDirection::Rtl
== table
->StyleVisibility()->mDirection
);
1783 nsIFrame
* closestFromStart
= nullptr;
1784 nsIFrame
* closestFromEnd
= nullptr;
1785 int32_t n
= numCells
;
1786 nsIFrame
* firstFrame
= frame
;
1788 LogicalRect rect
= frame
->GetLogicalRect(wm
, containerSize
);
1789 if (rect
.ISize(wm
) > 0) {
1790 // If pos.I() is inside this frame - this is it
1791 if (rect
.IStart(wm
) <= pos
.I(wm
) && rect
.IEnd(wm
) > pos
.I(wm
)) {
1792 closestFromStart
= closestFromEnd
= frame
;
1795 if (rect
.IStart(wm
) < pos
.I(wm
)) {
1796 if (!closestFromStart
||
1798 closestFromStart
->GetLogicalRect(wm
, containerSize
).IEnd(wm
))
1799 closestFromStart
= frame
;
1801 if (!closestFromEnd
||
1803 closestFromEnd
->GetLogicalRect(wm
, containerSize
).IStart(wm
))
1804 closestFromEnd
= frame
;
1807 frame
= frame
->GetNextSibling();
1809 if (!closestFromStart
&& !closestFromEnd
) {
1810 // All frames were zero-width. Just take the first one.
1811 closestFromStart
= closestFromEnd
= firstFrame
;
1813 *aPosIsBeforeFirstFrame
= isRTL
? !closestFromEnd
: !closestFromStart
;
1814 *aPosIsAfterLastFrame
= isRTL
? !closestFromStart
: !closestFromEnd
;
1815 if (closestFromStart
== closestFromEnd
) {
1816 *aFrameFound
= closestFromStart
;
1817 } else if (!closestFromStart
) {
1818 *aFrameFound
= closestFromEnd
;
1819 } else if (!closestFromEnd
) {
1820 *aFrameFound
= closestFromStart
;
1821 } else { // we're between two frames
1823 closestFromEnd
->GetLogicalRect(wm
, containerSize
).IStart(wm
) -
1824 closestFromStart
->GetLogicalRect(wm
, containerSize
).IEnd(wm
);
1826 closestFromStart
->GetLogicalRect(wm
, containerSize
).IEnd(wm
) +
1828 *aFrameFound
= closestFromStart
;
1830 *aFrameFound
= closestFromEnd
;
1836 // end nsLineIterator methods
1838 NS_DECLARE_FRAME_PROPERTY_DELETABLE(RowCursorProperty
,
1839 nsTableRowGroupFrame::FrameCursorData
)
1841 void nsTableRowGroupFrame::ClearRowCursor() {
1842 if (!HasAnyStateBits(NS_ROWGROUP_HAS_ROW_CURSOR
)) {
1846 RemoveStateBits(NS_ROWGROUP_HAS_ROW_CURSOR
);
1847 RemoveProperty(RowCursorProperty());
1850 nsTableRowGroupFrame::FrameCursorData
* nsTableRowGroupFrame::SetupRowCursor() {
1851 if (HasAnyStateBits(NS_ROWGROUP_HAS_ROW_CURSOR
)) {
1852 // We already have a valid row cursor. Don't waste time rebuilding it.
1856 nsIFrame
* f
= mFrames
.FirstChild();
1858 for (count
= 0; f
&& count
< MIN_ROWS_NEEDING_CURSOR
; ++count
) {
1859 f
= f
->GetNextSibling();
1862 // Less than MIN_ROWS_NEEDING_CURSOR rows, so just don't bother
1866 FrameCursorData
* data
= new FrameCursorData();
1867 SetProperty(RowCursorProperty(), data
);
1868 AddStateBits(NS_ROWGROUP_HAS_ROW_CURSOR
);
1872 nsIFrame
* nsTableRowGroupFrame::GetFirstRowContaining(nscoord aY
,
1873 nscoord
* aOverflowAbove
) {
1874 if (!HasAnyStateBits(NS_ROWGROUP_HAS_ROW_CURSOR
)) {
1878 FrameCursorData
* property
= GetProperty(RowCursorProperty());
1879 uint32_t cursorIndex
= property
->mCursorIndex
;
1880 uint32_t frameCount
= property
->mFrames
.Length();
1881 if (cursorIndex
>= frameCount
) return nullptr;
1882 nsIFrame
* cursorFrame
= property
->mFrames
[cursorIndex
];
1884 // The cursor's frame list excludes frames with empty overflow-area, so
1885 // we don't need to check that here.
1887 // We use property->mOverflowBelow here instead of computing the frame's
1888 // true overflowArea.YMost(), because it is essential for the thresholds
1889 // to form a monotonically increasing sequence. Otherwise we would break
1890 // encountering a row whose overflowArea.YMost() is <= aY but which has
1891 // a row above it containing cell(s) that span to include aY.
1892 while (cursorIndex
> 0 &&
1893 cursorFrame
->GetRect().YMost() + property
->mOverflowBelow
> aY
) {
1895 cursorFrame
= property
->mFrames
[cursorIndex
];
1897 while (cursorIndex
+ 1 < frameCount
&&
1898 cursorFrame
->GetRect().YMost() + property
->mOverflowBelow
<= aY
) {
1900 cursorFrame
= property
->mFrames
[cursorIndex
];
1903 property
->mCursorIndex
= cursorIndex
;
1904 *aOverflowAbove
= property
->mOverflowAbove
;
1908 bool nsTableRowGroupFrame::FrameCursorData::AppendFrame(nsIFrame
* aFrame
) {
1909 // The cursor requires a monotonically increasing sequence in order to
1910 // identify which rows can be skipped, and position:relative can move
1911 // rows around such that the overflow areas don't provide this.
1912 // We take the union of the overflow rect, and the frame's 'normal' position
1913 // (excluding position:relative changes) and record the max difference between
1914 // this combined overflow and the frame's rect.
1915 nsRect positionedOverflowRect
= aFrame
->InkOverflowRect();
1916 nsPoint positionedToNormal
=
1917 aFrame
->GetNormalPosition() - aFrame
->GetPosition();
1918 nsRect normalOverflowRect
= positionedOverflowRect
+ positionedToNormal
;
1920 nsRect overflowRect
= positionedOverflowRect
.Union(normalOverflowRect
);
1921 if (overflowRect
.IsEmpty()) return true;
1922 nscoord overflowAbove
= -overflowRect
.y
;
1923 nscoord overflowBelow
= overflowRect
.YMost() - aFrame
->GetSize().height
;
1924 mOverflowAbove
= std::max(mOverflowAbove
, overflowAbove
);
1925 mOverflowBelow
= std::max(mOverflowBelow
, overflowBelow
);
1926 // XXX(Bug 1631371) Check if this should use a fallible operation as it
1927 // pretended earlier, or change the return type to void.
1928 mFrames
.AppendElement(aFrame
);
1932 void nsTableRowGroupFrame::InvalidateFrame(uint32_t aDisplayItemKey
,
1933 bool aRebuildDisplayItems
) {
1934 nsIFrame::InvalidateFrame(aDisplayItemKey
, aRebuildDisplayItems
);
1935 if (GetTableFrame()->IsBorderCollapse()) {
1936 const bool rebuild
= StaticPrefs::layout_display_list_retain_sc();
1937 GetParent()->InvalidateFrameWithRect(InkOverflowRect() + GetPosition(),
1938 aDisplayItemKey
, rebuild
);
1942 void nsTableRowGroupFrame::InvalidateFrameWithRect(const nsRect
& aRect
,
1943 uint32_t aDisplayItemKey
,
1944 bool aRebuildDisplayItems
) {
1945 nsIFrame::InvalidateFrameWithRect(aRect
, aDisplayItemKey
,
1946 aRebuildDisplayItems
);
1947 // If we have filters applied that would affects our bounds, then
1948 // we get an inactive layer created and this is computed
1949 // within FrameLayerBuilder
1950 GetParent()->InvalidateFrameWithRect(aRect
+ GetPosition(), aDisplayItemKey
,
1951 aRebuildDisplayItems
);