Title: [143404] trunk/Source/WebCore
Revision
143404
Author
simon.fra...@apple.com
Date
2013-02-19 16:25:06 -0800 (Tue, 19 Feb 2013)

Log Message

Separate constraining for overhang from fixed-position zooming behavior in scrollOffsetForFixedPosition()
https://bugs.webkit.org/show_bug.cgi?id=110267

Reviewed by Beth Dakin.

The static scrollOffsetForFixedPosition() function in ScrollingCoordinator did two things;
it constrained the scroll position when rubber-banding, and applied the special scaling for
fixed position when zoomed.

Separate these out so that we can use the rubber-banding constrained elsewhere.

* page/FrameView.cpp:
(WebCore::FrameView::scrollOffsetForFixedPosition): The static function is here now.
* page/FrameView.h:
* page/scrolling/ScrollingCoordinator.cpp: Code moved to FrameView.
* page/scrolling/ScrollingCoordinator.h:
* page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm:
(WebCore::ScrollingTreeScrollingNodeMac::setScrollLayerPosition): scrollOffsetForFixedPosition()
is now on FrameView.
* platform/ScrollableArea.cpp:
(WebCore::constrainedScrollPosition): Helper to constrain one axis for overhang.
(WebCore::ScrollableArea::constrainScrollPositionForOverhang): Static function that
can be called by FrameView::scrollOffsetForFixedPosition().
* platform/ScrollableArea.h: Static function constrainScrollPositionForOverhang()
so we can call it from another thread. Also a member fuction of the same name, which takes
the scrollPosition as input (so we can feed it a layer position in a later patch).

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143403 => 143404)


--- trunk/Source/WebCore/ChangeLog	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/ChangeLog	2013-02-20 00:25:06 UTC (rev 143404)
@@ -1,3 +1,32 @@
+2013-02-19  Simon Fraser  <simon.fra...@apple.com>
+
+        Separate constraining for overhang from fixed-position zooming behavior in scrollOffsetForFixedPosition()
+        https://bugs.webkit.org/show_bug.cgi?id=110267
+
+        Reviewed by Beth Dakin.
+
+        The static scrollOffsetForFixedPosition() function in ScrollingCoordinator did two things;
+        it constrained the scroll position when rubber-banding, and applied the special scaling for
+        fixed position when zoomed.
+        
+        Separate these out so that we can use the rubber-banding constrained elsewhere.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::scrollOffsetForFixedPosition): The static function is here now.
+        * page/FrameView.h:
+        * page/scrolling/ScrollingCoordinator.cpp: Code moved to FrameView.
+        * page/scrolling/ScrollingCoordinator.h:
+        * page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeScrollingNodeMac::setScrollLayerPosition): scrollOffsetForFixedPosition()
+        is now on FrameView.
+        * platform/ScrollableArea.cpp:
+        (WebCore::constrainedScrollPosition): Helper to constrain one axis for overhang.
+        (WebCore::ScrollableArea::constrainScrollPositionForOverhang): Static function that
+        can be called by FrameView::scrollOffsetForFixedPosition().
+        * platform/ScrollableArea.h: Static function constrainScrollPositionForOverhang()
+        so we can call it from another thread. Also a member fuction of the same name, which takes
+        the scrollPosition as input (so we can feed it a layer position in a later patch).
+
 2013-02-19  Tony Gentilcore  <to...@chromium.org>
 
         Fix checkThatTokensAreSafeToSendToAnotherThread() now that the preload scanner is enabled

Modified: trunk/Source/WebCore/page/FrameView.cpp (143403 => 143404)


--- trunk/Source/WebCore/page/FrameView.cpp	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/page/FrameView.cpp	2013-02-20 00:25:06 UTC (rev 143404)
@@ -1512,6 +1512,18 @@
     return viewportRect;
 }
 
