Title: [103187] trunk/Source/WebCore
Revision
103187
Author
ander...@apple.com
Date
2011-12-18 13:41:44 -0800 (Sun, 18 Dec 2011)

Log Message

Scroll the main frame on the scrolling thread
https://bugs.webkit.org/show_bug.cgi?id=74820

Reviewed by Andreas Kling.

* page/ScrollingCoordinator.cpp:
(WebCore::ScrollingCoordinator::handleWheelEvent):
Compute a scroll offset from the wheel event and tell the scrolling thread to scroll by the given offset.

* page/ScrollingCoordinator.h:
* page/mac/ScrollingCoordinatorMac.mm:
(WebCore::ScrollingCoordinator::scrollByOnScrollingThread):
Clamp the updated position to the minimum and maximum scrollable position.

(WebCore::ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread):
Actually reposition the layer.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103186 => 103187)


--- trunk/Source/WebCore/ChangeLog	2011-12-18 20:43:35 UTC (rev 103186)
+++ trunk/Source/WebCore/ChangeLog	2011-12-18 21:41:44 UTC (rev 103187)
@@ -1,3 +1,22 @@
+2011-12-18  Anders Carlsson  <ander...@apple.com>
+
+        Scroll the main frame on the scrolling thread
+        https://bugs.webkit.org/show_bug.cgi?id=74820
+
+        Reviewed by Andreas Kling.
+
+        * page/ScrollingCoordinator.cpp:
+        (WebCore::ScrollingCoordinator::handleWheelEvent):
+        Compute a scroll offset from the wheel event and tell the scrolling thread to scroll by the given offset.
+
+        * page/ScrollingCoordinator.h:
+        * page/mac/ScrollingCoordinatorMac.mm:
+        (WebCore::ScrollingCoordinator::scrollByOnScrollingThread):
+        Clamp the updated position to the minimum and maximum scrollable position.
+
+        (WebCore::ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread):
+        Actually reposition the layer.
+
 2011-12-18  Andreas Kling  <kl...@webkit.org>
 
         HTMLAllCollection: Get rid of stateful namedItem traversal.

Modified: trunk/Source/WebCore/page/ScrollingCoordinator.cpp (103186 => 103187)


--- trunk/Source/WebCore/page/ScrollingCoordinator.cpp	2011-12-18 20:43:35 UTC (rev 103186)
+++ trunk/Source/WebCore/page/ScrollingCoordinator.cpp	2011-12-18 21:41:44 UTC (rev 103187)
@@ -33,6 +33,7 @@
 #include "FrameView.h"
 #include "IntRect.h"
 #include "Page.h"
+#include "PlatformWheelEvent.h"
 #include <wtf/Functional.h>
 #include <wtf/MainThread.h>
 #include <wtf/PassRefPtr.h>
@@ -81,10 +82,25 @@
     // FIXME: Inform the scrolling thread that the frame geometry has changed.
 }
 
-bool ScrollingCoordinator::handleWheelEvent(const PlatformWheelEvent&)
+bool ScrollingCoordinator::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
 {
-    // FIXME: Implement.
-    return false;
+    // FIXME: Check for wheel event handlers.
+    // FIXME: Check if we're over a subframe or overflow div.
+    // FIXME: As soon as we've determined that we can handle the wheel event, we should do the
+    // bulk of the work on the scrolling thread and return from this function.
+    // FIXME: Handle rubberbanding.
+    float deltaX = wheelEvent.deltaX();
+    float deltaY = wheelEvent.deltaY();
+
+    // Slightly prefer scrolling vertically by applying the = case to deltaY
+    if (fabsf(deltaY) >= fabsf(deltaX))
+        deltaX = 0;
+    else
+        deltaY = 0;
+
+    IntSize scrollOffset = IntSize(-deltaX, -deltaY);
+    dispatchOnScrollingThread(bind(&ScrollingCoordinator::scrollByOnScrollingThread, this, scrollOffset));
+    return true;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/ScrollingCoordinator.h (103186 => 103187)


--- trunk/Source/WebCore/page/ScrollingCoordinator.h	2011-12-18 20:43:35 UTC (rev 103186)
+++ trunk/Source/WebCore/page/ScrollingCoordinator.h	2011-12-18 21:41:44 UTC (rev 103187)
@@ -71,6 +71,13 @@
     static bool isScrollingThread();
     static void dispatchOnScrollingThread(const Function<void()>&);
 
+
+    // The following functions can only be called from the scrolling thread.
+    void scrollByOnScrollingThread(const IntSize& offset);
+
+    // This function must be called with the main frame geometry mutex held.
+    void updateMainFrameScrollLayerPositionOnScrollingThread(const FloatPoint&);
+
 private:
     Page* m_page;
 

Modified: trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm (103186 => 103187)


--- trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm	2011-12-18 20:43:35 UTC (rev 103186)
+++ trunk/Source/WebCore/page/mac/ScrollingCoordinatorMac.mm	2011-12-18 21:41:44 UTC (rev 103187)
@@ -30,6 +30,7 @@
 #import "ScrollingCoordinator.h"
 
 #import "Page.h"
+#import <QuartzCore/QuartzCore.h>
 #import <wtf/Functional.h>
 #import <wtf/MainThread.h>
 #import <wtf/RetainPtr.h>
@@ -183,6 +184,36 @@
     return scrollingThread().dispatch(function);
 }
 
+void ScrollingCoordinator::scrollByOnScrollingThread(const IntSize& offset)
+{
+    ASSERT(isScrollingThread());
+
+    MutexLocker locker(m_mainFrameGeometryMutex);
+
+    // FIXME: Should we cache the scroll position as well or always get it from the layer?
+    IntPoint scrollPosition = IntPoint([m_mainFrameScrollLayer.get() position]);
+    scrollPosition = -scrollPosition;
+
+    scrollPosition += offset;
+    scrollPosition.clampNegativeToZero();
+
+    IntPoint maximumScrollPosition = IntPoint(m_mainFrameContentsSize.width() - m_mainFrameVisibleContentRect.width(), m_mainFrameContentsSize.height() - m_mainFrameVisibleContentRect.height());
+    scrollPosition = scrollPosition.shrunkTo(maximumScrollPosition);
+
+    updateMainFrameScrollLayerPositionOnScrollingThread(-scrollPosition);
+}
+
+void ScrollingCoordinator::updateMainFrameScrollLayerPositionOnScrollingThread(const FloatPoint& scrollLayerPosition)
+{
+    ASSERT(isScrollingThread());
+    ASSERT(!m_mainFrameGeometryMutex.tryLock());
+
+    [CATransaction begin];
+    [CATransaction setDisableActions:YES];
+    [m_mainFrameScrollLayer.get() setPosition:scrollLayerPosition];
+    [CATransaction commit];
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(THREADED_SCROLLING)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to