Refactor paint overflow clipping
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Sep 2012 17:22:21 +0000 (17:22 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Sep 2012 17:22:21 +0000 (17:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=96625

Patch by Sami Kyostila <skyostil@chromium.org> on 2012-09-13
Reviewed by Simon Fraser.

The same logic for applying overflow clipping based on the cached size of a
RenderBox has been duplicated to four different places. Consolidate them to a
single RenderBox utility function.

This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=96087.

No new functionality; covered by existing tests.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::applyCachedClipAndScrollOffsetForRepaint):
(WebCore):
(WebCore::RenderBox::computeRectForRepaint):
* rendering/RenderBox.h:
(RenderBox):
* rendering/RenderInline.cpp:
(WebCore::RenderInline::clippedOverflowRectForRepaint):
(WebCore::RenderInline::computeRectForRepaint):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::computeRectForRepaint):

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h
Source/WebCore/rendering/RenderInline.cpp
Source/WebCore/rendering/RenderObject.cpp

index e49ec55..60f7af5 100644 (file)
@@ -1,3 +1,30 @@
+2012-09-13  Sami Kyostila  <skyostil@chromium.org>
+
+        Refactor paint overflow clipping
+        https://bugs.webkit.org/show_bug.cgi?id=96625
+
+        Reviewed by Simon Fraser.
+
+        The same logic for applying overflow clipping based on the cached size of a
+        RenderBox has been duplicated to four different places. Consolidate them to a
+        single RenderBox utility function.
+
+        This is in preparation for https://bugs.webkit.org/show_bug.cgi?id=96087.
+
+        No new functionality; covered by existing tests.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::applyCachedClipAndScrollOffsetForRepaint):
+        (WebCore):
+        (WebCore::RenderBox::computeRectForRepaint):
+        * rendering/RenderBox.h:
+        (RenderBox):
+        * rendering/RenderInline.cpp:
+        (WebCore::RenderInline::clippedOverflowRectForRepaint):
+        (WebCore::RenderInline::computeRectForRepaint):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::computeRectForRepaint):
+
 2012-09-13  Simon Hausmann  <simon.hausmann@nokia.com>
 
         Another prospective Qt/Windows build fix: Add missing CString.h include.
index d62b8f4..b22cdd0 100644 (file)
@@ -647,6 +647,17 @@ LayoutSize RenderBox::cachedSizeForOverflowClip() const
     return layer()->size();
 }
 
+void RenderBox::applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const
+{
+    paintRect.move(-scrolledContentOffset()); // For overflow:auto/scroll/hidden.
+
+    // height() is inaccurate if we're in the middle of a layout of this RenderBox, so use the
+    // layer's size instead. Even if the layer's size is wrong, the layer itself will repaint
+    // anyway if its size does change.
+    LayoutRect clipRect(LayoutPoint(), cachedSizeForOverflowClip());
+    paintRect = intersection(paintRect, clipRect);
+}
+
 LayoutUnit RenderBox::minPreferredLogicalWidth() const
 {
     if (preferredLogicalWidthsDirty())
@@ -1574,21 +1585,13 @@ void RenderBox::computeRectForRepaint(RenderBoxModelObject* repaintContainer, La
 
     // FIXME: We ignore the lightweight clipping rect that controls use, since if |o| is in mid-layout,
     // its controlClipRect will be wrong. For overflow clip we use the values cached by the layer.
+    rect.setLocation(topLeft);
     if (o->hasOverflowClip()) {
         RenderBox* containerBox = toRenderBox(o);
-
-        // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
-        // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
-        // anyway if its size does change.
-        topLeft -= containerBox->scrolledContentOffset(); // For overflow:auto/scroll/hidden.
-
-        LayoutRect repaintRect(topLeft, rect.size());
-        LayoutRect boxRect(LayoutPoint(), containerBox->cachedSizeForOverflowClip());
-        rect = intersection(repaintRect, boxRect);
+        containerBox->applyCachedClipAndScrollOffsetForRepaint(rect);
         if (rect.isEmpty())
             return;
-    } else
-        rect.setLocation(topLeft);
+    }
 
     if (containerSkipped) {
         // If the repaintContainer is below o, then we need to map the rect into repaintContainer's coordinates.
index dd433c9..590875a 100644 (file)
@@ -509,6 +509,7 @@ public:
 
     IntSize scrolledContentOffset() const;
     LayoutSize cachedSizeForOverflowClip() const;
+    void applyCachedClipAndScrollOffsetForRepaint(LayoutRect& paintRect) const;
 
     virtual bool hasRelativeDimensions() const;
     virtual bool hasRelativeLogicalHeight() const;
index 9413755..234cea2 100644 (file)
@@ -993,15 +993,8 @@ LayoutRect RenderInline::clippedOverflowRectForRepaint(RenderBoxModelObject* rep
     if (cb->hasColumns())
         cb->adjustRectForColumns(repaintRect);
 
-    if (cb->hasOverflowClip()) {
-        // cb->height() is inaccurate if we're in the middle of a layout of |cb|, so use the
-        // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
-        // anyway if its size does change.
-        repaintRect.move(-cb->scrolledContentOffset()); // For overflow:auto/scroll/hidden.
-
-        LayoutRect boxRect(LayoutPoint(), cb->cachedSizeForOverflowClip());
-        repaintRect.intersect(boxRect);
-    }
+    if (cb->hasOverflowClip())
+        cb->applyCachedClipAndScrollOffsetForRepaint(repaintRect);
 
     cb->computeRectForRepaint(repaintContainer, repaintRect);
 
@@ -1073,21 +1066,13 @@ void RenderInline::computeRectForRepaint(RenderBoxModelObject* repaintContainer,
     
     // FIXME: We ignore the lightweight clipping rect that controls use, since if |o| is in mid-layout,
     // its controlClipRect will be wrong. For overflow clip we use the values cached by the layer.
+    rect.setLocation(topLeft);
     if (o->hasOverflowClip()) {
         RenderBox* containerBox = toRenderBox(o);
-
-        // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
-        // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
-        // anyway if its size does change.
-        topLeft -= containerBox->scrolledContentOffset(); // For overflow:auto/scroll/hidden.
-
-        LayoutRect repaintRect(topLeft, rect.size());
-        LayoutRect boxRect(LayoutPoint(), containerBox->cachedSizeForOverflowClip());
-        rect = intersection(repaintRect, boxRect);
+        containerBox->applyCachedClipAndScrollOffsetForRepaint(rect);
         if (rect.isEmpty())
             return;
-    } else
-        rect.setLocation(topLeft);
+    }
 
     if (containerSkipped) {
         // If the repaintContainer is below o, then we need to map the rect into repaintContainer's coordinates.
index 4268e09..214970a 100755 (executable)
@@ -1507,16 +1507,8 @@ void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer,
         }
 
         if (o->hasOverflowClip()) {
-            // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
-            // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
-            // anyway if its size does change.
             RenderBox* boxParent = toRenderBox(o);
-
-            LayoutRect repaintRect(rect);
-            repaintRect.move(-boxParent->scrolledContentOffset()); // For overflow:auto/scroll/hidden.
-
-            LayoutRect boxRect(LayoutPoint(), boxParent->cachedSizeForOverflowClip());
-            rect = intersection(repaintRect, boxRect);
+            boxParent->applyCachedClipAndScrollOffsetForRepaint(rect);
             if (rect.isEmpty())
                 return;
         }