Skip to content

Commit

Permalink
[IFC][line-box-contain] line-height should not affect enclosing height
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=255211

Reviewed by Antti Koivisto.

Layout bounds geometry takes line-height into account potentially causing overlapping content
while line-box-contain (by definition) should always produce non-overlapping content.

* LayoutTests/fast/inline/line-box-contain-with-line-height-expected.html: Added.
* LayoutTests/fast/inline/line-box-contain-with-line-height.html: Added.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::LineBoxBuilder::adjustInlineBoxHeightsForLineBoxContainIfApplicable):

Canonical link: https://commits.webkit.org/262768@main
  • Loading branch information
alanbaradlay committed Apr 10, 2023
1 parent c0c0062 commit afa7e18
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
@@ -0,0 +1,13 @@
<!doctype html>
<style>
div {
font-family: Ahem;
font-size: 100px;
background-color: green;
color: green;
width: 100px;
padding-top: 50px;
padding-bottom: 50px;
}
</style>
<div>&nbsp</div>
17 changes: 17 additions & 0 deletions LayoutTests/fast/inline/line-box-contain-with-line-height.html
@@ -0,0 +1,17 @@
<!doctype html>
<style>
div {
-webkit-line-box-contain: inline-box;
font-size: 100px;
line-height: 0;
font-family: Ahem;
background-color: green;
width: 100px;
}

span {
background-color: red;
margin: 50px;
}
</style>
<div><span></span></div>
Expand Up @@ -470,9 +470,8 @@ void LineBoxBuilder::adjustInlineBoxHeightsForLineBoxContainIfApplicable(LineBox
if (!inlineLevelBox.isInlineBox())
continue;
auto& inlineBoxGeometry = formattingContext().geometryForBox(inlineLevelBox.layoutBox());
auto layoutBounds = *inlineLevelBox.layoutBounds();
auto ascent = layoutBounds.ascent + inlineBoxGeometry.marginBorderAndPaddingBefore();
auto descent = layoutBounds.descent + inlineBoxGeometry.marginBorderAndPaddingAfter();
auto ascent = inlineLevelBox.ascent() + inlineBoxGeometry.marginBorderAndPaddingBefore();
auto descent = valueOrDefault(inlineLevelBox.descent()) + inlineBoxGeometry.marginBorderAndPaddingAfter();
inlineBoxBoundsMap.set(&inlineLevelBox, TextUtil::EnclosingAscentDescent { ascent, descent });
}
}
Expand All @@ -481,12 +480,6 @@ void LineBoxBuilder::adjustInlineBoxHeightsForLineBoxContainIfApplicable(LineBox
// Assign font based layout bounds to all inline boxes.
auto ensureFontMetricsBasedHeight = [&] (auto& inlineBox) {
ASSERT(inlineBox.isInlineBox());
if (inlineBox.isPreferredLineHeightFontMetricsBased()) {
auto fontMetricsBaseLayoutBounds = *inlineBox.layoutBounds();
inlineBoxBoundsMap.set(&inlineBox, TextUtil::EnclosingAscentDescent { fontMetricsBaseLayoutBounds.ascent, fontMetricsBaseLayoutBounds.descent });
return;
}

auto ascentAndDescent = primaryFontMetricsForInlineBox(inlineBox, lineBox.baselineType());
InlineLayoutUnit lineGap = inlineBox.primarymetricsOfPrimaryFont().lineSpacing();
auto halfLeading = (lineGap - ascentAndDescent.height()) / 2;
Expand Down

0 comments on commit afa7e18

Please sign in to comment.