Changeset 83640 in webkit
- Timestamp:
- Apr 12, 2011 2:32:58 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r83638 r83640 1 2011-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 1 21 2011-04-12 Yael Aharon <yael.aharon@nokia.com> 2 22 -
trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp
r83638 r83640 1616 1616 } 1617 1617 1618 class LineWidth { 1619 public: 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 1638 private: 1639 float m_uncommittedWidth; 1640 float m_committedWidth; 1641 }; 1642 1618 1643 InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, bool& isLineEmpty, LineBreakIteratorInfo& lineBreakIteratorInfo, bool& previousLineBrokeCleanly, 1619 1644 bool& hyphenated, EClear* clear, FloatingObject* lastFloatFromPreviousLine, Vector<RenderBox*>& positionedBoxes) … … 1628 1653 skipLeadingWhitespace(resolver, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine, lineOffsets); 1629 1654 1630 float width = lineOffsets.width(); 1631 float w = 0; 1632 float tmpW = 0; 1655 float availableWidth = lineOffsets.width(); 1656 LineWidth width; 1633 1657 // The amount by which |width| has been inflated to account for possible contraction due to ruby overhang. 1634 1658 float totalOverhangWidth = 0; … … 1693 1717 1694 1718 if (o->isBR()) { 1695 if (w + tmpW <= width) {1719 if (width.currentWidth() <= availableWidth) { 1696 1720 lBreak.moveToStartOf(o); 1697 1721 lBreak.increment(); … … 1721 1745 // If it does, position it now, otherwise, position 1722 1746 // 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) { 1724 1748 positionNewFloatOnLine(f, lastFloatFromPreviousLine, lineOffsets); 1725 width = lineOffsets.width() + totalOverhangWidth;1749 availableWidth = lineOffsets.width() + totalOverhangWidth; 1726 1750 if (lBreak.m_obj == o) { 1727 1751 ASSERT(!lBreak.m_pos); … … 1784 1808 } 1785 1809 1786 tmpW += borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox);1810 width.addUncommittedWidth(borderPaddingMarginStart(flowBox) + borderPaddingMarginEnd(flowBox)); 1787 1811 } else if (o->isReplaced()) { 1788 1812 RenderBox* replacedBox = toRenderBox(o); … … 1790 1814 // Break on replaced elements if either has normal white-space. 1791 1815 if ((autoWrap || RenderStyle::autoWrap(lastWS)) && (!o->isImage() || allowImagesToBreak)) { 1792 w += tmpW; 1793 tmpW = 0; 1816 width.commit(); 1794 1817 lBreak.moveToStartOf(o); 1795 1818 } … … 1817 1840 } 1818 1841 if (toRenderListMarker(o)->isInside()) 1819 tmpW += replacedLogicalWidth;1842 width.addUncommittedWidth(replacedLogicalWidth); 1820 1843 } else 1821 tmpW += replacedLogicalWidth;1844 width.addUncommittedWidth(replacedLogicalWidth); 1822 1845 if (o->isRubyRun()) { 1823 1846 RenderRubyRun* rubyRun = toRenderRubyRun(o); … … 1825 1848 int endOverhang; 1826 1849 rubyRun->getOverhang(firstLine, last, next, startOverhang, endOverhang); 1827 startOverhang = min<int>(startOverhang, w );1850 startOverhang = min<int>(startOverhang, width.committedWidth()); 1828 1851 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); 1831 1854 totalOverhangWidth += endOverhang; 1832 width += endOverhang;1855 availableWidth += endOverhang; 1833 1856 } 1834 1857 } else if (o->isText()) { … … 1862 1885 float wordTrailingSpaceWidth = f.typesettingFeatures() & Kerning ? f.width(TextRun(&space, 1)) + wordSpacing : 0; 1863 1886 1864 float wrapW = tmpW+ inlineLogicalWidth(o, !appliedStartWidth, true);1887 float wrapW = width.uncommittedWidth() + inlineLogicalWidth(o, !appliedStartWidth, true); 1865 1888 float charWidth = 0; 1866 1889 bool breakNBSP = autoWrap && o->style()->nbspMode() == SPACE; 1867 1890 // Auto-wrapping text should wrap in the middle of a word only if it could not wrap before the word, 1868 1891 // 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); 1870 1893 bool midWordBreak = false; 1871 1894 bool breakAll = o->style()->wordBreak() == BreakAllWordBreak && autoWrap; … … 1873 1896 1874 1897 if (t->isWordBreak()) { 1875 w += tmpW; 1876 tmpW = 0; 1898 width.commit(); 1877 1899 lBreak.moveToStartOf(o); 1878 1900 ASSERT(!len); … … 1891 1913 const AtomicString& hyphenString = style->hyphenString(); 1892 1914 hyphenWidth = f.width(TextRun(hyphenString.characters(), hyphenString.length())); 1893 tmpW += hyphenWidth;1915 width.addUncommittedWidth(hyphenWidth); 1894 1916 } 1895 1917 … … 1900 1922 if ((breakAll || breakWords) && !midWordBreak) { 1901 1923 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; 1904 1926 } 1905 1927 … … 1932 1954 float additionalTmpW; 1933 1955 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; 1935 1957 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); 1938 1960 if (!appliedStartWidth) { 1939 tmpW += inlineLogicalWidth(o, true, false);1961 width.addUncommittedWidth(inlineLogicalWidth(o, true, false)); 1940 1962 appliedStartWidth = true; 1941 1963 } … … 1943 1965 applyWordSpacing = wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace; 1944 1966 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); 1947 1969 1948 1970 if (autoWrap || breakWords) { … … 1950 1972 // as candidate width for this line. 1951 1973 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); 1954 1976 // Check if line is too big even without the extra space 1955 1977 // at the end of the line. If it is not, do nothing. … … 1957 1979 // then move the line break to the space and skip all 1958 1980 // additional whitespace. 1959 if (w + tmpW + charWidth > width) {1981 if (width.currentWidth() + charWidth > availableWidth) { 1960 1982 lineWasTooWide = true; 1961 1983 lBreak.moveTo(o, pos, nextBreakable); … … 1963 1985 } 1964 1986 } 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); 1968 1990 if (hyphenated) 1969 1991 goto end; … … 1983 2005 } else { 1984 2006 if (!betweenWords || (midWordBreak && !autoWrap)) 1985 tmpW -= additionalTmpW;2007 width.addUncommittedWidth(-additionalTmpW); 1986 2008 if (hyphenWidth) { 1987 2009 // Subtract the width of the soft hyphen out since we fit on a line. 1988 tmpW -= hyphenWidth;2010 width.addUncommittedWidth(-hyphenWidth); 1989 2011 hyphenWidth = 0; 1990 2012 } … … 2005 2027 2006 2028 if (autoWrap && betweenWords) { 2007 w += tmpW;2029 width.commit(); 2008 2030 wrapW = 0; 2009 tmpW = 0;2010 2031 lBreak.moveTo(o, pos, nextBreakable); 2011 2032 // Auto-wrapping text should not wrap in the middle of a word once it has had an … … 2081 2102 2082 2103 // 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) { 2088 2108 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 2091 2111 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) 2092 2112 hyphenated = true; 2093 2113 2094 2114 if (hyphenated) 2095 2115 goto end; … … 2099 2119 2100 2120 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) 2102 2122 checkForBreak = true; 2103 2123 else if (next && o->isText() && next->isText() && !next->isBR()) { … … 2117 2137 } else if (nextText->isWordBreak()) 2118 2138 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; 2123 2143 } 2124 2144 bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine; 2125 2145 if (canPlaceOnLine && checkForBreak) { 2126 w += tmpW; 2127 tmpW = 0; 2146 width.commit(); 2128 2147 lBreak.moveToStartOf(next); 2129 2148 } … … 2132 2151 } 2133 2152 2134 if (checkForBreak && (w + tmpW > width)) {2153 if (checkForBreak && (width.currentWidth() > availableWidth)) { 2135 2154 // if we have floats, try to get below them. 2136 2155 if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace()) { … … 2139 2158 } 2140 2159 2141 if (w )2160 if (width.committedWidth()) 2142 2161 goto end; 2143 2162 2144 fitBelowFloats( tmpW, totalOverhangWidth, firstLine, width);2163 fitBelowFloats(width.uncommittedWidth(), totalOverhangWidth, firstLine, availableWidth); 2145 2164 2146 2165 // |width| may have been adjusted because we got shoved down past a float (thus 2147 2166 // giving us more room), so we need to retest, and only jump to 2148 2167 // the end label if we still don't fit on the line. -dwh 2149 if (w + tmpW > width)2168 if (width.currentWidth() > availableWidth) 2150 2169 goto end; 2151 2170 } … … 2154 2173 last = o; 2155 2174 if (last->isReplaced() && autoWrap && (!last->isImage() || allowImagesToBreak) && (!last->isListMarker() || toRenderListMarker(last)->isInside())) { 2156 w += tmpW; 2157 tmpW = 0; 2175 width.commit(); 2158 2176 lBreak.moveToStartOf(next); 2159 2177 } … … 2171 2189 atStart = false; 2172 2190 } 2173 2174 2191 2175 if (w + tmpW <= width || lastWS == NOWRAP)2192 if (width.currentWidth() <= availableWidth || lastWS == NOWRAP) 2176 2193 lBreak.clear(); 2177 2194
Note: See TracChangeset
for help on using the changeset viewer.