Title: [270446] trunk
Revision
270446
Author
katherine_che...@apple.com
Date
2020-12-04 11:53:50 -0800 (Fri, 04 Dec 2020)

Log Message

Create API to enable/disable text interaction gestures in WKWebView
https://bugs.webkit.org/show_bug.cgi?id=217784
<rdar://problem/63406241>

Reviewed by Wenson Hsieh.

Source/WebCore:

Add API to disable text selection for macOS.

* page/EventHandler.cpp:
(WebCore::EventHandler::selectClosestWordFromMouseEvent):
(WebCore::EventHandler::selectClosestContextualWordOrLinkFromMouseEvent):
(WebCore::EventHandler::handleMousePressEventDoubleClick):
(WebCore::EventHandler::handleMousePressEventTripleClick):
(WebCore::EventHandler::handleMousePressEventSingleClick):
(WebCore::EventHandler::mouseDownMayStartSelect):
Create a new function to return whether a click results in a
selection. It will always return false if text interaction is disabled.

(WebCore::EventHandler::handleMousePressEvent):
(WebCore::EventHandler::handleMouseDraggedEvent):
(WebCore::EventHandler::updateSelectionForMouseDrag):
(WebCore::EventHandler::selectCursor):
* page/EventHandler.h:
* page/Page.cpp:
(WebCore::m_textInteractionEnabled):
(WebCore::m_shouldRelaxThirdPartyCookieBlocking): Deleted.
* page/Page.h:
Store the textInteractionEnabled value in the Page so it is
accessible from the EventHandler.

(WebCore::Page::textInteractionEnabled):
(WebCore::Page::setTextInteractionEnabled):
* page/PageConfiguration.h:

Source/WebKit:

Create a new API to disable text interaction gestures in a WKWebView.
We have SPI for this for iOS, but it could be useful to other WebKit
clients and on macOS. Add the API to WKPreferences, instead of
WKWebViewConfiguration, so it can be changed on the fly.

Deprecate the SPI.

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode const):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
* UIProcess/API/Cocoa/WKPreferences.h:
* UIProcess/API/Cocoa/WKPreferences.mm:
(-[WKPreferences encodeWithCoder:]):
(-[WKPreferences initWithCoder:]):
(-[WKPreferences textInteractionEnabled]):
(-[WKPreferences setTextInteractionEnabled:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration init]):
(-[WKWebViewConfiguration encodeWithCoder:]):
(-[WKWebViewConfiguration initWithCoder:]):
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _textInteractionEnabled]):
(-[WKWebViewConfiguration _setTextInteractionEnabled:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::creationParameters):
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView hasSelectablePositionAtPoint:]):
(-[WKContentView pointIsNearMarkedText:]):
(-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
(-[WKContentView _cascadeInteractionTintColor]):
(-[WKContentView selectForWebView:]):
(-[WKContentView selectAllForWebView:]):
Add check for textInteractionEnabled in these select*
functions because disabling text interaction should disable selection
in WKWebView.

* WebProcess/WebPage/WebPage.cpp:
Update the textInteractionEnabled value in the page when
preferences are updated.

(WebKit::WebPage::updatePreferences):

Source/WTF:

Create new WKPreference. See WebKit Changelog for details.

* Scripts/Preferences/WebPreferences.yaml:

Tools:

Add API test coverage for macOS and support for layout tests for iOS.
API tests do not support user gestures which is why iOS tests must
use WebKitTestRunner.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDisableSelection.mm: Added.
(TEST):
(clickAndDragToSelectText):
* TestWebKitAPI/Tests/WebKitCocoa/try-text-select-with-disabled-text-interaction.html: Added.
* WebKitTestRunner/cocoa/TestControllerCocoa.mm:
(WTR::TestController::cocoaResetStateToConsistentValues):
* WebKitTestRunner/TestOptions.cpp:
(WTR::TestOptions::defaults):
(WTR::TestOptions::keyTypeMapping):
* WebKitTestRunner/TestOptions.h:
(WTR::TestOptions::textInteractionEnabled const):

LayoutTests:

Layout test coverage for iOS.

* LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction-expected.txt: Added.
* LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (270445 => 270446)


--- trunk/LayoutTests/ChangeLog	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/LayoutTests/ChangeLog	2020-12-04 19:53:50 UTC (rev 270446)
@@ -1,3 +1,16 @@
+2020-12-04  Kate Cheney  <katherine_che...@apple.com>
+
+        Create API to enable/disable text interaction gestures in WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=217784
+        <rdar://problem/63406241>
+
+        Reviewed by Wenson Hsieh.
+
+        Layout test coverage for iOS.
+
+        * LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction-expected.txt: Added.
+        * LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction.html: Added.
+
 2020-12-04  Lauro Moura  <lmo...@igalia.com>
 
         [GTK] Gardening wheel failures and timeouts

Added: trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction-expected.txt (0 => 270446)


--- trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction-expected.txt	2020-12-04 19:53:50 UTC (rev 270446)
@@ -0,0 +1,10 @@
+This test verifies that text selection fails when text interaction is disabled.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getSelection().toString() is ""
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Testing

Added: trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction.html (0 => 270446)


--- trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction.html	                        (rev 0)
+++ trunk/LayoutTests/editing/selection/ios/cannot-select-after-disabling-text-interaction.html	2020-12-04 19:53:50 UTC (rev 270446)
@@ -0,0 +1,32 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true textInteractionEnabled=false ] -->
+<html>
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
+<script src=""
+<script src=""
+<style>
+html, body {
+    width: 100%;
+    margin: 0;
+}
+
+#target {
+    font-size: 24px;
+}
+</style>
+<script>
+    jsTestIsAsync = true;
+
+    async function runTest()
+    {
+        description("This test verifies that text selection fails when text interaction is disabled.");
+
+        await UIHelper.longPressElement(target);
+        shouldBeEqualToString("getSelection().toString()", "");
+        finishJSTest();
+    }
+</script>
+<body _onload_="runTest()">
+    <div id="target">Testing</div>
+</body>
+</html>

