[iOS] Long press or link click can sometimes trigger during/after a preview
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jul 2015 23:27:21 +0000 (23:27 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jul 2015 23:27:21 +0000 (23:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147338
<rdar://problem/22020770>

Reviewed by Enrica Casucci.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _longPressRecognized:]):
Bail if we're previewing.

(-[WKContentView _dataForPreviewItemController:atPosition:type:]):
(-[WKContentView _presentedViewControllerForPreviewItemController:]):
Always avoid allowing clicks and start interaction when previewing a link.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index 2249fe8..291c60f 100644 (file)
@@ -1,3 +1,19 @@
+2015-07-27  Tim Horton  <timothy_horton@apple.com>
+
+        [iOS] Long press or link click can sometimes trigger during/after a preview
+        https://bugs.webkit.org/show_bug.cgi?id=147338
+        <rdar://problem/22020770>
+
+        Reviewed by Enrica Casucci.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _longPressRecognized:]):
+        Bail if we're previewing.
+
+        (-[WKContentView _dataForPreviewItemController:atPosition:type:]):
+        (-[WKContentView _presentedViewControllerForPreviewItemController:]):
+        Always avoid allowing clicks and start interaction when previewing a link.
+
 2015-07-27  Andreas Kling  <akling@apple.com>
 
         [iOS] Occasional crashes in WebPage::elementDidBlur()'s async block.
index 0279e58..91721ce 100644 (file)
@@ -1076,6 +1076,11 @@ static inline bool isSamePair(UIGestureRecognizer *a, UIGestureRecognizer *b, UI
 {
     ASSERT(gestureRecognizer == _longPressGestureRecognizer);
 
+#if HAVE(LINK_PREVIEW)
+    if ([_previewItemController interactionInProgress])
+        return;
+#endif
+
     _lastInteractionLocation = gestureRecognizer.startPoint;
 
     if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
@@ -3292,13 +3297,15 @@ static bool isAssistableInputType(InputType type)
     bool isValidURLForImagePreview = !coreTargetURL.isEmpty() && (WebCore::protocolIsInHTTPFamily(coreTargetURL) || WebCore::protocolIs(coreTargetURL, "data"));
 
     if ([_previewItemController type] == UIPreviewItemTypeLink) {
+        _highlightLongPressCanClick = NO;
+        _page->startInteractionWithElementAtPosition(_positionInformation.point);
+
         // Treat animated images like a link preview
         if (isValidURLForImagePreview && _positionInformation.isAnimatedImage) {
             RetainPtr<_WKActivatedElementInfo> animatedImageElementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
 
             if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForAnimatedImageAtURL:defaultActions:elementInfo:imageSize:)]) {
                 RetainPtr<NSArray> actions = [_actionSheetAssistant defaultActionsForImageSheet:animatedImageElementInfo.get()];
-                _highlightLongPressCanClick = NO;
                 return [uiDelegate _webView:_webView previewViewControllerForAnimatedImageAtURL:targetURL defaultActions:actions.get() elementInfo:animatedImageElementInfo.get() imageSize:_positionInformation.image->size()];
             }
         }
@@ -3306,16 +3313,11 @@ static bool isAssistableInputType(InputType type)
         RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink URL:targetURL location:_positionInformation.point title:_positionInformation.title rect:_positionInformation.bounds image:_positionInformation.image.get()]);
 
         RetainPtr<NSArray> actions = [_actionSheetAssistant defaultActionsForLinkSheet:elementInfo.get()];
-        if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:defaultActions:elementInfo:)]) {
-            _highlightLongPressCanClick = NO;
-            _page->startInteractionWithElementAtPosition(_positionInformation.point);
+        if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:defaultActions:elementInfo:)])
             return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL defaultActions:actions.get() elementInfo:elementInfo.get()];
-        }
 
-        if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:)]) {
-            _highlightLongPressCanClick = NO;
+        if ([uiDelegate respondsToSelector:@selector(_webView:previewViewControllerForURL:)])
             return [uiDelegate _webView:_webView previewViewControllerForURL:targetURL];
-        }
         return nil;
     }