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

Changeset 246484 in webkit


Ignore:
Timestamp:
Jun 16, 2019, 1:41:59 PM (7 years ago)
Author:
Alan Bujtas
Message:

[LFC][IFC] Decouple baseline ascent/descent and baseline offset.
https://bugs.webkit.org/show_bug.cgi?id=198901
<rdar://problem/51782393>

Reviewed by Antti Koivisto.

Baseline offset is the baseline's distance from the line's logical top -and it is not necessarily the same as the baseline's ascent.
It's easier to track the baseline and its top separately since certain properties only change one or the other.

  • 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::baselineOffset const):
(WebCore::Layout::Line::Content::setBaselineOffset):
(WebCore::Layout::Line::baselineOffset const):

  • layout/inlineformatting/InlineLineBox.h:

(WebCore::Layout::LineBox::baselineOffset const):
(WebCore::Layout::LineBox::LineBox):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r246483 r246484  
     12019-06-16  Zalan Bujtas  <zalan@apple.com>
     2
     3        [LFC][IFC] Decouple baseline ascent/descent and baseline offset.
     4        https://bugs.webkit.org/show_bug.cgi?id=198901
     5        <rdar://problem/51782393>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Baseline offset is the baseline's distance from the line's logical top -and it is not necessarily the same as the baseline's ascent.
     10        It's easier to track the baseline and its top separately since certain properties only change one or the other.
     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::baselineOffset const):
     22        (WebCore::Layout::Line::Content::setBaselineOffset):
     23        (WebCore::Layout::Line::baselineOffset const):
     24        * layout/inlineformatting/InlineLineBox.h:
     25        (WebCore::Layout::LineBox::baselineOffset const):
     26        (WebCore::Layout::LineBox::LineBox):
     27
    1282019-06-16  Zalan Bujtas  <zalan@apple.com>
    229
  • trunk/Source/WebCore/layout/inlineformatting/InlineFormattingContextLineLayout.cpp

    r246483 r246484  
    131131    if (lineInput.skipVerticalAligment == LineInput::SkipVerticalAligment::No) {
    132132        auto mimimumLineHeight = m_formattingRoot.style().computedLineHeight();
    133         auto initialBaselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).offset;
     133        auto initialBaselineOffset = Line::halfLeadingMetrics(m_formattingRoot.style().fontMetrics(), mimimumLineHeight).ascent;
    134134        line = std::make_unique<Line>(layoutState(), lineInput.horizontalConstraint.logicalTopLeft, lineInput.horizontalConstraint.availableLogicalWidth, mimimumLineHeight, initialBaselineOffset);
    135135    } else
     
    316316        // Spec tells us to create a zero height, empty line box.
    317317        auto lineBox = Display::Rect { lineContent.logicalTop(), lineContent.logicalLeft(), 0 , 0 };
    318         m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
     318        m_formattingState.addLineBox({ lineBox, lineContent.baseline(), lineContent.baselineOffset() });
    319319        return;
    320320    }
     
    407407    }
    408408    // FIXME linebox needs to be ajusted after content alignment.
    409     m_formattingState.addLineBox({ lineBox, lineContent.baseline() });
     409    m_formattingState.addLineBox({ lineBox, lineContent.baseline(), lineContent.baselineOffset() });
    410410    alignRuns(m_formattingRoot.style().textAlign(), previousLineLastRunIndex.valueOr(-1) + 1, widthConstraint - lineContent.logicalWidth());
    411411}
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.cpp

    r246481 r246484  
    5858    , m_content(std::make_unique<Line::Content>())
    5959    , m_logicalTopLeft(topLeft)
    60     , m_baseline({ baselineOffset, minimumHeight - baselineOffset, { } })
     60    , m_baseline({ baselineOffset, minimumHeight - baselineOffset })
    6161    , m_contentLogicalHeight(minimumHeight)
    6262    , m_lineLogicalWidth(availableWidth)
     
    9898        if (isVisuallyEmpty()) {
    9999            m_baseline = { };
     100            m_baselineTop = { };
    100101            m_contentLogicalHeight = { };
    101102        }
     
    150151    m_content->setLogicalRect({ logicalTop(), logicalLeft(), contentLogicalWidth(), logicalHeight() });
    151152    m_content->setBaseline(m_baseline);
     153    m_content->setBaselineOffset(baselineOffset());
    152154    return WTFMove(m_content);
    153155}
     
    337339    case VerticalAlign::Bottom:
    338340        if (m_contentLogicalHeight < runHeight) {
    339             m_baseline.offset = m_baseline.offset + (runHeight - m_contentLogicalHeight);
     341            m_baselineTop += runHeight - m_contentLogicalHeight;
    340342            m_contentLogicalHeight = runHeight;
    341343        }
     
    380382    auto adjustedAscent = std::max((ascent + leading / 2).floor(), 0);
    381383    auto adjustedDescent = std::max((descent + leading / 2).ceil(), 0);
    382     return { adjustedAscent, adjustedDescent, adjustedAscent };
     384    return { adjustedAscent, adjustedDescent };
    383385}
    384386
  • trunk/Source/WebCore/layout/inlineformatting/InlineLine.h

    r246478 r246484  
    6969        LayoutUnit logicalHeight() const { return m_logicalRect.height(); }
    7070        LineBox::Baseline baseline() const { return m_baseline; }
     71        LayoutUnit baselineOffset() const { return m_baselineOffset; }
    7172
    7273    private:
     
    7576        void setLogicalRect(const Display::Rect& logicalRect) { m_logicalRect = logicalRect; }
    7677        void setBaseline(LineBox::Baseline baseline) { m_baseline = baseline; }
     78        void setBaselineOffset(LayoutUnit baselineOffset) { m_baselineOffset = baselineOffset; }
    7779        Runs& runs() { return m_runs; }
    7880
    7981        Display::Rect m_logicalRect;
    8082        LineBox::Baseline m_baseline;
     83        LayoutUnit m_baselineOffset;
    8184        Runs m_runs;
    8285    };
     
    113116    LayoutUnit contentLogicalWidth() const { return m_contentLogicalWidth; }
    114117    LayoutUnit baselineAlignedContentHeight() const { return m_baseline.ascent + m_baseline.descent; }
    115     LayoutUnit baselineOffset() const { return m_baseline.offset; }
     118    LayoutUnit baselineOffset() const { return m_baseline.ascent + m_baselineTop; }
    116119
    117120    void appendNonBreakableSpace(const InlineItem&, const Display::Rect& logicalRect);
     
    130133
    131134    LineBox::Baseline m_baseline;
     135    LayoutUnit m_baselineTop;
     136
    132137    LayoutUnit m_contentLogicalHeight;
    133138    LayoutUnit m_lineLogicalWidth;
  • trunk/Source/WebCore/layout/inlineformatting/InlineLineBox.h

    r246234 r246484  
    3838        LayoutUnit ascent;
    3939        LayoutUnit descent;
    40         LayoutUnit offset; // baseline offset from line logical top. Note that offset does not necessarily equal to ascent.
    4140    };
    42     LineBox(Display::Rect, const Baseline&);
     41    LineBox(Display::Rect, const Baseline&, LayoutUnit baselineOffset);
    4342   
    4443    LayoutPoint logicalTopLeft() const { return m_rect.topLeft(); }
     
    5352
    5453    Baseline baseline() const { return m_baseline; }
     54    // Baseline offset from line logical top. Note that offset does not necessarily equal to ascent.
     55    //
     56    // ------------------- line logical top
     57    //             ^
     58    //             |
     59    //   ^         | baseline offset
     60    //   |         |
     61    //   | ascent  |
     62    //   |         |
     63    //   v         v
     64    //   ----------------- baseline
     65    //   ^
     66    //   | descent
     67    //   v
     68    // ------------------- line logical bottom
     69    LayoutUnit baselineOffset() const { return m_baselineOffset; }
    5570
    5671private:
    5772    Display::Rect m_rect;
    5873    Baseline m_baseline;
     74    LayoutUnit m_baselineOffset;
    5975};
    6076
    61 inline LineBox::LineBox(Display::Rect rect, const Baseline& baseline)
     77inline LineBox::LineBox(Display::Rect rect, const Baseline& baseline, LayoutUnit baselineOffset)
    6278    : m_rect(rect)
    6379    , m_baseline(baseline)
     80    , m_baselineOffset(baselineOffset)
    6481{
    6582}
Note: See TracChangeset for help on using the changeset viewer.