Modified: trunk/Source/WTF/ChangeLog (270445 => 270446)


--- trunk/Source/WTF/ChangeLog	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WTF/ChangeLog	2020-12-04 19:53:50 UTC (rev 270446)
@@ -1,3 +1,15 @@
+2020-12-04  Kate Cheney  <katherine_che...@apple.com>
+
+        Create API to enable/disable text interaction gestures in WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=217784
+        <rdar://problem/63406241>
+
+        Reviewed by Wenson Hsieh.
+
+        Create new WKPreference. See WebKit Changelog for details.
+
+        * Scripts/Preferences/WebPreferences.yaml:
+
 2020-12-04  Adam Roben  <aro...@apple.com>
 
         More FALLBACK_PLATFORM adoption

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml (270445 => 270446)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferences.yaml	2020-12-04 19:53:50 UTC (rev 270446)
@@ -2277,6 +2277,19 @@
       "PLATFORM(IOS_FAMILY)": true
       default: false
 
+TextInteractionEnabled:
+  type: bool
+  defaultValue:
+    WebKitLegacy:
+      "PLATFORM(WATCH_OS)": false
+      default: true
+    WebKit:
+      "PLATFORM(WATCH_OS)": false
+      default: true
+    WebCore:
+      "PLATFORM(WATCH_OS)": false
+      default: true
+
 ThreadedScrollingEnabled:
   type: bool
   webcoreBinding: none

Modified: trunk/Source/WebCore/ChangeLog (270445 => 270446)


--- trunk/Source/WebCore/ChangeLog	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/ChangeLog	2020-12-04 19:53:50 UTC (rev 270446)
@@ -1,3 +1,39 @@
+2020-12-04  Kate Cheney  <katherine_che...@apple.com>
+
+        Create API to enable/disable text interaction gestures in WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=217784
+        <rdar://problem/63406241>
+
+        Reviewed by Wenson Hsieh.
+
+        Add API to disable text selection for macOS.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::selectClosestWordFromMouseEvent):
+        (WebCore::EventHandler::selectClosestContextualWordOrLinkFromMouseEvent):
+        (WebCore::EventHandler::handleMousePressEventDoubleClick):
+        (WebCore::EventHandler::handleMousePressEventTripleClick):
+        (WebCore::EventHandler::handleMousePressEventSingleClick):
+        (WebCore::EventHandler::mouseDownMayStartSelect):
+        Create a new function to return whether a click results in a
+        selection. It will always return false if text interaction is disabled.
+
+        (WebCore::EventHandler::handleMousePressEvent):
+        (WebCore::EventHandler::handleMouseDraggedEvent):
+        (WebCore::EventHandler::updateSelectionForMouseDrag):
+        (WebCore::EventHandler::selectCursor):
+        * page/EventHandler.h:
+        * page/Page.cpp:
+        (WebCore::m_textInteractionEnabled):
+        (WebCore::m_shouldRelaxThirdPartyCookieBlocking): Deleted.
+        * page/Page.h:
+        Store the textInteractionEnabled value in the Page so it is
+        accessible from the EventHandler.
+
+        (WebCore::Page::textInteractionEnabled):
+        (WebCore::Page::setTextInteractionEnabled):
+        * page/PageConfiguration.h:
+
 2020-12-04  Adam Roben  <aro...@apple.com>
 
         More FALLBACK_PLATFORM adoption

Modified: trunk/Source/WebCore/page/EventHandler.cpp (270445 => 270446)


--- trunk/Source/WebCore/page/EventHandler.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -499,7 +499,7 @@
 
 void EventHandler::selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& result)
 {
-    if (m_mouseDownMayStartSelect)
+    if (mouseDownMayStartSelect())
         selectClosestWordFromHitTestResult(result.hitTestResult(), shouldAppendTrailingWhitespace(result, m_frame));
 }
 
@@ -548,7 +548,7 @@
 
     Node* targetNode = result.targetNode();
 
