Bug 1688690 Part 2 - Ensure nsTableFrame's computed margins are all zero. r=emilio

This patch makes the following changes:

1. Don't call ReflowInput::CalculateBlockSideMargins() for nsTableFrame
so that setting nsTableFrame's computed margins to zero in
SizeComputationInput::InitOffsets() remains true. Also, add an assertion
in nsTableFrame::Reflow() to ensure that.

2. Remove useless nsTableFrameWrapper::GetChildMargin() because the
method is used to get nsTableFrame's margins, which are now all zero.
Also, the old code that subtracts the block-axis margin from available
block-size doesn't really make sense.

3. Pass all-zero innerMargins to nsTableWrapperFrame::SetDesiredSize(),
and use table wrapper's content-box inline-size as the final desired
border-box inline-size rather than reconstructing it from caption and
inner table's inline-size & margin like the old code.

This inline-size already takes inner table's intrinsic size and
caption's inline-size into consideration in
nsTableWrapperFrame::ComputeAutoSize(), and is the final inline-size we
want to use.

In the next part, we are going to simplify all nsTableWrapperFrame's
methods that take inner frame's margin.

Differential Revision: https://phabricator.services.mozilla.com/D103065
This commit is contained in:
Ting-Yu Lin 2021-01-27 01:53:36 +00:00
Родитель 90546a2af8
Коммит 60ba2b527c
11 изменённых файлов: 23 добавлений и 72 удалений

Просмотреть файл

@ -206,7 +206,7 @@ load 412651-1.html
load 413587-1.svg
load 414058-1.html
load 415503.xhtml
load 416107.xhtml
asserts(1-1) load 416107.xhtml # bug 489100, ASSERTION: Out-of-flow frame got reflowed before its placeholder
HTTP load 419985.html
load 420031-1.html
load 420213-1.html

Просмотреть файл

