Title: [127795] trunk/Source/WebCore
Revision
127795
Author
[email protected]
Date
2012-09-06 16:21:09 -0700 (Thu, 06 Sep 2012)

Log Message

Parcel up logic related to sticky positioning into a Constraints class that will later be used for threaded scrolling
https://bugs.webkit.org/show_bug.cgi?id=96026

Reviewed by James Robinson.

Lay some groundwork for threaded scrolling with fixed position and sticky
position objects, by packaging up logic related to how to reposition
fixed and sticky things on viewport changes into "constraints" classes.

ScrollingConstraints contains a 'ViewportConstraints' base class
that is subclassed for sticky position. These classes store
data about the constraints that govern the position of an object outside
of the render tree, and know how to compute a new position when the
viewport changes using only data in the class.

This patch changes RenderBoxModelObject to use the StickyPositionViewportConstraints
class for computing stick offsets at layout time. In the future, we'll have
the scrolling tree store copies of the constraint data for threaded scrolling.

* CMakeLists.txt: Add ScrollingConstraints.* to the build.
* GNUmakefile.list.am: Ditto
* Target.pri: Ditto
* WebCore.gypi: Ditto
* WebCore.vcproj/WebCore.vcproj: Ditto
* WebCore.xcodeproj/project.pbxproj: Ditto
* page/scrolling/ScrollingConstraints.cpp: Added.
(WebCore::StickyPositionViewportConstraints::computeStickyOffset):
(WebCore::StickyPositionViewportConstraints::layerPositionForViewportRect):
* page/scrolling/ScrollingConstraints.h: Added.
(WebCore::ViewportConstraints::ViewportConstraints):
(WebCore::ViewportConstraints::~ViewportConstraints):
(WebCore::ViewportConstraints::anchorEdges):
(WebCore::ViewportConstraints::hasAnchorEdge):
(WebCore::ViewportConstraints::addAnchorEdge):
(WebCore::ViewportConstraints::alignmentOffset):
(WebCore::ViewportConstraints::setAlignmentOffset):
(StickyPositionViewportConstraints):
(WebCore::StickyPositionViewportConstraints::StickyPositionViewportConstraints):
(WebCore::StickyPositionViewportConstraints::stickyOffsetAtLastLayout):
(WebCore::StickyPositionViewportConstraints::setStickyOffsetAtLastLayout):
(WebCore::StickyPositionViewportConstraints::layerPositionAtLastLayout):
(WebCore::StickyPositionViewportConstraints::setLayerPositionAtLastLayout):
(WebCore::StickyPositionViewportConstraints::leftOffset):
(WebCore::StickyPositionViewportConstraints::rightOffset):
(WebCore::StickyPositionViewportConstraints::topOffset):
(WebCore::StickyPositionViewportConstraints::bottomOffset):
(WebCore::StickyPositionViewportConstraints::setLeftOffset):
(WebCore::StickyPositionViewportConstraints::setRightOffset):
(WebCore::StickyPositionViewportConstraints::setTopOffset):
(WebCore::StickyPositionViewportConstraints::setBottomOffset):
(WebCore::StickyPositionViewportConstraints::setAbsoluteContainingBlockRect):
(WebCore::StickyPositionViewportConstraints::setAbsoluteStickyBoxRect):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::computeStickyPositionConstraints): Fill out
data in the supplied StickyPositionViewportConstraints instance.
(WebCore::RenderBoxModelObject::stickyPositionOffset): Create a
StickyPositionViewportConstraints object on the stack and use it to
compute the sticky offset.
* rendering/RenderBoxModelObject.h:
(RenderBoxModelObject):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (127794 => 127795)


--- trunk/Source/WebCore/CMakeLists.txt	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/CMakeLists.txt	2012-09-06 23:21:09 UTC (rev 127795)
@@ -1731,6 +1731,7 @@
     page/animation/ImplicitAnimation.cpp
     page/animation/KeyframeAnimation.cpp
 
+    page/scrolling/ScrollingConstraints.cpp
     page/scrolling/ScrollingCoordinator.cpp
     page/scrolling/ScrollingCoordinatorNone.cpp
 