-    if (targetNode && targetNode->renderer() && m_mouseDownMayStartSelect) {
+    if (targetNode && targetNode->renderer() && mouseDownMayStartSelect()) {
         VisibleSelection newSelection;
         VisiblePosition pos(targetNode->renderer()->positionForPoint(result.localPoint(), nullptr));
         if (pos.isNotNull() && pos.deepEquivalent().deprecatedNode()->isDescendantOf(*urlElement))
@@ -582,7 +582,7 @@
         return false;
     
     Node* targetNode = event.targetNode();
-    if (!(targetNode && targetNode->renderer() && m_mouseDownMayStartSelect))
+    if (!(targetNode && targetNode->renderer() && mouseDownMayStartSelect()))
         return false;
 
     VisibleSelection newSelection;
@@ -609,7 +609,7 @@
 
     m_frame.document()->updateLayoutIgnorePendingStylesheets();
     Node* targetNode = event.targetNode();
-    if (!targetNode || !targetNode->renderer() || !m_mouseDownMayStartSelect || m_mouseDownDelegatedFocus)
+    if (!targetNode || !targetNode->renderer() || !mouseDownMayStartSelect() || m_mouseDownDelegatedFocus)
         return false;
 
     // Extend the selection if the Shift key is down, unless the click is in a link.
@@ -696,6 +696,15 @@
     return node->canStartSelection() || Position::nodeIsUserSelectAll(node);
 }
 
+bool EventHandler::mouseDownMayStartSelect()
+{
+    Page* page = m_frame.page();
+    if (page && !page->textInteractionEnabled())
+        return false;
+
+    return m_mouseDownMayStartSelect;
+}
+
 bool EventHandler::handleMousePressEvent(const MouseEventWithHitTestResults& event)
 {
     Ref<Frame> protectedFrame(m_frame);
@@ -773,7 +782,7 @@
     else
         swallowEvent = handleMousePressEventSingleClick(event);
     
-    m_mouseDownMayStartAutoscroll = m_mouseDownMayStartSelect
+    m_mouseDownMayStartAutoscroll = mouseDownMayStartSelect()
         || (m_mousePressNode && m_mousePressNode->renderBox() && m_mousePressNode->renderBox()->canBeProgramaticallyScrolled());
 
     return swallowEvent;
@@ -841,7 +850,7 @@
     }
 
 #if PLATFORM(COCOA) // FIXME: Why does this assertion fire on other platforms?
-    ASSERT(m_mouseDownMayStartSelect || m_mouseDownMayStartAutoscroll);
+    ASSERT(mouseDownMayStartSelect() || m_mouseDownMayStartAutoscroll);
 #endif
 
     m_mouseDownMayStartDrag = false;
@@ -915,7 +924,7 @@
     if (!supportsSelectionUpdatesOnMouseDrag())
         return;
 
-    if (!m_mouseDownMayStartSelect)
+    if (!mouseDownMayStartSelect())
         return;
 
     Node* target = hitTestResult.targetNode();
@@ -1471,7 +1480,7 @@
     // During selection, use an I-beam regardless of the content beneath the cursor.
     // If a drag may be starting or we're capturing mouse events for a particular node, don't treat this as a selection.
     if (m_mousePressed
-        && m_mouseDownMayStartSelect
+        && mouseDownMayStartSelect()
 #if ENABLE(DRAG_SUPPORT)
         && !m_mouseDownMayStartDrag
 #endif

Modified: trunk/Source/WebCore/page/EventHandler.h (270445 => 270446)


--- trunk/Source/WebCore/page/EventHandler.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/page/EventHandler.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -521,6 +521,8 @@
 
     bool canMouseDownStartSelect(const MouseEventWithHitTestResults&);
 
+    bool mouseDownMayStartSelect();
+    
     Frame& m_frame;
     RefPtr<Node> m_mousePressNode;
     Timer m_hoverTimer;

Modified: trunk/Source/WebCore/page/Page.cpp (270445 => 270446)


--- trunk/Source/WebCore/page/Page.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/page/Page.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -303,6 +303,7 @@
     , m_loadsSubresources(pageConfiguration.loadsSubresources)
     , m_loadsFromNetwork(pageConfiguration.loadsFromNetwork)
     , m_shouldRelaxThirdPartyCookieBlocking(pageConfiguration.shouldRelaxThirdPartyCookieBlocking)
+    , m_textInteractionEnabled(pageConfiguration.textInteractionEnabled)
 {
     updateTimerThrottlingState();
 

Modified: trunk/Source/WebCore/page/Page.h (270445 => 270446)


--- trunk/Source/WebCore/page/Page.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/page/Page.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -828,6 +828,9 @@
 
     MonotonicTime lastRenderingUpdateTimestamp() const { return m_lastRenderingUpdateTimestamp; }
 
+    bool textInteractionEnabled() { return m_textInteractionEnabled; }
+    void setTextInteractionEnabled(bool value) { m_textInteractionEnabled = value; }
+
 private:
     struct Navigation {
         RegistrableDomain domain;
@@ -1131,6 +1134,8 @@
     bool m_hasBeenNotifiedToInjectUserScripts { false };
 
     MonotonicTime m_lastRenderingUpdateTimestamp;
+    
+    bool m_textInteractionEnabled { true };
 };
 
 inline PageGroup& Page::group()

Modified: trunk/Source/WebCore/page/PageConfiguration.h (270445 => 270446)


--- trunk/Source/WebCore/page/PageConfiguration.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebCore/page/PageConfiguration.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -133,6 +133,7 @@
     bool loadsFromNetwork { true };
     bool userScriptsShouldWaitUntilNotification { true };
     ShouldRelaxThirdPartyCookieBlocking shouldRelaxThirdPartyCookieBlocking { ShouldRelaxThirdPartyCookieBlocking::No };
+    bool textInteractionEnabled { true };
 };
 
 }

Modified: trunk/Source/WebKit/ChangeLog (270445 => 270446)


--- trunk/Source/WebKit/ChangeLog	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/ChangeLog	2020-12-04 19:53:50 UTC (rev 270446)
@@ -1,3 +1,55 @@
+2020-12-04  Kate Cheney  <katherine_che...@apple.com>
+
+        Create API to enable/disable text interaction gestures in WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=217784
+        <rdar://problem/63406241>
+
+        Reviewed by Wenson Hsieh.
+
+        Create a new API to disable text interaction gestures in a WKWebView.
+        We have SPI for this for iOS, but it could be useful to other WebKit
+        clients and on macOS. Add the API to WKPreferences, instead of
+        WKWebViewConfiguration, so it can be changed on the fly.
+
+        Deprecate the SPI.
+
+        * Shared/WebPageCreationParameters.cpp:
+        (WebKit::WebPageCreationParameters::encode const):
+        (WebKit::WebPageCreationParameters::decode):
+        * Shared/WebPageCreationParameters.h:
+        * UIProcess/API/Cocoa/WKPreferences.h:
+        * UIProcess/API/Cocoa/WKPreferences.mm:
+        (-[WKPreferences encodeWithCoder:]):
+        (-[WKPreferences initWithCoder:]):
+        (-[WKPreferences textInteractionEnabled]):
+        (-[WKPreferences setTextInteractionEnabled:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration init]):
+        (-[WKWebViewConfiguration encodeWithCoder:]):
+        (-[WKWebViewConfiguration initWithCoder:]):
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _textInteractionEnabled]):
+        (-[WKWebViewConfiguration _setTextInteractionEnabled:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::creationParameters):
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView hasSelectablePositionAtPoint:]):
+        (-[WKContentView pointIsNearMarkedText:]):
+        (-[WKContentView textInteractionGesture:shouldBeginAtPoint:]):
+        (-[WKContentView _cascadeInteractionTintColor]):
+        (-[WKContentView selectForWebView:]):
+        (-[WKContentView selectAllForWebView:]):
+        Add check for textInteractionEnabled in these select*
+        functions because disabling text interaction should disable selection
+        in WKWebView.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        Update the textInteractionEnabled value in the page when
+        preferences are updated.
+
+        (WebKit::WebPage::updatePreferences):
+
 2020-12-04  Adam Roben  <aro...@apple.com>
 
         More FALLBACK_PLATFORM adoption

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp (270445 => 270446)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -170,6 +170,8 @@
 #if PLATFORM(GTK)
     encoder << themeName;
 #endif
