Changeset 83640 in webkit


Ignore:
Timestamp:
Apr 12, 2011 2:32:58 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

2011-04-12 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by David Hyatt.

Bundle w and tmpW in findNextLineBreak together as a class
https://bugs.webkit.org/show_bug.cgi?id=58362

Renamed w, tempW, and width in findNextLineBreak to committedWidth, uncommittedWidth,
and availableWidth respectively. Also bundled committedWidth and uncommittedWith as a class
named LineWidth.

  • rendering/RenderBlockLineLayout.cpp: (WebCore::LineWidth::LineWidth): Added. (WebCore::LineWidth::currentWidth): Added; returns the sum of committed and uncommitted width. (WebCore::LineWidth::uncommittedWidth): Added. (WebCore::LineWidth::committedWidth): Added. (WebCore::LineWidth::addUncommittedWidth): Added; adds the specified width to the uncommitted width. (WebCore::LineWidth::commit): Added; commits the current width and clears the uncommitted width. (WebCore::RenderBlock::findNextLineBreak): Uses LineWidth.
Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83638 r83640  
     12011-04-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by David Hyatt.
     4
     5        Bundle w and tmpW in findNextLineBreak together as a class
     6        https://bugs.webkit.org/show_bug.cgi?id=58362
     7
     8        Renamed w, tempW, and width in findNextLineBreak to committedWidth, uncommittedWidth,
     9        and availableWidth respectively. Also bundled committedWidth and uncommittedWith as a class
     10        named LineWidth.
     11
     12        * rendering/RenderBlockLineLayout.cpp:
     13        (WebCore::LineWidth::LineWidth): Added.
     14        (WebCore::LineWidth::currentWidth): Added; returns the sum of committed and uncommitted width.
     15        (WebCore::LineWidth::uncommittedWidth): Added.
     16        (WebCore::LineWidth::committedWidth): Added.
     17        (WebCore::LineWidth::addUncommittedWidth): Added; adds the specified width to the uncommitted width.
     18        (WebCore::LineWidth::commit): Added; commits the current width and clears the uncommitted width.
     19        (WebCore::RenderBlock::findNextLineBreak): Uses LineWidth.
     20
    1212011-04-12  Yael Aharon  <yael.aharon@nokia.com>
    222
  • trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp

    r83638 r83640  
    16161616}
    16171617
     1618class LineWidth {
     1619public:
     1620    LineWidth()
     1621        : m_uncommittedWidth(0)
     1622        , m_committedWidth(0)
     1623    {
     1624    }
     1625    float currentWidth() const { return m_committedWidth + m_uncommittedWidth; }
     1626
     1627    // FIXME: We should eventually replace these two functions by ones that work on a higher abstraction.
     1628    float uncommittedWidth() const { return m_uncommittedWidth; }
     1629    float committedWidth() const { return m_committedWidth; }
     1630
     1631    void addUncommittedWidth(float delta) { m_uncommittedWidth += delta; }
     1632    void commit()
     1633    {
     1634        m_committedWidth += m_uncommittedWidth;
     1635        m_uncommittedWidth = 0;
     1636    }
     1637
     1638private:
     1639    float m_uncommittedWidth;
     1640    float m_committedWidth;
     1641};
     1642
    16181643InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, bool& isLineEmpty, LineBreakIteratorInfo& lineBreakIteratorInfo, bool& previousLineBrokeCleanly,
    16191644                                              bool& hyphenated, EClear* clear, FloatingObject* lastFloatFromPreviousLine, Vector<RenderBox*>& positionedBoxes)
     
    16281653    skipLeadingWhitespace(resolver, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine, lineOffsets);
    16291654
    1630     float width = lineOffsets.width();
    1631     float w = 0;
    1632     float tmpW = 0;
     1655    float availableWidth = lineOffsets.width();
     1656    LineWidth width;
    16331657    // The amount by which |width| has been inflated to account for possible contraction due to ruby overhang.
    16341658    float totalOverhangWidth = 0;
     
    16931717           
    16941718        if (o->isBR()) {
    1695             if (w + tmpW <= width) {
     1719            if (width.currentWidth() <= availableWidth) {
    16961720                lBreak.moveToStartOf(o);
    16971721                lBreak.increment();
     
    17211745                // If it does, position it now, otherwise, position
    17221746                // it after moving to next line (in newLine() func)
    1723                 if (floatsFitOnLine && logicalWidthForFloat(f) + w + tmpW <= width) {
     1747                if (floatsFitOnLine && logicalWidthForFloat(f) + width.currentWidth() <= availableWidth) {
    17241748                    positionNewFloatOnLine(f, lastFloatFromPreviousLine, lineOffsets);
    1725                     width = lineOffsets.width() + totalOverhangWidth;
     1749                    availableWidth = lineOffsets.width() + totalOverhangWidth;
    17261750                    if (lBreak.m_obj == o) {
    17271751                        ASSERT(!lBreak.m_pos);
     
    17841808            }
    17851809
    1786             tmpW += borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox);
     1810            width.addUncommittedWidth(borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox));
    17871811        } else if (o->isReplaced()) {
    17881812            RenderBox* replacedBox = toRenderBox(o);
     
    17901814            // Break on replaced elements if either has normal white-space.
    17911815            if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!o->isImage() || allowImagesToBreak)) {
    1792                 w += tmpW;
    1793                 tmpW = 0;
     1816                width.commit();
    17941817                lBreak.moveToStartOf(o);
    17951818            }
     
    18171840                }
    18181841                if (toRenderListMarker(o)->isInside())
    1819                     tmpW += replacedLogicalWidth;
     1842                    width.addUncommittedWidth(replacedLogicalWidth);
    18201843            } else
    1821                 tmpW += replacedLogicalWidth;
     1844                width.addUncommittedWidth(replacedLogicalWidth);
    18221845            if (o->isRubyRun()) {
    18231846                RenderRubyRun* rubyRun = toRenderRubyRun(o);
     
    18251848                int endOverhang;
    18261849                rubyRun->getOverhang(firstLine, last, next, startOverhang, endOverhang);
    1827                 startOverhang = min<int>(startOverhang, w);
     1850                startOverhang = min<int>(startOverhang, width.committedWidth());
    18281851                totalOverhangWidth += startOverhang;
    1829                 width += startOverhang;
    1830                 endOverhang = max(min<int>(endOverhang, width - (w + tmpW)), 0);
     1852                availableWidth += startOverhang;
     1853                endOverhang = max(min<int>(endOverhang, availableWidth - width.currentWidth()), 0);
    18311854                totalOverhangWidth += endOverhang;
    1832                 width += endOverhang;
     1855                availableWidth += endOverhang;
    18331856            }
    18341857        } else if (o->isText()) {
     
    18621885            float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(TextRun(&space, 1)) + wordSpacing : 0;
    18631886
    1864             float wrapW = tmpW + inlineLogicalWidth(o, !appliedStartWidth, true);
     1887            float wrapW = width.uncommittedWidth() + inlineLogicalWidth(o, !appliedStartWidth, true);
    18651888            float charWidth = 0;
    18661889            bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE;
    18671890            // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word,
    18681891            // which is only possible if the word is the first thing on the line, that is, if |w| is zero.
    1869             bool breakWords = o->style()->breakWords() && ((autoWrap && !w) || currWS == PRE);
     1892            bool breakWords = o->style()->breakWords() && ((autoWrap && !width.committedWidth()) || currWS == PRE);
    18701893            bool midWordBreak = false;
    18711894            bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap;
     
    18731896
    18741897            if (t->isWordBreak()) {
    1875                 w += tmpW;
    1876                 tmpW = 0;
     1898                width.commit();
    18771899                lBreak.moveToStartOf(o);
    18781900                ASSERT(!len);
     
    18911913                    const AtomicString& hyphenString = style->hyphenString();
    18921914                    hyphenWidth = f.width(TextRun(hyphenString.characters(), hyphenString.length()));
    1893                     tmpW += hyphenWidth;
     1915                    width.addUncommittedWidth(hyphenWidth);
    18941916                }
    18951917
     
    19001922                if ((breakAll || breakWords) && !midWordBreak) {
    19011923                    wrapW += charWidth;
    1902                     charWidth = textWidth(t, pos, 1, f, w + wrapW, isFixedPitch, collapseWhiteSpace);
    1903                     midWordBreak = w + wrapW + charWidth > width;
     1924                    charWidth = textWidth(t, pos, 1, f, width.committedWidth() + wrapW, isFixedPitch, collapseWhiteSpace);
     1925                    midWordBreak = width.committedWidth() + wrapW + charWidth > availableWidth;
    19041926                }
    19051927
     
    19321954                    float additionalTmpW;
    19331955                    if (wordTrailingSpaceWidth && currentCharacterIsSpace)
    1934                         additionalTmpW = textWidth(t, lastSpace, pos + 1 - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) - wordTrailingSpaceWidth + lastSpaceWordSpacing;
     1956                        additionalTmpW = textWidth(t, lastSpace, pos + 1 - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) - wordTrailingSpaceWidth + lastSpaceWordSpacing;
    19351957                    else
    1936                         additionalTmpW = textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
    1937                     tmpW += additionalTmpW;
     1958                        additionalTmpW = textWidth(t, lastSpace, pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
     1959                    width.addUncommittedWidth(additionalTmpW);
    19381960                    if (!appliedStartWidth) {
    1939                         tmpW += inlineLogicalWidth(o, true, false);
     1961                        width.addUncommittedWidth(inlineLogicalWidth(o, true, false));
    19401962                        appliedStartWidth = true;
    19411963                    }
     
    19431965                    applyWordSpacing =  wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace;
    19441966
    1945                     if (!w && autoWrap && tmpW > width)
    1946                         fitBelowFloats(tmpW, totalOverhangWidth, firstLine, width);
     1967                    if (!width.committedWidth() && autoWrap && width.uncommittedWidth() > availableWidth)
     1968                        fitBelowFloats(width.uncommittedWidth(), totalOverhangWidth, firstLine, availableWidth);
    19471969
    19481970                    if (autoWrap || breakWords) {
     
    19501972                        // as candidate width for this line.
    19511973                        bool lineWasTooWide = false;
    1952                         if (w + tmpW <= width && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
    1953                             int charWidth = textWidth(t, pos, 1, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0);
     1974                        if (width.currentWidth() <= availableWidth && currentCharacterIsWS && o->style()->breakOnlyAfterWhiteSpace() && !midWordBreak) {
     1975                            int charWidth = textWidth(t, pos, 1, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + (applyWordSpacing ? wordSpacing : 0);
    19541976                            // Check if line is too big even without the extra space
    19551977                            // at the end of the line. If it is not, do nothing.
     
    19571979                            // then move the line break to the space and skip all
    19581980                            // additional whitespace.
    1959                             if (w + tmpW + charWidth > width) {
     1981                            if (width.currentWidth() + charWidth > availableWidth) {
    19601982                                lineWasTooWide = true;
    19611983                                lBreak.moveTo(o, pos, nextBreakable);
     
    19631985                            }
    19641986                        }
    1965                         if (lineWasTooWide || w + tmpW > width) {
    1966                             if (canHyphenate && w + tmpW > width) {
    1967                                 tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
     1987                        if (lineWasTooWide || width.currentWidth() > availableWidth) {
     1988                            if (canHyphenate && width.currentWidth() > availableWidth) {
     1989                                tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, width.currentWidth() - additionalTmpW, availableWidth, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
    19681990                                if (hyphenated)
    19691991                                    goto end;
     
    19832005                        } else {
    19842006                            if (!betweenWords || (midWordBreak && !autoWrap))
    1985                                 tmpW -= additionalTmpW;
     2007                                width.addUncommittedWidth(-additionalTmpW);
    19862008                            if (hyphenWidth) {
    19872009                                // Subtract the width of the soft hyphen out since we fit on a line.
    1988                                 tmpW -= hyphenWidth;
     2010                                width.addUncommittedWidth(-hyphenWidth);
    19892011                                hyphenWidth = 0;
    19902012                            }
     
    20052027
    20062028                    if (autoWrap && betweenWords) {
    2007                         w += tmpW;
     2029                        width.commit();
    20082030                        wrapW = 0;
    2009                         tmpW = 0;
    20102031                        lBreak.moveTo(o, pos, nextBreakable);
    20112032                        // Auto-wrapping text should not wrap in the middle of a word once it has had an
     
    20812102
    20822103            // IMPORTANT: pos is > length here!
    2083             float additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, pos - lastSpace, f, w + tmpW, isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
    2084             tmpW += additionalTmpW;
    2085             tmpW += inlineLogicalWidth(o, !appliedStartWidth, true);
    2086 
    2087             if (w + tmpW > width) {
     2104            float additionalTmpW = ignoringSpaces ? 0 : textWidth(t, lastSpace, pos - lastSpace, f, width.currentWidth(), isFixedPitch, collapseWhiteSpace) + lastSpaceWordSpacing;
     2105            width.addUncommittedWidth(additionalTmpW + inlineLogicalWidth(o, !appliedStartWidth, true));
     2106
     2107            if (width.currentWidth() > availableWidth) {
    20882108                if (canHyphenate)
    2089                     tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, w + tmpW - additionalTmpW, width, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
    2090                
     2109                    tryHyphenating(t, f, style->locale(), style->hyphenationLimitBefore(), style->hyphenationLimitAfter(), lastSpace, pos, width.currentWidth() - additionalTmpW, availableWidth, isFixedPitch, collapseWhiteSpace, lastSpaceWordSpacing, lBreak, nextBreakable, hyphenated);
     2110
    20912111                if (!hyphenated && lBreak.m_obj && lBreak.m_pos && lBreak.m_obj->isText() && toRenderText(lBreak.m_obj)->textLength() && toRenderText(lBreak.m_obj)->characters()[lBreak.m_pos - 1] == softHyphen && style->hyphens() != HyphensNone)
    20922112                    hyphenated = true;
    2093                
     2113
    20942114                if (hyphenated)
    20952115                    goto end;
     
    20992119
    21002120        bool checkForBreak = autoWrap;
    2101         if (w && w + tmpW > width && lBreak.m_obj && currWS == NOWRAP)
     2121        if (width.committedWidth() && width.currentWidth() > availableWidth && lBreak.m_obj && currWS == NOWRAP)
    21022122            checkForBreak = true;
    21032123        else if (next && o->isText() && next->isText() && !next->isBR()) {
     
    21172137                    } else if (nextText->isWordBreak())
    21182138                        checkForBreak = true;
    2119                     bool willFitOnLine = w + tmpW <= width;
    2120                     if (!willFitOnLine && !w) {
    2121                         fitBelowFloats(tmpW, totalOverhangWidth, firstLine, width);
    2122                         willFitOnLine = tmpW <= width;
     2139                    bool willFitOnLine = width.currentWidth() <= availableWidth;
     2140                    if (!willFitOnLine && !width.committedWidth()) {
     2141                        fitBelowFloats(width.uncommittedWidth(), totalOverhangWidth, firstLine, availableWidth);
     2142                        willFitOnLine = width.uncommittedWidth() <= availableWidth;
    21232143                    }
    21242144                    bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine;
    21252145                    if (canPlaceOnLine && checkForBreak) {
    2126                         w += tmpW;
    2127                         tmpW = 0;
     2146                        width.commit();
    21282147                        lBreak.moveToStartOf(next);
    21292148                    }
     
    21322151        }
    21332152
    2134         if (checkForBreak && (w + tmpW > width)) {
     2153        if (checkForBreak && (width.currentWidth() > availableWidth)) {
    21352154            // if we have floats, try to get below them.
    21362155            if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace()) {
     
    21392158            }
    21402159
    2141             if (w)
     2160            if (width.committedWidth())
    21422161                goto end;
    21432162
    2144             fitBelowFloats(tmpW, totalOverhangWidth, firstLine, width);
     2163            fitBelowFloats(width.uncommittedWidth(), totalOverhangWidth, firstLine, availableWidth);
    21452164
    21462165            // |width| may have been adjusted because we got shoved down past a float (thus
    21472166            // giving us more room), so we need to retest, and only jump to
    21482167            // the end label if we still don't fit on the line. -dwh
    2149             if (w + tmpW > width)
     2168            if (width.currentWidth() > availableWidth)
    21502169                goto end;
    21512170        }
     
    21542173            last = o;
    21552174            if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) {
    2156                 w += tmpW;
    2157                 tmpW = 0;
     2175                width.commit();
    21582176                lBreak.moveToStartOf(next);
    21592177            }
     
    21712189        atStart = false;
    21722190    }
    2173 
    21742191   
    2175     if (w + tmpW <= width || lastWS == NOWRAP)
     2192    if (width.currentWidth() <= availableWidth || lastWS == NOWRAP)
    21762193        lBreak.clear();
    21772194
Note: See TracChangeset for help on using the changeset viewer.