Prepare for position:sticky support inside accelerated overflow-scroll with WK2
https://bugs.webkit.org/show_bug.cgi?id=133329

Reviewed by Tim Horton.

RenderLayerCompositor::computeStickyViewportConstraints() was always using
the viewport rect as the constraining rect for sticky position. This is not
correct when inside overflow:scroll.

Refactor code in RenderBoxModelObject to make getting the rect easy, and use
it to compute the constraints.

* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::constrainingRectForStickyPosition):
(WebCore::RenderBoxModelObject::stickyPositionOffset):
* rendering/RenderBoxModelObject.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::computeStickyViewportConstraints):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@169408 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 3aad573..ffae4fd 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,24 @@
+2014-05-27  Simon Fraser  <simon.fraser@apple.com>
+
+        Prepare for position:sticky support inside accelerated overflow-scroll with WK2
+        https://bugs.webkit.org/show_bug.cgi?id=133329
+
+        Reviewed by Tim Horton.
+
+        RenderLayerCompositor::computeStickyViewportConstraints() was always using
+        the viewport rect as the constraining rect for sticky position. This is not
+        correct when inside overflow:scroll.
+        
+        Refactor code in RenderBoxModelObject to make getting the rect easy, and use
+        it to compute the constraints.
+
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::constrainingRectForStickyPosition):
+        (WebCore::RenderBoxModelObject::stickyPositionOffset):
+        * rendering/RenderBoxModelObject.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::computeStickyViewportConstraints):
+
 2014-05-27  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         vw/vh units used as font/line-height values don't scale with the viewport
diff --git a/Source/WebCore/rendering/RenderBoxModelObject.cpp b/Source/WebCore/rendering/RenderBoxModelObject.cpp
index 06c521c..9f8a5fa 100644
--- a/Source/WebCore/rendering/RenderBoxModelObject.cpp
+++ b/Source/WebCore/rendering/RenderBoxModelObject.cpp
@@ -435,28 +435,33 @@
     }
 }
 
-LayoutSize RenderBoxModelObject::stickyPositionOffset() const
+FloatRect RenderBoxModelObject::constrainingRectForStickyPosition() const
 {
-    FloatRect constrainingRect;
-
-    ASSERT(hasLayer());
     RenderLayer* enclosingClippingLayer = layer()->enclosingOverflowClipLayer(ExcludeSelf);
     if (enclosingClippingLayer) {
         RenderBox& enclosingClippingBox = toRenderBox(enclosingClippingLayer->renderer());
         LayoutRect clipRect = enclosingClippingBox.overflowClipRect(LayoutPoint(), 0); // FIXME: make this work in regions.
         clipRect.contract(LayoutSize(enclosingClippingBox.paddingLeft() + enclosingClippingBox.paddingRight(),
             enclosingClippingBox.paddingTop() + enclosingClippingBox.paddingBottom()));
-        constrainingRect = enclosingClippingBox.localToContainerQuad(FloatRect(clipRect), &view()).boundingBox();
+
+        FloatRect constrainingRect = enclosingClippingBox.localToContainerQuad(FloatRect(clipRect), &view()).boundingBox();
 
         FloatPoint scrollOffset = FloatPoint() + enclosingClippingLayer->scrollOffset();
         constrainingRect.setLocation(scrollOffset);
-    } else {
-        LayoutRect viewportRect = view().frameView().viewportConstrainedVisibleContentRect();
-        float scale = view().frameView().frame().frameScaleFactor();
-        viewportRect.scale(1 / scale);
-        constrainingRect = viewportRect;
+        return constrainingRect;
     }
     
+    LayoutRect viewportRect = view().frameView().viewportConstrainedVisibleContentRect();
+    float scale = frame().frameScaleFactor();
+    viewportRect.scale(1 / scale);
+    return viewportRect;
+}
+
+LayoutSize RenderBoxModelObject::stickyPositionOffset() const
+{
+    ASSERT(hasLayer());
+    
+    FloatRect constrainingRect = constrainingRectForStickyPosition();
     StickyPositionViewportConstraints constraints;
     computeStickyPositionConstraints(constraints, constrainingRect);
     
diff --git a/Source/WebCore/rendering/RenderBoxModelObject.h b/Source/WebCore/rendering/RenderBoxModelObject.h
index dac90d0..096b8b9 100644
--- a/Source/WebCore/rendering/RenderBoxModelObject.h
+++ b/Source/WebCore/rendering/RenderBoxModelObject.h
@@ -69,7 +69,8 @@
     LayoutSize relativePositionOffset() const;
     LayoutSize relativePositionLogicalOffset() const { return style().isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
 
-    void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& viewportRect) const;
+    FloatRect constrainingRectForStickyPosition() const;
+    void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& constrainingRect) const;
     LayoutSize stickyPositionOffset() const;
     LayoutSize stickyPositionLogicalOffset() const { return style().isHorizontalWritingMode() ? stickyPositionOffset() : stickyPositionOffset().transposedSize(); }
 
diff --git a/Source/WebCore/rendering/RenderLayerCompositor.cpp b/Source/WebCore/rendering/RenderLayerCompositor.cpp
index 755d624..73d0a62 100644
--- a/Source/WebCore/rendering/RenderLayerCompositor.cpp
+++ b/Source/WebCore/rendering/RenderLayerCompositor.cpp
@@ -3558,11 +3558,10 @@
     ASSERT(!layer.enclosingOverflowClipLayer(ExcludeSelf));
 #endif
 
-    LayoutRect viewportRect = m_renderView.frameView().viewportConstrainedVisibleContentRect();
     RenderBoxModelObject& renderer = toRenderBoxModelObject(layer.renderer());
 
     StickyPositionViewportConstraints constraints;
-    renderer.computeStickyPositionConstraints(constraints, viewportRect);
+    renderer.computeStickyPositionConstraints(constraints, renderer.constrainingRectForStickyPosition());
 
     GraphicsLayer* graphicsLayer = layer.backing()->graphicsLayer();