Title: [256551] branches/safari-609.1.17.0-branch
Revision
256551
Author
[email protected]
Date
2020-02-13 14:52:39 -0800 (Thu, 13 Feb 2020)

Log Message

Cherry-pick r256000. rdar://problem/59299326

    WebPage::rangeForGranularityAtPoint always returns null in the case of CharacterGranularity
    https://bugs.webkit.org/show_bug.cgi?id=207350
    <rdar://problem/59239914>

    Reviewed by Tim Horton.

    Source/WebKit:

    Handle the character granularity case in `WebPage::rangeForGranularityAtPoint` by just returning a collapsed
    Range. Certain internal clients will have a need to place and update the text selection using character
    granularity; see radar for more details.

    Test: UIWKInteractionViewProtocol.SelectTextWithCharacterGranularity

    * UIProcess/ios/WKContentViewInteraction.mm:
    (-[WKContentView supportsTextSelectionWithCharacterGranularity]):
    * WebProcess/WebPage/ios/WebPageIOS.mm:
    (WebKit::WebPage::rangeForGranularityAtPoint):

    Tools:

    Add a test to exercise the corner case in the SPI.

    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
    * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm: Added.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-609.1.17.0-branch/Source/WebKit/ChangeLog (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Source/WebKit/ChangeLog	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Source/WebKit/ChangeLog	2020-02-13 22:52:39 UTC (rev 256551)
@@ -1,5 +1,57 @@
 2020-02-13  Russell Epstein  <[email protected]>
 
+        Cherry-pick r256000. rdar://problem/59299326
+
+    WebPage::rangeForGranularityAtPoint always returns null in the case of CharacterGranularity
+    https://bugs.webkit.org/show_bug.cgi?id=207350
+    <rdar://problem/59239914>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    Handle the character granularity case in `WebPage::rangeForGranularityAtPoint` by just returning a collapsed
+    Range. Certain internal clients will have a need to place and update the text selection using character
+    granularity; see radar for more details.
+    
+    Test: UIWKInteractionViewProtocol.SelectTextWithCharacterGranularity
+    
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView supportsTextSelectionWithCharacterGranularity]):
+    * WebProcess/WebPage/ios/WebPageIOS.mm:
+    (WebKit::WebPage::rangeForGranularityAtPoint):
+    
+    Tools:
+    
+    Add a test to exercise the corner case in the SPI.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256000 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-06  Wenson Hsieh  <[email protected]>
+
+            WebPage::rangeForGranularityAtPoint always returns null in the case of CharacterGranularity
+            https://bugs.webkit.org/show_bug.cgi?id=207350
+            <rdar://problem/59239914>
+
+            Reviewed by Tim Horton.
+
+            Handle the character granularity case in `WebPage::rangeForGranularityAtPoint` by just returning a collapsed
+            Range. Certain internal clients will have a need to place and update the text selection using character
+            granularity; see radar for more details.
+
+            Test: UIWKInteractionViewProtocol.SelectTextWithCharacterGranularity
+
+            * UIProcess/ios/WKContentViewInteraction.mm:
+            (-[WKContentView supportsTextSelectionWithCharacterGranularity]):
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::rangeForGranularityAtPoint):
+
+2020-02-13  Russell Epstein  <[email protected]>
+
         Cherry-pick r255879. rdar://problem/59299329
 
     [macCatalyst] Incorrect IBeam cursor when selecting text on Wikipedia

Modified: branches/safari-609.1.17.0-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2020-02-13 22:52:39 UTC (rev 256551)
@@ -6366,6 +6366,11 @@
     return !_ignoreSelectionCommandFadeCount;
 }
 
