Changeset 269989 in webkit


Ignore:
Timestamp:
Nov 18, 2020 2:42:20 PM (3 years ago)
Author:
Alan Bujtas
Message:

[LFC][Integration] Line::enclosingRect should only include the border box (exclude vertical margins)
https://bugs.webkit.org/show_bug.cgi?id=219106

Reviewed by Antti Koivisto.

LineIteratorPath::top/bottom expects border box enclosing values (and not margin box values).
(and while we are here, let's just compute the vertical enclosing values and ignore the horizontal aspect of it as the line box always
encloses all the inline level boxes on the line anyway)

  • layout/inlineformatting/InlineFormattingContext.cpp:

(WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):

  • layout/inlineformatting/InlineLineBox.cpp:

(WebCore::Layout::LineBox::logicalMarginRectForInlineLevelBox const):
(WebCore::Layout::LineBox::logicalRectForInlineLevelBox const): Deleted.

  • layout/inlineformatting/InlineLineBox.h:
  • layout/integration/LayoutIntegrationInlineContentBuilder.cpp:

(WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):

  • layout/integration/LayoutIntegrationLine.h:

(WebCore::LayoutIntegration::Line::Line):
(WebCore::LayoutIntegration::Line::enclosingContentTop const):
(WebCore::LayoutIntegration::Line::enclosingContentBottom const):
(WebCore::LayoutIntegration::Line::enclosingContentRect const): Deleted.

  • layout/integration/LayoutIntegrationLineIteratorModernPath.h:

(WebCore::LayoutIntegration::LineIteratorModernPath::top const):
(WebCore::LayoutIntegration::LineIteratorModernPath::bottom const):

  • layout/integration/LayoutIntegrationPagination.cpp:

(WebCore::LayoutIntegration::makeAdjustedContent):

  • layout/integration/LayoutIntegrationRunIteratorModernPath.h:

