[iOS] Introduce -didNotHandleTapAsClickAtPoint: to WKUIDelegatePrivate
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Apr 2014 16:56:36 +0000 (16:56 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Apr 2014 16:56:36 +0000 (16:56 +0000)
https://bugs.webkit.org/show_bug.cgi?id=132316

Reviewed by Darin Adler.

One WebKit2 client is interested to know if a tap was not handled by an element that responds to clicks.
Introduce a new, private WKUIDelegate method telling it that a tap at a location was not handled as a click on
an element.

* UIProcess/API/APIUIClient.h:
(API::UIClient::didNotHandleTapAsClick):
* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::UIDelegate::UIClient::didNotHandleTapAsClick):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::didNotHandleTapAsClick):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::handleTap): Sent Messages::WebPageProxy::DidNotHandleTapAsClick if the tap wasn't handled, no
node responded to the click event, or the responding node wasn't an element.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APIUIClient.h
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.h
Source/WebKit2/UIProcess/Cocoa/UIDelegate.mm
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/UIProcess/ios/WebPageProxyIOS.mm
Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

index 78310fd..e1e33d3 100644 (file)
@@ -1,3 +1,29 @@
+2014-04-28  Andy Estes  <aestes@apple.com>
+
+        [iOS] Introduce -didNotHandleTapAsClickAtPoint: to WKUIDelegatePrivate
+        https://bugs.webkit.org/show_bug.cgi?id=132316
+
+        Reviewed by Darin Adler.
+
+        One WebKit2 client is interested to know if a tap was not handled by an element that responds to clicks.
+        Introduce a new, private WKUIDelegate method telling it that a tap at a location was not handled as a click on
+        an element.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::didNotHandleTapAsClick):
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::UIDelegate::UIClient::didNotHandleTapAsClick):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::didNotHandleTapAsClick):
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::handleTap): Sent Messages::WebPageProxy::DidNotHandleTapAsClick if the tap wasn't handled, no
+        node responded to the click event, or the responding node wasn't an element.
+
 2014-04-29  Zan Dobersek  <zdobersek@igalia.com>
 
         [GTK][WK2] Avoid Vector copies in WebViewBaseInputMethodFilter::setPreedit()
index c3d5c70..7dbb231 100644 (file)
@@ -135,6 +135,7 @@ public:
 
 #if PLATFORM(IOS)
     virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) { return std::move(defaultActions); }
+    virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) { }
 #endif
 };
 
index 598d800..24869cc 100644 (file)
@@ -35,6 +35,7 @@
 
 #if TARGET_OS_IPHONE
 - (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray *)defaultActions;
+- (void)_webView:(WKWebView *)webView didNotHandleTapAsClickAtPoint:(CGPoint)point;
 #endif
 
 @end
index c168cbc..16768f4 100644 (file)
@@ -64,6 +64,7 @@ private:
         virtual void runJavaScriptPrompt(WebKit::WebPageProxy*, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy*, std::function<void (const WTF::String&)> completionHandler) override;
     #if PLATFORM(IOS)
         virtual RetainPtr<NSArray> actionsForElement(_WKActivatedElementInfo *, RetainPtr<NSArray> defaultActions) override;
+        virtual void didNotHandleTapAsClick(const WebCore::IntPoint&) override;
     #endif
 
         UIDelegate& m_uiDelegate;
@@ -79,6 +80,7 @@ private:
         bool webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler : 1;
 #if PLATFORM(IOS)
         bool webViewActionsForElementDefaultActions : 1;
+        bool webViewDidNotHandleTapAsClickAtPoint : 1;
 #endif
     } m_delegateMethods;
 };
index bba3e8e..b77fa11 100644 (file)
@@ -67,6 +67,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewRunJavaScriptTextInputPanelWithPromptDefaultTextInitiatedByFrameCompletionHandler = [delegate respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:completionHandler:)];
 #if PLATFORM(IOS)
     m_delegateMethods.webViewActionsForElementDefaultActions = [delegate respondsToSelector:@selector(_webView:actionsForElement:defaultActions:)];
+    m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint = [delegate respondsToSelector:@selector(_webView:didNotHandleTapAsClickAtPoint:)];
 #endif
 }
 
@@ -175,6 +176,18 @@ RetainPtr<NSArray> UIDelegate::UIClient::actionsForElement(_WKActivatedElementIn
 
     return [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView actionsForElement:elementInfo defaultActions:defaultActions.get()];
 }