+IntSize FrameView::scrollOffsetForFixedPosition(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame)
+{
+    IntPoint constrainedPosition = ScrollableArea::constrainScrollPositionForOverhang(visibleContentRect, contentsSize, scrollPosition, scrollOrigin);
+
+    IntSize maxSize = contentsSize - visibleContentRect.size();
+
+    float dragFactorX = (fixedElementsLayoutRelativeToFrame || !maxSize.width()) ? 1 : (contentsSize.width() - visibleContentRect.width() * frameScaleFactor) / maxSize.width();
+    float dragFactorY = (fixedElementsLayoutRelativeToFrame || !maxSize.height()) ? 1 : (contentsSize.height() - visibleContentRect.height() * frameScaleFactor) / maxSize.height();
+
+    return IntSize(constrainedPosition.x() * dragFactorX / frameScaleFactor, constrainedPosition.y() * dragFactorY / frameScaleFactor);
+}
+
 IntSize FrameView::scrollOffsetForFixedPosition() const
 {
     IntRect visibleContentRect = this->visibleContentRect();
@@ -1519,7 +1531,7 @@
     IntPoint scrollPosition = this->scrollPosition();
     IntPoint scrollOrigin = this->scrollOrigin();
     float frameScaleFactor = m_frame ? m_frame->frameScaleFactor() : 1;
-    return WebCore::scrollOffsetForFixedPosition(visibleContentRect, contentsSize, scrollPosition, scrollOrigin, frameScaleFactor, fixedElementsLayoutRelativeToFrame());
+    return scrollOffsetForFixedPosition(visibleContentRect, contentsSize, scrollPosition, scrollOrigin, frameScaleFactor, fixedElementsLayoutRelativeToFrame());
 }
 
 bool FrameView::fixedElementsLayoutRelativeToFrame() const

Modified: trunk/Source/WebCore/page/FrameView.h (143403 => 143404)


--- trunk/Source/WebCore/page/FrameView.h	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/page/FrameView.h	2013-02-20 00:25:06 UTC (rev 143404)
@@ -222,6 +222,8 @@
     // Functions for querying the current scrolled position, negating the effects of overhang
     // and adjusting for page scale.
     IntSize scrollOffsetForFixedPosition() const;
+    // Static function can be called from another thread.
+    static IntSize scrollOffsetForFixedPosition(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame);
 
     bool fixedElementsLayoutRelativeToFrame() const;
 

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp (143403 => 143404)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.cpp	2013-02-20 00:25:06 UTC (rev 143404)
@@ -75,35 +75,6 @@
     return adoptRef(new ScrollingCoordinator(page));
 }
 
-static int fixedPositionScrollOffset(int visibleContentSize, int contentsSize, int scrollPosition, int scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame)
-{
-    int maxValue = contentsSize - visibleContentSize;
-    if (maxValue <= 0)
-        return 0;
-
-    if (!scrollOrigin) {
-        if (scrollPosition <= 0)
-            return 0;
-        if (scrollPosition > maxValue)
-            scrollPosition = maxValue;
-    } else {
-        if (scrollPosition >= 0)
-            return 0;
-        if (scrollPosition < -maxValue)
-            scrollPosition = -maxValue;
-    }
-
-    float dragFactor = fixedElementsLayoutRelativeToFrame ? 1 : (contentsSize - visibleContentSize * frameScaleFactor) / maxValue;
-    return scrollPosition * dragFactor / frameScaleFactor;
-}
-
-IntSize scrollOffsetForFixedPosition(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame)
-{
-    int x = fixedPositionScrollOffset(visibleContentRect.width(), contentsSize.width(), scrollPosition.x(), scrollOrigin.x(), frameScaleFactor, fixedElementsLayoutRelativeToFrame);
-    int y = fixedPositionScrollOffset(visibleContentRect.height(), contentsSize.height(), scrollPosition.y(), scrollOrigin.y(), frameScaleFactor, fixedElementsLayoutRelativeToFrame);
-    return IntSize(x, y);
-}
-
 ScrollingCoordinator::ScrollingCoordinator(Page* page)
     : m_page(page)
     , m_updateMainFrameScrollPositionTimer(this, &ScrollingCoordinator::updateMainFrameScrollPositionTimerFired)

Modified: trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h (143403 => 143404)


--- trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/page/scrolling/ScrollingCoordinator.h	2013-02-20 00:25:06 UTC (rev 143404)
@@ -64,9 +64,6 @@
 class ScrollingTree;
 #endif
 
