Bug 1936563: Recursively ensure inline elements in an empty linebox as having zero BSize and no baseline. r=layout-reviewers,emilio

Differential Revision: https://phabricator.services.mozilla.com/D231803
This commit is contained in:
David Shin
2024-12-11 18:10:42 +00:00
parent a15eb85904
commit bcb30f8c42
2 changed files with 30 additions and 15 deletions

View File

@@ -1486,6 +1486,30 @@ bool nsLineLayout::NotifyOptionalBreakPosition(nsIFrame* aFrame,
#define VALIGN_TOP 1
#define VALIGN_BOTTOM 2
void nsLineLayout::SetSpanForEmptyLine(PerSpanData* aPerSpanData,
WritingMode aWM,
const nsSize& aContainerSize,
nscoord aBStartEdge) {
for (PerFrameData* pfd = aPerSpanData->mFirstFrame; pfd; pfd = pfd->mNext) {
// Ideally, if the frame would collapse itself - but it depends on
// knowing that the line is empty.
if (!pfd->mFrame->IsInlineFrame() && !pfd->mFrame->IsRubyFrame() &&
!pfd->mFrame->IsPlaceholderFrame()) {
continue;
}
// Collapse the physical size to 0.
pfd->mBounds.BStart(aWM) = aBStartEdge;
pfd->mBounds.BSize(aWM) = 0;
// Initialize mBlockDirAlign (though it doesn't make much difference
// because we don't align empty boxes).
pfd->mBlockDirAlign = VALIGN_OTHER;
pfd->mFrame->SetRect(aWM, pfd->mBounds, aContainerSize);
if (pfd->mSpan) {
SetSpanForEmptyLine(pfd->mSpan, aWM, aContainerSize, aBStartEdge);
}
}
}
void nsLineLayout::VerticalAlignLine() {
// Partially place the children of the block frame. The baseline for
// this operation is set to zero so that the y coordinates for all
@@ -1494,21 +1518,8 @@ void nsLineLayout::VerticalAlignLine() {
if (mLineIsEmpty) {
// This line is empty, and should be consisting of only inline elements.
// (inline-block elements would make the line non-empty).
WritingMode lineWM = psd->mWritingMode;
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
// Ideally, if the frame would collapse itself - but it depends on
// knowing that the line is empty.
if (!pfd->mFrame->IsInlineFrame() && !pfd->mFrame->IsRubyFrame()) {
continue;
}
// Collapse the physical size to 0.
pfd->mBounds.BStart(lineWM) = mBStartEdge;
pfd->mBounds.BSize(lineWM) = 0;
// Initialize mBlockDirAlign (though it doesn't make much difference
// because we don't align empty boxes).
pfd->mBlockDirAlign = VALIGN_OTHER;
pfd->mFrame->SetRect(lineWM, pfd->mBounds, ContainerSize());
}
SetSpanForEmptyLine(psd, mRootSpan->mWritingMode, ContainerSize(),
mBStartEdge);
mFinalLineBSize = 0;
if (mGotLineBox) {

View File

@@ -648,6 +648,10 @@ class nsLineLayout {
const nsStyleText* aStyleText, float aInflation,
bool* aZeroEffectiveSpanBox);
static void SetSpanForEmptyLine(PerSpanData* aPerSpanData,
mozilla::WritingMode aWM,
const nsSize& aContainerSize,
nscoord aBStartEdge);
void VerticalAlignFrames(PerSpanData* psd);
void PlaceTopBottomFrames(PerSpanData* psd, nscoord aDistanceFromStart,