+    
+    encoder << textInteractionEnabled;
 }
 
 Optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder)
@@ -535,6 +537,9 @@
     if (!decoder.decode(parameters.themeName))
         return WTF::nullopt;
 #endif
+    
+    if (!decoder.decode(parameters.textInteractionEnabled))
+        return WTF::nullopt;
 
     return parameters;
 }

Modified: trunk/Source/WebKit/Shared/WebPageCreationParameters.h (270445 => 270446)


--- trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/Shared/WebPageCreationParameters.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -242,6 +242,8 @@
 #if PLATFORM(GTK)
     String themeName;
 #endif
+
+    bool textInteractionEnabled { true };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.h (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -60,6 +60,10 @@
 @property (nonatomic) BOOL tabFocusesLinks WK_API_AVAILABLE(macos(10.12.3));
 #endif
 
+/*! @abstract A Boolean value indicating whether text interaction is disabled.
+*/
+@property (nonatomic) BOOL textInteractionEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 @end
 
 @interface WKPreferences (WKDeprecated)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm	2020-12-04 19:53:50 UTC (rev 270446)
@@ -78,6 +78,7 @@
 ALLOW_DEPRECATED_DECLARATIONS_END
     [coder encodeBool:self.tabFocusesLinks forKey:@"tabFocusesLinks"];
 #endif
+    [coder encodeBool:self.textInteractionEnabled forKey:@"textInteractionEnabled"];
 }
 
 - (instancetype)initWithCoder:(NSCoder *)coder
@@ -99,6 +100,7 @@
 ALLOW_DEPRECATED_DECLARATIONS_END
     self.tabFocusesLinks = [coder decodeBoolForKey:@"tabFocusesLinks"];
 #endif
+    self.textInteractionEnabled = [coder decodeBoolForKey:@"textInteractionEnabled"];
 
     return self;
 }
@@ -138,6 +140,16 @@
     _preferences->setJavaScriptCanOpenWindowsAutomatically(_javascript_CanOpenWindowsAutomatically);
 }
 
+- (BOOL)textInteractionEnabled
+{
+    return _preferences->textInteractionEnabled();
+}
+
+- (void)setTextInteractionEnabled:(BOOL)textInteractionEnabled
+{
+    _preferences->setTextInteractionEnabled(textInteractionEnabled);
+}
+
 #pragma mark OS X-specific methods
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfiguration.mm	2020-12-04 19:53:50 UTC (rev 270446)
@@ -309,7 +309,9 @@
     [coder encodeBool:self.allowsPictureInPictureMediaPlayback forKey:@"allowsPictureInPictureMediaPlayback"];
     [coder encodeBool:self.ignoresViewportScaleLimits forKey:@"ignoresViewportScaleLimits"];
     [coder encodeInteger:self._dragLiftDelay forKey:@"dragLiftDelay"];
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     [coder encodeBool:self._textInteractionGesturesEnabled forKey:@"textInteractionGesturesEnabled"];
+    ALLOW_DEPRECATED_DECLARATIONS_END
     [coder encodeBool:self._longPressActionsEnabled forKey:@"longPressActionsEnabled"];
     [coder encodeBool:self._systemPreviewEnabled forKey:@"systemPreviewEnabled"];
     [coder encodeBool:self._shouldDecidePolicyBeforeLoadingQuickLookPreview forKey:@"shouldDecidePolicyBeforeLoadingQuickLookPreview"];
