Skip to content

Commit

Permalink
[LFC][IFC] Set layout bounds only on inline box and related types of …
Browse files Browse the repository at this point in the history
…inline level boxes

https://bugs.webkit.org/show_bug.cgi?id=246986

Reviewed by Antti Koivisto.

Remove redundant setLayoutBounds calls (this is in preparation for supporting line-box-contain.)

* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.cpp:
(WebCore::Layout::LineBoxBuilder::setVerticalPropertiesForInlineLevelBox const):
(WebCore::Layout::LineBoxBuilder::adjustIdeographicBaselineIfApplicable):
(WebCore::Layout::LineBoxBuilder::setLayoutBounds const): Deleted.
* Source/WebCore/layout/formattingContexts/inline/InlineLineBoxBuilder.h:

Canonical link: https://commits.webkit.org/256067@main
  • Loading branch information
alanbaradlay committed Oct 27, 2022
1 parent 94530b0 commit 617c271
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
Expand Up @@ -214,42 +214,41 @@ static TextMetrics primaryFontMetricsForInlineBox(const InlineLevelBox& inlineBo
return { { ascent, descent }, lineSpacing, inlineBox.isPreferredLineHeightFontMetricsBased() ? std::nullopt : std::make_optional(inlineBox.preferredLineHeight()) };
}

void LineBoxBuilder::setLayoutBounds(InlineLevelBox& inlineLevelBox, const TextMetrics& textMetrics) const
{
auto logicalHeight = textMetrics.ascentAndDescent.ascent + textMetrics.ascentAndDescent.descent;
auto halfLeading = InlineLayoutUnit { };
if (textMetrics.preferredLineHeight) {
// If line-height computes to normal and either text-edge is leading or this is the root inline box,
// the font’s line gap metric may also be incorporated into A and D by adding half to each side as half-leading.
// https://www.w3.org/TR/css-inline-3/#inline-height
// Since text-edge is not supported yet and the initial value is leading, we should just apply it to
// all inline boxes.
halfLeading = (*textMetrics.preferredLineHeight - logicalHeight) / 2;
} else {
// Preferred line height is purely font metrics based (i.e glyphs stretch the line).
halfLeading = (textMetrics.lineSpacing - logicalHeight) / 2;
}
inlineLevelBox.setLayoutBounds({ floorf(textMetrics.ascentAndDescent.ascent + halfLeading), ceilf(textMetrics.ascentAndDescent.descent + halfLeading) });
}

