Need WKWebView API to enable/disable link preview
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Aug 2015 21:27:19 +0000 (21:27 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Aug 2015 21:27:19 +0000 (21:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147573
-and corresponding-
rdar://problem/22077836

Reviewed by Dan Bernstein.

WKView implementation.
* UIProcess/API/Cocoa/WKViewPrivate.h:

New API. Call into WKView to handle Mac.
* UIProcess/API/Cocoa/WKWebView.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
(-[WKWebView allowsLinkPreview]):
(-[WKWebView setAllowsLinkPreview:]):

Remove the SPI declaration from WKWebViewPrivate in order to make this API.
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Handle the Mac side.
* UIProcess/API/mac/WKView.mm:
(-[WKView viewDidMoveToWindow]):
(-[WKView initWithFrame:processPool:configuration:webView:]):
(-[WKView allowsBackForwardNavigationGestures]):
(-[WKView allowsLinkPreview]):
(-[WKView setAllowsLinkPreview:]):

Don’t register previews when link preview is prevented.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _registerPreview]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index 8de2274..6fceb65 100644 (file)
@@ -1,3 +1,37 @@
+2015-08-03  Beth Dakin  <bdakin@apple.com>
+
+        Need WKWebView API to enable/disable link preview
+        https://bugs.webkit.org/show_bug.cgi?id=147573
+        -and corresponding-
+        rdar://problem/22077836
+
+        Reviewed by Dan Bernstein.
+
+        WKView implementation.
+        * UIProcess/API/Cocoa/WKViewPrivate.h:
+
+        New API. Call into WKView to handle Mac.
+        * UIProcess/API/Cocoa/WKWebView.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        (-[WKWebView allowsLinkPreview]):
+        (-[WKWebView setAllowsLinkPreview:]):
+
+        Remove the SPI declaration from WKWebViewPrivate in order to make this API.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        Handle the Mac side.
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView viewDidMoveToWindow]):
+        (-[WKView initWithFrame:processPool:configuration:webView:]):
+        (-[WKView allowsBackForwardNavigationGestures]):
+        (-[WKView allowsLinkPreview]):
+        (-[WKView setAllowsLinkPreview:]):
+
+        Don’t register previews when link preview is prevented.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _registerPreview]):
+
 2015-08-03  Tim Horton  <timothy_horton@apple.com>
 
         [iOS] Link previews sometimes don't hide the link highlight
index 819ab2e..454f504 100644 (file)
 
 - (void)setMagnification:(double)magnification centeredAtPoint:(NSPoint)point;
 
+- (void)setAllowsLinkPreview:(BOOL)allowsLinkPreview;
+- (BOOL)allowsLinkPreview;
+
 - (void)saveBackForwardSnapshotForCurrentItem;
 - (void)saveBackForwardSnapshotForItem:(WKBackForwardListItemRef)item;
 
index 04fe7fe..3c3bc01 100644 (file)
@@ -231,6 +231,12 @@ WK_CLASS_AVAILABLE(10_10, 8_0)
 */
 @property (WK_NULLABLE_PROPERTY nonatomic, copy) NSString *customUserAgent WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
+/*! @abstract A Boolean value indicating whether link preview is allowed for any
+ links inside this WKWebView.
+ @discussion The default value is NO on iOS and YES on Mac.
+ */
+@property (nonatomic) BOOL allowsLinkPreview WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
 #if TARGET_OS_IPHONE
 /*! @abstract The scroll view associated with the web view.
  */
index 316322e..f06ff78 100644 (file)
@@ -351,7 +351,6 @@ static bool shouldAllowPictureInPictureMediaPlayback()
     [self _updateScrollViewBackground];
 
     _viewportMetaTagWidth = -1;
-    _allowsLinkPreview = YES;
 
     [self _frameOrBoundsChanged];
 
@@ -659,6 +658,35 @@ static WKErrorCode callbackErrorCode(WebKit::CallbackBase::Error error)
     return toAPI(_page.get());
 }
 
+- (BOOL)allowsLinkPreview
+{
+#if PLATFORM(MAC)
+    return [_wkView allowsLinkPreview];
+#elif PLATFORM(IOS)
+    return _allowsLinkPreview;
+#endif
+}
+
+- (void)setAllowsLinkPreview:(BOOL)allowsLinkPreview
+{
+#if PLATFORM(MAC)
+    [_wkView setAllowsLinkPreview:allowsLinkPreview];
+    return;
+#elif PLATFORM(IOS)
+    if (_allowsLinkPreview == allowsLinkPreview)
+        return;
+
+    _allowsLinkPreview = allowsLinkPreview;
+
+#if HAVE(LINK_PREVIEW)
+    if (_allowsLinkPreview)
+        [_contentView _registerPreview];
+    else
+        [_contentView _unregisterPreview];
+#endif // HAVE(LINK_PREVIEW)
+#endif // PLATFORM(IOS)
+}
+
 #pragma mark iOS-specific methods
 
 #if PLATFORM(IOS)
@@ -3029,20 +3057,7 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
     return (_WKWebViewPrintFormatter *)viewPrintFormatter;
 }
 