+- (BOOL)supportsTextSelectionWithCharacterGranularity
+{
+    return YES;
+}
+
 - (BOOL)hasHiddenContentEditable
 {
     return _suppressSelectionAssistantReasons.contains(WebKit::EditableRootIsTransparentOrFullyClipped);

Modified: branches/safari-609.1.17.0-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-02-13 22:52:39 UTC (rev 256551)
@@ -2050,6 +2050,9 @@
 
     RefPtr<Range> range;
     switch (static_cast<WebCore::TextGranularity>(granularity)) {
+    case CharacterGranularity:
+        range = makeRange(position, position);
+        break;
     case WordGranularity:
         range = wordRangeFromPosition(position);
         break;
@@ -2060,6 +2063,7 @@
         range = enclosingTextUnitOfGranularity(position, ParagraphGranularity, DirectionForward);
         break;
     case DocumentGranularity:
+        // FIXME: It's not clear why this mutates the current selection and returns null.
         frame.selection().selectAll();
         break;
     default:

Modified: branches/safari-609.1.17.0-branch/Tools/ChangeLog (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Tools/ChangeLog	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Tools/ChangeLog	2020-02-13 22:52:39 UTC (rev 256551)
@@ -1,3 +1,49 @@
+2020-02-13  Russell Epstein  <[email protected]>
+
+        Cherry-pick r256000. rdar://problem/59299326
+
+    WebPage::rangeForGranularityAtPoint always returns null in the case of CharacterGranularity
+    https://bugs.webkit.org/show_bug.cgi?id=207350
+    <rdar://problem/59239914>
+    
+    Reviewed by Tim Horton.
+    
+    Source/WebKit:
+    
+    Handle the character granularity case in `WebPage::rangeForGranularityAtPoint` by just returning a collapsed
+    Range. Certain internal clients will have a need to place and update the text selection using character
+    granularity; see radar for more details.
+    
+    Test: UIWKInteractionViewProtocol.SelectTextWithCharacterGranularity
+    
+    * UIProcess/ios/WKContentViewInteraction.mm:
+    (-[WKContentView supportsTextSelectionWithCharacterGranularity]):
+    * WebProcess/WebPage/ios/WebPageIOS.mm:
+    (WebKit::WebPage::rangeForGranularityAtPoint):
+    
+    Tools:
+    
+    Add a test to exercise the corner case in the SPI.
+    
+    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+    * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256000 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-02-06  Wenson Hsieh  <[email protected]>
+
+            WebPage::rangeForGranularityAtPoint always returns null in the case of CharacterGranularity
+            https://bugs.webkit.org/show_bug.cgi?id=207350
+            <rdar://problem/59239914>
+
+            Reviewed by Tim Horton.
+
+            Add a test to exercise the corner case in the SPI.
+
+            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+            * TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm: Added.
+
 2020-02-04  Russell Epstein  <[email protected]>
 
         Cherry-pick r255461. rdar://problem/59153618

Modified: branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2020-02-13 22:52:39 UTC (rev 256551)
@@ -979,6 +979,7 @@
 		E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3DEA8101F0A588000CBC2E8 /* ThreadGroup.cpp */; };
 		E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E5036F77211BC22800BFDBE2 /* color-drop.html */; };
 		ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = ECA680CD1E68CC0900731D20 /* StringUtilities.mm */; };
+		F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */ = {isa = PBXBuildFile; fileRef = F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */; };
 		F407FE391F1D0DFC0017CF25 /* enormous.svg in Copy Resources */ = {isa = PBXBuildFile; fileRef = F407FE381F1D0DE60017CF25 /* enormous.svg */; };
 		F4106C6921ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */; };
 		F415086D1DA040C50044BE9B /* play-audio-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F415086C1DA040C10044BE9B /* play-audio-on-click.html */; };
@@ -2519,6 +2520,7 @@
 		EC79F168BE454E579E417B05 /* Markable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Markable.cpp; sourceTree = "<group>"; };
 		ECA680CD1E68CC0900731D20 /* StringUtilities.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = StringUtilities.mm; sourceTree = "<group>"; };
 		F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UIWKInteractionViewProtocol.mm; sourceTree = "<group>"; };
 		F407FE381F1D0DE60017CF25 /* enormous.svg */ = {isa = PBXFileReference; lastKnownFileType = text; path = enormous.svg; sourceTree = "<group>"; };
 		F4106C6821ACBF84004B89A1 /* WKWebViewFirstResponderTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewFirstResponderTests.mm; sourceTree = "<group>"; };
 		F415086C1DA040C10044BE9B /* play-audio-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "play-audio-on-click.html"; sourceTree = "<group>"; };
@@ -3217,6 +3219,7 @@
 				F45E15752112CE6200307E82 /* TestInputDelegate.mm */,
 				F45033F4206BEC95009351CE /* TextAutosizingBoost.mm */,
 				F46849BD1EEF58E400B937FE /* UIPasteboardTests.mm */,