Modified: trunk/Source/WebCore/ChangeLog (127794 => 127795)


--- trunk/Source/WebCore/ChangeLog	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/ChangeLog	2012-09-06 23:21:09 UTC (rev 127795)
@@ -1,3 +1,66 @@
+2012-09-06  Simon Fraser  <[email protected]>
+
+        Parcel up logic related to sticky positioning into a Constraints class that will later be used for threaded scrolling
+        https://bugs.webkit.org/show_bug.cgi?id=96026
+
+        Reviewed by James Robinson.
+
+        Lay some groundwork for threaded scrolling with fixed position and sticky
+        position objects, by packaging up logic related to how to reposition
+        fixed and sticky things on viewport changes into "constraints" classes.
+        
+        ScrollingConstraints contains a 'ViewportConstraints' base class
+        that is subclassed for sticky position. These classes store
+        data about the constraints that govern the position of an object outside
+        of the render tree, and know how to compute a new position when the
+        viewport changes using only data in the class.
+        
+        This patch changes RenderBoxModelObject to use the StickyPositionViewportConstraints
+        class for computing stick offsets at layout time. In the future, we'll have
+        the scrolling tree store copies of the constraint data for threaded scrolling.
+        
+        * CMakeLists.txt: Add ScrollingConstraints.* to the build.
+        * GNUmakefile.list.am: Ditto
+        * Target.pri: Ditto
+        * WebCore.gypi: Ditto
+        * WebCore.vcproj/WebCore.vcproj: Ditto
+        * WebCore.xcodeproj/project.pbxproj: Ditto
+        * page/scrolling/ScrollingConstraints.cpp: Added.
+        (WebCore::StickyPositionViewportConstraints::computeStickyOffset):
+        (WebCore::StickyPositionViewportConstraints::layerPositionForViewportRect):
+        * page/scrolling/ScrollingConstraints.h: Added.
+        (WebCore::ViewportConstraints::ViewportConstraints):
+        (WebCore::ViewportConstraints::~ViewportConstraints):
+        (WebCore::ViewportConstraints::anchorEdges):
+        (WebCore::ViewportConstraints::hasAnchorEdge):
+        (WebCore::ViewportConstraints::addAnchorEdge):
+        (WebCore::ViewportConstraints::alignmentOffset):
+        (WebCore::ViewportConstraints::setAlignmentOffset):
+        (StickyPositionViewportConstraints):
+        (WebCore::StickyPositionViewportConstraints::StickyPositionViewportConstraints):
+        (WebCore::StickyPositionViewportConstraints::stickyOffsetAtLastLayout):
+        (WebCore::StickyPositionViewportConstraints::setStickyOffsetAtLastLayout):
+        (WebCore::StickyPositionViewportConstraints::layerPositionAtLastLayout):
+        (WebCore::StickyPositionViewportConstraints::setLayerPositionAtLastLayout):
+        (WebCore::StickyPositionViewportConstraints::leftOffset):
+        (WebCore::StickyPositionViewportConstraints::rightOffset):
+        (WebCore::StickyPositionViewportConstraints::topOffset):
+        (WebCore::StickyPositionViewportConstraints::bottomOffset):
+        (WebCore::StickyPositionViewportConstraints::setLeftOffset):
+        (WebCore::StickyPositionViewportConstraints::setRightOffset):
+        (WebCore::StickyPositionViewportConstraints::setTopOffset):
+        (WebCore::StickyPositionViewportConstraints::setBottomOffset):
+        (WebCore::StickyPositionViewportConstraints::setAbsoluteContainingBlockRect):
+        (WebCore::StickyPositionViewportConstraints::setAbsoluteStickyBoxRect):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::computeStickyPositionConstraints): Fill out
+        data in the supplied StickyPositionViewportConstraints instance.
+        (WebCore::RenderBoxModelObject::stickyPositionOffset): Create a
+        StickyPositionViewportConstraints object on the stack and use it to
+        compute the sticky offset.
+        * rendering/RenderBoxModelObject.h:
+        (RenderBoxModelObject):
+
 2012-09-06  James Robinson  <[email protected]>
 
         [chromium] Use WebCompositorSupport functions instead of WebCompositor statics