@ -2369,11 +2369,11 @@ void ReflowInput::InitConstraints(
// items from block margin calculations.
if (isBlockLevel && !IsSideCaption(mFrame, mStyleDisplay, cbwm) &&
mStyleDisplay->mDisplay != StyleDisplay::InlineTable &&
!alignCB->IsFlexOrGridContainer() &&
!mFrame->IsTableFrame() && !alignCB->IsFlexOrGridContainer() &&
!(mFrame->Style()->GetPseudoType() == PseudoStyleType::marker &&
mFrame->GetParent()->StyleList()->mListStylePosition ==
NS_STYLE_LIST_STYLE_POSITION_OUTSIDE)) {
CalculateBlockSideMargins(aFrameType);
CalculateBlockSideMargins();
}
}
}
@ -2534,7 +2534,10 @@ void SizeComputationInput::InitOffsets(WritingMode aCBWM, nscoord aPercentBasis,
// = width of containing block
//
// Note: the width unit is not auto when this is called
void ReflowInput::CalculateBlockSideMargins(LayoutFrameType aFrameType) {
void ReflowInput::CalculateBlockSideMargins() {
MOZ_ASSERT(!mFrame->IsTableFrame(),
"Inner table frame cannot have computed margins!");
// Calculations here are done in the containing block's writing mode,
// which is where margins will eventually be applied: we're calculating
// margins that will be used by the container in its inline direction,
@ -2595,13 +2598,6 @@ void ReflowInput::CalculateBlockSideMargins(LayoutFrameType aFrameType) {
// ignore
// First check if there is an HTML alignment that we should honor
const ReflowInput* pri = mParentReflowInput;
if (aFrameType == LayoutFrameType::Table) {
NS_ASSERTION(pri->mFrame->IsTableWrapperFrame(),
"table not inside table wrapper");
// Center the table within the table wrapper based on the alignment
// of the table wrapper's parent.
pri = pri->mParentReflowInput;
}
if (pri && (pri->mStyleText->mTextAlign == StyleTextAlign::MozLeft ||
pri->mStyleText->mTextAlign == StyleTextAlign::MozCenter ||
pri->mStyleText->mTextAlign == StyleTextAlign::MozRight)) {

Просмотреть файл

@ -906,7 +906,7 @@ struct ReflowInput : public SizeComputationInput {
nscoord* aInsideBoxSizing,
nscoord* aOutsideBoxSizing) const;
void CalculateBlockSideMargins(LayoutFrameType aFrameType);
void CalculateBlockSideMargins();
/**
* @return true if mFrame is an internal table frame, i.e. an

Просмотреть файл

@ -7,7 +7,7 @@ fuzzy-if(skiaContent,0-3,0-750) == vertical-table-2b.html vertical-table-2-ref.h
== vertical-table-colspan-1.html vertical-table-colspan-1-ref.html
== vertical-table-colspan-2.html vertical-table-colspan-2-ref.html
== vertical-table-specified-width-1.html vertical-table-specified-width-1-ref.html
asserts(1) == vertical-table-specified-width-2.html vertical-table-specified-width-2-ref.html # bug 1179741
== vertical-table-specified-width-2.html vertical-table-specified-width-2-ref.html
fuzzy-if(cocoaWidget,0-141,0-24) == vertical-border-collapse-1.html vertical-border-collapse-1-ref.html
fuzzy-if(cocoaWidget,0-141,0-24) == vertical-border-collapse-2.html vertical-border-collapse-2-ref.html

Просмотреть файл

@ -1750,8 +1750,11 @@ void nsTableFrame::Reflow(nsPresContext* aPresContext,
MOZ_ASSERT(!HasAnyStateBits(NS_FRAME_OUT_OF_FLOW),
"The nsTableWrapperFrame should be the out-of-flow if needed");
const WritingMode wm = aReflowInput.GetWritingMode();
MOZ_ASSERT(aReflowInput.ComputedLogicalMargin(wm).IsAllZero(),
"Only nsTableWrapperFrame can have margins!");
bool isPaginated = aPresContext->IsPaginated();
WritingMode wm = aReflowInput.GetWritingMode();
if (!GetPrevInFlow() && !mTableLayoutStrategy) {
NS_ERROR("strategy should have been created in Init");

Просмотреть файл

@ -257,30 +257,6 @@ void nsTableWrapperFrame::InitChildReflowInput(nsPresContext& aPresContext,
aReflowInput.Init(&aPresContext, cbSize, collapseBorder, collapsePadding);
}
// get the margin and padding data. ReflowInput doesn't handle the
// case of auto margins
void nsTableWrapperFrame::GetChildMargin(nsPresContext* aPresContext,
const ReflowInput& aOuterRI,
nsIFrame* aChildFrame,
nscoord aAvailISize,
LogicalMargin& aMargin) {
NS_ASSERTION(!aChildFrame->IsTableCaption(),
"didn't expect caption frame; writing-mode may be wrong!");
// construct a reflow input to compute margin and padding. Auto margins
// will not be computed at this time.
// create and init the child reflow input
// XXX We really shouldn't construct a reflow input to do this.
WritingMode wm = aOuterRI.GetWritingMode();
LogicalSize availSize(wm, aAvailISize, aOuterRI.AvailableSize(wm).BSize(wm));
ReflowInput childRI(aPresContext, aOuterRI, aChildFrame, availSize, Nothing(),
ReflowInput::InitFlag::CallerWillInit);
InitChildReflowInput(*aPresContext, aOuterRI, childRI);
aMargin = childRI.ComputedLogicalMargin(childRI.GetWritingMode());
}
static nsSize GetContainingBlockSize(const ReflowInput& aOuterRI) {
nsSize size(0, 0);
const ReflowInput* containRS = aOuterRI.mCBReflowInput;
@ -715,18 +691,6 @@ void nsTableWrapperFrame::OuterBeginReflowChild(nsPresContext* aPresContext,
if (NS_UNCONSTRAINEDSIZE != availBSize) {
if (mCaptionFrames.FirstChild() == aChildFrame) {
availBSize = NS_UNCONSTRAINEDSIZE;
} else {
LogicalMargin margin(wm);
GetChildMargin(aPresContext, aOuterRI, aChildFrame, outerSize.ISize(wm),
margin);
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != margin.BStart(wm),
"No unconstrainedsize arithmetic, please");
availBSize -= margin.BStart(wm);
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != margin.BEnd(wm),
"No unconstrainedsize arithmetic, please");
availBSize -= margin.BEnd(wm);
}
}
LogicalSize availSize(wm, aAvailISize, availBSize);
@ -929,7 +893,6 @@ void nsTableWrapperFrame::Reflow(nsPresContext* aPresContext,
OuterDoReflowChild(aPresContext, InnerTableFrame(), *innerRI, innerMet,
aStatus);
LogicalSize innerSize(wm, innerMet.ISize(wm), innerMet.BSize(wm));
LogicalMargin innerMargin = innerRI->ComputedLogicalMargin(wm);
LogicalSize containSize(wm, GetContainingBlockSize(aOuterRI));
@ -942,9 +905,17 @@ void nsTableWrapperFrame::Reflow(nsPresContext* aPresContext,
// Compute the desiredSize so that we can use it as the containerSize
// for the FinishReflowChild calls below.
LogicalSize desiredSize(wm);
// We have zero border and padding, so content-box inline-size is our desired
// border-box inline-size.
desiredSize.ISize(wm) = contentBoxISize;
// TODO: Simplified SetDesiredSize() since innerMargin is now all zero,
// and we only need to compute our block-size.
LogicalMargin innerMargin(wm);
nscoord dummyISize = 0;
SetDesiredSize(captionSide, innerSize, captionSize, innerMargin,
captionMargin, desiredSize.ISize(wm), desiredSize.BSize(wm),
wm);
captionMargin, dummyISize, desiredSize.BSize(wm), wm);
aDesiredSize.SetSize(wm, desiredSize);
nsSize containerSize = aDesiredSize.PhysicalSize();
// XXX It's possible for this to be NS_UNCONSTRAINEDSIZE, which will result

Просмотреть файл

@ -247,11 +247,6 @@ class nsTableWrapperFrame : public nsContainerFrame {
// Set the overflow areas in our reflow metrics
void UpdateOverflowAreas(ReflowOutput& aMet);
// Get the margin.
void GetChildMargin(nsPresContext* aPresContext, const ReflowInput& aOuterRI,
nsIFrame* aChildFrame, nscoord aAvailableWidth,
mozilla::LogicalMargin& aMargin);
virtual bool IsFrameOfType(uint32_t aFlags) const override {
return nsContainerFrame::IsFrameOfType(aFlags &
(~eCanContainOverflowContainers));

Просмотреть файл

@ -1,3 +0,0 @@
[ortho-table-item-001.html]
expected: FAIL
max-asserts: 3

Просмотреть файл

@ -1,4 +0,0 @@
[absolute-tables-002.html]
[.table 3]
expected: FAIL

Просмотреть файл

@ -1,7 +1,4 @@
[caption-writing-mode-001.html]
[Caption percent margins are resolved against table's height for vertical-lr tables]
expected: FAIL
[Caption with auto top/bottom margins is centered vertically for vertical-lr tables]
expected: FAIL

Просмотреть файл

@ -1,4 +0,0 @@
[caption-writing-mode-002.html]
[caption-writing-mode-002]
expected: FAIL