+
+void UIDelegate::UIClient::didNotHandleTapAsClick(const WebCore::IntPoint& point)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewDidNotHandleTapAsClickAtPoint)
+        return;
+
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return;
+
+    [static_cast<id <WKUIDelegatePrivate>>(delegate) _webView:m_uiDelegate.m_webView didNotHandleTapAsClickAtPoint:point];
+}
 #endif
 
 } // namespace WebKit
index e7fc3dc..cb8d312 100644 (file)
@@ -614,6 +614,7 @@ public:
     void applicationWillResignActive();
     void applicationDidBecomeActive();
     void zoomToRect(WebCore::FloatRect, double minimumScale, double maximumScale);
+    void didNotHandleTapAsClick(const WebCore::IntPoint&);
 #endif
 
     const EditorState& editorState() const { return m_editorState; }
index 18836a8..aa6e399 100644 (file)
@@ -169,6 +169,7 @@ messages -> WebPageProxy {
     DidUpdateBlockSelectionWithTouch(uint32_t touch, uint32_t flags, float growThreshold, float shrinkThreshold)
     ShowPlaybackTargetPicker(bool hasVideo, WebCore::IntRect elementRect)
     ZoomToRect(WebCore::FloatRect rect, double minimumScale, double maximumScale)
+    DidNotHandleTapAsClick(WebCore::IntPoint point)
 #endif
 #if PLATFORM(GTK)
     PrintFinishedCallback(WebCore::ResourceError error, uint64_t callbackID)
index 3f4683b..129e96a 100644 (file)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(IOS)
 
+#import "APIUIClient.h"
 #import "DataReference.h"
 #import "EditingRange.h"
 #import "NativeWebKeyboardEvent.h"
@@ -580,6 +581,11 @@ void WebPageProxy::zoomToRect(FloatRect rect, double minimumScale, double maximu
     m_pageClient.zoomToRect(rect, minimumScale, maximumScale);
 }
 
+void WebPageProxy::didNotHandleTapAsClick(const WebCore::IntPoint& point)
+{
+    m_uiClient->didNotHandleTapAsClick(point);
+}
+
 #if USE(QUICK_LOOK)
     
 void WebPageProxy::didStartLoadForQuickLookDocumentInMainFrame(const String& fileName, const String& uti)
index 6ffcd5b..30e0f94 100644 (file)
@@ -322,7 +322,7 @@ void WebPage::handleTap(const IntPoint& point)
 {
     Frame& mainframe = m_page->mainFrame();
     FloatPoint adjustedPoint;
-    mainframe.nodeRespondingToClickEvents(point, adjustedPoint);
+    Node* nodeRespondingToClick = mainframe.nodeRespondingToClickEvents(point, adjustedPoint);
     IntPoint roundedAdjustedPoint = roundedIntPoint(adjustedPoint);
 
     WKBeginObservingContentChanges(true);
@@ -336,9 +336,10 @@ void WebPage::handleTap(const IntPoint& point)
     RefPtr<Element> oldFocusedElement = oldFocusedFrame ? oldFocusedFrame->document()->focusedElement() : nullptr;
     m_userIsInteracting = true;
 
+    bool tapWasHandled = false;
     m_lastInteractionLocation = roundedAdjustedPoint;
-    mainframe.eventHandler().handleMousePressEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, 0));
-    mainframe.eventHandler().handleMouseReleaseEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MouseReleased, 1, false, false, false, false, 0));
+    tapWasHandled |= mainframe.eventHandler().handleMousePressEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MousePressed, 1, false, false, false, false, 0));
+    tapWasHandled |= mainframe.eventHandler().handleMouseReleaseEvent(PlatformMouseEvent(roundedAdjustedPoint, roundedAdjustedPoint, LeftButton, PlatformEvent::MouseReleased, 1, false, false, false, false, 0));
 
     RefPtr<Frame> newFocusedFrame = m_page->focusController().focusedFrame();
     RefPtr<Element> newFocusedElement = newFocusedFrame ? newFocusedFrame->document()->focusedElement() : nullptr;
@@ -351,6 +352,9 @@ void WebPage::handleTap(const IntPoint& point)
         elementDidFocus(newFocusedElement.get());
 
     m_userIsInteracting = false;
+
+    if (!tapWasHandled || !nodeRespondingToClick || !nodeRespondingToClick->isElementNode())
+        send(Messages::WebPageProxy::DidNotHandleTapAsClick(point));
 }
 
 void WebPage::tapHighlightAtPosition(uint64_t requestID, const FloatPoint& position)