@@ -347,7 +349,9 @@
     self.allowsPictureInPictureMediaPlayback = [coder decodeBoolForKey:@"allowsPictureInPictureMediaPlayback"];
     self.ignoresViewportScaleLimits = [coder decodeBoolForKey:@"ignoresViewportScaleLimits"];
     self._dragLiftDelay = toDragLiftDelay([coder decodeIntegerForKey:@"dragLiftDelay"]);
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     self._textInteractionGesturesEnabled = [coder decodeBoolForKey:@"textInteractionGesturesEnabled"];
+    ALLOW_DEPRECATED_DECLARATIONS_END
     self._longPressActionsEnabled = [coder decodeBoolForKey:@"longPressActionsEnabled"];
     self._systemPreviewEnabled = [coder decodeBoolForKey:@"systemPreviewEnabled"];
     self._shouldDecidePolicyBeforeLoadingQuickLookPreview = [coder decodeBoolForKey:@"shouldDecidePolicyBeforeLoadingQuickLookPreview"];
@@ -757,16 +761,6 @@
     _dragLiftDelay = dragLiftDelay;
 }
 
-- (BOOL)_textInteractionGesturesEnabled
-{
-    return _textInteractionGesturesEnabled;
-}
-
-- (void)_setTextInteractionGesturesEnabled:(BOOL)enabled
-{
-    _textInteractionGesturesEnabled = enabled;
-}
-
 - (BOOL)_longPressActionsEnabled
 {
     return _longPressActionsEnabled;
@@ -1280,7 +1274,22 @@
 {
     self.mediaTypesRequiringUserActionForPlayback = requiresUserActionForMediaPlayback ? WKAudiovisualMediaTypeAll : WKAudiovisualMediaTypeNone;
 }
+#endif // PLATFORM(IOS_FAMILY)
 
+@end
+
+@implementation WKWebViewConfiguration (WKPrivateDeprecated)
+
+#if PLATFORM(IOS_FAMILY)
+- (BOOL)_textInteractionGesturesEnabled
+{
+    return _textInteractionGesturesEnabled;
+}
+
+- (void)_setTextInteractionGesturesEnabled:(BOOL)enabled
+{
+    _textInteractionGesturesEnabled = enabled;
+}
 #endif // PLATFORM(IOS_FAMILY)
 
 @end

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -89,7 +89,6 @@
 @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=_setDragLiftDelay:) _WKDragLiftDelay _dragLiftDelay WK_API_AVAILABLE(ios(11.0));
-@property (nonatomic, setter=_setTextInteractionGesturesEnabled:) BOOL _textInteractionGesturesEnabled WK_API_AVAILABLE(ios(12.0));
 @property (nonatomic, setter=_setLongPressActionsEnabled:) BOOL _longPressActionsEnabled WK_API_AVAILABLE(ios(12.0));
 @property (nonatomic, setter=_setSystemPreviewEnabled:) BOOL _systemPreviewEnabled WK_API_AVAILABLE(ios(12.0));
 @property (nonatomic, setter=_setShouldDecidePolicyBeforeLoadingQuickLookPreview:) BOOL _shouldDecidePolicyBeforeLoadingQuickLookPreview WK_API_AVAILABLE(ios(13.0));
@@ -123,3 +122,13 @@
 @property (nonatomic, setter=_setProcessDisplayName:) NSString *_processDisplayName WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
+
+#if TARGET_OS_IPHONE
+
+@interface WKWebViewConfiguration (WKPrivateDeprecated)
+
+@property (nonatomic, setter=_setTextInteractionGesturesEnabled:) BOOL _textInteractionGesturesEnabled WK_API_DEPRECATED_WITH_REPLACEMENT("WKPreferences.textInteractionGesturesEnabled", ios(12.0, WK_IOS_TBA));
+
+@end
+
+#endif

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -8000,6 +8000,8 @@
 #if ENABLE(APP_BOUND_DOMAINS)
     parameters.needsInAppBrowserPrivacyQuirks = preferences().needsInAppBrowserPrivacyQuirks();
 #endif
