Bug 1866836 Part 1 - Consolidate available size computation in TableReflowInput's constructor. r=layout-reviewers,emilio

Before this patch, we get available block-size in `Reflow()` and available
inline-size in `ReflowTable()`. Then we adjust them in TableReflowInput's
constructor. This patch moves all the computation into TableReflowInput's
constructor.

This is a preparation for bug 1863421, and doesn't change behavior.

Differential Revision: https://phabricator.services.mozilla.com/D194788
This commit is contained in:
Ting-Yu Lin 2023-11-27 23:10:39 +00:00
parent 476009c507
commit 61ae4fb8ad
2 changed files with 38 additions and 48 deletions

View File

@ -68,39 +68,31 @@ using mozilla::gfx::ToDeviceColor;
namespace mozilla {
struct TableReflowInput final {
TableReflowInput(const ReflowInput& aReflowInput,
const LogicalSize& aAvailSize)
TableReflowInput(const ReflowInput& aReflowInput, TableReflowMode aMode)
: mReflowInput(aReflowInput),
mWM(aReflowInput.GetWritingMode()),
mAvailSize(aAvailSize) {
mAvailSize(mWM) {
MOZ_ASSERT(mReflowInput.mFrame->IsTableFrame(),
"TableReflowInput should only be created for nsTableFrame");
nsTableFrame* table =
static_cast<nsTableFrame*>(mReflowInput.mFrame->FirstInFlow());
auto* table = static_cast<nsTableFrame*>(mReflowInput.mFrame);
// XXX: We need to call ApplySkipSides() for borderPadding. Otherwise,
// mAvailSize will be wrong in a continuation.
// Bug 1863421: We need to call ApplySkipSides() for borderPadding.
// Otherwise, mAvailSize will be wrong in a continuation.
LogicalMargin borderPadding =
mReflowInput.ComputedLogicalBorderPadding(mWM);
mICoord = borderPadding.IStart(mWM) + table->GetColSpacing(-1);
mBCoord = borderPadding.BStart(mWM); // rowspacing added during reflow
mAvailSize.ISize(mWM) =
std::max(0, mReflowInput.ComputedISize() - table->GetColSpacing(-1) -
table->GetColSpacing(table->GetColCount()));
// XXX do we actually need to check for unconstrained inline-size here?
if (NS_UNCONSTRAINEDSIZE != mAvailSize.ISize(mWM)) {
int32_t colCount = table->GetColCount();
mAvailSize.ISize(mWM) -= borderPadding.IStartEnd(mWM) +
table->GetColSpacing(-1) +
table->GetColSpacing(colCount);
mAvailSize.ISize(mWM) = std::max(0, mAvailSize.ISize(mWM));
}
if (NS_UNCONSTRAINEDSIZE != mAvailSize.BSize(mWM)) {
mAvailSize.BSize(mWM) -= borderPadding.BStartEnd(mWM) +
table->GetRowSpacing(-1) +
table->GetRowSpacing(table->GetRowCount());
mAvailSize.BSize(mWM) = std::max(0, mAvailSize.BSize(mWM));
}
// Bug 1863421 will fix border-spacing issue in the block-axis in printing.
AdvanceBCoord(borderPadding.BStart(mWM));
mAvailSize.BSize(mWM) = aMode == TableReflowMode::Measuring
? NS_UNCONSTRAINEDSIZE
: mReflowInput.AvailableBSize();
ReduceAvailableBSizeBy(borderPadding.BEnd(mWM) + table->GetRowSpacing(-1) +
table->GetRowSpacing(table->GetRowCount()));
}
// Advance to the next block-offset and reduce the available block-size.
@ -1716,18 +1708,12 @@ void nsTableFrame::Reflow(nsPresContext* aPresContext,
NS_ASSERTION(!aReflowInput.mFlags.mSpecialBSizeReflow,
"Shouldn't be in special bsize reflow here!");
// do the pass 2 reflow unless this is a special bsize reflow and we will be
// initiating a special bsize reflow
// XXXldb I changed this. Should I change it back?
// if we need to initiate a special bsize reflow, then don't constrain the
// bsize of the reflow before that
nscoord availBSize = needToInitiateSpecialReflow
? NS_UNCONSTRAINEDSIZE
: aReflowInput.AvailableBSize();
ReflowTable(aDesiredSize, aReflowInput, availBSize, lastChildReflowed,
const TableReflowMode firstReflowMode = needToInitiateSpecialReflow
? TableReflowMode::Measuring
: TableReflowMode::Final;
ReflowTable(aDesiredSize, aReflowInput, firstReflowMode, lastChildReflowed,
aStatus);
// When in vertical-rl mode, there may be two kinds of scenarios in which
// the positioning of all the children need to be adjusted along the x-axis
// because the width we assumed for the table when the child frames were
@ -1765,7 +1751,7 @@ void nsTableFrame::Reflow(nsPresContext* aPresContext,
aDesiredSize.BSize(wm) = CalcDesiredBSize(aReflowInput);
mutable_rs.mFlags.mSpecialBSizeReflow = true;
ReflowTable(aDesiredSize, aReflowInput, aReflowInput.AvailableBSize(),
ReflowTable(aDesiredSize, aReflowInput, TableReflowMode::Final,
lastChildReflowed, aStatus);
if (lastChildReflowed && aStatus.IsIncomplete()) {
@ -1922,7 +1908,7 @@ bool nsTableFrame::ComputeCustomOverflow(OverflowAreas& aOverflowAreas) {
void nsTableFrame::ReflowTable(ReflowOutput& aDesiredSize,
const ReflowInput& aReflowInput,
nscoord aAvailBSize,
TableReflowMode aReflowMode,
nsIFrame*& aLastChildReflowed,
nsReflowStatus& aStatus) {
aLastChildReflowed = nullptr;
@ -1930,16 +1916,8 @@ void nsTableFrame::ReflowTable(ReflowOutput& aDesiredSize,
if (!GetPrevInFlow()) {
mTableLayoutStrategy->ComputeColumnISizes(aReflowInput);
}
// Constrain our reflow isize to the computed table isize (of the 1st in
// flow). and our reflow bsize to our avail bsize minus border, padding,
// cellspacing
WritingMode wm = aReflowInput.GetWritingMode();
LogicalSize availSize(
wm,
aReflowInput.ComputedISize() +
aReflowInput.ComputedLogicalBorderPadding(wm).IStartEnd(wm),
aAvailBSize);
TableReflowInput reflowInput(aReflowInput, availSize);
TableReflowInput reflowInput(aReflowInput, aReflowMode);
ReflowChildren(reflowInput, aStatus, aLastChildReflowed,
aDesiredSize.mOverflowAreas);

View File

@ -35,6 +35,18 @@ namespace layers {
class StackingContextHelper;
}
// An input to nsTableFrame::ReflowTable() and TableReflowInput.
enum class TableReflowMode : uint8_t {
// A reflow to measure the block-size of the table. We use this value to
// request an unconstrained available block in the first reflow if a second
// special block-size reflow is needed later.
Measuring,
// A final reflow with the available block-size in the table frame's
// ReflowInput.
Final,
};
class nsDisplayTableItem : public nsPaintedDisplayItem {
public:
nsDisplayTableItem(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
@ -334,8 +346,8 @@ class nsTableFrame : public nsContainerFrame {
nsReflowStatus& aStatus) override;
void ReflowTable(ReflowOutput& aDesiredSize, const ReflowInput& aReflowInput,
nscoord aAvailBSize, nsIFrame*& aLastChildReflowed,
nsReflowStatus& aStatus);
mozilla::TableReflowMode aReflowMode,
nsIFrame*& aLastChildReflowed, nsReflowStatus& aStatus);
nsFrameList& GetColGroups();