2011-04-06 Ryosuke Niwa <rniwa@webkit.org>
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Apr 2011 18:34:11 +0000 (18:34 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 6 Apr 2011 18:34:11 +0000 (18:34 +0000)
        Reviewed by Dimitri Glazkov.

        Bundle lineLeftOffset and lineRightOffset as a class
        https://bugs.webkit.org/show_bug.cgi?id=57851

        Added a new class LineOffsets that encapsulates lineLeftOffset and lineRightOffset.
        The patch makes clear that lineLeftOffset and lineRightOffset are never read individually
        and only the difference is used to compute the width.

        * rendering/RenderBlock.h:
        * rendering/RenderBlockLineLayout.cpp:
        (WebCore::RenderBlock::skipLeadingWhitespace): Takes LineOffsets instead of two integers.
        (WebCore::LineOffsets::LineOffsets): Added.
        (WebCore::LineOffsets::width): Added.
        (WebCore::LineOffsets::setLeft): Added.
        (WebCore::LineOffsets::setRight): Added.
        (WebCore::RenderBlock::findNextLineBreak): Calls skipLeadingWhitespace and positionNewFloatOnLine.
        (WebCore::RenderBlock::positionNewFloatOnLine): Takes LineOffsets instead of two integers.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83076 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlock.h
Source/WebCore/rendering/RenderBlockLineLayout.cpp

index 64f3044b625408cd2676ea65f1079874bed78db6..5371fc9e1057f2c2fdd9da27cf43f14b74fe9cdc 100644 (file)
@@ -1,3 +1,24 @@
+2011-04-06  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Bundle lineLeftOffset and lineRightOffset as a class
+        https://bugs.webkit.org/show_bug.cgi?id=57851
+
+        Added a new class LineOffsets that encapsulates lineLeftOffset and lineRightOffset.
+        The patch makes clear that lineLeftOffset and lineRightOffset are never read individually
+        and only the difference is used to compute the width.
+
+        * rendering/RenderBlock.h:
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::RenderBlock::skipLeadingWhitespace): Takes LineOffsets instead of two integers.
+        (WebCore::LineOffsets::LineOffsets): Added.
+        (WebCore::LineOffsets::width): Added.
+        (WebCore::LineOffsets::setLeft): Added.
+        (WebCore::LineOffsets::setRight): Added.
+        (WebCore::RenderBlock::findNextLineBreak): Calls skipLeadingWhitespace and positionNewFloatOnLine.
+        (WebCore::RenderBlock::positionNewFloatOnLine): Takes LineOffsets instead of two integers.
+
 2011-04-06  David Hyatt  <hyatt@apple.com>
 
         Reviewed by Dan Bernstein.
index 3b1fed0b4a0dd8d0a354b9014de43e7b809e73fd..c8add2fc41dab9cf15699ec3c9e884797460cf43 100644 (file)
@@ -36,6 +36,7 @@ class ColumnInfo;
 class InlineIterator;
 class LayoutStateMaintainer;
 class LazyLineBreakIterator;
+class LineOffsets;
 class RenderInline;
 
 struct BidiRun;
@@ -493,7 +494,7 @@ private:
                         RootInlineBox*& endLine, int& endYPos, int& repaintBottom, int& repaintTop);
 
     void skipTrailingWhitespace(InlineIterator&, bool isLineEmpty, bool previousLineBrokeCleanly);
-    void skipLeadingWhitespace(InlineBidiResolver&, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly, FloatingObject* lastFloatFromPreviousLine, int& lineLeftOffset, int& lineRightOffset);
+    void skipLeadingWhitespace(InlineBidiResolver&, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly, FloatingObject* lastFloatFromPreviousLine, LineOffsets&);
     void fitBelowFloats(float widthToFit, float totalOverhangWidth, bool firstLine, float& availableWidth);
     typedef std::pair<RenderText*, LazyLineBreakIterator> LineBreakIteratorInfo;
     InlineIterator findNextLineBreak(InlineBidiResolver&, bool firstLine, bool& isLineEmpty, LineBreakIteratorInfo&, bool& previousLineBrokeCleanly, bool& hyphenated,
@@ -508,7 +509,7 @@ private:
 
     // Positions new floats and also adjust all floats encountered on the line if any of them
     // have to move to the next page/column.
-    bool positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, bool firstLine, int& lineLeftOffset, int& lineRightOffset);
+    bool positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, bool firstLine, LineOffsets&);
 
     // End of functions defined in RenderBlockLineLayout.cpp.
 