Modified: trunk/Source/WebCore/GNUmakefile.list.am (127794 => 127795)


--- trunk/Source/WebCore/GNUmakefile.list.am	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/GNUmakefile.list.am	2012-09-06 23:21:09 UTC (rev 127795)
@@ -4030,6 +4030,8 @@
 	Source/WebCore/page/PrintContext.h \
 	Source/WebCore/page/Screen.cpp \
 	Source/WebCore/page/Screen.h \
+	Source/WebCore/page/scrolling/ScrollingConstraints.cpp \
+	Source/WebCore/page/scrolling/ScrollingConstraints.h \
 	Source/WebCore/page/scrolling/ScrollingCoordinator.cpp \
 	Source/WebCore/page/scrolling/ScrollingCoordinator.h \
 	Source/WebCore/page/scrolling/ScrollingCoordinatorNone.cpp \

Modified: trunk/Source/WebCore/Target.pri (127794 => 127795)


--- trunk/Source/WebCore/Target.pri	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/Target.pri	2012-09-06 23:21:09 UTC (rev 127795)
@@ -893,6 +893,7 @@
     page/PerformanceTiming.cpp \
     page/PrintContext.cpp \
     page/Screen.cpp \
+    page/scrolling/ScrollingConstraints.cpp \
     page/scrolling/ScrollingCoordinator.cpp \
     page/scrolling/ScrollingCoordinatorNone.cpp \
     page/SecurityOrigin.cpp \

Modified: trunk/Source/WebCore/WebCore.gypi (127794 => 127795)


--- trunk/Source/WebCore/WebCore.gypi	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/WebCore.gypi	2012-09-06 23:21:09 UTC (rev 127795)
@@ -3220,6 +3220,8 @@
             'page/mac/PageMac.cpp',
             'page/qt/DragControllerQt.cpp',
             'page/qt/EventHandlerQt.cpp',
+            'page/scrolling/ScrollingConstraints.cpp',
+            'page/scrolling/ScrollingConstraints.h',
             'page/scrolling/ScrollingCoordinator.cpp',
             'page/scrolling/ScrollingCoordinator.h',
             'page/scrolling/ScrollingThread.cpp',

Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (127794 => 127795)


--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj	2012-09-06 23:21:09 UTC (rev 127795)
@@ -27283,6 +27283,14 @@
 				>
 			</File>
 			<File
+				RelativePath="..\page\scrolling\ScrollingConstraints.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\page\scrolling\ScrollingConstraints.h"
+				>
+			</File>
+			<File
 				RelativePath="..\page\scrolling\ScrollingCoordinator.cpp"
 				>
 			</File>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (127794 => 127795)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2012-09-06 23:21:09 UTC (rev 127795)
@@ -262,6 +262,8 @@
 		0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		0F5B7A5410F65D7A00376302 /* RenderEmbeddedObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */; };
 		0F5B7A5510F65D7A00376302 /* RenderEmbeddedObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		0F605AEC15F94848004DF0C0 /* ScrollingConstraints.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F605AEA15F94848004DF0C0 /* ScrollingConstraints.cpp */; };
+		0F605AED15F94848004DF0C0 /* ScrollingConstraints.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F605AEB15F94848004DF0C0 /* ScrollingConstraints.h */; };
 		0FCF33240F2B9715004B6795 /* ColorCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FCF33230F2B9715004B6795 /* ColorCG.cpp */; };
 		0FCF332C0F2B9A25004B6795 /* WebTiledLayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0FCF33280F2B9A25004B6795 /* WebTiledLayer.mm */; };
 		0FCF332D0F2B9A25004B6795 /* WebTiledLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FCF33290F2B9A25004B6795 /* WebTiledLayer.h */; };