-IntSize scrollOffsetForFixedPosition(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition,
-    const IntPoint& scrollOrigin, float frameScaleFactor, bool fixedElementsLayoutRelativeToFrame);
-
 enum SetOrSyncScrollingLayerPosition {
     SetScrollingLayerPosition,
     SyncScrollingLayerPosition

Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm (143403 => 143404)


--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeMac.mm	2013-02-20 00:25:06 UTC (rev 143404)
@@ -28,6 +28,7 @@
 
 #if ENABLE(THREADED_SCROLLING)
 
+#include "FrameView.h"
 #include "PlatformWheelEvent.h"
 #include "ScrollingCoordinator.h"
 #include "ScrollingTree.h"
@@ -304,7 +305,7 @@
     ASSERT(!shouldUpdateScrollLayerPositionOnMainThread());
     m_scrollLayer.get().position = CGPointMake(-position.x() + scrollOrigin().x(), -position.y() + scrollOrigin().y());
 
-    IntSize scrollOffsetForFixedChildren = WebCore::scrollOffsetForFixedPosition(viewportRect(), contentsSize(), position, scrollOrigin(), frameScaleFactor(), false);
+    IntSize scrollOffsetForFixedChildren = FrameView::scrollOffsetForFixedPosition(viewportRect(), contentsSize(), position, scrollOrigin(), frameScaleFactor(), false);
     if (m_counterScrollingLayer)
         m_counterScrollingLayer.get().position = FloatPoint(scrollOffsetForFixedChildren);
 

Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (143403 => 143404)


--- trunk/Source/WebCore/platform/ScrollableArea.cpp	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp	2013-02-20 00:25:06 UTC (rev 143404)
@@ -421,6 +421,38 @@
                    std::max(0, visibleHeight() + horizontalScrollbarHeight));
 }
 
+static int constrainedScrollPosition(int visibleContentSize, int contentsSize, int scrollPosition, int scrollOrigin)
+{
+    int maxValue = contentsSize - visibleContentSize;
+    if (maxValue <= 0)
+        return 0;
+
+    if (!scrollOrigin) {
+        if (scrollPosition <= 0)
+            return 0;
+        if (scrollPosition > maxValue)
+            scrollPosition = maxValue;
+    } else {
+        if (scrollPosition >= 0)
+            return 0;
+        if (scrollPosition < -maxValue)
+            scrollPosition = -maxValue;
+    }
+
+    return scrollPosition;
+}
+
+IntPoint ScrollableArea::constrainScrollPositionForOverhang(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin)
+{
+    return IntPoint(constrainedScrollPosition(visibleContentRect.width(), contentsSize.width(), scrollPosition.x(), scrollOrigin.x()),
+        constrainedScrollPosition(visibleContentRect.height(), contentsSize.height(), scrollPosition.y(), scrollOrigin.y()));
+}
+
+IntPoint ScrollableArea::constrainScrollPositionForOverhang(const IntPoint& scrollPosition)
+{
+    return constrainScrollPositionForOverhang(visibleContentRect(), contentsSize(), scrollPosition, scrollOrigin());
+}
+
 void ScrollableArea::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this);

Modified: trunk/Source/WebCore/platform/ScrollableArea.h (143403 => 143404)


--- trunk/Source/WebCore/platform/ScrollableArea.h	2013-02-20 00:20:29 UTC (rev 143403)
+++ trunk/Source/WebCore/platform/ScrollableArea.h	2013-02-20 00:25:06 UTC (rev 143404)
@@ -167,6 +167,9 @@
     // NOTE: Only called from Internals for testing.
     void setScrollOffsetFromInternals(const IntPoint&);
 
+    static IntPoint constrainScrollPositionForOverhang(const IntRect& visibleContentRect, const IntSize& contentsSize, const IntPoint& scrollPosition, const IntPoint& scrollOrigin);
+    IntPoint constrainScrollPositionForOverhang(const IntPoint& scrollPosition);
+
     // Let subclasses provide a way of asking for and servicing scroll
     // animations.
     virtual bool scheduleAnimation() { return false; }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to