+    
+    parameters.textInteractionEnabled = preferences().textInteractionEnabled();
 
     return parameters;
 }

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (270445 => 270446)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-12-04 19:53:50 UTC (rev 270446)
@@ -2554,9 +2554,14 @@
 
 - (BOOL)hasSelectablePositionAtPoint:(CGPoint)point
 {
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     if (!self.webView.configuration._textInteractionGesturesEnabled)
         return NO;
+    ALLOW_DEPRECATED_DECLARATIONS_END
 
+    if (!_page->preferences().textInteractionEnabled())
+        return NO;
+
     if (_suppressSelectionAssistantReasons)
         return NO;
 
@@ -2577,9 +2582,14 @@
 
 - (BOOL)pointIsNearMarkedText:(CGPoint)point
 {
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     if (!self.webView.configuration._textInteractionGesturesEnabled)
         return NO;
+    ALLOW_DEPRECATED_DECLARATIONS_END
 
+    if (!_page->preferences().textInteractionEnabled())
+        return NO;
+    
     if (_suppressSelectionAssistantReasons)
         return NO;
 
@@ -2591,9 +2601,14 @@
 
 - (BOOL)textInteractionGesture:(UIWKGestureType)gesture shouldBeginAtPoint:(CGPoint)point
 {
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     if (!self.webView.configuration._textInteractionGesturesEnabled)
         return NO;
+    ALLOW_DEPRECATED_DECLARATIONS_END
 
+    if (!_page->preferences().textInteractionEnabled())
+        return NO;
+    
     if (_domPasteRequestHandler)
         return NO;
 
@@ -3317,9 +3332,14 @@
 
 - (UIColor *)_cascadeInteractionTintColor
 {
+    ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     if (!self.webView.configuration._textInteractionGesturesEnabled)
         return [UIColor clearColor];
+    ALLOW_DEPRECATED_DECLARATIONS_END
 
+    if (!_page->preferences().textInteractionEnabled())
+        return [UIColor clearColor];
+
     if (!_page->editorState().isMissingPostLayoutData) {
         WebCore::Color caretColor = _page->editorState().postLayoutData().caretColor;
         if (caretColor.isValid())
@@ -3600,6 +3620,9 @@
 
 - (void)selectForWebView:(id)sender
 {
+    if (!_page->preferences().textInteractionEnabled())
+        return;
+
     [_textInteractionAssistant selectWord];
     // We cannot use selectWord command, because we want to be able to select the word even when it is the last in the paragraph.
     _page->extendSelection(WebCore::TextGranularity::WordGranularity);
@@ -3607,6 +3630,9 @@
 
 - (void)selectAllForWebView:(id)sender
 {
+    if (!_page->preferences().textInteractionEnabled())
+        return;
+
     [_textInteractionAssistant selectAll:sender];
     _page->selectAll();
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (270445 => 270446)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -572,6 +572,8 @@
     pageConfiguration.loadsFromNetwork = parameters.loadsFromNetwork;
     pageConfiguration.shouldRelaxThirdPartyCookieBlocking = parameters.shouldRelaxThirdPartyCookieBlocking;
 
+    pageConfiguration.textInteractionEnabled = parameters.textInteractionEnabled;
+    
     if (!parameters.crossOriginAccessControlCheckEnabled)
         CrossOriginAccessControlCheckDisabler::singleton().setCrossOriginAccessControlCheckEnabled(false);
 
@@ -3807,6 +3809,8 @@
 #if ENABLE(IPC_TESTING_API)
     m_ipcTestingAPIEnabled = store.getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey());
 #endif
+
+    m_page->setTextInteractionEnabled(store.getBoolValueForKey(WebPreferencesKey::textInteractionEnabledKey()));
 }
 
 #if ENABLE(DATA_DETECTION)

Modified: trunk/Tools/ChangeLog (270445 => 270446)


--- trunk/Tools/ChangeLog	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Tools/ChangeLog	2020-12-04 19:53:50 UTC (rev 270446)
@@ -1,3 +1,28 @@
+2020-12-04  Kate Cheney  <katherine_che...@apple.com>
+
+        Create API to enable/disable text interaction gestures in WKWebView
+        https://bugs.webkit.org/show_bug.cgi?id=217784
+        <rdar://problem/63406241>
+
+        Reviewed by Wenson Hsieh.
+
+        Add API test coverage for macOS and support for layout tests for iOS.
+        API tests do not support user gestures which is why iOS tests must
+        use WebKitTestRunner.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDisableSelection.mm: Added.
+        (TEST):
+        (clickAndDragToSelectText):
+        * TestWebKitAPI/Tests/WebKitCocoa/try-text-select-with-disabled-text-interaction.html: Added.
+        * WebKitTestRunner/cocoa/TestControllerCocoa.mm:
+        (WTR::TestController::cocoaResetStateToConsistentValues):
+        * WebKitTestRunner/TestOptions.cpp:
+        (WTR::TestOptions::defaults):
+        (WTR::TestOptions::keyTypeMapping):
+        * WebKitTestRunner/TestOptions.h:
+        (WTR::TestOptions::textInteractionEnabled const):
+
 2020-12-04  Adam Roben  <aro...@apple.com>
 
         More FALLBACK_PLATFORM adoption

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (270445 => 270446)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-12-04 19:53:50 UTC (rev 270446)
@@ -275,6 +275,8 @@
 		46FA2FEE23846CA5000CCB0C /* HTTPHeaderMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */; };
 		46FACF7423E8842300A9EBC6 /* beforeunload-slow.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */; };
 		4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EC79F168BE454E579E417B05 /* Markable.cpp */; };
+		4952BE5E2578115600B0AEF1 /* WKWebViewDisableSelection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4952BE5D2578115500B0AEF1 /* WKWebViewDisableSelection.mm */; };
+		4952BE5F257816F800B0AEF1 /* try-text-select-with-disabled-text-interaction.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4952BE5C2578113900B0AEF1 /* try-text-select-with-disabled-text-interaction.html */; };
 		4971B1182451F29A0096994D /* incorrectCreateTableSchema.db in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4971B1172451F2780096994D /* incorrectCreateTableSchema.db */; };
 		4971B1202453A88C0096994D /* missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db in Copy Resources */ = {isa = PBXBuildFile; fileRef = 4971B11F2453A87F0096994D /* missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db */; };
 		4971B12F24623A3B0096994D /* basicITPDatabase.db-shm in Resources */ = {isa = PBXBuildFile; fileRef = 4971B12D24623A3B0096994D /* basicITPDatabase.db-shm */; };