@@ -7281,6 +7283,8 @@
 		0F580FAE149800D400FB5BD8 /* AnimationUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AnimationUtilities.h; path = animation/AnimationUtilities.h; sourceTree = "<group>"; };
 		0F5B7A5210F65D7A00376302 /* RenderEmbeddedObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderEmbeddedObject.cpp; sourceTree = "<group>"; };
 		0F5B7A5310F65D7A00376302 /* RenderEmbeddedObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderEmbeddedObject.h; sourceTree = "<group>"; };
+		0F605AEA15F94848004DF0C0 /* ScrollingConstraints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollingConstraints.cpp; sourceTree = "<group>"; };
+		0F605AEB15F94848004DF0C0 /* ScrollingConstraints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollingConstraints.h; sourceTree = "<group>"; };
 		0FCF33230F2B9715004B6795 /* ColorCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ColorCG.cpp; sourceTree = "<group>"; };
 		0FCF33280F2B9A25004B6795 /* WebTiledLayer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebTiledLayer.mm; sourceTree = "<group>"; };
 		0FCF33290F2B9A25004B6795 /* WebTiledLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebTiledLayer.h; sourceTree = "<group>"; };
@@ -14542,6 +14546,8 @@
 			isa = PBXGroup;
 			children = (
 				1AF62EE214DA22A70041556C /* mac */,
+				0F605AEA15F94848004DF0C0 /* ScrollingConstraints.cpp */,
+				0F605AEB15F94848004DF0C0 /* ScrollingConstraints.h */,
 				1AF62EE414DA22A70041556C /* ScrollingCoordinator.cpp */,
 				1AF62EE514DA22A70041556C /* ScrollingCoordinator.h */,
 				3866AF3714F1C17100283D68 /* ScrollingCoordinatorNone.cpp */,
@@ -25500,6 +25506,7 @@
 				FBD6AF8A15EF25DF008B7110 /* BasicShapeFunctions.h in Headers */,
 				FBD6AF8C15EF2604008B7110 /* BasicShapes.h in Headers */,
 				76F2E2EC15F74CEF005FF664 /* RenderDialog.h in Headers */,
+				0F605AED15F94848004DF0C0 /* ScrollingConstraints.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -28591,6 +28598,7 @@
 				377A3A9015EFCE9B0059F5C7 /* BitmapImageCG.cpp in Sources */,
 				BCD8A5F015F56F2C0098D071 /* TextBreakIterator.cpp in Sources */,
 				76F2E2EB15F74CEF005FF664 /* RenderDialog.cpp in Sources */,
