scroll snap points do not properly account for zoomed pages
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 19:13:36 +0000 (19:13 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 15 Mar 2015 19:13:36 +0000 (19:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142706
<rdar://problem/20165771>

Reviewed by Anders Carlsson.

When a WebView is zoomed (such that it has a non-unity pageScaleFactor), we need to account for this
scaling value when selecting our correct scroll snap point target, as well as when specifying the
pixel location for our animation to target.

* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h:
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::pageScaleFactor): Added new delegate method.
* platform/cocoa/ScrollController.h:
(WebCore::ScrollControllerClient::pageScaleFactor): Added new default delegate.
* platform/cocoa/ScrollController.mm:
(WebCore::ScrollController::beginScrollSnapAnimation): Calculate the correct scroll target
based on the page scale factor.

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

Source/WebCore/ChangeLog
Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h
Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
Source/WebCore/platform/cocoa/ScrollController.h
Source/WebCore/platform/cocoa/ScrollController.mm

index b2a70dd..af94782 100644 (file)
@@ -1,3 +1,24 @@
+2015-03-15  Brent Fulgham  <bfulgham@apple.com>
+
+        scroll snap points do not properly account for zoomed pages
+        https://bugs.webkit.org/show_bug.cgi?id=142706
+        <rdar://problem/20165771>
+
+        Reviewed by Anders Carlsson.
+
+        When a WebView is zoomed (such that it has a non-unity pageScaleFactor), we need to account for this
+        scaling value when selecting our correct scroll snap point target, as well as when specifying the
+        pixel location for our animation to target.
+
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h:
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::pageScaleFactor): Added new delegate method.
+        * platform/cocoa/ScrollController.h:
+        (WebCore::ScrollControllerClient::pageScaleFactor): Added new default delegate.
+        * platform/cocoa/ScrollController.mm:
+        (WebCore::ScrollController::beginScrollSnapAnimation): Calculate the correct scroll target
+        based on the page scale factor.
+
 2015-03-15  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Fix run-bindings-tests on the WinCairo bot
index 3dc8b58..7f655f2 100644 (file)
@@ -82,6 +82,7 @@ private:
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const override;
     void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
+    float pageScaleFactor() const override;
 #endif
 
     void logExposedUnfilledArea();
index 2707251..65794d6 100644 (file)
@@ -558,6 +558,11 @@ void ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis(ScrollEventAxis a
 
     immediateScrollBy(change - currentPosition);
 }
+
+float ScrollingTreeFrameScrollingNodeMac::pageScaleFactor() const
+{
+    return frameScaleFactor();
+}
 #endif
 
 } // namespace WebCore
index beb95c0..ba918de 100644 (file)
@@ -86,7 +86,11 @@ public:
     virtual void stopScrollSnapTimer(ScrollEventAxis)
     {
         // Override to perform client-specific scroll snap point end logic
-        
+    }
+
+    virtual float pageScaleFactor() const
+    {
+        return 1.0f;
     }
 #endif
 };
index 6b052cf..b25df87 100644 (file)
@@ -684,9 +684,11 @@ void ScrollController::beginScrollSnapAnimation(ScrollEventAxis axis, ScrollSnap
     if (snapState.m_snapOffsets.isEmpty())
         return;
 
-    projectedScrollDestination = std::min(std::max(projectedScrollDestination, snapState.m_snapOffsets.first()), snapState.m_snapOffsets.last());
+    float scaleFactor = m_client->pageScaleFactor();
+    
+    projectedScrollDestination = std::min(std::max(LayoutUnit(projectedScrollDestination / scaleFactor), snapState.m_snapOffsets.first()), snapState.m_snapOffsets.last());
     snapState.m_initialOffset = offset;
-    snapState.m_targetOffset = closestSnapOffset<LayoutUnit, float>(snapState.m_snapOffsets, projectedScrollDestination, initialWheelDelta);
+    snapState.m_targetOffset = scaleFactor * closestSnapOffset<LayoutUnit, float>(snapState.m_snapOffsets, projectedScrollDestination, initialWheelDelta);
     if (snapState.m_initialOffset == snapState.m_targetOffset)
         return;