@@ -1635,6 +1637,7 @@
 				F44C7A0520FAAE3C0014478C /* text-with-deferred-script.html in Copy Resources */,
 				F41AB9AA1EF4696B0083FA08 /* textarea-to-input.html in Copy Resources */,
 				C22FA32D228F8AEB009D7988 /* TextWidth.html in Copy Resources */,
+				4952BE5F257816F800B0AEF1 /* try-text-select-with-disabled-text-interaction.html in Copy Resources */,
 				F4451C761EB8FD890020C5DA /* two-paragraph-contenteditable.html in Copy Resources */,
 				1D67BFDD2433EE66006B5047 /* two-videos.html in Copy Resources */,
 				C540F784152E5A9A00A40C8C /* verboseMarkup.html in Copy Resources */,
@@ -2007,6 +2010,8 @@
 		46F03C1B255B2D3600AA51C5 /* audio-context-playing.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "audio-context-playing.html"; sourceTree = "<group>"; };
 		46FA2FED23846C9A000CCB0C /* HTTPHeaderMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTTPHeaderMap.cpp; sourceTree = "<group>"; };
 		46FACF7323E883EE00A9EBC6 /* beforeunload-slow.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "beforeunload-slow.html"; sourceTree = "<group>"; };
+		4952BE5C2578113900B0AEF1 /* try-text-select-with-disabled-text-interaction.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "try-text-select-with-disabled-text-interaction.html"; sourceTree = "<group>"; };
+		4952BE5D2578115500B0AEF1 /* WKWebViewDisableSelection.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewDisableSelection.mm; sourceTree = "<group>"; };
 		4971B1172451F2780096994D /* incorrectCreateTableSchema.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = incorrectCreateTableSchema.db; sourceTree = "<group>"; };
 		4971B11F2453A87F0096994D /* missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db */ = {isa = PBXFileReference; lastKnownFileType = file; name = missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db; path = Tests/WebKitCocoa/missingTopFrameUniqueRedirectSameSiteStrictTableSchema.db; sourceTree = SOURCE_ROOT; };
 		4971B12C246239D30096994D /* basicITPDatabase.db */ = {isa = PBXFileReference; lastKnownFileType = file; path = basicITPDatabase.db; sourceTree = SOURCE_ROOT; };
@@ -3463,6 +3468,7 @@
 				5CB3CE381FA1691700C3A2D6 /* WKWebViewConfiguration.mm */,
 				7C417F311D19E14800B8EF53 /* WKWebViewDefaultNavigationDelegate.mm */,
 				46E66A8F1F0D75590026D83C /* WKWebViewDiagnosticLogging.mm */,
+				4952BE5D2578115500B0AEF1 /* WKWebViewDisableSelection.mm */,
 				2DB647871F4161F70051A89E /* WKWebViewDoesNotLogDuringInitialization.mm */,
 				F4811E5821940B4400A5E0FD /* WKWebViewEditActions.mm */,
 				0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */,
@@ -3936,6 +3942,7 @@
 				F44C7A0420FAAE320014478C /* text-with-deferred-script.html */,
 				F41AB9951EF4692C0083FA08 /* textarea-to-input.html */,
 				C22FA32C228F877A009D7988 /* TextWidth.html */,
+				4952BE5C2578113900B0AEF1 /* try-text-select-with-disabled-text-interaction.html */,
 				F4451C751EB8FD7C0020C5DA /* two-paragraph-contenteditable.html */,
 				CD57779B211CE6CE001B371E /* video-with-audio-and-web-audio.html */,
 				CD577798211CDE8F001B371E /* web-audio-only.html */,
@@ -5664,6 +5671,7 @@
 				5797FE311EB15A6800B2F4A0 /* NavigationClientDefaultCrypto.cpp in Sources */,
 				CDCFFEC122E26A1500DF4223 /* NoPauseWhenSwitchingTabs.mm in Sources */,
 				7AD3FE8E1D76131200B169A4 /* TransformationMatrix.cpp in Sources */,
