Diff
Modified: trunk/Source/WebKit2/ChangeLog (162983 => 162984)
--- trunk/Source/WebKit2/ChangeLog 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/ChangeLog 2014-01-29 00:50:56 UTC (rev 162984)
@@ -1,3 +1,45 @@
+2014-01-28 Tim Horton <timothy_hor...@apple.com>
+
+ WebKit2 View Gestures (Swipe): Give WebCore the first crack at scroll events if it needs it
+ https://bugs.webkit.org/show_bug.cgi?id=127396
+
+ Reviewed by Anders Carlsson.
+
+ * UIProcess/API/ios/PageClientImplIOS.h:
+ * UIProcess/API/ios/PageClientImplIOS.mm:
+ (WebKit::PageClientImpl::wheelEventWasNotHandledByWebCore):
+ * UIProcess/API/mac/PageClientImpl.h:
+ * UIProcess/API/mac/PageClientImpl.mm:
+ (WebKit::PageClientImpl::wheelEventWasNotHandledByWebCore):
+ * UIProcess/API/mac/WKView.mm:
+ (-[WKView _wheelEventWasNotHandledByWebCore:]):
+ * UIProcess/API/mac/WKViewInternal.h:
+ * UIProcess/PageClient.h:
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::didReceiveEvent):
+ In addition to informing the page client about un-handled wheel events,
+ inform the ViewGestureController, in a roundabout way.
+
+ * UIProcess/mac/ViewGestureController.h:
+ Add and use SwipeDirection enum instead of 'bool willSwipeLeft'.
+
+ * UIProcess/mac/ViewGestureController.mm:
+ (WebKit::ViewGestureController::ViewGestureController):
+ (WebKit::ViewGestureController::handleScrollWheelEvent):
+ If we get a Begin scroll wheel event, any previously deferred
+ swipes are invalid.
+
+ If the page has subframes or wheel handlers, defer starting the
+ swipe until we get a wheelEventWasNotHandledByWebCore back from the WebProcess.
+
+ (WebKit::ViewGestureController::wheelEventWasNotHandledByWebCore):
+ Start the swipe if the WebProcess didn't eat the event.
+
+ (WebKit::ViewGestureController::trackSwipeGesture):
+ (WebKit::ViewGestureController::beginSwipeGesture):
+ (WebKit::ViewGestureController::handleSwipeGesture):
+ Use SwipeDirection.
+
2014-01-28 Anders Carlsson <ander...@apple.com>
Fix build.
Modified: trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.h (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.h 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.h 2014-01-29 00:50:56 UTC (rev 162984)
@@ -98,6 +98,7 @@
#endif
virtual RetainPtr<CGImageRef> takeViewSnapshot() override;
+ virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
virtual void mainDocumentDidReceiveMobileDocType() override;
Modified: trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.mm (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.mm 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/ios/PageClientImplIOS.mm 2014-01-29 00:50:56 UTC (rev 162984)
@@ -328,6 +328,11 @@
return nullptr;
}
+void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
+{
+ notImplemented();
+}
+
void PageClientImpl::mainDocumentDidReceiveMobileDocType()
{
[m_view _didReceiveMobileDocTypeForMainFrame];
Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.h 2014-01-29 00:50:56 UTC (rev 162984)
@@ -115,6 +115,7 @@
virtual void updateAcceleratedCompositingMode(const LayerTreeContext&);
virtual RetainPtr<CGImageRef> takeViewSnapshot() override;
+ virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) override;
virtual void accessibilityWebProcessTokenReceived(const IPC::DataReference&);
Modified: trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/mac/PageClientImpl.mm 2014-01-29 00:50:56 UTC (rev 162984)
@@ -32,6 +32,7 @@
#import "DictionaryPopupInfo.h"
#import "FindIndicator.h"
#import "NativeWebKeyboardEvent.h"
+#import "NativeWebWheelEvent.h"
#import "StringUtilities.h"
#import "WKAPICast.h"
#import "WKFullScreenWindowController.h"
@@ -444,6 +445,11 @@
return [m_wkView _takeViewSnapshot];
}
+void PageClientImpl::wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent& event)
+{
+ [m_wkView _wheelEventWasNotHandledByWebCore:event.nativeEvent()];
+}
+
void PageClientImpl::pluginFocusOrWindowFocusChanged(uint64_t pluginComplexTextInputIdentifier, bool pluginHasFocusAndWindowHasFocus)
{
[m_wkView _pluginFocusOrWindowFocusChanged:pluginHasFocusAndWindowHasFocus pluginComplexTextInputIdentifier:pluginComplexTextInputIdentifier];
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm 2014-01-29 00:50:56 UTC (rev 162984)
@@ -2564,6 +2564,11 @@
return adoptCF(CGImageCreateWithImageInRect(windowSnapshotImage.get(), NSRectToCGRect([window convertRectToBacking:croppedImageRect])));
}
+- (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event
+{
+ _data->_gestureController->wheelEventWasNotHandledByWebCore(event);
+}
+
- (void)_setAccessibilityWebProcessToken:(NSData *)data
{
_data->_remoteAccessibilityChild = WKAXRemoteElementForToken(data);
Modified: trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h 2014-01-29 00:50:56 UTC (rev 162984)
@@ -72,6 +72,7 @@
- (CALayer *)_acceleratedCompositingModeRootLayer;
- (RetainPtr<CGImageRef>)_takeViewSnapshot;
+- (void)_wheelEventWasNotHandledByWebCore:(NSEvent *)event;
- (void)_setAccessibilityWebProcessToken:(NSData *)data;
Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/PageClient.h 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h 2014-01-29 00:50:56 UTC (rev 162984)
@@ -174,6 +174,7 @@
virtual void setAcceleratedCompositingRootLayer(CALayer *) = 0;
virtual CALayer *acceleratedCompositingRootLayer() const = 0;
virtual RetainPtr<CGImageRef> takeViewSnapshot() = 0;
+ virtual void wheelEventWasNotHandledByWebCore(const NativeWebWheelEvent&) = 0;
#endif
#if USE(APPKIT)
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-01-29 00:50:56 UTC (rev 162984)
@@ -3535,8 +3535,11 @@
OwnPtr<Vector<NativeWebWheelEvent>> oldestCoalescedEvent = m_currentlyProcessedWheelEvents.takeFirst();
// FIXME: Dispatch additional events to the didNotHandleWheelEvent client function.
- if (!handled && m_uiClient.implementsDidNotHandleWheelEvent())
- m_uiClient.didNotHandleWheelEvent(this, oldestCoalescedEvent->last());
+ if (!handled) {
+ if (m_uiClient.implementsDidNotHandleWheelEvent())
+ m_uiClient.didNotHandleWheelEvent(this, oldestCoalescedEvent->last());
+ m_pageClient.wheelEventWasNotHandledByWebCore(oldestCoalescedEvent->last());
+ }
if (!m_wheelEventQueue.isEmpty())
processNextQueuedWheelEvent();
Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h 2014-01-29 00:50:56 UTC (rev 162984)
@@ -55,6 +55,8 @@
bool handleScrollWheelEvent(NSEvent *);
void didHitRenderTreeSizeThreshold();
+ void wheelEventWasNotHandledByWebCore(NSEvent *);
+
void endActiveGesture();
enum class ViewGestureType {
@@ -80,8 +82,10 @@
void endMagnificationGesture();
WebCore::FloatPoint scaledMagnificationOrigin(WebCore::FloatPoint origin, double scale);
- void beginSwipeGesture(WebBackForwardListItem* targetItem, bool swipingLeft);
- void handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, bool swipingLeft);
+ enum class SwipeDirection { Left, Right };
+ void trackSwipeGesture(NSEvent *, SwipeDirection);
+ void beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection);
+ void handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection);
void endSwipeGesture(WebBackForwardListItem* targetItem, bool cancelled);
void removeSwipeSnapshot();
void swipeSnapshotWatchdogTimerFired(WebCore::Timer<ViewGestureController>*);
@@ -103,6 +107,11 @@
RetainPtr<CALayer> m_swipeSnapshotLayer;
SwipeTransitionStyle m_swipeTransitionStyle;
WebCore::Timer<ViewGestureController> m_swipeWatchdogTimer;
+
+ // If we need to wait for content to decide if it is going to consume
+ // the scroll event that would have started a swipe, we'll fill these in.
+ bool m_hasPendingSwipe;
+ SwipeDirection m_pendingSwipeDirection;
};
} // namespace WebKit
Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.mm (162983 => 162984)
--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.mm 2014-01-29 00:48:17 UTC (rev 162983)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.mm 2014-01-29 00:50:56 UTC (rev 162984)
@@ -28,6 +28,7 @@
#if !PLATFORM(IOS)
+#import "NativeWebWheelEvent.h"
#import "WebPageGroup.h"
#import "ViewGestureControllerMessages.h"
#import "ViewGestureGeometryCollectorMessages.h"
@@ -98,6 +99,7 @@
, m_frameHandlesMagnificationGesture(false)
, m_swipeTransitionStyle(SwipeTransitionStyle::Overlap)
, m_swipeWatchdogTimer(this, &ViewGestureController::swipeSnapshotWatchdogTimerFired)
+ , m_hasPendingSwipe(false)
{
m_webPageProxy.process().addMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID(), *this);
}
@@ -249,6 +251,8 @@
if (event.phase != NSEventPhaseBegan)
return false;
+ m_hasPendingSwipe = false;
+
if (fabs(event.scrollingDeltaX) < fabs(event.scrollingDeltaY))
return false;
@@ -257,34 +261,56 @@
if (!willSwipeLeft && !willSwipeRight)
return false;
+ SwipeDirection direction = willSwipeLeft ? SwipeDirection::Left : SwipeDirection::Right;
+
if (!event.hasPreciseScrollingDeltas)
return false;
if (![NSEvent isSwipeTrackingFromScrollEventsEnabled])
return false;
+ if (m_webPageProxy.willHandleHorizontalScrollEvents()) {
+ m_hasPendingSwipe = true;
+ m_pendingSwipeDirection = direction;
+ return false;
+ }
+
+ trackSwipeGesture(event, direction);
+
+ return true;
+}
+
+void ViewGestureController::wheelEventWasNotHandledByWebCore(NSEvent *event)
+{
+ if (!m_hasPendingSwipe)
+ return;
+
+ m_hasPendingSwipe = false;
+ trackSwipeGesture(event, m_pendingSwipeDirection);
+}
+
+void ViewGestureController::trackSwipeGesture(NSEvent *event, SwipeDirection direction)
+{
ViewSnapshotStore::shared().recordSnapshot(m_webPageProxy);
- CGFloat maxProgress = willSwipeLeft ? 1 : 0;
- CGFloat minProgress = willSwipeRight ? -1 : 0;
- RefPtr<WebBackForwardListItem> targetItem = willSwipeLeft ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
+ CGFloat maxProgress = (direction == SwipeDirection::Left) ? 1 : 0;
+ CGFloat minProgress = (direction == SwipeDirection::Right) ? -1 : 0;
+ RefPtr<WebBackForwardListItem> targetItem = (direction == SwipeDirection::Left) ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
__block bool swipeCancelled = false;
[event trackSwipeEventWithOptions:0 dampenAmountThresholdMin:minProgress max:maxProgress usingHandler:^(CGFloat progress, NSEventPhase phase, BOOL isComplete, BOOL *stop) {
if (phase == NSEventPhaseBegan)
- this->beginSwipeGesture(targetItem.get(), willSwipeLeft);
+ this->beginSwipeGesture(targetItem.get(), direction);
CGFloat clampedProgress = std::min(std::max(progress, minProgress), maxProgress);
- this->handleSwipeGesture(targetItem.get(), clampedProgress, willSwipeLeft);
+ this->handleSwipeGesture(targetItem.get(), clampedProgress, direction);
if (phase == NSEventPhaseCancelled)
swipeCancelled = true;
if (isComplete)
this->endSwipeGesture(targetItem.get(), swipeCancelled);
}];
-
- return true;
}
-void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem, bool swipingLeft)
+void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection direction)
{
m_activeGestureType = ViewGestureType::Swipe;
@@ -333,13 +359,13 @@
[rootLayer setShadowPath:shadowPath.get()];
}
- if (swipingLeft)
+ if (direction == SwipeDirection::Left)
[rootLayer.superlayer insertSublayer:m_swipeSnapshotLayer.get() below:rootLayer];
else
[rootLayer.superlayer insertSublayer:m_swipeSnapshotLayer.get() above:rootLayer];
}
-void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, bool swipingLeft)
+void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection direction)
{
ASSERT(m_activeGestureType == ViewGestureType::Swipe);
@@ -348,13 +374,13 @@
double swipingLayerOffset = floor(width * progress);
if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
- if (swipingLeft)
+ if (direction == SwipeDirection::Left)
[rootLayer setPosition:CGPointMake(swipingLayerOffset, 0)];
else
[m_swipeSnapshotLayer setPosition:CGPointMake(width + swipingLayerOffset, 0)];
} else if (m_swipeTransitionStyle == SwipeTransitionStyle::Push) {
[rootLayer setPosition:CGPointMake(swipingLayerOffset, 0)];
- [m_swipeSnapshotLayer setPosition:CGPointMake((swipingLeft ? -width : width) + swipingLayerOffset, 0)];
+ [m_swipeSnapshotLayer setPosition:CGPointMake((direction == SwipeDirection::Left ? -width : width) + swipingLayerOffset, 0)];
}
}