[iOS DnD] [WK2] Add an internal hook to change the drag lift delay
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jun 2017 20:25:50 +0000 (20:25 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jun 2017 20:25:50 +0000 (20:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173523
<rdar://problem/32224510>

Reviewed by Tim Horton.

Add a new private property on WKWebViewConfiguration, _dragLiftDelay, for changing the UIDragInteraction's lift
delay to one of three values: short, medium or long. The short setting simply uses UIKit's default drag lift
delay (at the time of writing, this is 325ms); medium and long are 500ms and 650ms, respectively.

In combination with an internal switch to toggle between lift delays, the purpose of this change is to make it
easier to choose a drag lift delay for web content that doesn't easily cause unintended dragging while panning.

* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(toDragLiftDelay):

Converts an integer (e.g. retrieved from user defaults) to a drag lift delay type.

(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration encodeWithCoder:]):
(-[WKWebViewConfiguration initWithCoder:]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _dragLiftDelay]):

Add boilerplate plumbing for the _dragLiftDelay setting.

(-[WKWebViewConfiguration _setDragLiftDelay:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:

Add _dragLiftDelay to as a private property of WKWebViewConiguration.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView dragLiftDelay]):

Convert the web view configuration's _WKDragLiftDelay to an actual time interval.

(-[WKContentView setupDataInteractionDelegates]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm

index 3fed073..19ac778 100644 (file)
@@ -1,3 +1,43 @@
+2017-06-19  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS DnD] [WK2] Add an internal hook to change the drag lift delay
+        https://bugs.webkit.org/show_bug.cgi?id=173523
+        <rdar://problem/32224510>
+
+        Reviewed by Tim Horton.
+
+        Add a new private property on WKWebViewConfiguration, _dragLiftDelay, for changing the UIDragInteraction's lift
+        delay to one of three values: short, medium or long. The short setting simply uses UIKit's default drag lift
+        delay (at the time of writing, this is 325ms); medium and long are 500ms and 650ms, respectively.
+
+        In combination with an internal switch to toggle between lift delays, the purpose of this change is to make it
+        easier to choose a drag lift delay for web content that doesn't easily cause unintended dragging while panning.
+
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (toDragLiftDelay):
+
+        Converts an integer (e.g. retrieved from user defaults) to a drag lift delay type.
+
+        (-[WKWebViewConfiguration init]):
+        (-[WKWebViewConfiguration encodeWithCoder:]):
+        (-[WKWebViewConfiguration initWithCoder:]):
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _dragLiftDelay]):
+
+        Add boilerplate plumbing for the _dragLiftDelay setting.
+
+        (-[WKWebViewConfiguration _setDragLiftDelay:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+
+        Add _dragLiftDelay to as a private property of WKWebViewConiguration.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView dragLiftDelay]):
+
+        Convert the web view configuration's _WKDragLiftDelay to an actual time interval.
+
+        (-[WKContentView setupDataInteractionDelegates]):
+
 2017-06-19  Konstantin Tokarev  <annulen@yandex.ru>
 
         Removed unused lambda captures from WebKit2
index fa83d0f..606089a 100644 (file)
@@ -88,6 +88,19 @@ private:
     T m_value;
 };
 
