WebCore:
[WebKit-https.git] / WebCore / rendering / bidi.cpp
index 9acf79d94f4b22641509f7da92ad94f2b28b2375..c9edd5f7dd1acfff5cc9be0c482ffb424f135a33 100644 (file)
@@ -1349,6 +1349,30 @@ static bool shouldSkipWhitespaceAfterStartObject(RenderBlock* block, RenderObjec
     return false;
 }
 
+void RenderBlock::fitBelowFloats(int widthToFit, int& availableWidth)
+{
+    ASSERT(widthToFit > availableWidth);
+
+    int floatBottom;
+    int lastFloatBottom = m_height;
+    int newLineWidth = availableWidth;
+    while (true) {
+        floatBottom = nextFloatBottomBelow(lastFloatBottom);
+        if (!floatBottom)
+            break;
+
+        newLineWidth = lineWidth(floatBottom);
+        lastFloatBottom = floatBottom;
+        if (newLineWidth >= widthToFit)
+            break;
+    }
+
+    if (newLineWidth > availableWidth) {
+        m_height = lastFloatBottom;
+        availableWidth = newLineWidth;
+    }
+}
+
 BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi)
 {
     // eliminate spaces at beginning of line
@@ -1652,24 +1676,9 @@ BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi
                     
                     applyWordSpacing =  wordSpacing && currentCharacterIsSpace && !previousCharacterIsSpace;
 
-                    if (autoWrap && w + tmpW > width && !w) {
-                        int fb = nearestFloatBottom(m_height);
-                        int newLineWidth = lineWidth(fb);
-                        // See if |tmpW| will fit on the new line.  As long as it does not,
-                        // keep adjusting our float bottom until we find some room.
-                        int lastFloatBottom = m_height;
-                        while (lastFloatBottom < fb && tmpW > newLineWidth) {
-                            lastFloatBottom = fb;
-                            fb = nearestFloatBottom(fb);
-                            newLineWidth = lineWidth(fb);
-                        }
-                        
-                        if (!w && m_height < fb && width < newLineWidth) {
-                            m_height = fb;
-                            width = newLineWidth;
-                        }
-                    }
-        
+                    if (!w && autoWrap && tmpW > width)
+                        fitBelowFloats(tmpW, width);
+
                     if (autoWrap || breakWords) {
                         // If we break only after white-space, consider the current character
                         // as candidate width for this line.
@@ -1822,7 +1831,11 @@ BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi
                             checkForBreak = true;
                     } else if (nextText->isWordBreak())
                         checkForBreak = true;
-                    bool willFitOnLine = (w + tmpW <= width);
+                    bool willFitOnLine = w + tmpW <= width;
+                    if (!willFitOnLine && !w) {
+                        fitBelowFloats(tmpW, width);
+                        willFitOnLine = tmpW <= width;
+                    }
                     bool canPlaceOnLine = willFitOnLine || !autoWrapWasEverTrueOnLine;
                     if (canPlaceOnLine && checkForBreak) {
                         w += tmpW;
@@ -1838,21 +1851,11 @@ BidiIterator RenderBlock::findNextLineBreak(BidiIterator &start, BidiState &bidi
             // if we have floats, try to get below them.
             if (currentCharacterIsSpace && !ignoringSpaces && o->style()->collapseWhiteSpace())
                 trailingSpaceObject = 0;
-            
-            int fb = nearestFloatBottom(m_height);
-            int newLineWidth = lineWidth(fb);
-            // See if |tmpW| will fit on the new line.  As long as it does not,
-            // keep adjusting our float bottom until we find some room.
-            int lastFloatBottom = m_height;
-            while (lastFloatBottom < fb && tmpW > newLineWidth) {
-                lastFloatBottom = fb;
-                fb = nearestFloatBottom(fb);
-                newLineWidth = lineWidth(fb);
-            }            
-            if (!w && m_height < fb && width < newLineWidth) {
-                m_height = fb;
-                width = newLineWidth;
-            }
+
+            if (w)
+                goto end;
+
+            fitBelowFloats(tmpW, width);
 
             // |width| may have been adjusted because we got shoved down past a float (thus
             // giving us more room), so we need to retest, and only jump to