Changeset 266978 in webkit


Ignore:
Timestamp:
Sep 12, 2020 10:07:38 AM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Add support for non-root-inline-box line spacing
https://bugs.webkit.org/show_bug.cgi?id=216433

Reviewed by Antti Koivisto.

Source/WebCore:

While the LineBox vertically contains all the LineBox::InlineBoxes, its height value does not
include any line spacing (FontMetrics::lineSpacing).
Each LineBox::InlineBox may have a different line spacing value (this value is zero in many cases).
This patch collects line spacing values from the LineBox::InlineBoxes on the line and adjusts the final
line height value accordingly.

Test: fast/layoutformattingcontext/inline-box-with-line-spacing-simple.html

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::computedLineLogicalRect const):

  • layout/inlineformatting/InlineLineBox.cpp:

(WebCore::Layout::LineBox::constructInlineBoxes):

  • layout/inlineformatting/InlineLineBox.h:

(WebCore::Layout::LineBox::InlineBox::lineSpacing const):
(WebCore::Layout::LineBox::InlineBox::setLineSpacing):
(WebCore::Layout::LineBox::inlineBoxList const):

LayoutTests:

  • fast/layoutformattingcontext/inline-box-with-line-spacing-simple-expected.html: Added.
  • fast/layoutformattingcontext/inline-box-with-line-spacing-simple.html: Added.
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r266976 r266978  
     12020-09-12  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add support for non-root-inline-box line spacing
     4        https://bugs.webkit.org/show_bug.cgi?id=216433
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/layoutformattingcontext/inline-box-with-line-spacing-simple-expected.html: Added.
     9        * fast/layoutformattingcontext/inline-box-with-line-spacing-simple.html: Added.
     10
    1112020-09-12  Rob Buis  <rbuis@igalia.com>
    212
  • trunk/LayoutTests/platform/win/TestExpectations

    r266913 r266978  
    36923692fast/forms/file/entries-api/webkitdirectory-open-panel.html [ Skip ]
    36933693
     3694fast/layoutformattingcontext [ Skip ]
     3695
    36943696# Requires WK2 loading support
    36953697http/wpt/fetch/dnt-header-after-redirection.html [ Skip ]
     
    44464448webkit.org/b/204794 webanimations/accelerated-animation-removal-upon-transition-completion.html [ Timeout ]
    44474449
    4448 webkit.org/b/204795 fast/layoutformattingcontext/flow-integration-basic.html [ Failure ]
    4449 
    44504450webkit.org/b/204974 http/tests/xmlhttprequest/sync-xhr-in-unload.html [ Failure ]
    44514451
  • trunk/Source/WebCore/ChangeLog

    r266977 r266978  
     12020-09-12  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Add support for non-root-inline-box line spacing
     4        https://bugs.webkit.org/show_bug.cgi?id=216433
     5
     6        Reviewed by Antti Koivisto.
     7
     8        While the LineBox vertically contains all the LineBox::InlineBoxes, its height value does not
     9        include any line spacing (FontMetrics::lineSpacing).
     10        Each LineBox::InlineBox may have a different line spacing value (this value is zero in many cases).
     11        This patch collects line spacing values from the LineBox::InlineBoxes on the line and adjusts the final
     12        line height value accordingly.
     13
     14        Test: fast/layoutformattingcontext/inline-box-with-line-spacing-simple.html
     15
     16        * layout/inlineformatting/InlineFormattingContext.cpp:
     17        (WebCore::Layout::InlineFormattingContext::computedLineLogicalRect const):
     18        * layout/inlineformatting/InlineLineBox.cpp:
     19        (WebCore::Layout::LineBox::constructInlineBoxes):
     20        * layout/inlineformatting/InlineLineBox.h:
     21        (WebCore::Layout::LineBox::InlineBox::lineSpacing const):
     22        (WebCore::Layout::LineBox::InlineBox::setLineSpacing):
     23        (WebCore::Layout::LineBox::inlineBoxList const):
     24
    1252020-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
    226
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r266848 r266978  
    410410    // |____________________v_______________________|  scrollable overflow
    411411    //
    412     if (lineContent.runs.isEmpty() || lineContent.lineBox.isLineVisuallyEmpty())
     412    auto& lineBox = lineContent.lineBox;
     413    if (lineContent.runs.isEmpty() || lineBox.isLineVisuallyEmpty())
    413414        return { { }, { lineContent.logicalTopLeft, lineContent.lineLogicalWidth, { } } };
     415
    414416    auto& rootStyle = root().style();
    415     auto& fontMetrics = rootStyle.fontMetrics();
    416     InlineLayoutUnit lineSpacing = fontMetrics.lineSpacing();
    417     auto& lineBox = lineContent.lineBox;
    418     auto lineLogicalHeight = rootStyle.lineHeight().isNegative() ? std::max(lineBox.logicalHeight(), lineSpacing) : rootStyle.computedLineHeight();
     417    auto lineLogicalHeight = InlineLayoutUnit { };
     418    if (rootStyle.lineHeight().isNegative()) {
     419        // Negative line height value means the line height is driven by the content.
     420        auto usedLineSpacing = [&] {
     421            auto lineBoxLogicalHeight = lineBox.logicalHeight();
     422            auto logicalTopWithLineSpacing = InlineLayoutUnit { };
     423            auto logicalBottomWithLineSpacing = lineBoxLogicalHeight;
     424            for (auto& inlineBox : lineBox.inlineBoxList()) {
     425                if (auto lineSpacing = inlineBox->lineSpacing()) {
     426                    // FIXME: check if line spacing is distributed evenly.
     427                    logicalTopWithLineSpacing = std::min(logicalTopWithLineSpacing, inlineBox->logicalTop() - *lineSpacing / 2);
     428                    logicalBottomWithLineSpacing = std::max(logicalBottomWithLineSpacing, inlineBox->logicalBottom() + *lineSpacing / 2);
     429                }
     430            }
     431            return -logicalTopWithLineSpacing + (logicalBottomWithLineSpacing - lineBoxLogicalHeight);
     432        };
     433        lineLogicalHeight = lineBox.logicalHeight() + usedLineSpacing();
     434    } else
     435        lineLogicalHeight = rootStyle.computedLineHeight();
     436
    419437    auto logicalRect = Display::InlineRect { lineContent.logicalTopLeft, lineContent.lineLogicalWidth, lineLogicalHeight};
    420 
    421438    auto halfLeadingOffset = [&] {
     439        auto& fontMetrics = rootStyle.fontMetrics();
    422440        InlineLayoutUnit ascent = fontMetrics.ascent();
    423441        InlineLayoutUnit descent = fontMetrics.descent();
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp

    r266921 r266978  
    165165        inlineBox.setBaseline(baseline);
    166166        inlineBox.setDescent(logicalHeight - baseline);
     167        if (auto lineSpacing = fontMetrics.lineSpacing() - logicalHeight)
     168            inlineBox.setLineSpacing(lineSpacing);
    167169    };
    168170
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h

    r266921 r266978  
    7777        void setIsNonEmpty() { m_isEmpty = false; }
    7878
     79        Optional<InlineLayoutUnit> lineSpacing() const { return m_lineSpacing; }
    7980        const FontMetrics& fontMetrics() const { return layoutBox().style().fontMetrics(); }
    8081        const Box& layoutBox() const { return *m_layoutBox; }
     
    8889        void setBaseline(InlineLayoutUnit baseline) { m_baseline = baseline; }
    8990        void setDescent(InlineLayoutUnit descent) { m_descent = descent; }
     91        void setLineSpacing(InlineLayoutUnit lineSpacing) { m_lineSpacing = lineSpacing; }
    9092
    9193        WeakPtr<const Box> m_layoutBox;
     
    9395        InlineLayoutUnit m_baseline { 0 };
    9496        Optional<InlineLayoutUnit> m_descent;
     97        Optional<InlineLayoutUnit> m_lineSpacing;
    9598        bool m_isEmpty { true };
    9699    };
     
    109112    const InlineBox& inlineBoxForLayoutBox(const Box& layoutBox) const { return *m_inlineBoxRectMap.get(&layoutBox); }
    110113    Display::InlineRect logicalRectForTextRun(const Line::Run&) const;
     114
     115    using InlineBoxMap = HashMap<const Box*, InlineBox*>;
     116    auto inlineBoxList() const { return m_inlineBoxRectMap.values(); }
    111117
    112118    InlineLayoutUnit alignmentBaseline() const { return m_rootInlineBox.logicalTop() + m_rootInlineBox.baseline(); }
     
    130136
    131137    Optional<InlineLayoutUnit> m_horizontalAlignmentOffset;
    132     HashMap<const Box*, InlineBox*> m_inlineBoxRectMap;
     138    InlineBoxMap m_inlineBoxRectMap;
    133139    Vector<std::unique_ptr<InlineBox>> m_inlineBoxList;
    134140    const InlineFormattingContext& m_inlineFormattingContext;
Note: See TracChangeset for help on using the changeset viewer.