diff --git a/layout/generic/nsGridContainerFrame.cpp b/layout/generic/nsGridContainerFrame.cpp index d28665b6101b..72949661cb98 100644 --- a/layout/generic/nsGridContainerFrame.cpp +++ b/layout/generic/nsGridContainerFrame.cpp @@ -11,7 +11,6 @@ #include #include #include // for div() -#include #include #include "gfxContext.h" #include "mozilla/AutoRestore.h" @@ -162,7 +161,7 @@ static nscoord ResolveToDefiniteSize(const StyleTrackBreadth& aBreadth, // Synthesize a baseline from a border box. For an alphabetical baseline // this is the end edge of the border box. For a central baseline it's // the center of the border box. -// https://drafts.csswg.org/css-align-3/#synthesize-baseline +// https://drafts.csswg.org/css-align-3/#synthesize-baselines // For a 'first baseline' the measure is from the border-box start edge and // for a 'last baseline' the measure is from the border-box end edge. static nscoord SynthesizeBaselineFromBorderBox(BaselineSharingGroup aGroup, @@ -5743,26 +5742,21 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines( // A grid container's subgridded axis doesn't have a baseline. return; } - nsTArray firstBaselineItems; nsTArray lastBaselineItems; - const WritingMode containerWM = aState.mWM; - ComputedStyle* containerStyle = aState.mFrame->Style(); - + WritingMode wm = aState.mWM; + ComputedStyle* containerSC = aState.mFrame->Style(); for (GridItemInfo& gridItem : aGridItems) { if (gridItem.IsSubgrid(mAxis)) { // A subgrid itself is never baseline-aligned. continue; } - nsIFrame* child = gridItem.mFrame; uint32_t baselineTrack = kAutoLine; auto state = ItemState(0); - const auto childWM = child->GetWritingMode(); - - const bool isOrthogonal = containerWM.IsOrthogonalTo(childWM); + auto childWM = child->GetWritingMode(); + const bool isOrthogonal = wm.IsOrthogonalTo(childWM); const bool isInlineAxis = mAxis == eLogicalAxisInline; // i.e. columns - // XXX update the line below to include orthogonal grid/table boxes // XXX since they have baselines in both dimensions. And flexbox with // XXX reversed main/cross axis? @@ -5770,9 +5764,8 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines( if (itemHasBaselineParallelToTrack) { // [align|justify]-self:[last ]baseline. auto selfAlignment = - isOrthogonal - ? child->StylePosition()->UsedJustifySelf(containerStyle)._0 - : child->StylePosition()->UsedAlignSelf(containerStyle)._0; + isOrthogonal ? child->StylePosition()->UsedJustifySelf(containerSC)._0 + : child->StylePosition()->UsedAlignSelf(containerSC)._0; selfAlignment &= ~StyleAlignFlags::FLAG_BITS; if (selfAlignment == StyleAlignFlags::BASELINE) { state |= ItemState::eFirstBaseline | ItemState::eSelfBaseline; @@ -5806,14 +5799,13 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines( LogicalAxis alignAxis = GetOrthogonalAxis(mAxis); // |sameSide| is true if the container's start side in this axis is // the same as the child's start side, in the child's parallel axis. - bool sameSide = - containerWM.ParallelAxisStartsOnSameSide(alignAxis, childWM); + bool sameSide = wm.ParallelAxisStartsOnSameSide(alignAxis, childWM); if (selfAlignment == StyleAlignFlags::LEFT) { - selfAlignment = !isInlineAxis || containerWM.IsBidiLTR() + selfAlignment = !isInlineAxis || wm.IsBidiLTR() ? StyleAlignFlags::START : StyleAlignFlags::END; } else if (selfAlignment == StyleAlignFlags::RIGHT) { - selfAlignment = isInlineAxis && containerWM.IsBidiLTR() + selfAlignment = isInlineAxis && wm.IsBidiLTR() ? StyleAlignFlags::END : StyleAlignFlags::START; } @@ -5861,112 +5853,57 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines( // XXX For now we just pass an unconstrined-bsize CB: LogicalSize cbSize(childWM, 0, NS_UNCONSTRAINEDSIZE); ::MeasuringReflow(child, aState.mReflowInput, rc, avail, cbSize); - nscoord baseline; nsGridContainerFrame* grid = do_QueryFrame(child); - auto frameSize = - isInlineAxis ? child->ISize(containerWM) : child->BSize(containerWM); - auto margin = child->GetLogicalUsedMargin(containerWM); - auto alignSize = - frameSize + (isInlineAxis ? margin.IStartEnd(containerWM) - : margin.BStartEnd(containerWM)); - - // Check if the item crosses any tracks that is intrinsically sized. - auto range = gridItem.mArea.LineRangeForAxis(mAxis).Range(); - auto isTrackAutoSize = - std::find_if(range.begin(), range.end(), [&](auto track) { - constexpr auto intrinsicSizeFlags = TrackSize::eIntrinsicMinSizing | - TrackSize::eIntrinsicMaxSizing | - TrackSize::eFitContent | - TrackSize::eFlexMaxSizing; - return (mSizes[track].mState & intrinsicSizeFlags) != 0; - }) != range.end(); - - const auto ItemParticipatesInBaselineAlignment = [&]() -> bool { - // If baseline alignment is specified on a grid item whose size in that - // axis depends on the size of an intrinsically-sized track, that item - // does not participate in baseline alignment, and instead uses its - // fallback alignment as if that were originally specified. - // https://drafts.csswg.org/css-grid-1/#row-align - - if (!isTrackAutoSize) { - return true; - } - - const auto IsDependentOnContainerSize = [](const auto& size) -> bool { - return size.HasPercent() || size.IsMozAvailable(); - }; - - const nsStylePosition* stylePos = child->StylePosition(); - bool isItemAutoSize = - IsDependentOnContainerSize(stylePos->BSize(containerWM)) || - IsDependentOnContainerSize(stylePos->MinBSize(containerWM)) || - IsDependentOnContainerSize(stylePos->MaxBSize(containerWM)); - - return !isItemAutoSize; - }; - - const auto CalculateAndAppendItemWithBaseline = - [&](BaselineSharingGroup aBaselineSharingGroup) { - const auto isFirstBaseline = - aBaselineSharingGroup == BaselineSharingGroup::First; - bool hasBaseline = false; - if (grid) { - if (isOrthogonal == isInlineAxis) { - baseline = grid->GetBBaseline(aBaselineSharingGroup); - } else { - baseline = grid->GetIBaseline(aBaselineSharingGroup); - } - hasBaseline = true; - } else { - hasBaseline = isFirstBaseline - ? nsLayoutUtils::GetFirstLineBaseline( - containerWM, child, &baseline) - : nsLayoutUtils::GetLastLineBaseline( - containerWM, child, &baseline); - - if (!hasBaseline && ItemParticipatesInBaselineAlignment()) { - // TODO(tlouw): This should really be `aBaselineSharingGroup`, - // but then "last baseline" tests start to fail. - baseline = Baseline::SynthesizeBOffsetFromBorderBox( - child, containerWM, BaselineSharingGroup::First); - hasBaseline = true; - } - } - - if (hasBaseline) { - NS_ASSERTION(baseline != NS_INTRINSIC_ISIZE_UNKNOWN, - "about to use an unknown baseline"); - - if (isFirstBaseline) { - baseline += isInlineAxis ? margin.IStart(containerWM) - : margin.BStart(containerWM); - - } else { - if (!grid) { - // Convert to distance from border-box end. - baseline = frameSize - baseline; - } - baseline += isInlineAxis ? margin.IEnd(containerWM) - : margin.BEnd(containerWM); - state |= ItemState::eEndSideBaseline; - } - - (isFirstBaseline ? firstBaselineItems : lastBaselineItems) - .AppendElement(ItemBaselineData{baselineTrack, baseline, - alignSize, &gridItem}); - } else { - state &= ~ItemState::eAllBaselineBits; - } - }; - if (state & ItemState::eFirstBaseline) { - CalculateAndAppendItemWithBaseline(BaselineSharingGroup::First); + if (grid) { + if (isOrthogonal == isInlineAxis) { + baseline = grid->GetBBaseline(BaselineSharingGroup::First); + } else { + baseline = grid->GetIBaseline(BaselineSharingGroup::First); + } + } + if (grid || nsLayoutUtils::GetFirstLineBaseline(wm, child, &baseline)) { + NS_ASSERTION(baseline != NS_INTRINSIC_ISIZE_UNKNOWN, + "about to use an unknown baseline"); + auto frameSize = isInlineAxis ? child->ISize(wm) : child->BSize(wm); + auto m = child->GetLogicalUsedMargin(wm); + baseline += isInlineAxis ? m.IStart(wm) : m.BStart(wm); + auto alignSize = + frameSize + (isInlineAxis ? m.IStartEnd(wm) : m.BStartEnd(wm)); + firstBaselineItems.AppendElement(ItemBaselineData( + {baselineTrack, baseline, alignSize, &gridItem})); + } else { + state &= ~ItemState::eAllBaselineBits; + } } else { - CalculateAndAppendItemWithBaseline(BaselineSharingGroup::Last); + if (grid) { + if (isOrthogonal == isInlineAxis) { + baseline = grid->GetBBaseline(BaselineSharingGroup::Last); + } else { + baseline = grid->GetIBaseline(BaselineSharingGroup::Last); + } + } + if (grid || nsLayoutUtils::GetLastLineBaseline(wm, child, &baseline)) { + NS_ASSERTION(baseline != NS_INTRINSIC_ISIZE_UNKNOWN, + "about to use an unknown baseline"); + auto frameSize = isInlineAxis ? child->ISize(wm) : child->BSize(wm); + auto m = child->GetLogicalUsedMargin(wm); + if (!grid) { + // Convert to distance from border-box end. + baseline = frameSize - baseline; + } + auto descent = baseline + (isInlineAxis ? m.IEnd(wm) : m.BEnd(wm)); + auto alignSize = + frameSize + (isInlineAxis ? m.IStartEnd(wm) : m.BStartEnd(wm)); + lastBaselineItems.AppendElement( + ItemBaselineData({baselineTrack, descent, alignSize, &gridItem})); + state |= ItemState::eEndSideBaseline; + } else { + state &= ~ItemState::eAllBaselineBits; + } } } - MOZ_ASSERT( (state & (ItemState::eFirstBaseline | ItemState::eLastBaseline)) != (ItemState::eFirstBaseline | ItemState::eLastBaseline), @@ -5979,7 +5916,6 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines( !(state & (ItemState::eFirstBaseline | ItemState::eLastBaseline)) == !(state & (ItemState::eSelfBaseline | ItemState::eContentBaseline)), "first/last bit requires self/content bit and vice versa"); - gridItem.mState[mAxis] |= state; gridItem.mBaselineOffset[mAxis] = nscoord(0); } diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-flex-002.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-flex-002.html.ini index 0ef96717c33e..1fcee9e880ef 100644 --- a/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-flex-002.html.ini +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-flex-002.html.ini @@ -1,6 +1,9 @@ [grid-align-baseline-flex-002.html] expected: if (os == "android") and fission: [OK, TIMEOUT] + [.target > * 3] + expected: FAIL + [.target > * 7] expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-vertical.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-vertical.html.ini new file mode 100644 index 000000000000..1a283e2c42b5 --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline-vertical.html.ini @@ -0,0 +1,5 @@ +[grid-align-baseline-vertical.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.grid 1] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline.html.ini new file mode 100644 index 000000000000..47e81638746c --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-align-baseline.html.ini @@ -0,0 +1,5 @@ +[grid-align-baseline.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.grid 2] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-001.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-001.html.ini new file mode 100644 index 000000000000..9eebdf8d4387 --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-001.html.ini @@ -0,0 +1,11 @@ +[grid-alignment-style-changes-001.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.before 3] + expected: FAIL + + [.before 1] + expected: FAIL + + [.after 4] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-002.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-002.html.ini new file mode 100644 index 000000000000..80f8c31d5a07 --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-002.html.ini @@ -0,0 +1,11 @@ +[grid-alignment-style-changes-002.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.before 1] + expected: FAIL + + [.after 4] + expected: FAIL + + [.after 6] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-003.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-003.html.ini new file mode 100644 index 000000000000..a5584be9821a --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-003.html.ini @@ -0,0 +1,11 @@ +[grid-alignment-style-changes-003.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.before 3] + expected: FAIL + + [.before 1] + expected: FAIL + + [.after 4] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-004.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-004.html.ini new file mode 100644 index 000000000000..5baad96c7fc7 --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-alignment-style-changes-004.html.ini @@ -0,0 +1,11 @@ +[grid-alignment-style-changes-004.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.before 1] + expected: FAIL + + [.after 4] + expected: FAIL + + [.after 6] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-baseline-004.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-baseline-004.html.ini index a7abcaddda0b..1d18f922ecb8 100644 --- a/testing/web-platform/meta/css/css-grid/alignment/grid-baseline-004.html.ini +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-baseline-004.html.ini @@ -1,3 +1,23 @@ [grid-baseline-004.html] + expected: + if (os == "android") and fission: [OK, TIMEOUT] + [.grid, container 11] + expected: FAIL + + [.grid, container 10] + expected: FAIL + + [.grid, container 5] + expected: FAIL + + [.grid, container 4] + expected: FAIL + + [.grid, container 6] + expected: FAIL + + [.grid, container 12] + expected: FAIL + [.grid, container 17] expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-container-baseline-001.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-container-baseline-001.html.ini index 3526a1914825..c437888c9a56 100644 --- a/testing/web-platform/meta/css/css-grid/alignment/grid-container-baseline-001.html.ini +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-container-baseline-001.html.ini @@ -7,8 +7,17 @@ [.wrapper 9] expected: FAIL + [.wrapper 10] + expected: FAIL + + [.wrapper 1] + expected: FAIL + [.wrapper 3] expected: FAIL [.wrapper 2] expected: FAIL + + [.wrapper 8] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/grid-self-baseline-not-applied-if-sizing-cyclic-dependency-001.html.ini b/testing/web-platform/meta/css/css-grid/alignment/grid-self-baseline-not-applied-if-sizing-cyclic-dependency-001.html.ini index 124a74f233ed..db0285dffafb 100644 --- a/testing/web-platform/meta/css/css-grid/alignment/grid-self-baseline-not-applied-if-sizing-cyclic-dependency-001.html.ini +++ b/testing/web-platform/meta/css/css-grid/alignment/grid-self-baseline-not-applied-if-sizing-cyclic-dependency-001.html.ini @@ -15,6 +15,3 @@ [.inline-grid 11] expected: FAIL - - [.inline-grid 12] - expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html.ini b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html.ini new file mode 100644 index 000000000000..ca12e151dcee --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html.ini @@ -0,0 +1,3 @@ +[grid-self-baseline-changes-grid-area-size-002.html] + expected: + if os == "mac": FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-003.html.ini b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-003.html.ini new file mode 100644 index 000000000000..5e960632143b --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-003.html.ini @@ -0,0 +1,2 @@ +[grid-self-baseline-changes-grid-area-size-003.html] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-006.html.ini b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-006.html.ini new file mode 100644 index 000000000000..12fd6bcac951 --- /dev/null +++ b/testing/web-platform/meta/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-006.html.ini @@ -0,0 +1,2 @@ +[grid-self-baseline-changes-grid-area-size-006.html] + expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-007.html.ini b/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-007.html.ini index 22bf71eda8d3..4ffbc93abf71 100644 --- a/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-007.html.ini +++ b/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-007.html.ini @@ -28,6 +28,3 @@ [.item 12] expected: FAIL - - [.item 8] - expected: FAIL diff --git a/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-008.html.ini b/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-008.html.ini index 54fecb91f21a..6d5451572810 100644 --- a/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-008.html.ini +++ b/testing/web-platform/meta/css/css-grid/subgrid/subgrid-baseline-008.html.ini @@ -5,6 +5,9 @@ [.item 3] expected: FAIL + [.item 4] + expected: FAIL + [.item 5] expected: FAIL diff --git a/testing/web-platform/tests/css/css-grid/alignment/grid-align-baseline.html b/testing/web-platform/tests/css/css-grid/alignment/grid-align-baseline.html index 175811718f71..25744ce61e57 100644 --- a/testing/web-platform/tests/css/css-grid/alignment/grid-align-baseline.html +++ b/testing/web-platform/tests/css/css-grid/alignment/grid-align-baseline.html @@ -67,13 +67,6 @@
-
-
-
-
-
-
-
ahem
diff --git a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html index ae6f3e4eed6b..fb4e3f1a4c47 100644 --- a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html +++ b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-002.html @@ -30,7 +30,6 @@ grid-auto-columns: 50px; align-items: baseline; align-content: space-evenly; - vertical-align: top; } .firstRowFirstColumn { grid-row: 1; diff --git a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-004.html b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-004.html index e877b81480dc..e882ea9a9c13 100644 --- a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-004.html +++ b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-004.html @@ -28,7 +28,6 @@ grid-auto-columns: 50px; align-items: baseline; align-content: start; - vertical-align: top; } .firstRowFirstColumn { grid-row: 1; diff --git a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-005.html b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-005.html index 21cc0b8ac21c..8c91c67a9e43 100644 --- a/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-005.html +++ b/testing/web-platform/tests/css/css-grid/alignment/self-baseline/grid-self-baseline-changes-grid-area-size-005.html @@ -28,7 +28,6 @@ grid-auto-columns: 50px; align-items: baseline; grid-row-gap: 20px; - vertical-align: top; } .firstRowFirstColumn { grid-row: 1;