-- (BOOL)_allowsLinkPreview
-{
-    return _allowsLinkPreview;
-}
-
-- (void)_setAllowsLinkPreview:(BOOL)allowsLinkPreview
-{
-    if (_allowsLinkPreview == allowsLinkPreview)
-        return;
-
-    _allowsLinkPreview = allowsLinkPreview;
-}
-
-#else
+#else // #if PLATFORM(IOS)
 
 #pragma mark - OS X-specific methods
 
index 2551c63..08e47f6 100644 (file)
@@ -131,9 +131,6 @@ WK_EXTERN NSString * const _WKShouldOpenExternalURLsKey WK_AVAILABLE(WK_MAC_TBA,
 
 @property (nonatomic, readonly) _WKWebViewPrintFormatter *_webViewPrintFormatter;
 
-// Indicating whether link preview is allowed. The default value is YES.
-@property (nonatomic, getter=_allowsLinkPreview, setter=_setAllowsLinkPreview:) BOOL _allowsLinkPreview WK_AVAILABLE(NA, WK_IOS_TBA);
-
 - (void)_beginInteractiveObscuredInsetsChange;
 - (void)_endInteractiveObscuredInsetsChange;
 - (void)_hideContentUntilNextUpdate;
index 1ede68a..4ef7a58 100644 (file)
@@ -261,6 +261,7 @@ struct WKViewInterpretKeyEventsParameters {
     BOOL _ignoresNonWheelEvents;
     BOOL _ignoresAllEvents;
     BOOL _allowsBackForwardNavigationGestures;
+    BOOL _allowsLinkPreview;
 
     RetainPtr<WKViewLayoutStrategy> _layoutStrategy;
     CGSize _minimumViewSize;
@@ -2706,7 +2707,7 @@ static void* keyValueObservingContext = &keyValueObservingContext;
         [self _accessibilityRegisterUIProcessTokens];
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
-        if (_data->_immediateActionGestureRecognizer && ![[self gestureRecognizers] containsObject:_data->_immediateActionGestureRecognizer.get()] && !_data->_ignoresNonWheelEvents)
+        if (_data->_immediateActionGestureRecognizer && ![[self gestureRecognizers] containsObject:_data->_immediateActionGestureRecognizer.get()] && !_data->_ignoresNonWheelEvents && _data->_allowsLinkPreview)
             [self addGestureRecognizer:_data->_immediateActionGestureRecognizer.get()];
 #endif
     } else {
@@ -3797,6 +3798,8 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     [workspaceNotificationCenter addObserver:self selector:@selector(_activeSpaceDidChange:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+    _data->_allowsLinkPreview = YES;
+
     if (Class gestureClass = NSClassFromString(@"NSImmediateActionGestureRecognizer")) {
         _data->_immediateActionGestureRecognizer = adoptNS([(NSImmediateActionGestureRecognizer *)[gestureClass alloc] init]);
         _data->_immediateActionController = adoptNS([[WKImmediateActionController alloc] initWithPage:*_data->_page view:self recognizer:_data->_immediateActionGestureRecognizer.get()]);
@@ -4221,6 +4224,26 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
     return _data->_allowsBackForwardNavigationGestures;
 }
 
+- (BOOL)allowsLinkPreview
+{
+    return _data->_allowsLinkPreview;
+}
+
+- (void)setAllowsLinkPreview:(BOOL)allowsLinkPreview
+{
+    if (_data->_allowsLinkPreview == allowsLinkPreview)
+        return;
+
+    _data->_allowsLinkPreview = allowsLinkPreview;
+    
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+    if (!allowsLinkPreview)
+        [self removeGestureRecognizer:_data->_immediateActionGestureRecognizer.get()];
+    else if (NSGestureRecognizer *immediateActionRecognizer = _data->_immediateActionGestureRecognizer.get())
+        [self addGestureRecognizer:immediateActionRecognizer];
+#endif
+}
+
 - (void)_setIgnoresAllEvents:(BOOL)ignoresAllEvents
 {
     _data->_ignoresAllEvents = ignoresAllEvents;
@@ -4244,8 +4267,10 @@ static NSString *pathWithUniqueFilenameForPath(NSString *path)
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
     if (ignoresNonWheelEvents)
         [self removeGestureRecognizer:_data->_immediateActionGestureRecognizer.get()];
-    else if (NSGestureRecognizer *immediateActionRecognizer = _data->_immediateActionGestureRecognizer.get())
-        [self addGestureRecognizer:immediateActionRecognizer];
+    else if (NSGestureRecognizer *immediateActionRecognizer = _data->_immediateActionGestureRecognizer.get()) {
+        if (_data->_allowsLinkPreview)
+            [self addGestureRecognizer:immediateActionRecognizer];
+    }
 #endif
 }
 
index f2bfbfb..052c5bf 100644 (file)
@@ -3211,6 +3211,9 @@ static bool isAssistableInputType(InputType type)
 
 - (void)_registerPreview
 {
+    if (!_webView.allowsLinkPreview)
+        return;
+
     _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
     [_previewItemController setDelegate:self];
     _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;