+				4952BE5E2578115600B0AEF1 /* WKWebViewDisableSelection.mm in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDisableSelection.mm (0 => 270446)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDisableSelection.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewDisableSelection.mm	2020-12-04 19:53:50 UTC (rev 270446)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <WebKit/WKWebViewPrivateForTesting.h>
+#import <wtf/BlockPtr.h>
+#import <wtf/RetainPtr.h>
+
+#if PLATFORM(MAC)
+
+TEST(WKWebViewDisableSelection, DoubleClickDoesNotSelectWhenTextInteractionsAreDisabled)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+    [webView synchronouslyLoadTestPageNamed:@"try-text-select-with-disabled-text-interaction"];
+
+    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:2];
+    [webView waitForPendingMouseEvents];
+
+    NSString *selectedText = [webView stringByEvaluatingJavaScript:@"getSelection().getRangeAt(0).toString()"];
+    EXPECT_WK_STREQ("Hello", selectedText);
+
+    // Clear the selection by clicking once.
+    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:1];
+    [webView waitForPendingMouseEvents];
+
+    // Disable text selection then double click again. This should result in no text selected.
+    [webView configuration].preferences.textInteractionEnabled = NO;
+
+    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:2];
+    [webView waitForPendingMouseEvents];
+
+    NSString *selectedText2 = [webView stringByEvaluatingJavaScript:@"getSelection().getRangeAt(0).toString()"];
+    EXPECT_WK_STREQ("", selectedText2);
+}
+
+static NSString *clickAndDragToSelectText(TestWKWebView *webView)
+{
+    [webView mouseEnterAtPoint:CGPointMake(150, 200)];
+    [webView mouseMoveToPoint:CGPointMake(150, 200) withFlags:0];
+    [webView mouseDownAtPoint:CGPointMake(150, 200) simulatePressure:NO];
+    [webView waitForPendingMouseEvents];
+
+    [webView mouseDragToPoint:CGPointMake(900, 200)];
+    [webView waitForPendingMouseEvents];
+
+    [webView mouseUpAtPoint:CGPointMake(900, 200)];
+    [webView waitForPendingMouseEvents];
+    
+    return [webView stringByEvaluatingJavaScript:@"getSelection().getRangeAt(0).toString()"];
+}
+
+TEST(WKWebViewDisableSelection, DragDoesNotSelectWhenTextInteractionsAreDisabled)
+{
+    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1000, 400)]);
+    [webView synchronouslyLoadTestPageNamed:@"try-text-select-with-disabled-text-interaction"];
+
+    NSString *selectedText = clickAndDragToSelectText(webView.get());
+    EXPECT_WK_STREQ("Hello", selectedText);
+    
+    // Clear the selection by clicking once.
+    [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:1];
+    [webView waitForPendingMouseEvents];
+    
+    // Disable text selection then click and drag again. This should result in no text selected.
+    [webView configuration].preferences.textInteractionEnabled = NO;
+
+    NSString *selectedText2 = clickAndDragToSelectText(webView.get());
+    EXPECT_WK_STREQ("", selectedText2);
+}
+
+#endif // PLATFORM(MAC)

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/try-text-select-with-disabled-text-interaction.html (0 => 270446)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/try-text-select-with-disabled-text-interaction.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/try-text-select-with-disabled-text-interaction.html	2020-12-04 19:53:50 UTC (rev 270446)
@@ -0,0 +1,15 @@
+<style>
+body {
+    width: 100%;
+    height: 100%;
+}
+
+#editable {
+    width: 100%;
+    height: 400px;
+    font-size: 400px;
+    white-space: nowrap;
+    border: 1px blue dashed;
+}
+</style>
+<div id="editable" contenteditable>Hello world</div>

Modified: trunk/Tools/WebKitTestRunner/TestOptions.cpp (270445 => 270446)


--- trunk/Tools/WebKitTestRunner/TestOptions.cpp	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Tools/WebKitTestRunner/TestOptions.cpp	2020-12-04 19:53:50 UTC (rev 270446)
@@ -86,6 +86,7 @@
             { "shouldShowTouches", false },
             { "shouldShowWebView", false },
             { "spellCheckingDots", false },
+            { "textInteractionEnabled", true },
             { "useCharacterSelectionGranularity", false },
             { "useDataDetection", false },
             { "useEphemeralSession", false },
@@ -135,6 +136,7 @@
         { "shouldShowTouches", TestHeaderKeyType::BoolTestRunner },
         { "shouldShowWebView", TestHeaderKeyType::BoolTestRunner },
         { "spellCheckingDots", TestHeaderKeyType::BoolTestRunner },
+        { "textInteractionEnabled", TestHeaderKeyType::BoolTestRunner },
         { "useCharacterSelectionGranularity", TestHeaderKeyType::BoolTestRunner },
         { "useDataDetection", TestHeaderKeyType::BoolTestRunner },
         { "useEphemeralSession", TestHeaderKeyType::BoolTestRunner },

Modified: trunk/Tools/WebKitTestRunner/TestOptions.h (270445 => 270446)


--- trunk/Tools/WebKitTestRunner/TestOptions.h	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Tools/WebKitTestRunner/TestOptions.h	2020-12-04 19:53:50 UTC (rev 270446)
@@ -63,6 +63,7 @@
     bool shouldShowSpellCheckingDots() const { return boolTestRunnerFeatureValue("spellCheckingDots"); }
     bool shouldShowTouches() const { return boolTestRunnerFeatureValue("shouldShowTouches"); }
     bool shouldShowWebView() const { return boolTestRunnerFeatureValue("shouldShowWebView"); }
+    bool textInteractionEnabled() const { return boolTestRunnerFeatureValue("textInteractionEnabled"); }
     bool useCharacterSelectionGranularity() const { return boolTestRunnerFeatureValue("useCharacterSelectionGranularity"); }
     bool useDataDetection() const { return boolTestRunnerFeatureValue("useDataDetection"); }
     bool useEphemeralSession() const { return boolTestRunnerFeatureValue("useEphemeralSession"); }

Modified: trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm (270445 => 270446)


--- trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2020-12-04 19:51:39 UTC (rev 270445)
+++ trunk/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm	2020-12-04 19:53:50 UTC (rev 270446)
@@ -290,6 +290,7 @@
         [platformView _setContinuousSpellCheckingEnabledForTesting:options.shouldShowSpellCheckingDots()];
         [platformView resetInteractionCallbacks];
         [platformView _resetNavigationGestureStateForTesting];
+        [platformView.configuration.preferences setTextInteractionEnabled:options.textInteractionEnabled()];
     }
 
     [globalWebsiteDataStoreDelegateClient setAllowRaisingQuota:YES];
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to