⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 268823 in webkit


Ignore:
Timestamp:
Oct 21, 2020, 2:21:22 PM (6 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Apply font line-spacing to <br> inline level box
https://bugs.webkit.org/show_bug.cgi?id=218043

Reviewed by Antti Koivisto.

The inline level box initiated by <br> should be vertically sized the same way as the root inline box is.
(e.g. <div>root text<br></div> <- line break's inline level box should match the layout bounds of the root inline box).

  • layout/inlineformatting/InlineFormattingContextGeometry.cpp:

(WebCore::Layout::LineBoxBuilder::isRootInlineBox const):
(WebCore::Layout::LineBoxBuilder::isRootBox const):
(WebCore::Layout::LineBoxBuilder::setVerticalGeometryForInlineBox const):
(WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r268822 r268823  
     12020-10-21  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Apply font line-spacing to <br> inline level box
     4        https://bugs.webkit.org/show_bug.cgi?id=218043
     5
     6        Reviewed by Antti Koivisto.
     7
     8        The inline level box initiated by <br> should be vertically sized the same way as the root inline box is.
     9        (e.g. <div>root text<br></div> <- line break's inline level box should match the layout bounds of the root inline box).
     10
     11        * layout/inlineformatting/InlineFormattingContextGeometry.cpp:
     12        (WebCore::Layout::LineBoxBuilder::isRootInlineBox const):
     13        (WebCore::Layout::LineBoxBuilder::isRootBox const):
     14        (WebCore::Layout::LineBoxBuilder::setVerticalGeometryForInlineBox const):
     15        (WebCore::Layout::LineBoxBuilder::constructInlineLevelBoxes):
     16
    1172020-10-21  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextGeometry.cpp

    r268815 r268823  
    5454    LayoutState& layoutState() const { return formattingContext().layoutState(); }
    5555
     56    bool isRootInlineBox(const LineBox::InlineLevelBox& inlineLevelBox) const { return &inlineLevelBox.layoutBox() == &rootBox(); }
     57    bool isRootBox(const ContainerBox& containerBox) const { return &containerBox == &rootBox(); }
     58
    5659private:
    5760    const InlineFormattingContext& m_inlineFormattingContext;
     
    178181        // If line-height computes to normal and either text-edge is leading or this is the root inline box,
    179182        // the font’s line gap metric may also be incorporated into A and D by adding half to each side as half-leading.
    180         auto lineSpacing = &inlineLevelBox.layoutBox() == &rootBox() ? fontMetrics.lineSpacing() - logicalHeight : InlineLayoutUnit();
    181         ascent += lineSpacing / 2;
    182         descent += lineSpacing / 2;
     183        auto shouldLineGapStretchInlineLevelBox = isRootInlineBox(inlineLevelBox) || inlineLevelBox.isLineBreakBox();
     184        if (shouldLineGapStretchInlineLevelBox) {
     185            auto halfLineGap = (fontMetrics.lineSpacing() - logicalHeight) / 2;
     186            ascent += halfLineGap;
     187            descent += halfLineGap;
     188        }
    183189    } else {
    184190        InlineLayoutUnit lineHeight = style.computedLineHeight();
     
    224230        // nested with a [container start] run.
    225231        auto& firstRun = runs[0];
    226         auto& firstRunParentInlineBox = firstRun.layoutBox().parent();
     232        auto& firstRunParentLayoutBox = firstRun.layoutBox().parent();
    227233        // If the parent is the formatting root, we can stop here. This is root inline box content, there's no nesting inline box from the previous line(s)
    228234        // unless the inline box closing (container end run) is forced over to the current line.
     
    230236        // <span>normally the inline box closing forms a continuous content</span>
    231237        // <span>unless it's forced to the next line<br></span>
    232         if (&firstRunParentInlineBox == &rootBox() && !firstRun.isContainerEnd())
     238        if (isRootBox(firstRunParentLayoutBox) && !firstRun.isContainerEnd())
    233239            return;
    234         auto* ancestor = &firstRunParentInlineBox;
     240        auto* ancestor = &firstRunParentLayoutBox;
    235241        Vector<const Box*> ancestorsWithoutInlineBoxes;
    236         while (ancestor != &rootBox()) {
     242        while (!isRootBox(*ancestor)) {
    237243            ancestorsWithoutInlineBoxes.append(ancestor);
    238244            ancestor = &ancestor->parent();
     
    249255    auto stretchRootInlineBoxIfNeededQuirk = [&] (const auto& layoutBox) {
    250256        auto& parentInlineBox = lineBox.inlineLevelBoxForLayoutBox(layoutBox.parent());
    251         if (&parentInlineBox.layoutBox() != &rootBox() || !parentInlineBox.isEmpty())
     257        if (!isRootInlineBox(parentInlineBox) || !parentInlineBox.isEmpty())
    252258            return;
    253259        setVerticalGeometryForInlineBox(parentInlineBox);
Note: See TracChangeset for help on using the changeset viewer.