[iOS DnD] [WK2] Add SPI to enable, disable, or follow default behavior for DnD on...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Jul 2017 02:39:12 +0000 (02:39 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 13 Jul 2017 02:39:12 +0000 (02:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174440
<rdar://problem/33272627>

Reviewed by Beth Dakin.

Adds a new _dragInteractionPolicy property to WKWebView, which an internal client may use to always allow
dragging out of the web view (_WKDragInteractionPolicyAlwaysEnable), never allow
(_WKDragInteractionPolicyAlwaysDisable) or just use the default device-dependent behavior
(_WKDragInteractionPolicyDefault).

Also removes an extraneous class from WKContentViewInteraction.mm that is no longer used anywhere.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):

Set _dragInteractionPolicy to _WKDragInteractionPolicyDefault upon initialization.

(-[WKWebView _dragInteractionPolicy]):
(-[WKWebView _setDragInteractionPolicy:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(shouldEnableDragInteractionForPolicy):
(-[WKContentView _didChangeDragInteractionPolicy]):

Called by the WKWebView when its _dragInteractionPolicy changes. The content view updates its
UIDragInteraction's -enabled property here in response.

(-[WKContentView setupDataInteractionDelegates]):

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

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

index 231efc2..a83f367 100644 (file)
@@ -1,3 +1,36 @@
+2017-07-12  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS DnD] [WK2] Add SPI to enable, disable, or follow default behavior for DnD on a WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=174440
+        <rdar://problem/33272627>
+
+        Reviewed by Beth Dakin.
+
+        Adds a new _dragInteractionPolicy property to WKWebView, which an internal client may use to always allow
+        dragging out of the web view (_WKDragInteractionPolicyAlwaysEnable), never allow
+        (_WKDragInteractionPolicyAlwaysDisable) or just use the default device-dependent behavior
+        (_WKDragInteractionPolicyDefault).
+
+        Also removes an extraneous class from WKContentViewInteraction.mm that is no longer used anywhere.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+
+        Set _dragInteractionPolicy to _WKDragInteractionPolicyDefault upon initialization.
+
+        (-[WKWebView _dragInteractionPolicy]):
+        (-[WKWebView _setDragInteractionPolicy:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (shouldEnableDragInteractionForPolicy):
+        (-[WKContentView _didChangeDragInteractionPolicy]):
+
+        Called by the WKWebView when its _dragInteractionPolicy changes. The content view updates its
+        UIDragInteraction's -enabled property here in response.
+
+        (-[WKContentView setupDataInteractionDelegates]):
+
 2017-07-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Async image decoding for large images should be disabled by default
 2017-07-12  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Async image decoding for large images should be disabled by default
index 64071cb..3221d75 100644 (file)
@@ -308,6 +308,10 @@ WKWebView* fromWebPageProxy(WebKit::WebPageProxy& page)
     std::unique_ptr<WebKit::WebViewImpl> _impl;
     RetainPtr<WKTextFinderClient> _textFinderClient;
 #endif
     std::unique_ptr<WebKit::WebViewImpl> _impl;
     RetainPtr<WKTextFinderClient> _textFinderClient;
 #endif
+
+#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+    _WKDragInteractionPolicy _dragInteractionPolicy;
+#endif
 }
 
 - (instancetype)initWithFrame:(CGRect)frame
 }
 
 - (instancetype)initWithFrame:(CGRect)frame
@@ -594,6 +598,10 @@ static uint32_t convertSystemLayoutDirection(NSUserInterfaceLayoutDirection dire
         _page->setURLSchemeHandlerForScheme(WebKit::WebURLSchemeHandlerCocoa::create(handlers[key]), key);
 
     pageToViewMap().add(_page.get(), self);
         _page->setURLSchemeHandlerForScheme(WebKit::WebURLSchemeHandlerCocoa::create(handlers[key]), key);
 
     pageToViewMap().add(_page.get(), self);
+
+#if PLATFORM(IOS) && ENABLE(DRAG_SUPPORT)
+    _dragInteractionPolicy = _WKDragInteractionPolicyDefault;
+#endif
 }
 
 - (void)_setUpSQLiteDatabaseTrackerClient
 }
 
 - (void)_setUpSQLiteDatabaseTrackerClient
@@ -1079,6 +1087,24 @@ static WKErrorCode callbackErrorCode(WebKit::CallbackBase::Error error)
 
 #if PLATFORM(IOS)
 
 
 #if PLATFORM(IOS)
 
+#if ENABLE(DRAG_SUPPORT)
+
+- (_WKDragInteractionPolicy)_dragInteractionPolicy
+{
+    return _dragInteractionPolicy;
+}
+
+- (void)_setDragInteractionPolicy:(_WKDragInteractionPolicy)policy
+{
+    if (_dragInteractionPolicy == policy)
+        return;
+
+    _dragInteractionPolicy = policy;
+    [_contentView _didChangeDragInteractionPolicy];
+}
+
+#endif
+
 - (void)_populateArchivedSubviews:(NSMutableSet *)encodedViews
 {
     [super _populateArchivedSubviews:encodedViews];
 - (void)_populateArchivedSubviews:(NSMutableSet *)encodedViews
 {
     [super _populateArchivedSubviews:encodedViews];
index 9be9f0a..899e27c 100644 (file)
@@ -59,6 +59,16 @@ typedef NS_OPTIONS(NSUInteger, _WKCaptureDevices) {
     _WKCaptureDeviceCamera = 1 << 1,
 } WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
     _WKCaptureDeviceCamera = 1 << 1,
 } WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+#if TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
+
+typedef NS_ENUM(NSUInteger, _WKDragInteractionPolicy) {
+    _WKDragInteractionPolicyDefault = 0,
+    _WKDragInteractionPolicyAlwaysEnable,
+    _WKDragInteractionPolicyAlwaysDisable
+} WK_API_AVAILABLE(ios(WK_IOS_TBA));
+
+#endif
+
 #if !TARGET_OS_IPHONE
 
 typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 #if !TARGET_OS_IPHONE
 
 typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
@@ -184,6 +194,10 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 
 @property (nonatomic, readonly) _WKWebViewPrintFormatter *_webViewPrintFormatter;
 
 
 @property (nonatomic, readonly) _WKWebViewPrintFormatter *_webViewPrintFormatter;
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
+@property (nonatomic, setter=_setDragInteractionPolicy:) _WKDragInteractionPolicy _dragInteractionPolicy WK_API_AVAILABLE(ios(WK_IOS_TBA));
+#endif
+
 - (void)_beginInteractiveObscuredInsetsChange;
 - (void)_endInteractiveObscuredInsetsChange;
 - (void)_hideContentUntilNextUpdate;
 - (void)_beginInteractiveObscuredInsetsChange;
 - (void)_endInteractiveObscuredInsetsChange;
 - (void)_hideContentUntilNextUpdate;
index b228036..ccb0e79 100644 (file)
@@ -335,6 +335,7 @@ FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
 - (BOOL)ensurePositionInformationIsUpToDate:(WebKit::InteractionInformationRequest)request;
 
 #if ENABLE(DATA_INTERACTION)
 - (BOOL)ensurePositionInformationIsUpToDate:(WebKit::InteractionInformationRequest)request;
 
 #if ENABLE(DATA_INTERACTION)
+- (void)_didChangeDragInteractionPolicy;
 - (void)_didPerformDataInteractionControllerOperation:(BOOL)handled;
 - (void)_didHandleStartDataInteractionRequest:(BOOL)started;
 - (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const WebCore::DragItem&)item;
 - (void)_didPerformDataInteractionControllerOperation:(BOOL)handled;
 - (void)_didHandleStartDataInteractionRequest:(BOOL)started;
 - (void)_startDrag:(RetainPtr<CGImageRef>)image item:(const WebCore::DragItem&)item;
index c63da84..65c5ef5 100644 (file)
 
 @end
 
 
 @end
 
-#if ENABLE(DATA_INTERACTION)
-
-@interface WKDataInteractionCaretView : UIView
-
-- (instancetype)initWithTextInputView:(UIView<UITextInput> *)textInputView;
-- (void)insertAtPosition:(UITextPosition *)position;
-- (void)updateToPosition:(UITextPosition *)position;
-- (void)remove;
-
-@end
-
-#endif
-
 using namespace WebCore;
 using namespace WebKit;
 
 using namespace WebCore;
 using namespace WebKit;
 
@@ -4185,6 +4172,23 @@ static bool isAssistableInputType(InputType type)
 
 #if ENABLE(DRAG_SUPPORT)
 
 
 #if ENABLE(DRAG_SUPPORT)
 
+static BOOL shouldEnableDragInteractionForPolicy(_WKDragInteractionPolicy policy)
+{
+    switch (policy) {
+    case _WKDragInteractionPolicyAlwaysEnable:
+        return YES;
+    case _WKDragInteractionPolicyAlwaysDisable:
+        return NO;
+    default:
+        return [UIDragInteraction isEnabledByDefault];
+    }
+}
+
+- (void)_didChangeDragInteractionPolicy
+{
+    [_dataInteraction setEnabled:shouldEnableDragInteractionForPolicy(_webView._dragInteractionPolicy)];
+}
+
 - (NSTimeInterval)dragLiftDelay
 {
     static const NSTimeInterval mediumDragLiftDelay = 0.5;
 - (NSTimeInterval)dragLiftDelay
 {
     static const NSTimeInterval mediumDragLiftDelay = 0.5;
@@ -4207,7 +4211,7 @@ static bool isAssistableInputType(InputType type)
     _dataInteraction = adoptNS([[UIDragInteraction alloc] initWithDelegate:self]);
     _dataOperation = adoptNS([[UIDropInteraction alloc] initWithDelegate:self]);
     [_dataInteraction _setLiftDelay:self.dragLiftDelay];
     _dataInteraction = adoptNS([[UIDragInteraction alloc] initWithDelegate:self]);
     _dataOperation = adoptNS([[UIDropInteraction alloc] initWithDelegate:self]);
     [_dataInteraction _setLiftDelay:self.dragLiftDelay];
-    [_dataInteraction setEnabled:YES];
+    [_dataInteraction setEnabled:shouldEnableDragInteractionForPolicy(_webView._dragInteractionPolicy)];
 
     [self addInteraction:_dataInteraction.get()];
     [self addInteraction:_dataOperation.get()];
 
     [self addInteraction:_dataInteraction.get()];
     [self addInteraction:_dataOperation.get()];