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

Changeset 276200 in webkit


Ignore:
Timestamp:
Apr 17, 2021, 6:48:00 AM (5 years ago)
Author:
Alan Bujtas
Message:

[Cleanup] inlineLogicalWidth should take const RenderObject&
https://bugs.webkit.org/show_bug.cgi?id=224700

Reviewed by Antti Koivisto.

  1. inlineLogicalWidth takes const RenderObject& now.
  2. Both previousInFlowSibling and shouldAddBorderPaddingMargin moved to inlineLogicalWidth
  • rendering/line/BreakingContext.h:

(WebCore::inlineLogicalWidth):
(WebCore::BreakingContext::handleOutOfFlowPositioned):
(WebCore::BreakingContext::handleEmptyInline):
(WebCore::BreakingContext::handleReplaced):
(WebCore::BreakingContext::handleText):
(WebCore::shouldAddBorderPaddingMargin): Deleted.
(WebCore::previousInFlowSibling): Deleted.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r276198 r276200  
     12021-04-17  Zalan Bujtas  <zalan@apple.com>
     2
     3        [Cleanup] inlineLogicalWidth should take const RenderObject&
     4        https://bugs.webkit.org/show_bug.cgi?id=224700
     5
     6        Reviewed by Antti Koivisto.
     7
     8        1. inlineLogicalWidth takes const RenderObject& now.
     9        2. Both previousInFlowSibling and shouldAddBorderPaddingMargin moved to inlineLogicalWidth
     10
     11        * rendering/line/BreakingContext.h:
     12        (WebCore::inlineLogicalWidth):
     13        (WebCore::BreakingContext::handleOutOfFlowPositioned):
     14        (WebCore::BreakingContext::handleEmptyInline):
     15        (WebCore::BreakingContext::handleReplaced):
     16        (WebCore::BreakingContext::handleText):
     17        (WebCore::shouldAddBorderPaddingMargin): Deleted.
     18        (WebCore::previousInFlowSibling): Deleted.
     19
    1202021-04-17  Philippe Normand  <pnormand@igalia.com>
    221
  • trunk/Source/WebCore/rendering/line/BreakingContext.h

    r276169 r276200  
    318318}
    319319
    320 inline bool shouldAddBorderPaddingMargin(RenderObject* child)
    321 {
    322     if (!child)
    323         return true;
    324     // When deciding whether we're at the edge of an inline, adjacent collapsed whitespace is the same as no sibling at all.
    325     if (is<RenderText>(*child) && !downcast<RenderText>(*child).text().length())
    326         return true;
     320inline LayoutUnit inlineLogicalWidth(const RenderObject& renderer, bool checkStartEdge = true, bool checkEndEdge = true)
     321{
     322    auto previousInFlowSibling = [] (const auto& renderer) {
     323        auto* previousSibling = renderer.previousSibling();
     324        for (; previousSibling && previousSibling->isOutOfFlowPositioned(); previousSibling = previousSibling->previousSibling()) { }
     325        return previousSibling;
     326    };
     327
     328    auto shouldAddBorderPaddingMargin = [] (const auto& renderer) {
     329        // When deciding whether we're at the edge of an inline, adjacent collapsed whitespace is the same as no sibling at all.
     330        if (is<RenderText>(renderer) && !downcast<RenderText>(renderer).text().length())
     331            return true;
    327332#if ENABLE(CSS_BOX_DECORATION_BREAK)
    328     if (is<RenderLineBreak>(*child) && child->parent()->style().boxDecorationBreak() == BoxDecorationBreak::Clone)
    329         return true;
     333        if (is<RenderLineBreak>(renderer) && renderer.parent()->style().boxDecorationBreak() == BoxDecorationBreak::Clone)
     334            return true;
    330335#endif
    331     return false;
    332 }
    333 
    334 inline RenderObject* previousInFlowSibling(RenderObject* child)
    335 {
    336     do {
    337         child = child->previousSibling();
    338     } while (child && child->isOutOfFlowPositioned());
    339     return child;
    340 }
    341 
    342 inline LayoutUnit inlineLogicalWidth(RenderObject* child, bool checkStartEdge = true, bool checkEndEdge = true)
    343 {
     336        return false;
     337    };
     338
    344339    unsigned lineDepth = 1;
    345     LayoutUnit extraWidth;
    346     RenderElement* parent = child->parent();
     340    auto extraWidth = LayoutUnit { };
     341    auto* parent = renderer.parent();
     342    auto* child = &renderer;
    347343    while (is<RenderInline>(*parent) && lineDepth++ < cMaxLineDepth) {
    348344        const auto& parentAsRenderInline = downcast<RenderInline>(*parent);
    349345        if (!isEmptyInline(parentAsRenderInline)) {
    350             checkStartEdge = checkStartEdge && shouldAddBorderPaddingMargin(previousInFlowSibling(child));
     346            auto* previousSibling = previousInFlowSibling(*child);
     347            checkStartEdge = checkStartEdge && (!previousSibling || shouldAddBorderPaddingMargin(*previousSibling));
    351348            if (checkStartEdge)
    352349                extraWidth += borderPaddingMarginStart(parentAsRenderInline);
    353             checkEndEdge = checkEndEdge && shouldAddBorderPaddingMargin(child->nextSibling());
     350            auto* nextSibling = child->nextSibling();
     351            checkEndEdge = checkEndEdge && (!nextSibling || shouldAddBorderPaddingMargin(*nextSibling));
    354352            if (checkEndEdge)
    355353                extraWidth += borderPaddingMarginEnd(parentAsRenderInline);
     
    359357        child = parent;
    360358        parent = child->parent();
     359        ASSERT(parent);
    361360    }
    362361    return extraWidth;
     
    384383        positionedObjects.append(&box);
    385384
    386     m_width.addUncommittedWidth(inlineLogicalWidth(&box));
     385    m_width.addUncommittedWidth(inlineLogicalWidth(box));
    387386    // Reset prior line break context characters.
    388387    m_renderTextInfo.lineBreakIterator.resetPriorContext();
     
    459458    }
    460459   
    461     float inlineWidth = inlineLogicalWidth(m_current.renderer()) + borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox);
     460    float inlineWidth = inlineLogicalWidth(*m_current.renderer()) + borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox);
    462461    m_width.addUncommittedWidth(inlineWidth);
    463462    if (m_hangsAtEnd && inlineWidth)
     
    493492    // Optimize for a common case. If we can't find whitespace after the list
    494493    // item, then this is all moot.
    495     LayoutUnit replacedLogicalWidth = m_block.logicalWidthForChild(replacedBox) + m_block.marginStartForChild(replacedBox) + m_block.marginEndForChild(replacedBox) + inlineLogicalWidth(&replacedBox);
     494    LayoutUnit replacedLogicalWidth = m_block.logicalWidthForChild(replacedBox) + m_block.marginStartForChild(replacedBox) + m_block.marginEndForChild(replacedBox) + inlineLogicalWidth(replacedBox);
    496495    if (is<RenderListMarker>(replacedBox)) {
    497496        if (m_blockStyle.collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, &replacedBox, m_lineWhitespaceCollapsingState)) {
     
    704703    float wordSpacingForWordMeasurement = 0;
    705704
    706     float wrapWidthOffset = m_width.uncommittedWidth() + inlineLogicalWidth(m_current.renderer(), !m_appliedStartWidth, true);
     705    float wrapWidthOffset = m_width.uncommittedWidth() + inlineLogicalWidth(*m_current.renderer(), !m_appliedStartWidth, true);
    707706    float wrapW = wrapWidthOffset;
    708707    float charWidth = 0;
     
    760759        }
    761760
    762         if (canHangPunctuationAtStart && m_width.isFirstLine() && !m_width.committedWidth() && !wrapW && !inlineLogicalWidth(m_current.renderer(), true, false)) {
     761        if (canHangPunctuationAtStart && m_width.isFirstLine() && !m_width.committedWidth() && !wrapW && !inlineLogicalWidth(*m_current.renderer(), true, false)) {
    763762            m_width.addUncommittedWidth(-renderer.hangablePunctuationStartWidth(m_current.offset()));
    764763            canHangPunctuationAtStart = false;
    765764        }
    766765       
    767         if (canHangPunctuationAtEnd && !m_nextObject && (int)m_current.offset() == endPunctuationIndex && !inlineLogicalWidth(m_current.renderer(), false, true)) {
     766        if (canHangPunctuationAtEnd && !m_nextObject && (int)m_current.offset() == endPunctuationIndex && !inlineLogicalWidth(*m_current.renderer(), false, true)) {
    768767            m_width.addUncommittedWidth(-renderer.hangablePunctuationEndWidth(endPunctuationIndex));
    769768            canHangPunctuationAtEnd = false;
     
    798797            // the stop/comma at the end. First measure including the comma.
    799798            m_hangsAtEnd = false;
    800             float inlineStartWidth = !m_appliedStartWidth ? inlineLogicalWidth(m_current.renderer(), true, false) : 0_lu;
     799            float inlineStartWidth = !m_appliedStartWidth ? inlineLogicalWidth(*m_current.renderer(), true, false) : 0_lu;
    801800            float widthIncludingComma = computeAdditionalBetweenWordsWidth(renderer, textLayout, c, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset() + 1) + inlineStartWidth;
    802801            m_width.addUncommittedWidth(widthIncludingComma);
     
    838837
    839838            if (!m_appliedStartWidth) {
    840                 float inlineStartWidth = inlineLogicalWidth(m_current.renderer(), true, false);
     839                float inlineStartWidth = inlineLogicalWidth(*m_current.renderer(), true, false);
    841840                m_width.addUncommittedWidth(inlineStartWidth);
    842841                m_appliedStartWidth = true;
     
    10511050    additionalTempWidth += lastSpaceWordSpacing;
    10521051
    1053     float inlineLogicalTempWidth = inlineLogicalWidth(m_current.renderer(), !m_appliedStartWidth, m_includeEndWidth);
     1052    float inlineLogicalTempWidth = inlineLogicalWidth(*m_current.renderer(), !m_appliedStartWidth, m_includeEndWidth);
    10541053    m_width.addUncommittedWidth(additionalTempWidth + inlineLogicalTempWidth);
    10551054    if (m_hangsAtEnd && inlineLogicalTempWidth)
Note: See TracChangeset for help on using the changeset viewer.