void LineBoxBuilder::setVerticalPropertiesForInlineLevelBox(const LineBox& lineBox, InlineLevelBox& inlineLevelBox) const
{
auto setAscentAndDescent = [&] (auto ascentAndDescent) {
inlineLevelBox.setAscent(ascentAndDescent.ascent);
inlineLevelBox.setDescent(ascentAndDescent.descent);
};

auto setLayoutBounds = [&] (auto& textMetrics) {
auto logicalHeight = textMetrics.ascentAndDescent.ascent + textMetrics.ascentAndDescent.descent;
auto halfLeading = InlineLayoutUnit { };
if (textMetrics.preferredLineHeight) {
// If line-height computes to normal and either text-edge is leading or this is the root inline box,
// the font’s line gap metric may also be incorporated into A and D by adding half to each side as half-leading.
// https://www.w3.org/TR/css-inline-3/#inline-height
// Since text-edge is not supported yet and the initial value is leading, we should just apply it to
// all inline boxes.
halfLeading = (*textMetrics.preferredLineHeight - logicalHeight) / 2;
} else {
// Preferred line height is purely font metrics based (i.e glyphs stretch the line).
halfLeading = (textMetrics.lineSpacing - logicalHeight) / 2;
}
inlineLevelBox.setLayoutBounds({ floorf(textMetrics.ascentAndDescent.ascent + halfLeading), ceilf(textMetrics.ascentAndDescent.descent + halfLeading) });
};

if (inlineLevelBox.isInlineBox()) {
auto textMetrics = primaryFontMetricsForInlineBox(inlineLevelBox, lineBox.baselineType());
setLayoutBounds(inlineLevelBox, textMetrics);
setLayoutBounds(textMetrics);
// We need floor/ceil to match legacy layout integral positioning.
setAscentAndDescent(AscentAndDescent { floorf(textMetrics.ascentAndDescent.ascent), ceilf(textMetrics.ascentAndDescent.descent) });
inlineLevelBox.setLogicalHeight(textMetrics.ascentAndDescent.height());
return;
}
if (inlineLevelBox.isLineBreakBox()) {
auto parentTextMetrics = primaryFontMetricsForInlineBox(lineBox.inlineLevelBoxForLayoutBox(inlineLevelBox.layoutBox().parent()), lineBox.baselineType());
setLayoutBounds(inlineLevelBox, parentTextMetrics);
setLayoutBounds(parentTextMetrics);
// We need floor/ceil to match legacy layout integral positioning.
setAscentAndDescent(AscentAndDescent { floorf(parentTextMetrics.ascentAndDescent.ascent), ceilf(parentTextMetrics.ascentAndDescent.descent) });
inlineLevelBox.setLogicalHeight(parentTextMetrics.ascentAndDescent.height());
Expand All @@ -265,20 +264,19 @@ void LineBoxBuilder::setVerticalPropertiesForInlineLevelBox(const LineBox& lineB
if (lineBox.baselineType() == IdeographicBaseline) {
// FIXME: We should rely on the integration baseline.
auto parentTextMetrics = primaryFontMetricsForInlineBox(lineBox.inlineLevelBoxForLayoutBox(inlineLevelBox.layoutBox().parent()), lineBox.baselineType());
setLayoutBounds(inlineLevelBox, parentTextMetrics);
setLayoutBounds(parentTextMetrics);
// We need floor/ceil to match legacy layout integral positioning.
setAscentAndDescent(AscentAndDescent { floorf(parentTextMetrics.ascentAndDescent.ascent), ceilf(parentTextMetrics.ascentAndDescent.descent) });
return;
}
if (auto ascent = downcast<ElementBox>(layoutBox).baselineForIntegration()) {
auto textMetrics = TextMetrics { { *ascent, marginBoxHeight - *ascent }, { }, { } };
setLayoutBounds(inlineLevelBox, textMetrics);
setLayoutBounds(textMetrics);
// We need floor/ceil to match legacy layout integral positioning.
setAscentAndDescent(AscentAndDescent { floorf(textMetrics.ascentAndDescent.ascent), ceilf(textMetrics.ascentAndDescent.descent) });
return;
}
setAscentAndDescent(AscentAndDescent { marginBoxHeight, { } });
inlineLevelBox.setLayoutBounds({ marginBoxHeight, { } });
return;
}
if (inlineLevelBox.isAtomicInlineLevelBox()) {
Expand All @@ -305,7 +303,6 @@ void LineBoxBuilder::setVerticalPropertiesForInlineLevelBox(const LineBox& lineB
}();
setAscentAndDescent(AscentAndDescent { ascent, marginBoxHeight - ascent });
inlineLevelBox.setLogicalHeight(marginBoxHeight);
inlineLevelBox.setLayoutBounds({ ascent, marginBoxHeight - ascent });
return;
}
ASSERT_NOT_REACHED();
Expand Down Expand Up @@ -471,7 +468,6 @@ void LineBoxBuilder::adjustIdeographicBaselineIfApplicable(LineBox& lineBox, siz
InlineLayoutUnit ideographicBaseline = roundToInt(inlineLevelBoxHeight / 2);
// Move the baseline position but keep the same logical height.
inlineLevelBox.setAscent(ideographicBaseline);
inlineLevelBox.setLayoutBounds({ ideographicBaseline, inlineLevelBoxHeight - ideographicBaseline });
}

auto needsFontFallbackAdjustment = inlineLevelBox.isInlineBox() || inlineLevelBox.isLineBreakBox();
Expand Down
Expand Up @@ -35,7 +35,6 @@ namespace Layout {
class Box;
class ElementBox;
class LayoutState;
struct TextMetrics;

class LineBoxBuilder {
public:
Expand All @@ -45,7 +44,6 @@ class LineBoxBuilder {

private:
void setVerticalPropertiesForInlineLevelBox(const LineBox&, InlineLevelBox&) const;
void setLayoutBounds(InlineLevelBox&, const TextMetrics&) const;
void adjustLayoutBoundsWithFallbackFonts(InlineLevelBox&, const TextUtil::FallbackFontList& fallbackFontsForContent, FontBaseline) const;
TextUtil::FallbackFontList collectFallbackFonts(const InlineLevelBox& parentInlineBox, const Line::Run&, const RenderStyle&);

Expand Down

0 comments on commit 617c271

Please sign in to comment.