Changeset 246234 in webkit


Ignore:
Timestamp:
Jun 8, 2019 11:48:41 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Introduce Baseline to LineBox
https://bugs.webkit.org/show_bug.cgi?id=198686
<rdar://problem/51545175>

Reviewed by Antti Koivisto.

Make baselines alignment explicit in Line.
This is in preparation for adding non-baseline vertical alignment support.

  • layout/inlineformatting/InlineFormattingContextLineLayout.cpp:

(WebCore::Layout::InlineFormattingContext::LineLayout::placeInlineItems const):
(WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const):

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::Line):
(WebCore::Layout::Line::close):
(WebCore::Layout::Line::adjustBaselineAndLineHeight):
(WebCore::Layout::Line::halfLeadingMetrics):

  • layout/inlineformatting/InlineLine.h:

(WebCore::Layout::Line::Content::baseline const):
(WebCore::Layout::Line::Content::setBaseline):
(WebCore::Layout::Line::logicalHeight const):
(WebCore::Layout::Line::baselineAlignedContentHeight const):
(WebCore::Layout::Line::baselineOffset const):

  • layout/inlineformatting/InlineLineBox.h:

(WebCore::Layout::LineBox::baseline const):
(WebCore::Layout::LineBox::LineBox):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246231 r246234  
     12019-06-08  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Introduce Baseline to LineBox
     4        https://bugs.webkit.org/show_bug.cgi?id=198686
     5        <rdar://problem/51545175>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Make baselines alignment explicit in Line.
     10        This is in preparation for adding non-baseline vertical alignment support.
     11
     12        * layout/inlineformatting/InlineFormattingContextLineLayout.cpp:
     13        (WebCore::Layout::InlineFormattingContext::LineLayout::placeInlineItems const):
     14        (WebCore::Layout::InlineFormattingContext::LineLayout::createDisplayRuns const):
     15        * layout/inlineformatting/InlineLine.cpp:
     16        (WebCore::Layout::Line::Line):
     17        (WebCore::Layout::Line::close):
     18        (WebCore::Layout::Line::adjustBaselineAndLineHeight):
     19        (WebCore::Layout::Line::halfLeadingMetrics):
     20        * layout/inlineformatting/InlineLine.h:
     21        (WebCore::Layout::Line::Content::baseline const):
     22        (WebCore::Layout::Line::Content::setBaseline):
     23        (WebCore::Layout::Line::logicalHeight const):
     24        (WebCore::Layout::Line::baselineAlignedContentHeight const):
     25        (WebCore::Layout::Line::baselineOffset const):
     26        * layout/inlineformatting/InlineLineBox.h:
     27        (WebCore::Layout::LineBox::baseline const):
     28        (WebCore::Layout::LineBox::LineBox):
     29
    1302019-06-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
    231
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp

    r246206 r246234  
    131131    if (lineInput.skipVerticalAligment == LineInput::SkipVerticalAligment::No) {
    132132        auto mimimumLineHeight = m_formattingRoot.style().computedLineHeight();
    133         auto baselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).height;
    134         line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, baselineOffset);
     133        auto initialBaselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).offset;
     134        line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, initialBaselineOffset);
    135135    } else
    136136        line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft.x(), lineInput.horizontalConstraint.availableLogicalWidth);
     
    302302        // Spec tells us to create a zero height, empty line box.
    303303        auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 };
    304         m_formattingState.addLineBox({ lineBox });
     304        m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
    305305        return;
    306306    }
     
    312312
    313313    // Ignore the initial strut.
    314     auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } };
     314    auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0, !lineContent.isVisuallyEmpty() ? lineContent.logicalHeight() : LayoutUnit { } };
    315315    // Create final display runs.
    316316    auto& lineRuns = lineContent.runs();
     
    393393    }
    394394    // FIXME linebox needs to be ajusted after content alignment.
    395     m_formattingState.addLineBox({ lineBox });
     395    m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
    396396    if (!lineContent.isVisuallyEmpty())
    397397        alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth());
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r246206 r246234  
    7070    , m_content(std::make_unique<Line::Content>())
    7171    , m_logicalTopLeft(topLeft)
    72     , m_logicalHeight({ baselineOffset, minimumHeight - baselineOffset })
     72    , m_baseline({ baselineOffset, minimumHeight - baselineOffset, { } })
     73    , m_contentLogicalHeight(minimumHeight)
    7374    , m_lineLogicalWidth(availableWidth)
    7475{
     
    8182        // Convert inline run geometry from relative to the baseline to relative to logical top.
    8283        for (auto& run : m_content->runs()) {
    83             auto adjustedLogicalTop = run->logicalRect.top() + m_logicalHeight.height + m_logicalTopLeft.y();
     84            auto adjustedLogicalTop = run->logicalRect.top() + baselineOffset();
    8485            run->logicalRect.setTop(adjustedLogicalTop);
    8586        }
    8687    }
    8788    m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
     89    m_content->setBaseline(m_baseline);
    8890    return WTFMove(m_content);
    8991}
     
    246248        auto& fontMetrics = style.fontMetrics();
    247249        auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight());
    248         if (halfLeading.depth > 0)
    249             m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
    250         if (halfLeading.height > 0)
    251             m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
     250        if (halfLeading.descent > 0)
     251            m_baseline.descent = std::max(m_baseline.descent, halfLeading.descent);
     252        if (halfLeading.ascent > 0)
     253            m_baseline.ascent = std::max(m_baseline.ascent, halfLeading.ascent);
     254        m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
    252255        return;
    253256    }
     
    258261            return;
    259262        // FIXME: This fails when the line height difference comes from font-size diff.
    260         m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
    261         m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
     263        m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent);
     264        m_baseline.ascent = std::max(runHeight, m_baseline.ascent);
     265        m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
    262266        return;
    263267    }
    264268    // 0 descent -> baseline aligment for now.
    265     m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
    266     m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
     269    m_baseline.descent = std::max<LayoutUnit>(0, m_baseline.descent);
     270    m_baseline.ascent = std::max(runHeight, m_baseline.ascent);
     271    m_contentLogicalHeight = std::max(m_contentLogicalHeight, baselineAlignedContentHeight());
    267272}
    268273
     
    291296}
    292297
    293 Line::UsedHeightAndDepth Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)
     298LineBox::Baseline Line::halfLeadingMetrics(const FontMetrics& fontMetrics, LayoutUnit lineLogicalHeight)
    294299{
    295300    auto ascent = fontMetrics.ascent();
     
    300305    auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0);
    301306    auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0);
    302     return { adjustedAscent, adjustedDescent };
     307    return { adjustedAscent, adjustedDescent, adjustedAscent };
    303308}
    304309
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r246206 r246234  
    7070        LayoutUnit logicalWidth() const { return m_logicalRect.width(); }
    7171        LayoutUnit logicalHeight() const { return m_logicalRect.height(); }
     72        LineBox::Baseline baseline() const { return m_baseline; }
    7273
    7374    private:
     
    7576
    7677        void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; }
     78        void setBaseline(LineBox::Baseline baseline) { m_baseline = baseline; }
    7779        Runs& runs() { return m_runs; }
    7880
    7981        Display::Rect m_logicalRect;
     82        LineBox::Baseline m_baseline;
    8083        Runs m_runs;
    8184    };
     
    101104    LayoutUnit logicalBottom() const { return logicalTop() + logicalHeight(); }
    102105
    103     struct UsedHeightAndDepth {
    104         LayoutUnit height;
    105         LayoutUnit depth;
    106     };
    107     static UsedHeightAndDepth halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
     106    static LineBox::Baseline halfLeadingMetrics(const FontMetrics&, LayoutUnit lineLogicalHeight);
    108107
    109108private:
     
    112111
    113112    LayoutUnit logicalWidth() const { return m_lineLogicalWidth; }
    114     LayoutUnit logicalHeight() const { return m_logicalHeight.height + m_logicalHeight.depth; }
     113    LayoutUnit logicalHeight() const { return m_contentLogicalHeight; }
    115114
    116115    LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
     116    LayoutUnit baselineAlignedContentHeight() const { return m_baseline.ascent + m_baseline.descent; }
     117    LayoutUnit baselineOffset() const { return m_baseline.offset; }
    117118
    118119    void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
     
    129130    LayoutUnit m_contentLogicalWidth;
    130131
    131     UsedHeightAndDepth m_logicalHeight;
     132    LineBox::Baseline m_baseline;
     133    LayoutUnit m_contentLogicalHeight;
    132134    LayoutUnit m_lineLogicalWidth;
    133135    bool m_skipVerticalAligment { false };
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h

    r245776 r246234  
    3535class LineBox {
    3636public:
    37     LineBox(Display::Rect);
     37    struct Baseline {
     38        LayoutUnit ascent;
     39        LayoutUnit descent;
     40        LayoutUnit offset; // baseline offset from line logical top. Note that offset does not necessarily equal to ascent.
     41    };
     42    LineBox(Display::Rect, const Baseline&);
    3843   
    3944    LayoutPoint logicalTopLeft() const { return m_rect.topLeft(); }
     
    4752    LayoutUnit logicalHeight() const { return m_rect.height(); }
    4853
     54    Baseline baseline() const { return m_baseline; }
     55
    4956private:
    5057    Display::Rect m_rect;
     58    Baseline m_baseline;
    5159};
    5260
    53 inline LineBox::LineBox(Display::Rect rect)
     61inline LineBox::LineBox(Display::Rect rect, const Baseline& baseline)
    5462    : m_rect(rect)
     63    , m_baseline(baseline)
    5564{
    5665}
Note: See TracChangeset for help on using the changeset viewer.