+#if PLATFORM(IOS)
+
+static _WKDragLiftDelay toDragLiftDelay(NSUInteger value)
+{
+    if (value == _WKDragLiftDelayMedium)
+        return _WKDragLiftDelayMedium;
+    if (value == _WKDragLiftDelayLong)
+        return _WKDragLiftDelayLong;
+    return _WKDragLiftDelayShort;
+}
+
+#endif
+
 @implementation WKWebViewConfiguration {
     LazyInitialized<RetainPtr<WKProcessPool>> _processPool;
     LazyInitialized<RetainPtr<WKPreferences>> _preferences;
@@ -115,6 +128,7 @@ private:
     BOOL _inlineMediaPlaybackRequiresPlaysInlineAttribute;
     BOOL _allowsInlineMediaPlaybackAfterFullscreen;
     BOOL _allowsBlockSelection;
+    _WKDragLiftDelay _dragLiftDelay;
 #endif
 
     BOOL _invisibleAutoplayNotPermitted;
@@ -199,6 +213,7 @@ private:
 #if PLATFORM(IOS)
     _selectionGranularity = WKSelectionGranularityDynamic;
     _allowsBlockSelection = [[NSUserDefaults standardUserDefaults] boolForKey:@"WebKitDebugAllowBlockSelection"];
+    _dragLiftDelay = toDragLiftDelay([[NSUserDefaults standardUserDefaults] integerForKey:@"WebKitDebugDragLiftDelay"]);
 #endif
 
     _mediaContentTypesRequiringHardwareSupport = Settings::defaultMediaContentTypesRequiringHardwareSupport();
@@ -232,6 +247,7 @@ private:
     [coder encodeInteger:self.selectionGranularity forKey:@"selectionGranularity"];
     [coder encodeBool:self.allowsPictureInPictureMediaPlayback forKey:@"allowsPictureInPictureMediaPlayback"];
     [coder encodeBool:self.ignoresViewportScaleLimits forKey:@"ignoresViewportScaleLimits"];
+    [coder encodeInteger:self._dragLiftDelay forKey:@"dragLiftDelay"];
 #else
     [coder encodeInteger:self.userInterfaceDirectionPolicy forKey:@"userInterfaceDirectionPolicy"];
 #endif
@@ -259,6 +275,7 @@ private:
     self.selectionGranularity = static_cast<WKSelectionGranularity>([coder decodeIntegerForKey:@"selectionGranularity"]);
     self.allowsPictureInPictureMediaPlayback = [coder decodeBoolForKey:@"allowsPictureInPictureMediaPlayback"];
     self.ignoresViewportScaleLimits = [coder decodeBoolForKey:@"ignoresViewportScaleLimits"];
+    self._dragLiftDelay = toDragLiftDelay([coder decodeIntegerForKey:@"dragLiftDelay"]);
 #else
     auto userInterfaceDirectionPolicyCandidate = static_cast<WKUserInterfaceDirectionPolicy>([coder decodeIntegerForKey:@"userInterfaceDirectionPolicy"]);
     if (userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicyContent || userInterfaceDirectionPolicyCandidate == WKUserInterfaceDirectionPolicySystem)
@@ -313,6 +330,7 @@ private:
     configuration->_selectionGranularity = self->_selectionGranularity;
     configuration->_allowsBlockSelection = self->_allowsBlockSelection;
     configuration->_ignoresViewportScaleLimits = self->_ignoresViewportScaleLimits;
+    configuration->_dragLiftDelay = self->_dragLiftDelay;
 #endif
 #if PLATFORM(MAC)
     configuration->_userInterfaceDirectionPolicy = self->_userInterfaceDirectionPolicy;
@@ -644,6 +662,16 @@ static NSString *defaultApplicationNameForUserAgent()
 {
     _allowsBlockSelection = allowsBlockSelection;
 }
+
+- (_WKDragLiftDelay)_dragLiftDelay
+{
+    return _dragLiftDelay;
+}
+
+- (void)_setDragLiftDelay:(_WKDragLiftDelay)dragLiftDelay
+{
+    _dragLiftDelay = dragLiftDelay;
+}
 #endif // PLATFORM(IOS)
 
 - (BOOL)_invisibleAutoplayNotPermitted
index 7608727..067df10 100644 (file)
 
 #if WK_API_ENABLED
 
+#if TARGET_OS_IPHONE
+typedef NS_ENUM(NSUInteger, _WKDragLiftDelay) {
+    _WKDragLiftDelayShort = 0,
+    _WKDragLiftDelayMedium,
+    _WKDragLiftDelayLong
+} WK_API_AVAILABLE(ios(WK_IOS_TBA));
+#endif
+
 @class WKWebView;
 @class _WKVisitedLinkStore;
 @class _WKWebsiteDataStore;
@@ -64,6 +72,7 @@
 @property (nonatomic, setter=_setInlineMediaPlaybackRequiresPlaysInlineAttribute:) BOOL _inlineMediaPlaybackRequiresPlaysInlineAttribute WK_API_AVAILABLE(ios(10.0));
 @property (nonatomic, setter=_setAllowsInlineMediaPlaybackAfterFullscreen:) BOOL _allowsInlineMediaPlaybackAfterFullscreen  WK_API_AVAILABLE(ios(10.0));
 @property (nonatomic, setter=_setAllowsBlockSelection:) BOOL _allowsBlockSelection WK_API_AVAILABLE(ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setDragLiftDelay:) _WKDragLiftDelay _dragLiftDelay WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #else
 @property (nonatomic, setter=_setShowsURLsInToolTips:) BOOL _showsURLsInToolTips WK_API_AVAILABLE(macosx(10.12));
 @property (nonatomic, setter=_setServiceControlsEnabled:) BOOL _serviceControlsEnabled WK_API_AVAILABLE(macosx(10.12));
index 88e1c2f..676e308 100644 (file)
@@ -50,6 +50,7 @@
 #import "WKPreviewElementInfoInternal.h"
 #import "WKUIDelegatePrivate.h"
 #import "WKWebViewConfiguration.h"
+#import "WKWebViewConfigurationPrivate.h"
 #import "WKWebViewInternal.h"
 #import "WKWebViewPrivate.h"
 #import "WebEvent.h"
@@ -4168,6 +4169,18 @@ static bool isAssistableInputType(InputType type)
 
 #if ENABLE(DRAG_SUPPORT)
 
+- (NSTimeInterval)dragLiftDelay
+{
+    static const NSTimeInterval mediumDragLiftDelay = 0.5;
+    static const NSTimeInterval longDragLiftDelay = 0.65;
+    auto dragLiftDelay = _webView.configuration._dragLiftDelay;
+    if (dragLiftDelay == _WKDragLiftDelayMedium)
+        return mediumDragLiftDelay;
+    if (dragLiftDelay == _WKDragLiftDelayLong)
+        return longDragLiftDelay;
+    return _UIDragInteractionDefaultLiftDelay();
+}
+
 static NSTimeInterval longPressActionDelayAfterLift()
 {
     return _UIDragInteractionDefaultCompetingLongPressDelay() - _UIDragInteractionDefaultLiftDelay();
@@ -4182,6 +4195,7 @@ static NSTimeInterval longPressActionDelayAfterLift()
 {
     _dataInteraction = adoptNS([[UIDragInteraction alloc] initWithDelegate:self]);
     _dataOperation = adoptNS([[UIDropInteraction alloc] initWithDelegate:self]);
+    [_dataInteraction _setLiftDelay:self.dragLiftDelay];
     [self addInteraction:_dataInteraction.get()];
     [self addInteraction:_dataOperation.get()];
 }