index 7bdde1f4dcbab18a99cce0e900eccadaeb9046f1..d7b535c69994cfc03ab0f23f779d296fdd70b846 100644 (file)
@@ -1456,12 +1456,12 @@ void RenderBlock::skipTrailingWhitespace(InlineIterator& iterator, bool isLineEm
 }
 
 void RenderBlock::skipLeadingWhitespace(InlineBidiResolver& resolver, bool firstLine, bool isLineEmpty, bool previousLineBrokeCleanly,
-                                       FloatingObject* lastFloatFromPreviousLine, int& lineLeftOffset, int& lineRightOffset)
+    FloatingObject* lastFloatFromPreviousLine, LineOffsets& lineOffsets)
 {
     while (!resolver.position().atEnd() && !requiresLineBox(resolver.position(), isLineEmpty, previousLineBrokeCleanly)) {
         RenderObject* object = resolver.position().m_obj;
         if (object->isFloating())
-            positionNewFloatOnLine(insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine, firstLine, lineLeftOffset, lineRightOffset);
+            positionNewFloatOnLine(insertFloatingObject(toRenderBox(object)), lastFloatFromPreviousLine, firstLine, lineOffsets);
         else if (object->isPositioned())
             setStaticPositions(this, toRenderBox(object));
         resolver.increment();
@@ -1562,6 +1562,21 @@ static void tryHyphenating(RenderText* text, const Font& font, const AtomicStrin
     hyphenated = true;
 }
 
+class LineOffsets {
+public:
+    LineOffsets(int leftOffset, int rightOffset)
+    : m_left(leftOffset)
+    , m_right(rightOffset)
+    {
+    }
+    int width() const { return max(0, m_right - m_left); }
+    void setLeft(int left) { m_left = left; }
+    void setRight(int right) { m_right = right; }
+private:
+    int m_left;
+    int m_right;
+};
+
 InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool firstLine, bool& isLineEmpty, LineBreakIteratorInfo& lineBreakIteratorInfo, bool& previousLineBrokeCleanly, 
                                               bool& hyphenated, EClear* clear, FloatingObject* lastFloatFromPreviousLine, Vector<RenderBox*>& positionedBoxes)
 {
@@ -1571,12 +1586,11 @@ InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool
     LineMidpointState& lineMidpointState = resolver.midpointState();
     
     int blockOffset = logicalHeight();
-    int lineLeftOffset = logicalLeftOffsetForLine(blockOffset, firstLine);
-    int lineRightOffset = logicalRightOffsetForLine(blockOffset, firstLine);
-    
-    skipLeadingWhitespace(resolver, firstLine, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine, lineLeftOffset, lineRightOffset);
+    LineOffsets lineOffsets(logicalLeftOffsetForLine(blockOffset, firstLine), logicalRightOffsetForLine(blockOffset, firstLine));
+
+    skipLeadingWhitespace(resolver, firstLine, isLineEmpty, previousLineBrokeCleanly, lastFloatFromPreviousLine, lineOffsets);
 
-    float width = max(0, lineRightOffset - lineLeftOffset);
+    float width = lineOffsets.width();
     float w = 0;
     float tmpW = 0;
     // The amount by which |width| has been inflated to account for possible contraction due to ruby overhang.
@@ -1670,8 +1684,8 @@ InlineIterator RenderBlock::findNextLineBreak(InlineBidiResolver& resolver, bool
                 // If it does, position it now, otherwise, position
                 // it after moving to next line (in newLine() func)
                 if (floatsFitOnLine && logicalWidthForFloat(f) + w + tmpW <= width) {
-                    positionNewFloatOnLine(f, lastFloatFromPreviousLine, firstLine, lineLeftOffset, lineRightOffset);
-                    width = max(0, lineRightOffset - lineLeftOffset) + totalOverhangWidth;
+                    positionNewFloatOnLine(f, lastFloatFromPreviousLine, firstLine, lineOffsets);
+                    width = lineOffsets.width() + totalOverhangWidth;
                     if (lBreak.m_obj == o) {
                         ASSERT(!lBreak.m_pos);
                         lBreak.increment();
@@ -2257,7 +2271,7 @@ void RenderBlock::checkLinesForTextOverflow()
     }
 }
 
-bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, bool firstLine, int& lineLeftOffset, int& lineRightOffset)
+bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObject* lastFloatFromPreviousLine, bool firstLine, LineOffsets& lineOffsets)
 {
     bool didPosition = positionNewFloats();
     if (!didPosition)
@@ -2266,9 +2280,9 @@ bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObjec
     int blockOffset = logicalHeight();
     if (blockOffset >= logicalTopForFloat(newFloat) && blockOffset < logicalBottomForFloat(newFloat)) {
         if (newFloat->type() == FloatingObject::FloatLeft)
-            lineLeftOffset = logicalRightForFloat(newFloat);
+            lineOffsets.setLeft(logicalRightForFloat(newFloat));
         else
-            lineRightOffset = logicalLeftForFloat(newFloat);
+            lineOffsets.setRight(logicalLeftForFloat(newFloat));
     }
 
     if (!newFloat->m_paginationStrut)
@@ -2304,8 +2318,8 @@ bool RenderBlock::positionNewFloatOnLine(FloatingObject* newFloat, FloatingObjec
     }
 
     setLogicalHeight(blockOffset + paginationStrut);
-    lineLeftOffset = logicalLeftOffsetForLine(logicalHeight(), firstLine);
-    lineRightOffset = logicalRightOffsetForLine(logicalHeight(), firstLine);
+    lineOffsets.setLeft(logicalLeftOffsetForLine(logicalHeight(), firstLine));
+    lineOffsets.setRight(logicalRightOffsetForLine(logicalHeight(), firstLine));
 
     return didPosition;
 }