+				F402F56B23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm */,
 				F43E3BBE20DADA1E00A4E7ED /* WKScrollViewTests.mm */,
 				514958BD1F7427AC00E87BAD /* WKWebViewAutofillTests.mm */,
 				1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */,
@@ -4929,6 +4932,7 @@
 				57152B7821DD4E8D000C37CA /* U2fCommandConstructorTest.cpp in Sources */,
 				5CB40B4E1F4B98D3007DC7B9 /* UIDelegate.mm in Sources */,
 				F46849BE1EEF58E400B937FE /* UIPasteboardTests.mm in Sources */,
+				F402F56C23ECC2FB00865549 /* UIWKInteractionViewProtocol.mm in Sources */,
 				5C9D922E22D7DE1C008E9266 /* UnifiedSource1.cpp in Sources */,
 				5C9D922C22D7DE12008E9266 /* UnifiedSource1-mm.mm in Sources */,
 				5C9D922F22D7DE1F008E9266 /* UnifiedSource2.cpp in Sources */,

Added: branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm (0 => 256551)


--- branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm	                        (rev 0)
+++ branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/Tests/ios/UIWKInteractionViewProtocol.mm	2020-02-13 22:52:39 UTC (rev 256551)
@@ -0,0 +1,71 @@
+/*
+ * 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"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+#import <wtf/RetainPtr.h>
+
+@interface TestWKWebView (UIWKInteractionViewTesting)
+- (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point;
+- (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity;
+@end
+
+@implementation TestWKWebView (UIWKInteractionViewTesting)
+
+- (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point
+{
+    __block bool done = false;
+    [self.textInputContentView selectTextWithGranularity:granularity atPoint:point completionHandler:^{
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+}
+
+- (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity
+{
+    __block bool done = false;
+    [self.textInputContentView updateSelectionWithExtentPoint:point withBoundary:granularity completionHandler:^(BOOL) {
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+}
+
+@end
+
+TEST(UIWKInteractionViewProtocol, SelectTextWithCharacterGranularity)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)]);
+    [webView synchronouslyLoadHTMLString:@"<body style='font-size: 20px;'>Hello world</body>"];
+    [webView selectTextWithGranularity:UITextGranularityCharacter atPoint:CGPointMake(10, 20)];
+    [webView updateSelectionWithExtentPoint:CGPointMake(300, 20) withBoundary:UITextGranularityCharacter];
+    EXPECT_WK_STREQ("Hello world", [webView stringByEvaluatingJavaScript:@"getSelection().toString()"]);
+}
+
+#endif

Modified: branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h (256550 => 256551)


--- branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-02-13 22:52:36 UTC (rev 256550)
+++ branches/safari-609.1.17.0-branch/Tools/TestWebKitAPI/ios/UIKitSPI.h	2020-02-13 22:52:39 UTC (rev 256551)
@@ -173,6 +173,8 @@
 - (void)requestAutocorrectionRectsForString:(NSString *)input withCompletionHandler:(void (^)(UIWKAutocorrectionRects *rectsForInput))completionHandler;
 - (void)requestAutocorrectionContextWithCompletionHandler:(void (^)(UIWKAutocorrectionContext *autocorrectionContext))completionHandler;
 - (void)selectWordBackward;
+- (void)selectTextWithGranularity:(UITextGranularity)granularity atPoint:(CGPoint)point completionHandler:(void (^)(void))completionHandler;
+- (void)updateSelectionWithExtentPoint:(CGPoint)point withBoundary:(UITextGranularity)granularity completionHandler:(void (^)(BOOL selectionEndIsMoving))completionHandler;
 @property (nonatomic, readonly) NSString *selectedText;
 @end
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to