Changeset 246158 in webkit


Ignore:
Timestamp:
Jun 6, 2019 9:53:29 AM (5 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Move baseline and line height computation to a dedicated function
https://bugs.webkit.org/show_bug.cgi?id=198611
<rdar://problem/51482708>

Reviewed by Antti Koivisto.

This is in preparation for adding vertical aligment.

  • layout/inlineformatting/InlineLine.cpp:

(WebCore::Layout::Line::appendInlineContainerStart):
(WebCore::Layout::Line::appendNonReplacedInlineBox):
(WebCore::Layout::Line::adjustBaselineAndLineHeight):

  • layout/inlineformatting/InlineLine.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246156 r246158  
     12019-06-06  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Move baseline and line height computation to a dedicated function
     4        https://bugs.webkit.org/show_bug.cgi?id=198611
     5        <rdar://problem/51482708>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        This is in preparation for adding vertical aligment.
     10
     11        * layout/inlineformatting/InlineLine.cpp:
     12        (WebCore::Layout::Line::appendInlineContainerStart):
     13        (WebCore::Layout::Line::appendNonReplacedInlineBox):
     14        (WebCore::Layout::Line::adjustBaselineAndLineHeight):
     15        * layout/inlineformatting/InlineLine.h:
     16
    1172019-06-06  Antti Koivisto  <antti@apple.com>
    218
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r246105 r246158  
    122122void Line::appendInlineContainerStart(const InlineItem& inlineItem, InlineItemSize runSize)
    123123{
     124    if (runSize.logicalHeight)
     125        adjustBaselineAndLineHeight(inlineItem, *runSize.logicalHeight);
     126
    124127    auto& layoutBox = inlineItem.layoutBox();
    125     auto& style = layoutBox.style();
    126     auto& fontMetrics = style.fontMetrics();
    127 
    128     auto alignAndAdjustLineHeight = [&] {
    129         LayoutUnit inlineBoxHeight = style.computedLineHeight();
    130 
    131         auto halfLeading = halfLeadingMetrics(fontMetrics, inlineBoxHeight);
    132         if (halfLeading.depth > 0)
    133             m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
    134         if (halfLeading.height > 0)
    135             m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
    136     };
    137 
    138     alignAndAdjustLineHeight();
     128    auto& fontMetrics = layoutBox.style().fontMetrics();
    139129    auto& displayBox = m_layoutState.displayBoxForLayoutBox(layoutBox);
     130
    140131    auto logicalTop = -fontMetrics.ascent() - displayBox.borderTop() - displayBox.paddingTop().valueOr(0);
    141132    auto logicalRect = Display::Rect { logicalTop, contentLogicalRight(), runSize.logicalWidth, runSize.logicalHeight.valueOr(0) };
     
    192183void Line::appendNonReplacedInlineBox(const InlineItem& inlineItem, InlineItemSize runSize)
    193184{
     185    if (runSize.logicalHeight)
     186        adjustBaselineAndLineHeight(inlineItem, *runSize.logicalHeight);
     187
    194188    auto inlineBoxHeight = runSize.logicalHeight.valueOr(0);
    195     auto alignAndAdjustLineHeight = [&] {
    196         // FIXME: We need to look inside the inline-block's formatting context and check the lineboxes (if any) to be able to baseline align.
    197         if (inlineItem.layoutBox().establishesInlineFormattingContext()) {
    198             if (inlineBoxHeight == logicalHeight())
    199                 return;
    200             // FIXME: This fails when the line height difference comes from font-size diff.
    201             m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
    202             m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);
    203             return;
    204         }
    205         // 0 descent -> baseline aligment for now.
    206         m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
    207         m_logicalHeight.height = std::max(inlineBoxHeight, m_logicalHeight.height);
    208     };
    209 
    210     alignAndAdjustLineHeight();
    211189    auto& displayBox = m_layoutState.displayBoxForLayoutBox(inlineItem.layoutBox());
    212190    auto logicalTop = -inlineBoxHeight;
     
    230208    auto logicalRect = Display::Rect { -ascent, contentLogicalRight(), { }, logicalHeight() };
    231209    m_content->runs().append(std::make_unique<Content::Run>(Display::Run { logicalRect }, inlineItem, false, false));
     210}
     211
     212void Line::adjustBaselineAndLineHeight(const InlineItem& inlineItem, LayoutUnit runHeight)
     213{
     214    ASSERT(!inlineItem.isContainerEnd() && !inlineItem.isText());
     215    auto& layoutBox = inlineItem.layoutBox();
     216    auto& style = layoutBox.style();
     217
     218    if (inlineItem.isContainerStart()) {
     219        auto& fontMetrics = style.fontMetrics();
     220        auto halfLeading = halfLeadingMetrics(fontMetrics, style.computedLineHeight());
     221        if (halfLeading.depth > 0)
     222            m_logicalHeight.depth = std::max(m_logicalHeight.depth, halfLeading.depth);
     223        if (halfLeading.height > 0)
     224            m_logicalHeight.height = std::max(m_logicalHeight.height, halfLeading.height);
     225        return;
     226    }
     227    // Replaced and non-replaced inline level box.
     228    // FIXME: We need to look inside the inline-block's formatting context and check the lineboxes (if any) to be able to baseline align.
     229    if (layoutBox.establishesInlineFormattingContext()) {
     230        if (runHeight == logicalHeight())
     231            return;
     232        // FIXME: This fails when the line height difference comes from font-size diff.
     233        m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
     234        m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
     235        return;
     236    }
     237    // 0 descent -> baseline aligment for now.
     238    m_logicalHeight.depth = std::max<LayoutUnit>(0, m_logicalHeight.depth);
     239    m_logicalHeight.height = std::max(runHeight, m_logicalHeight.height);
    232240}
    233241
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r246105 r246158  
    117117    void removeTrailingTrimmableContent();
    118118
     119    void adjustBaselineAndLineHeight(const InlineItem&, LayoutUnit runHeight);
     120
    119121    const LayoutState& m_layoutState;
    120122    std::unique_ptr<Content> m_content;
Note: See TracChangeset for help on using the changeset viewer.