Bug 1812679 - Handle central baseline calculation in GetNaturalBaselineBOffset. r=layout-reviewers,emilio

Previously, for writing-mode using central baseline alignment (i.e. `vertical-(lr|rl)`,
we simply used the center of content-box in `nsLineLayout::VerticalAlignFrames`.
However, this is incorrect for e.g. a `div` with two lines of text - just like how
its alphabetical baseline is the baseline of the second line of text, the central
baseline should be the centerline of the second line.

Differential Revision: https://phabricator.services.mozilla.com/D172165
This commit is contained in:
David Shin
2023-03-23 14:35:12 +00:00
parent bc1fbeed7a
commit 751d326ba7
25 changed files with 99 additions and 113 deletions

View File

@@ -3548,20 +3548,25 @@ Maybe<nscoord> nsTableFrame::GetNaturalBaselineBOffset(
OrderRowGroups(orderedRowGroups);
// XXX not sure if this should be the size of the containing block instead.
nsSize containerSize = mRect.Size();
auto TableBaseline = [aWM, containerSize](nsTableRowGroupFrame* aRowGroup,
nsTableRowFrame* aRow) {
auto TableBaseline = [aWM, containerSize](
nsTableRowGroupFrame* aRowGroup,
nsTableRowFrame* aRow) -> Maybe<nscoord> {
nscoord rgBStart =
LogicalRect(aWM, aRowGroup->GetNormalRect(), containerSize).BStart(aWM);
nscoord rowBStart =
LogicalRect(aWM, aRow->GetNormalRect(), containerSize).BStart(aWM);
return rgBStart + rowBStart + aRow->GetRowBaseline(aWM);
LogicalRect(aWM, aRow->GetNormalRect(), aRowGroup->GetSize())
.BStart(aWM);
return aRow->GetRowBaseline(aWM).map(
[rgBStart, rowBStart](nscoord aBaseline) {
return rgBStart + rowBStart + aBaseline;
});
};
if (aBaselineGroup == BaselineSharingGroup::First) {
for (uint32_t rgIndex = 0; rgIndex < orderedRowGroups.Length(); rgIndex++) {
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetFirstRow();
if (row) {
return Some(TableBaseline(rgFrame, row));
return TableBaseline(rgFrame, row);
}
}
} else {
@@ -3569,7 +3574,9 @@ Maybe<nscoord> nsTableFrame::GetNaturalBaselineBOffset(
nsTableRowGroupFrame* rgFrame = orderedRowGroups[rgIndex];
nsTableRowFrame* row = rgFrame->GetLastRow();
if (row) {
return Some(BSize(aWM) - TableBaseline(rgFrame, row));
return TableBaseline(rgFrame, row).map([this, aWM](nscoord aBaseline) {
return BSize(aWM) - aBaseline;
});
}
}
}