Add WKUIDelegatePrivate callback corresponding to PageUIClient's didNotHandleWheelEvent
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Aug 2017 22:10:57 +0000 (22:10 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 24 Aug 2017 22:10:57 +0000 (22:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175957
<rdar://problem/29270035>

Reviewed by Geoffrey Garen.

Source/WebKit:

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didNotHandleWheelEvent):

Tools:

* TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
(synthesizeWheelEvents):
(-[WheelDelegate _webView:didNotHandleWheelEvent:]):
(-[WheelDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
(TEST):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm

index 5ef49c0..96dc280 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-24  Alex Christensen  <achristensen@webkit.org>
+
+        Add WKUIDelegatePrivate callback corresponding to PageUIClient's didNotHandleWheelEvent
+        https://bugs.webkit.org/show_bug.cgi?id=175957
+        <rdar://problem/29270035>
+
+        Reviewed by Geoffrey Garen.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::didNotHandleWheelEvent):
+
 2017-08-24  Tim Horton  <timothy_horton@apple.com>
 
         Overflow scroll views are inset to avoid safe areas even if the parent view is not
index 5dce93d..97d2adb 100644 (file)
@@ -129,6 +129,7 @@ struct UIEdgeInsets;
 - (void)_focusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_unfocusWebView:(WKWebView *)webView WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_webView:(WKWebView *)webView takeFocus:(_WKFocusDirection)direction WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
 #endif
index 250e532..64ab425 100644 (file)
@@ -100,6 +100,7 @@ private:
         void takeFocus(WebPageProxy*, WKFocusDirection) final;
         void focus(WebPageProxy*) final;
         void unfocus(WebPageProxy*) final;
+        void didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent&) final;
         bool runOpenPanel(WebPageProxy*, WebFrameProxy*, const WebCore::SecurityOriginData&, API::OpenPanelParameters*, WebOpenPanelResultListenerProxy*) final;
 #endif
         bool decidePolicyForUserMediaPermissionRequest(WebPageProxy&, WebFrameProxy&, API::SecurityOrigin&, API::SecurityOrigin&, UserMediaPermissionRequestProxy&) final;
@@ -144,6 +145,7 @@ private:
         bool focusWebView : 1;
         bool unfocusWebView : 1;
         bool webViewTakeFocus : 1;
+        bool webViewDidNotHandleWheelEvent : 1;
         bool webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler : 1;
 #endif
         bool webViewDecideDatabaseQuotaForSecurityOriginCurrentQuotaCurrentOriginUsageCurrentDatabaseUsageExpectedUsageDecisionHandler : 1;
index 279a259..b54ec4d 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "APIFrameInfo.h"
 #import "CompletionHandlerCallChecker.h"
+#import "NativeWebWheelEvent.h"
 #import "NavigationActionData.h"
 #import "UserMediaPermissionCheckProxy.h"
 #import "UserMediaPermissionRequestProxy.h"
@@ -104,6 +105,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.focusWebView = [delegate respondsToSelector:@selector(_focusWebView:)];
     m_delegateMethods.unfocusWebView = [delegate respondsToSelector:@selector(_unfocusWebView:)];
     m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
+    m_delegateMethods.webViewDidNotHandleWheelEvent = [delegate respondsToSelector:@selector(_webView:didNotHandleWheelEvent:)];
     m_delegateMethods.webViewRunOpenPanelWithParametersInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runOpenPanelWithParameters:initiatedByFrame:completionHandler:)];
 #endif
 
@@ -423,6 +425,18 @@ void UIDelegate::UIClient::unfocus(WebKit::WebPageProxy*)
     [(id <WKUIDelegatePrivate>)delegate _unfocusWebView:m_uiDelegate.m_webView];
 }
 
+void UIDelegate::UIClient::didNotHandleWheelEvent(WebKit::WebPageProxy*, const WebKit::NativeWebWheelEvent& event)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewDidNotHandleWheelEvent)
+        return;
+    
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return;
+    
+    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didNotHandleWheelEvent:event.nativeEvent()];
+}
+
 void UIDelegate::UIClient::showPage(WebPageProxy*)
 {
     if (!m_uiDelegate.m_delegateMethods.showWebView)
index 7c19201..32069c3 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-24  Alex Christensen  <achristensen@webkit.org>
+
+        Add WKUIDelegatePrivate callback corresponding to PageUIClient's didNotHandleWheelEvent
+        https://bugs.webkit.org/show_bug.cgi?id=175957
+        <rdar://problem/29270035>
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/UIDelegate.mm:
+        (synthesizeWheelEvents):
+        (-[WheelDelegate _webView:didNotHandleWheelEvent:]):
+        (-[WheelDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+        (TEST):
+
 2017-08-24  Tim Horton  <timothy_horton@apple.com>
 
         Layout size override changes during in-flight animated resize are dropped on the floor forever
index 3a5c3b1..c8002a2 100644 (file)
@@ -136,6 +136,45 @@ TEST(WebKit2, Focus)
     ASSERT_EQ(takenDirection, WKFocusDirectionBackward);
 }
 
+static void synthesizeWheelEvents(NSView *view, int x, int y)
+{
+    RetainPtr<CGEventRef> cgScrollEvent = adoptCF(CGEventCreateScrollWheelEvent(nullptr, kCGScrollEventUnitLine, 2, y, x));
+    NSEvent* event = [NSEvent eventWithCGEvent:cgScrollEvent.get()];
+    [view scrollWheel:event];
+    
+    // Wheel events get coalesced sometimes. Make more events until one is not handled.
+    dispatch_async(dispatch_get_main_queue(), ^ {
+        synthesizeWheelEvents(view, x, y);
+    });
+}
+
+@interface WheelDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation WheelDelegate
+
+- (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event
+{
+    done = true;
+}
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler
+{
+    completionHandler();
+    synthesizeWheelEvents(webView, 1, 1);
+}
+
+@end
+
+TEST(WebKit2, DidNotHandleWheelEvent)
+{
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
+    auto delegate = adoptNS([[WheelDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+    [webView loadHTMLString:@"<body onload='alert(\"ready\")' onwheel='()=>{}' style='overflow:hidden; height:10000vh;'></body>" baseURL:[NSURL URLWithString:@"http://example.com/"]];
+    TestWebKitAPI::Util::run(&done);
+}
+
 #endif // PLATFORM(MAC)
 
 #endif // WK_API_ENABLED