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

Changeset 276169 in webkit


Ignore:
Timestamp:
Apr 16, 2021, 2:13:11 PM (5 years ago)
Author:
Alan Bujtas
Message:

Remove redundant renderObject in BreakingContext::handleText
https://bugs.webkit.org/show_bug.cgi?id=224682

Reviewed by Darin Adler.

  • rendering/line/BreakingContext.h:

(WebCore::BreakingContext::handleText):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r276167 r276169  
     12021-04-16  Zalan Bujtas  <zalan@apple.com>
     2
     3        Remove redundant renderObject in BreakingContext::handleText
     4        https://bugs.webkit.org/show_bug.cgi?id=224682
     5
     6        Reviewed by Darin Adler.
     7
     8        * rendering/line/BreakingContext.h:
     9        (WebCore::BreakingContext::handleText):
     10
    1112021-04-16  Basuke Suzuki  <basuke.suzuki@sony.com>
    212
  • trunk/Source/WebCore/rendering/line/BreakingContext.h

    r275130 r276169  
    672672        m_appliedStartWidth = false;
    673673
    674     RenderObject& renderObject = *m_current.renderer();
    675     RenderText& renderText = downcast<RenderText>(renderObject);
    676 
    677     bool isSVGText = renderText.isSVGInlineText();
     674    auto& renderer = downcast<RenderText>(*m_current.renderer());
     675    bool isSVGText = renderer.isSVGInlineText();
    678676
    679677    // If we have left a no-wrap inline and entered an autowrap inline while ignoring spaces
    680678    // then we need to mark the start of the autowrap inline as a potential linebreak now.
    681679    if (m_autoWrap && !RenderStyle::autoWrap(m_lastWS) && m_ignoringSpaces)
    682         commitLineBreakAtCurrentWidth(renderText);
    683 
    684     if (renderText.style().hasTextCombine() && is<RenderCombineText>(*m_current.renderer())) {
     680        commitLineBreakAtCurrentWidth(renderer);
     681
     682    if (renderer.style().hasTextCombine() && is<RenderCombineText>(*m_current.renderer())) {
    685683        auto& combineRenderer = downcast<RenderCombineText>(*m_current.renderer());
    686684        combineRenderer.combineTextIfNeeded();
     
    693691    }
    694692
    695     const RenderStyle& style = lineStyle(renderText, m_lineInfo);
     693    const RenderStyle& style = lineStyle(renderer, m_lineInfo);
    696694    const FontCascade& font = style.fontCascade();
    697695    bool isFixedPitch = font.isFixedPitch();
     
    700698    bool canHangPunctuationAtEnd = style.hangingPunctuation().contains(HangingPunctuation::Last);
    701699    bool canHangStopOrCommaAtLineEnd = style.hangingPunctuation().contains(HangingPunctuation::AllowEnd);
    702     int endPunctuationIndex = canHangPunctuationAtEnd && m_collapseWhiteSpace ? renderText.lastCharacterIndexStrippingSpaces() : renderText.text().length() - 1;
     700    int endPunctuationIndex = canHangPunctuationAtEnd && m_collapseWhiteSpace ? renderer.lastCharacterIndexStrippingSpaces() : renderer.text().length() - 1;
    703701    unsigned lastSpace = m_current.offset();
    704702    float wordSpacing = m_currentStyle->fontCascade().wordSpacing();
     
    727725    }
    728726
    729     if (m_renderTextInfo.text != &renderText) {
    730         updateCounterIfNeeded(renderText);
    731         m_renderTextInfo.text = &renderText;
     727    if (m_renderTextInfo.text != &renderer) {
     728        updateCounterIfNeeded(renderer);
     729        m_renderTextInfo.text = &renderer;
    732730        m_renderTextInfo.font = &font;
    733         m_renderTextInfo.layout = font.createLayout(renderText, m_width.currentWidth(), m_collapseWhiteSpace);
    734         m_renderTextInfo.lineBreakIterator.resetStringAndReleaseIterator(renderText.text(), style.computedLocale(), iteratorMode);
     731        m_renderTextInfo.layout = font.createLayout(renderer, m_width.currentWidth(), m_collapseWhiteSpace);
     732        m_renderTextInfo.lineBreakIterator.resetStringAndReleaseIterator(renderer.text(), style.computedLocale(), iteratorMode);
    735733    } else if (m_renderTextInfo.layout && m_renderTextInfo.font != &font) {
    736734        m_renderTextInfo.font = &font;
    737         m_renderTextInfo.layout = font.createLayout(renderText, m_width.currentWidth(), m_collapseWhiteSpace);
     735        m_renderTextInfo.layout = font.createLayout(renderer, m_width.currentWidth(), m_collapseWhiteSpace);
    738736    }
    739737
     
    748746    TextLayout* textLayout = m_renderTextInfo.layout.get();
    749747    WordTrailingSpace wordTrailingSpace(style, !textLayout);
    750     for (; m_current.offset() < renderText.text().length(); m_current.fastIncrementInTextNode()) {
     748    for (; m_current.offset() < renderer.text().length(); m_current.fastIncrementInTextNode()) {
    751749        bool previousCharacterIsSpace = m_currentCharacterIsSpace;
    752750        bool previousCharacterIsWS = m_currentCharacterIsWS;
     
    763761
    764762        if (canHangPunctuationAtStart && m_width.isFirstLine() && !m_width.committedWidth() && !wrapW && !inlineLogicalWidth(m_current.renderer(), true, false)) {
    765             m_width.addUncommittedWidth(-renderText.hangablePunctuationStartWidth(m_current.offset()));
     763            m_width.addUncommittedWidth(-renderer.hangablePunctuationStartWidth(m_current.offset()));
    766764            canHangPunctuationAtStart = false;
    767765        }
    768766       
    769767        if (canHangPunctuationAtEnd && !m_nextObject && (int)m_current.offset() == endPunctuationIndex && !inlineLogicalWidth(m_current.renderer(), false, true)) {
    770             m_width.addUncommittedWidth(-renderText.hangablePunctuationEndWidth(endPunctuationIndex));
     768            m_width.addUncommittedWidth(-renderer.hangablePunctuationEndWidth(endPunctuationIndex));
    771769            canHangPunctuationAtEnd = false;
    772770        }
     
    776774
    777775        if (c == softHyphen && m_autoWrap && !hyphenWidth && style.hyphens() != Hyphens::None) {
    778             hyphenWidth = measureHyphenWidth(renderText, font, &fallbackFonts);
     776            hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
    779777            m_width.addUncommittedWidth(hyphenWidth);
    780778        }
     
    786784        if (canBreakMidWord && !midWordBreak && (!m_currentCharacterIsSpace || m_atStart || style.whiteSpace() != WhiteSpace::PreWrap)) {
    787785            wrapW += charWidth;
    788             bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && U16_IS_TRAIL(renderText.characterAt(m_current.offset() + 1));
    789             charWidth = textWidth(renderText, m_current.offset(), midWordBreakIsBeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitch, m_collapseWhiteSpace, fallbackFonts, textLayout);
     786            bool midWordBreakIsBeforeSurrogatePair = U16_IS_LEAD(c) && U16_IS_TRAIL(renderer.characterAt(m_current.offset() + 1));
     787            charWidth = textWidth(renderer, m_current.offset(), midWordBreakIsBeforeSurrogatePair ? 2 : 1, font, m_width.committedWidth() + wrapW, isFixedPitch, m_collapseWhiteSpace, fallbackFonts, textLayout);
    790788            midWordBreak = m_width.committedWidth() + wrapW + charWidth > m_width.availableWidth();
    791789        }
     
    796794        m_current.setNextBreakablePosition(nextBreakablePosition);
    797795       
    798         if (canHangStopOrCommaAtLineEnd && renderText.isHangableStopOrComma(c) && m_width.fitsOnLine()) {
     796        if (canHangStopOrCommaAtLineEnd && renderer.isHangableStopOrComma(c) && m_width.fitsOnLine()) {
    799797            // We need to see if a measurement that excludes the stop would fit. If so, then we should hang
    800798            // the stop/comma at the end. First measure including the comma.
    801799            m_hangsAtEnd = false;
    802800            float inlineStartWidth = !m_appliedStartWidth ? inlineLogicalWidth(m_current.renderer(), true, false) : 0_lu;
    803             float widthIncludingComma = computeAdditionalBetweenWordsWidth(renderText, textLayout, c, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset() + 1) + inlineStartWidth;
     801            float widthIncludingComma = computeAdditionalBetweenWordsWidth(renderer, textLayout, c, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset() + 1) + inlineStartWidth;
    804802            m_width.addUncommittedWidth(widthIncludingComma);
    805803            if (!m_width.fitsOnLine()) {
    806804                // See if we fit without the comma involved. If we do, then this is a potential hang point.
    807                 float widthWithoutStopOrComma = computeAdditionalBetweenWordsWidth(renderText, textLayout, lastCharacter, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset()) + inlineStartWidth;
     805                float widthWithoutStopOrComma = computeAdditionalBetweenWordsWidth(renderer, textLayout, lastCharacter, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset()) + inlineStartWidth;
    808806                m_width.addUncommittedWidth(widthWithoutStopOrComma - widthIncludingComma);
    809807                if (m_width.fitsOnLine())
     
    831829            }
    832830           
    833             float additionalTempWidth = computeAdditionalBetweenWordsWidth(renderText, textLayout, c, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset());
     831            float additionalTempWidth = computeAdditionalBetweenWordsWidth(renderer, textLayout, c, wordTrailingSpace, fallbackFonts, wordMeasurements, font, isFixedPitch, lastSpace, lastSpaceWordSpacing, wordSpacingForWordMeasurement, m_current.offset());
    834832            m_width.addUncommittedWidth(additionalTempWidth);
    835833           
     
    857855                bool lineWasTooWide = false;
    858856                if (fitsOnLineOrHangsAtEnd() && m_currentCharacterIsWS && m_currentStyle->breakOnlyAfterWhiteSpace() && (!midWordBreak || m_currWS == WhiteSpace::BreakSpaces)) {
    859                     float charWidth = textWidth(renderText, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0);
     857                    float charWidth = textWidth(renderer, m_current.offset(), 1, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout) + (applyWordSpacing ? wordSpacing : 0);
    860858                    // Check if line is too big even without the extra space
    861859                    // at the end of the line. If it is not, do nothing.
     
    866864                        lineWasTooWide = true;
    867865                        if (m_currWS == WhiteSpace::BreakSpaces)
    868                             trailingSpacesHang(m_lineBreak, renderObject, canBreakMidWord, previousCharacterIsSpace);
     866                            trailingSpacesHang(m_lineBreak, renderer, canBreakMidWord, previousCharacterIsSpace);
    869867                        else {
    870                             m_lineBreak.moveTo(renderObject, m_current.offset(), m_current.nextBreakablePosition());
     868                            m_lineBreak.moveTo(renderer, m_current.offset(), m_current.nextBreakablePosition());
    871869                            m_lineBreaker.skipTrailingWhitespace(m_lineBreak, m_lineInfo);
    872870                        }
     
    877875                    // no more content, and a hyphenated single word would end up on a line by itself. This looks
    878876                    // bad so just don't allow it.
    879                     if (canHyphenate && !m_width.fitsOnLine() && (m_nextObject || !renderText.containsOnlyHTMLWhitespace(m_current.offset(), renderText.text().length() - m_current.offset()) || isLineEmpty)) {
    880                         tryHyphenating(renderText, font, style.computedLocale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
     877                    if (canHyphenate && !m_width.fitsOnLine() && (m_nextObject || !renderer.containsOnlyHTMLWhitespace(m_current.offset(), renderer.text().length() - m_current.offset()) || isLineEmpty)) {
     878                        tryHyphenating(renderer, font, style.computedLocale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
    881879                        if (m_lineBreaker.m_hyphenated) {
    882880                            m_atEnd = true;
     
    943941                if (!stoppedIgnoringSpaces && m_current.offset())
    944942                    ensureCharacterGetsLineBox(m_lineWhitespaceCollapsingState, m_current);
    945                 commitLineBreakAtCurrentWidth(renderObject, m_current.offset(), m_current.nextBreakablePosition());
     943                commitLineBreakAtCurrentWidth(renderer, m_current.offset(), m_current.nextBreakablePosition());
    946944                m_lineBreak.increment();
    947945                m_lineInfo.setPreviousLineBrokeCleanly(true);
     
    950948
    951949            if (m_autoWrap && betweenWords) {
    952                 commitLineBreakAtCurrentWidth(renderObject, m_current.offset(), m_current.nextBreakablePosition());
     950                commitLineBreakAtCurrentWidth(renderer, m_current.offset(), m_current.nextBreakablePosition());
    953951                wrapWidthOffset = 0;
    954952                wrapW = wrapWidthOffset;
     
    963961                // Remember this as a breakable position in case
    964962                // adding the end width forces a break.
    965                 m_lineBreak.moveTo(renderObject, m_current.offset(), m_current.nextBreakablePosition());
     963                m_lineBreak.moveTo(renderer, m_current.offset(), m_current.nextBreakablePosition());
    966964                midWordBreak &= canBreakMidWord;
    967965            }
     
    988986            // Measuring the width of complex text character-by-character, rather than measuring it all together,
    989987            // could produce considerably different width values.
    990             if (!renderText.canUseSimpleFontCodePath() && midWordBreak && m_width.fitsOnLine()) {
     988            if (!renderer.canUseSimpleFontCodePath() && midWordBreak && m_width.fitsOnLine()) {
    991989                midWordBreak = false;
    992990                wrapW = wrapWidthOffset + additionalTempWidth;
     
    10021000                m_lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(nullptr, m_current.renderer(), m_current.offset()));
    10031001            }
    1004             if (m_hangsAtEnd && !renderText.isHangableStopOrComma(c))
     1002            if (m_hangsAtEnd && !renderer.isHangableStopOrComma(c))
    10051003                m_hangsAtEnd = false;
    10061004        }
     
    10081006        if (isSVGText && m_current.offset()) {
    10091007            // Force creation of new InlineBoxes for each absolute positioned character (those that start new text chunks).
    1010             if (downcast<RenderSVGInlineText>(renderText).characterStartsNewTextChunk(m_current.offset()))
     1008            if (downcast<RenderSVGInlineText>(renderer).characterStartsNewTextChunk(m_current.offset()))
    10111009                ensureCharacterGetsLineBox(m_lineWhitespaceCollapsingState, m_current);
    10121010        }
     
    10211019                m_startOfIgnoredSpaces.setOffset(m_startOfIgnoredSpaces.offset() - 1);
    10221020                // If there's just a single trailing space start ignoring it now so it collapses away.
    1023                 if (m_current.offset() == renderText.text().length() - 1)
     1021                if (m_current.offset() == renderer.text().length() - 1)
    10241022                    m_lineWhitespaceCollapsingState.startIgnoringSpaces(m_startOfIgnoredSpaces);
    10251023            }
     
    10281026        if (!m_currentCharacterIsWS && previousCharacterIsWS) {
    10291027            if (m_autoWrap && m_currentStyle->breakOnlyAfterWhiteSpace())
    1030                 m_lineBreak.moveTo(renderObject, m_current.offset(), m_current.nextBreakablePosition());
     1028                m_lineBreak.moveTo(renderer, m_current.offset(), m_current.nextBreakablePosition());
    10311029        }
    10321030
     
    10441042    wordMeasurements.grow(wordMeasurements.size() + 1);
    10451043    WordMeasurement& wordMeasurement = wordMeasurements.last();
    1046     wordMeasurement.renderer = &renderText;
     1044    wordMeasurement.renderer = &renderer;
    10471045
    10481046    // IMPORTANT: current.m_pos is > length here!
    1049     float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(renderText, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
     1047    float additionalTempWidth = m_ignoringSpaces ? 0 : textWidth(renderer, lastSpace, m_current.offset() - lastSpace, font, m_width.currentWidth(), isFixedPitch, m_collapseWhiteSpace, wordMeasurement.fallbackFonts, textLayout);
    10501048    wordMeasurement.startOffset = lastSpace;
    10511049    wordMeasurement.endOffset = m_current.offset();
     
    10721070        // bad so just don't allow it.
    10731071        if (canHyphenate && (m_nextObject || isLineEmpty))
    1074             tryHyphenating(renderText, font, style.computedLocale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
     1072            tryHyphenating(renderer, font, style.computedLocale(), consecutiveHyphenatedLines, m_blockStyle.hyphenationLimitLines(), style.hyphenationLimitBefore(), style.hyphenationLimitAfter(), lastSpace, m_current.offset(), m_width.currentWidth() - additionalTempWidth, m_width.availableWidth(), isFixedPitch, m_collapseWhiteSpace, lastSpaceWordSpacing, m_lineBreak, m_current.nextBreakablePosition(), m_lineBreaker.m_hyphenated);
    10751073
    10761074        if (!hyphenated && m_lineBreak.previousInSameNode() == softHyphen && style.hyphens() != Hyphens::None) {
Note: See TracChangeset for help on using the changeset viewer.