+				0F605AEC15F94848004DF0C0 /* ScrollingConstraints.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Source/WebCore/page/scrolling/ScrollingConstraints.cpp (0 => 127795)


--- trunk/Source/WebCore/page/scrolling/ScrollingConstraints.cpp	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/ScrollingConstraints.cpp	2012-09-06 23:21:09 UTC (rev 127795)
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ScrollingConstraints.h"
+
+namespace WebCore {
+
+FloatSize StickyPositionViewportConstraints::computeStickyOffset(const FloatRect& viewportRect) const
+{
+    FloatRect boxRect = m_absoluteStickyBoxRect;
+    
+    if (hasAnchorEdge(AnchorEdgeRight)) {
+        float rightLimit = viewportRect.maxX() - m_rightOffset;
+        float rightDelta = std::min<float>(0, rightLimit - m_absoluteStickyBoxRect.maxX());
+        float availableSpace = std::min<float>(0, m_absoluteContainingBlockRect.x() - m_absoluteStickyBoxRect.x());
+        if (rightDelta < availableSpace)
+            rightDelta = availableSpace;
+
+        boxRect.move(rightDelta, 0);
+    }
+
+    if (hasAnchorEdge(AnchorEdgeLeft)) {
+        float leftLimit = viewportRect.x() + m_leftOffset;
+        float leftDelta = std::max<float>(0, leftLimit - m_absoluteStickyBoxRect.x());
+        float availableSpace = std::max<float>(0, m_absoluteContainingBlockRect.maxX() - m_absoluteStickyBoxRect.maxX());
+        if (leftDelta > availableSpace)
+            leftDelta = availableSpace;
+
+        boxRect.move(leftDelta, 0);
+    }
+    
+    if (hasAnchorEdge(AnchorEdgeBottom)) {
+        float bottomLimit = viewportRect.maxY() - m_bottomOffset;
+        float bottomDelta = std::min<float>(0, bottomLimit - m_absoluteStickyBoxRect.maxY());
+        float availableSpace = std::min<float>(0, m_absoluteContainingBlockRect.y() - m_absoluteStickyBoxRect.y());
+        if (bottomDelta < availableSpace)
+            bottomDelta = availableSpace;
+
+        boxRect.move(0, bottomDelta);
+    }
+
+    if (hasAnchorEdge(AnchorEdgeTop)) {
+        float topLimit = viewportRect.y() + m_topOffset;
+        float topDelta = std::max<float>(0, topLimit - m_absoluteStickyBoxRect.y());
+        float availableSpace = std::max<float>(0, m_absoluteContainingBlockRect.maxY() - m_absoluteStickyBoxRect.maxY());
+        if (topDelta > availableSpace)
+            topDelta = availableSpace;
+
+        boxRect.move(0, topDelta);
+    }
+
+    return boxRect.location() - m_absoluteStickyBoxRect.location();
+}
+
+FloatPoint StickyPositionViewportConstraints::layerPositionForViewportRect(const FloatRect& viewportRect) const
+{
+    FloatSize offset = computeStickyOffset(viewportRect);
+    return m_layerPositionAtLastLayout + offset - m_stickyOffsetAtLastLayout;
+}
+
+} // namespace WebCore
Property changes on: trunk/Source/WebCore/page/scrolling/ScrollingConstraints.cpp
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: trunk/Source/WebCore/page/scrolling/ScrollingConstraints.h (0 => 127795)


--- trunk/Source/WebCore/page/scrolling/ScrollingConstraints.h	                        (rev 0)
+++ trunk/Source/WebCore/page/scrolling/ScrollingConstraints.h	2012-09-06 23:21:09 UTC (rev 127795)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ScrollingConstraints_h
+#define ScrollingConstraints_h
+
+#include "FloatRect.h"
+
+namespace WebCore {
+
+// ViewportConstraints classes encapsulate data and logic required to reposition elements whose layout
+// depends on the viewport rect (positions fixed and sticky), when scrolling and zooming.
+class ViewportConstraints {
+public:
+    enum ConstraintType {
+        FixedPositionConstaint,
+        StickyPositionConstraint
+    };
+
+    enum AnchorEdgeFlags {
+        AnchorEdgeLeft = 1 << 0,
+        AnchorEdgeRight = 1 << 1,
+        AnchorEdgeTop = 1 << 2,
+        AnchorEdgeBottom = 1 << 3
+    };
+    typedef unsigned AnchorEdges;
+    
+    ViewportConstraints()
+        : m_anchorEdges(0)
+    { }
+
+    virtual ~ViewportConstraints() { }
+    
+    virtual ConstraintType constraintType() const = 0;
+    
+    AnchorEdges anchorEdges() const { return m_anchorEdges; }
+    bool hasAnchorEdge(AnchorEdgeFlags flag) const { return m_anchorEdges & flag; }
+    void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
+    
+    FloatSize alignmentOffset() const { return m_alignmentOffset; }
+    void setAlignmentOffset(const FloatSize& offset) { m_alignmentOffset = offset; }
+
+protected:
+    FloatSize m_alignmentOffset;
+    AnchorEdges m_anchorEdges;
+};
+
+class StickyPositionViewportConstraints : public ViewportConstraints {
+public:
+    StickyPositionViewportConstraints()
+        : m_leftOffset(0)
+        , m_rightOffset(0)
+        , m_topOffset(0)
+        , m_bottomOffset(0)
+    { }
+
+    virtual ConstraintType constraintType() const OVERRIDE { return StickyPositionConstraint; };
+    FloatSize computeStickyOffset(const FloatRect& viewportRect) const;
+
+    const FloatSize stickyOffsetAtLastLayout() const { return m_stickyOffsetAtLastLayout; }
+    void setStickyOffsetAtLastLayout(const FloatSize& offset) { m_stickyOffsetAtLastLayout = offset; }
+
+    FloatPoint layerPositionForViewportRect(const FloatRect& viewportRect) const;
+
+    const FloatPoint& layerPositionAtLastLayout() const { return m_layerPositionAtLastLayout; }
+    void setLayerPositionAtLastLayout(const FloatPoint& point) { m_layerPositionAtLastLayout = point; }
+
+    float leftOffset() const { return m_leftOffset; }
+    float rightOffset() const { return m_rightOffset; }
+    float topOffset() const { return m_topOffset; }
+    float bottomOffset() const { return m_bottomOffset; }
+
+    void setLeftOffset(float offset) { m_leftOffset = offset; }
+    void setRightOffset(float offset) { m_rightOffset = offset; }
+    void setTopOffset(float offset) { m_topOffset = offset; }
+    void setBottomOffset(float offset) { m_bottomOffset = offset; }
+
+    void setAbsoluteContainingBlockRect(const FloatRect& rect) { m_absoluteContainingBlockRect = rect; }
+    void setAbsoluteStickyBoxRect(const FloatRect& rect) { m_absoluteStickyBoxRect = rect; }
+
+private:
+    float m_leftOffset;
+    float m_rightOffset;
+    float m_topOffset;
+    float m_bottomOffset;
+    FloatRect m_absoluteContainingBlockRect;
+    FloatRect m_absoluteStickyBoxRect;
+    FloatSize m_stickyOffsetAtLastLayout;
+    FloatPoint m_layerPositionAtLastLayout;
+};
+
+} // namespace WebCore
+
+#endif // ScrollingConstraints_h
Property changes on: trunk/Source/WebCore/page/scrolling/ScrollingConstraints.h
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (127794 => 127795)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2012-09-06 23:21:09 UTC (rev 127795)
@@ -37,6 +37,7 @@
 #include "RenderInline.h"
 #include "RenderLayer.h"
 #include "RenderView.h"
+#include "ScrollingConstraints.h"
 #include "Settings.h"
 #include "TransformState.h"
 #include <wtf/CurrentTime.h>
@@ -573,11 +574,10 @@
     return referencePoint;
 }
 
-LayoutSize RenderBoxModelObject::stickyPositionOffset() const
+void RenderBoxModelObject::computeStickyPositionConstraints(StickyPositionViewportConstraints& constraints, const FloatRect& viewportRect) const
 {
     RenderBlock* containingBlock = this->containingBlock();
 
-    LayoutRect viewportRect = view()->frameView()->visibleContentRect();
     LayoutRect containerContentRect = containingBlock->contentBoxRect();
 
     LayoutUnit minLeftMargin = minimumValueForLength(style()->marginLeft(), containingBlock->availableLogicalWidth(), view());
@@ -588,7 +588,7 @@
     // Compute the container-relative area within which the sticky element is allowed to move.
     containerContentRect.move(minLeftMargin, minTopMargin);
     containerContentRect.contract(minLeftMargin + minRightMargin, minTopMargin + minBottomMargin);
-    FloatRect absContainerContentRect = containingBlock->localToAbsoluteQuad(FloatRect(containerContentRect)).boundingBox();
+    constraints.setAbsoluteContainingBlockRect(containingBlock->localToAbsoluteQuad(FloatRect(containerContentRect)).boundingBox());
 
     LayoutRect stickyBoxRect = frameRectForStickyPositioning();
     LayoutRect flippedStickyBoxRect = stickyBoxRect;
@@ -599,53 +599,38 @@
     FloatRect absContainerFrame = containingBlock->localToAbsoluteQuad(FloatRect(FloatPoint(), containingBlock->size())).boundingBox();
     // We can't call localToAbsolute on |this| because that will recur. FIXME: For now, assume that |this| is not transformed.
     FloatRect absoluteStickyBoxRect(absContainerFrame.location() + stickyLocation, flippedStickyBoxRect.size());
+    constraints.setAbsoluteStickyBoxRect(absoluteStickyBoxRect);
 
-    FloatPoint originalLocation = absoluteStickyBoxRect.location();
+    if (!style()->left().isAuto()) {
+        constraints.setLeftOffset(valueForLength(style()->left(), viewportRect.width(), view()));
+        constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
+    }
 
-    // Horizontal position.
     if (!style()->right().isAuto()) {
-        LayoutUnit rightLimit = viewportRect.maxX() - valueForLength(style()->right(), viewportRect.width(), view());
-        LayoutUnit rightDelta = min<float>(0, rightLimit.toFloat() - absoluteStickyBoxRect.maxX());
-        LayoutUnit availableSpace = min<float>(0, absContainerContentRect.x() - absoluteStickyBoxRect.x());
-        if (rightDelta < availableSpace)
-            rightDelta = availableSpace;
-
-        absoluteStickyBoxRect.move(rightDelta, 0);
+        constraints.setRightOffset(valueForLength(style()->right(), viewportRect.width(), view()));
+        constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight);
     }
 
-    if (!style()->left().isAuto()) {
-        LayoutUnit leftLimit = viewportRect.x() + valueForLength(style()->left(), viewportRect.width(), view());
-        LayoutUnit leftDelta = max<float>(0, leftLimit.toFloat() - absoluteStickyBoxRect.x());
-        LayoutUnit availableSpace = max<float>(0, absContainerContentRect.maxX() - absoluteStickyBoxRect.maxX());
-        if (leftDelta > availableSpace)
-            leftDelta = availableSpace;
-
-        absoluteStickyBoxRect.move(leftDelta, 0);
+    if (!style()->top().isAuto()) {
+        constraints.setTopOffset(valueForLength(style()->top(), viewportRect.height(), view()));
+        constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
     }
 
-    // Vertical position.
     if (!style()->bottom().isAuto()) {
-        LayoutUnit bottomLimit = viewportRect.maxY() - valueForLength(style()->bottom(), viewportRect.height(), view());
-        LayoutUnit bottomDelta = min<float>(0, bottomLimit.toFloat() - absoluteStickyBoxRect.maxY());
-        LayoutUnit availableSpace = min<float>(0, absContainerContentRect.y() - absoluteStickyBoxRect.y());
-        if (bottomDelta < availableSpace)
-            bottomDelta = availableSpace;
-
-        absoluteStickyBoxRect.move(0, bottomDelta);
+        constraints.setBottomOffset(valueForLength(style()->bottom(), viewportRect.height(), view()));
+        constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom);
     }
+}
 
-    if (!style()->top().isAuto()) {
-        LayoutUnit topLimit = viewportRect.y() + valueForLength(style()->top(), viewportRect.height(), view());
-        LayoutUnit topDelta = max<float>(0, topLimit.toFloat() - absoluteStickyBoxRect.y());
-        LayoutUnit availableSpace = max<float>(0, absContainerContentRect.maxY() - absoluteStickyBoxRect.maxY());
-        if (topDelta > availableSpace)
-            topDelta = availableSpace;
+LayoutSize RenderBoxModelObject::stickyPositionOffset() const
+{
+    LayoutRect viewportRect = view()->frameView()->visibleContentRect();
 
-        absoluteStickyBoxRect.move(0, topDelta);
-    }
+    StickyPositionViewportConstraints constraints;
+    computeStickyPositionConstraints(constraints, viewportRect);
     
     // The sticky offset is physical, so we can just return the delta computed in absolute coords (though it may be wrong with transforms).
-    return roundedLayoutSize(absoluteStickyBoxRect.location() - originalLocation);
+    return LayoutSize(constraints.computeStickyOffset(viewportRect));
 }
 
 LayoutSize RenderBoxModelObject::offsetForInFlowPosition() const

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.h (127794 => 127795)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2012-09-06 23:17:48 UTC (rev 127794)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.h	2012-09-06 23:21:09 UTC (rev 127795)
@@ -51,6 +51,7 @@
 };
 
 class KeyframeList;
+class StickyPositionViewportConstraints;
 
 // This class is the base for all objects that adhere to the CSS box model as described
 // at http://www.w3.org/TR/CSS21/box.html
@@ -63,6 +64,7 @@
     LayoutSize relativePositionOffset() const;
     LayoutSize relativePositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? relativePositionOffset() : relativePositionOffset().transposedSize(); }
 
+    void computeStickyPositionConstraints(StickyPositionViewportConstraints&, const FloatRect& viewportRect) const;
     LayoutSize stickyPositionOffset() const;
     LayoutSize stickyPositionLogicalOffset() const { return style()->isHorizontalWritingMode() ? stickyPositionOffset() : stickyPositionOffset().transposedSize(); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to