Use additional members and protocols from WebKitAdditions in WKContentViewInteraction
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 19:35:30 +0000 (19:35 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Apr 2019 19:35:30 +0000 (19:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197184
<rdar://problem/50113848>

Reviewed by Wenson Hsieh.

WebKitAdditions defines some macros to include additional members
and protocols for WKContentViewInteraction.

It also defines some new functions. Provide empty version
of those functions when WebKitAdditions is not available.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _registerPreview]):
(-[WKContentView _unregisterPreview]):

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm

index 5c2e7bb..d334713 100644 (file)
@@ -1,3 +1,22 @@
+2019-04-22  Dean Jackson  <dino@apple.com>
+
+        Use additional members and protocols from WebKitAdditions in WKContentViewInteraction
+        https://bugs.webkit.org/show_bug.cgi?id=197184
+        <rdar://problem/50113848>
+
+        Reviewed by Wenson Hsieh.
+
+        WebKitAdditions defines some macros to include additional members
+        and protocols for WKContentViewInteraction.
+
+        It also defines some new functions. Provide empty version
+        of those functions when WebKitAdditions is not available.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _registerPreview]):
+        (-[WKContentView _unregisterPreview]):
+
 2019-04-23  Tim Horton  <timothy_horton@apple.com>
 
         Action sheet shares a stringified URL instead of a URL object
 2019-04-23  Tim Horton  <timothy_horton@apple.com>
 
         Action sheet shares a stringified URL instead of a URL object
index 8c89214..2d1a0ab 100644 (file)
 #import <wtf/WeakObjCPtr.h>
 #import <wtf/text/WTFString.h>
 
 #import <wtf/WeakObjCPtr.h>
 #import <wtf/text/WTFString.h>
 
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKInteractionPreviewAdditions.h>)
+#import <WebKitAdditions/WKInteractionPreviewAdditions.h>
+#else
+#ifndef ADDITIONAL_LINK_PREVIEW_MEMBERS
+#define ADDITIONAL_LINK_PREVIEW_MEMBERS
+#endif
+#ifndef ADDITIONAL_LINK_PREVIEW_PROTOCOLS
+#define ADDITIONAL_LINK_PREVIEW_PROTOCOLS
+#endif
+#endif
+
 namespace API {
 class OpenPanelParameters;
 }
 namespace API {
 class OpenPanelParameters;
 }
@@ -240,6 +251,7 @@ struct WKAutoCorrectionData {
     Vector<bool> _focusStateStack;
 #if HAVE(LINK_PREVIEW)
     RetainPtr<UIPreviewItemController> _previewItemController;
     Vector<bool> _focusStateStack;
 #if HAVE(LINK_PREVIEW)
     RetainPtr<UIPreviewItemController> _previewItemController;
+    ADDITIONAL_LINK_PREVIEW_MEMBERS
 #endif
 
     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
 #endif
 
     std::unique_ptr<WebKit::SmartMagnificationController> _smartMagnificationController;
@@ -503,7 +515,7 @@ FOR_EACH_PRIVATE_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
 @end
 
 #if HAVE(LINK_PREVIEW)
 @end
 
 #if HAVE(LINK_PREVIEW)
-@interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate>
+@interface WKContentView (WKInteractionPreview) <UIPreviewItemDelegate ADDITIONAL_LINK_PREVIEW_PROTOCOLS>
 
 @property (nonatomic, readonly) BOOL shouldUsePreviewForLongPress;
 
 
 @property (nonatomic, readonly) BOOL shouldUsePreviewForLongPress;
 
index 9f9e47d..e8a893d 100644 (file)
@@ -148,6 +148,10 @@ SOFT_LINK_CLASS(ManagedConfiguration, MCProfileConnection);
 SOFT_LINK_CONSTANT(ManagedConfiguration, MCFeatureDefinitionLookupAllowed, NSString *)
 #endif
 
 SOFT_LINK_CONSTANT(ManagedConfiguration, MCFeatureDefinitionLookupAllowed, NSString *)
 #endif
 
+#if USE(APPLE_INTERNAL_SDK) && __has_include(<WebKitAdditions/WKInteractionPreviewAdditions.h>)
+#import <WebKitAdditions/WKInteractionPreviewAdditions.h>
+#endif
+
 #if PLATFORM(WATCHOS)
 
 @interface WKContentView (WatchSupport) <WKFocusedFormControlViewDelegate, WKSelectMenuListViewControllerDelegate, WKTextInputListViewControllerDelegate>
 #if PLATFORM(WATCHOS)
 
 @interface WKContentView (WatchSupport) <WKFocusedFormControlViewDelegate, WKSelectMenuListViewControllerDelegate, WKTextInputListViewControllerDelegate>
@@ -7143,6 +7147,14 @@ static BOOL shouldUsePreviewForLongPress()
 {
     return NO;
 }
 {
     return NO;
 }
+
+- (void)_registerPreviewLongPress
+{
+}
+
+- (void)_unregisterPreviewLongPress
+{
+}
 #endif
 
 - (BOOL)shouldUsePreviewForLongPress
 #endif
 
 - (BOOL)shouldUsePreviewForLongPress
@@ -7155,19 +7167,27 @@ static BOOL shouldUsePreviewForLongPress()
     if (!_webView.allowsLinkPreview)
         return;
 
     if (!_webView.allowsLinkPreview)
         return;
 
-    _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
-    [_previewItemController setDelegate:self];
-    _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;
-    if ([_previewItemController respondsToSelector:@selector(presentationSecondaryGestureRecognizer)])
-        _previewSecondaryGestureRecognizer = _previewItemController.get().presentationSecondaryGestureRecognizer;
+    if (shouldUsePreviewForLongPress())
+        [self _registerPreviewLongPress];
+    else {
+        _previewItemController = adoptNS([[UIPreviewItemController alloc] initWithView:self]);
+        [_previewItemController setDelegate:self];
+        _previewGestureRecognizer = _previewItemController.get().presentationGestureRecognizer;
+        if ([_previewItemController respondsToSelector:@selector(presentationSecondaryGestureRecognizer)])
+            _previewSecondaryGestureRecognizer = _previewItemController.get().presentationSecondaryGestureRecognizer;
+    }
 }
 
 - (void)_unregisterPreview
 {
 }
 
 - (void)_unregisterPreview
 {
-    [_previewItemController setDelegate:nil];
-    _previewGestureRecognizer = nil;
-    _previewSecondaryGestureRecognizer = nil;
-    _previewItemController = nil;
+    if (shouldUsePreviewForLongPress())
+        [self _unregisterPreviewLongPress];
+    else {
+        [_previewItemController setDelegate:nil];
+        _previewGestureRecognizer = nil;
+        _previewSecondaryGestureRecognizer = nil;
+        _previewItemController = nil;
+    }
 }
 
 - (BOOL)_interactionShouldBeginFromPreviewItemController:(UIPreviewItemController *)controller forPosition:(CGPoint)position
 }
 
 - (BOOL)_interactionShouldBeginFromPreviewItemController:(UIPreviewItemController *)controller forPosition:(CGPoint)position