(WebCore::LayoutIntegration::RunIteratorModernPath::selectionRect const):

  • layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::showInlineTreeAndRuns):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r269984 r269989  
     12020-11-18  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][Integration] Line::enclosingRect should only include the border box (exclude vertical margins)
     4        https://bugs.webkit.org/show_bug.cgi?id=219106
     5
     6        Reviewed by Antti Koivisto.
     7
     8        LineIteratorPath::top/bottom expects border box enclosing values (and not margin box values).
     9        (and while we are here, let's just compute the vertical enclosing values and ignore the horizontal aspect of it as the line box always
     10        encloses all the inline level boxes on the line anyway)
     11
     12        * layout/inlineformatting/InlineFormattingContext.cpp:
     13        (WebCore::Layout::InlineFormattingContext::computeGeometryForLineContent):
     14        * layout/inlineformatting/InlineLineBox.cpp:
     15        (WebCore::Layout::LineBox::logicalMarginRectForInlineLevelBox const):
     16        (WebCore::Layout::LineBox::logicalRectForInlineLevelBox const): Deleted.
     17        * layout/inlineformatting/InlineLineBox.h:
     18        * layout/integration/LayoutIntegrationInlineContentBuilder.cpp:
     19        (WebCore::LayoutIntegration::InlineContentBuilder::createDisplayLines const):
     20        * layout/integration/LayoutIntegrationLine.h:
     21        (WebCore::LayoutIntegration::Line::Line):
     22        (WebCore::LayoutIntegration::Line::enclosingContentTop const):
     23        (WebCore::LayoutIntegration::Line::enclosingContentBottom const):
     24        (WebCore::LayoutIntegration::Line::enclosingContentRect const): Deleted.
     25        * layout/integration/LayoutIntegrationLineIteratorModernPath.h:
     26        (WebCore::LayoutIntegration::LineIteratorModernPath::top const):
     27        (WebCore::LayoutIntegration::LineIteratorModernPath::bottom const):
     28        * layout/integration/LayoutIntegrationPagination.cpp:
     29        (WebCore::LayoutIntegration::makeAdjustedContent):
     30        * layout/integration/LayoutIntegrationRunIteratorModernPath.h:
     31        (WebCore::LayoutIntegration::RunIteratorModernPath::selectionRect const):
     32        * layout/layouttree/LayoutTreeBuilder.cpp:
     33        (WebCore::Layout::showInlineTreeAndRuns):
     34
    1352020-11-18  Antoine Quint  <graouts@webkit.org>
    236
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContext.cpp

    r269571 r269989  
    439439                formattingState.addLineRun({ lineIndex, lineRun.layoutBox(), lineBox.logicalRectForTextRun(lineRun), lineRun.expansion(), lineRun.textContent() });
    440440            else if (lineRun.isBox())
    441                 formattingState.addLineRun({ lineIndex, lineRun.layoutBox(), lineBox.logicalRectForInlineLevelBox(lineRun.layoutBox()), lineRun.expansion(), { } });
     441                formattingState.addLineRun({ lineIndex, lineRun.layoutBox(), lineBox.logicalMarginRectForInlineLevelBox(lineRun.layoutBox()), lineRun.expansion(), { } });
    442442        }
    443443    };
     
    456456            // Inline box coordinates are relative to the line box.
    457457            // Let's convert top/left relative to the formatting context root.
    458             auto logicalRect = lineBox.logicalRectForInlineLevelBox(layoutBox);
     458            auto logicalRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox);
    459459            // Inline box height includes the margin box. Let's account for that.
    460460            auto borderBoxLogicalTopLeft = lineLogicalRect.topLeft();
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.cpp

    r269912 r269989  
    111111}
    112112
    113 InlineRect LineBox::logicalRectForInlineLevelBox(const Box& layoutBox) const
     113InlineRect LineBox::logicalMarginRectForInlineLevelBox(const Box& layoutBox) const
    114114{
    115115    auto* inlineBox = &inlineLevelBoxForLayoutBox(layoutBox);
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h

    r269912 r269989  
    142142
    143143    InlineRect logicalRectForTextRun(const Line::Run&) const;
    144     InlineRect logicalRectForInlineLevelBox(const Box&) const;
     144    InlineRect logicalMarginRectForInlineLevelBox(const Box&) const;
    145145
    146146    auto inlineLevelBoxList() const { return m_inlineLevelBoxRectMap.values(); }
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationInlineContentBuilder.cpp

    r269817 r269989  
    318318        auto runCount = runIndex - firstRunIndex;
    319319        auto lineRect = FloatRect { line.logicalRect() };
    320         auto enclosingContentRect = [&] {
     320        auto enclosingTopAndBottom = [&] {
    321321            // Let's (vertically)enclose all the inline level boxes.
    322322            // This mostly matches 'lineRect', unless line-height triggers line box overflow (not to be confused with ink or scroll overflow).
    323             auto enclosingRect = FloatRect { lineRect.location(), lineBoxLogicalSize };
     323            auto enclosingTop = Optional<float> { };
     324            auto enclosingBottom = Optional<float> { };
    324325            auto& lineBox = lineBoxes[lineIndex];
    325326            for (auto& inlineLevelBox : lineBox.inlineLevelBoxList()) {
    326                 auto inlineLevelBoxLogicalRect = lineBox.logicalRectForInlineLevelBox(inlineLevelBox->layoutBox());
    327                 // inlineLevelBoxLogicalRect is relative to the line.
    328                 inlineLevelBoxLogicalRect.moveBy(lineRect.location());
    329                 enclosingRect.setY(std::min(enclosingRect.y(), inlineLevelBoxLogicalRect.top()));
    330                 enclosingRect.shiftMaxYEdgeTo(std::max(enclosingRect.maxY(), inlineLevelBoxLogicalRect.bottom()));
    331             }
    332             return enclosingRect;
     327                auto& layoutBox = inlineLevelBox->layoutBox();
     328                auto inlineLevelBoxLogicalRect = lineBox.logicalMarginRectForInlineLevelBox(layoutBox);
     329                // inlineLevelBoxLogicalRect encloses the margin box, but we need border box for the display line.
     330                auto& geometry = m_layoutState.geometryForBox(layoutBox);
     331                inlineLevelBoxLogicalRect.expandVertically(-std::max(0_lu, geometry.marginBefore() + geometry.marginAfter()));
     332                inlineLevelBoxLogicalRect.moveVertically(std::max(0_lu, geometry.marginBefore()));
     333
     334                enclosingTop = std::min(enclosingTop.valueOr(inlineLevelBoxLogicalRect.top()), inlineLevelBoxLogicalRect.top());
     335                enclosingBottom = std::max(enclosingBottom.valueOr(inlineLevelBoxLogicalRect.bottom()), inlineLevelBoxLogicalRect.bottom());
     336            }
     337            // There's always at least one inline level box, the root inline box.
     338            ASSERT(enclosingBottom && enclosingTop);
     339            // inline boxes are relative to the line, let's make them relative to the root's content box.
     340            return Line::EnclosingTopAndBottom { lineRect.y() + *enclosingTop, lineRect.y() + *enclosingBottom };
    333341        }();
    334342        if (lineLevelVisualAdjustmentsForRuns[lineIndex].needsIntegralPosition) {
    335343            lineRect.setY(roundToInt(lineRect.y()));
    336             enclosingContentRect.setY(roundToInt(enclosingContentRect.y()));
     344            enclosingTopAndBottom.top = roundToInt(enclosingTopAndBottom.top);
     345            enclosingTopAndBottom.bottom = roundToInt(enclosingTopAndBottom.bottom);
    337346        }
    338         inlineContent.lines.append({ firstRunIndex, runCount, lineRect, lineBoxLogicalSize.width(), enclosingContentRect, scrollableOverflowRect, lineInkOverflowRect, line.baseline(), line.horizontalAlignmentOffset() });
     347        inlineContent.lines.append({ firstRunIndex, runCount, lineRect, lineBoxLogicalSize.width(), enclosingTopAndBottom, scrollableOverflowRect, lineInkOverflowRect, line.baseline(), line.horizontalAlignmentOffset() });
    339348    }
    340349}
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationLine.h

    r269571 r269989  
    3636    WTF_MAKE_FAST_ALLOCATED;
    3737public:
    38     Line(size_t firstRunIndex, size_t runCount, const FloatRect& lineRect, float lineBoxWidth, const FloatRect& enclosingContentRect, const FloatRect& scrollableOverflow, const FloatRect& inkOverflow, float baseline, float horizontalAlignmentOffset)
     38    struct EnclosingTopAndBottom {
     39        // This values encloses the root inline box and any other inline level box's border box.
     40        float top { 0 };
     41        float bottom { 0 };
     42    };
     43    Line(size_t firstRunIndex, size_t runCount, const FloatRect& lineRect, float lineBoxWidth, EnclosingTopAndBottom enclosingTopAndBottom, const FloatRect& scrollableOverflow, const FloatRect& inkOverflow, float baseline, float horizontalAlignmentOffset)
    3944        : m_firstRunIndex(firstRunIndex)
    4045        , m_runCount(runCount)
    4146        , m_lineRect(lineRect)
    4247        , m_lineBoxWidth(lineBoxWidth)
    43         , m_enclosingContentRect(enclosingContentRect)
     48        , m_enclosingTopAndBottom(enclosingTopAndBottom)
    4449        , m_scrollableOverflow(scrollableOverflow)
    4550        , m_inkOverflow(inkOverflow)
     
    5358    const FloatRect& rect() const { return m_lineRect; }
    5459    float lineBoxWidth() const { return m_lineBoxWidth; }
    55     const FloatRect& enclosingContentRect() const { return m_enclosingContentRect; }
     60    float enclosingContentTop() const { return m_enclosingTopAndBottom.top; }
     61    float enclosingContentBottom() const { return m_enclosingTopAndBottom.bottom; }
    5662    const FloatRect& scrollableOverflow() const { return m_scrollableOverflow; }
    5763    const FloatRect& inkOverflow() const { return m_inkOverflow; }
     
    6470    // Line is always as tall as the line box is. However they may differ in width.
    6571    // While line box encloses all the inline level boxes on the line horizontally, the line itself may be shorter (and trigger horizontal overflow).
    66     // Enclosing content rect includes all inline level boxes both vertically and horizontally. In certain cases (see line-height property)
     72    // Enclosing top and bottom includes all inline level boxes (border box) vertically. In certain cases (see line-height property)
    6773    // the line (and the line box) is not as tall as the inline level boxes on the line.
    6874    FloatRect m_lineRect;
    6975    float m_lineBoxWidth { 0 };
    70     FloatRect m_enclosingContentRect;
     76    EnclosingTopAndBottom m_enclosingTopAndBottom;
    7177    FloatRect m_scrollableOverflow;
    7278    FloatRect m_inkOverflow;
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationLineIteratorModernPath.h

    r269916 r269989  
    5050    LineIteratorModernPath& operator=(LineIteratorModernPath&&) = default;
    5151
    52     LayoutUnit top() const { return LayoutUnit::fromFloatRound(line().enclosingContentRect().y()); }
    53     LayoutUnit bottom() const { return LayoutUnit::fromFloatRound(line().enclosingContentRect().maxY()); }
     52    LayoutUnit top() const { return LayoutUnit::fromFloatRound(line().enclosingContentTop()); }
     53    LayoutUnit bottom() const { return LayoutUnit::fromFloatRound(line().enclosingContentBottom()); }
    5454    LayoutUnit lineBoxTop() const { return LayoutUnit::fromFloatRound(line().rect().y()); }
    5555    LayoutUnit lineBoxBottom() const { return LayoutUnit::fromFloatRound(line().rect().maxY()); }
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationPagination.cpp

    r269571 r269989  
    132132            moveVertically(line.rect(), offset),
    133133            line.rect().width(),
    134             moveVertically(line.enclosingContentRect(), offset),
     134            { line.enclosingContentTop() + offset, line.enclosingContentBottom() + offset },
    135135            moveVertically(line.scrollableOverflow(), offset),
    136136            moveVertically(line.inkOverflow(), offset),
  • trunk/Source/WebCore/layout/integration/LayoutIntegrationRunIteratorModernPath.h

    r269916 r269989  
    118118
    119119        // FIXME: These should share implementation with the line iterator.
    120         auto selectionTop = LayoutUnit::fromFloatRound(line().enclosingContentRect().y());
    121         auto selectionHeight = LayoutUnit::fromFloatRound(line().enclosingContentRect().height());
     120        auto selectionTop = LayoutUnit::fromFloatRound(line().enclosingContentTop());
     121        auto selectionHeight = LayoutUnit::fromFloatRound(line().enclosingContentBottom() - line().enclosingContentTop());
    122122
    123123        LayoutRect selectionRect { logicalLeft, selectionTop, logicalWidth, selectionHeight };
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r269298 r269989  
    416416            else
    417417                stream << "Generic inline level box";
    418             auto logicalRect = lineBox.logicalRectForInlineLevelBox(inlineLevelBox.layoutBox());
     418            auto logicalRect = lineBox.logicalMarginRectForInlineLevelBox(inlineLevelBox.layoutBox());
    419419            stream
    420420                << " at (" << logicalRect.left() << "," << logicalRect.top() << ")"
Note: See TracChangeset for help on using the changeset viewer.