Title: [249701] trunk
Revision
249701
Author
[email protected]
Date
2019-09-09 20:50:04 -0700 (Mon, 09 Sep 2019)

Log Message

Tap and hold on Facebook sometimes creates a tall empty selection.
https://bugs.webkit.org/show_bug.cgi?id=201618
rdar://53630145

Reviewed by Megan Gardner.

Source/WebCore:

API Test: SelectionTests.ByWordAtEndOfDocument

* editing/VisibleUnits.cpp:
(WebCore::wordRangeFromPosition):
Remove special case code for the possibility of an empty paragraph and at the end
of the document. This is no longer needed and was causing a large selection to be
created on Facebook due to large areas of non-selectable content on the page.

Tools:

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

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249700 => 249701)


--- trunk/Source/WebCore/ChangeLog	2019-09-10 03:20:08 UTC (rev 249700)
+++ trunk/Source/WebCore/ChangeLog	2019-09-10 03:50:04 UTC (rev 249701)
@@ -1,3 +1,19 @@
+2019-09-09  Timothy Hatcher  <[email protected]>
+
+        Tap and hold on Facebook sometimes creates a tall empty selection.
+        https://bugs.webkit.org/show_bug.cgi?id=201618
+        rdar://53630145
+
+        Reviewed by Megan Gardner.
+
+        API Test: SelectionTests.ByWordAtEndOfDocument
+
+        * editing/VisibleUnits.cpp:
+        (WebCore::wordRangeFromPosition):
+        Remove special case code for the possibility of an empty paragraph and at the end
+        of the document. This is no longer needed and was causing a large selection to be
+        created on Facebook due to large areas of non-selectable content on the page.
+
 2019-09-09  Joonghun Park  <[email protected]>
 
         getComputedStyle for line-height: normal should return the keyword instead of a length

Modified: trunk/Source/WebCore/editing/VisibleUnits.cpp (249700 => 249701)


--- trunk/Source/WebCore/editing/VisibleUnits.cpp	2019-09-10 03:20:08 UTC (rev 249700)
+++ trunk/Source/WebCore/editing/VisibleUnits.cpp	2019-09-10 03:50:04 UTC (rev 249701)
@@ -1969,6 +1969,7 @@
         // We could be at the start of a word, try forward.
         range = enclosingTextUnitOfGranularity(position, WordGranularity, DirectionForward);
     }
+
     if (range)
         return range;
 
@@ -1977,18 +1978,6 @@
         currentPosition = positionOfNextBoundaryOfGranularity(currentPosition, WordGranularity, DirectionBackward);
     } while (currentPosition.isNotNull() && !atBoundaryOfGranularity(currentPosition, WordGranularity, DirectionBackward));
 
-    // If the position is an empty paragraph and at the end of the document
-    // the word iterator could not pass the paragraph boundary, therefore iterating to
-    // the previous line is required.
-    if (currentPosition.isNull() && isEndOfDocument(position)) {
-        VisiblePosition previousLinePosition = positionOfNextBoundaryOfGranularity(position, LineGranularity, DirectionBackward);
-        if (previousLinePosition.isNotNull()) {
-            currentPosition = positionOfNextBoundaryOfGranularity(previousLinePosition, WordGranularity, DirectionBackward);
-            if (currentPosition.isNull())
-                currentPosition = previousLinePosition;
-        }
-    }
-
     if (currentPosition.isNull())
         currentPosition = positionOfNextBoundaryOfGranularity(position, WordGranularity, DirectionForward);
 
@@ -1996,6 +1985,7 @@
         range = Range::create(position.deepEquivalent().deprecatedNode()->document(), currentPosition, position);
         ASSERT(range);
     }
+
     return range;
 }
 

Modified: trunk/Tools/ChangeLog (249700 => 249701)


--- trunk/Tools/ChangeLog	2019-09-10 03:20:08 UTC (rev 249700)
+++ trunk/Tools/ChangeLog	2019-09-10 03:50:04 UTC (rev 249701)
@@ -1,3 +1,14 @@
+2019-09-09  Timothy Hatcher  <[email protected]>
+
+        Tap and hold on Facebook sometimes creates a tall empty selection.
+        https://bugs.webkit.org/show_bug.cgi?id=201618
+        rdar://53630145
+
+        Reviewed by Megan Gardner.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/ios/SelectionByWord.mm: Added.
+
 2019-09-09  Aakash Jain  <[email protected]>
 
         [EWS] Watchlist doesn't work sometimes

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (249700 => 249701)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 03:20:08 UTC (rev 249700)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2019-09-10 03:50:04 UTC (rev 249701)
@@ -104,6 +104,7 @@
 		1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
 		1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
 		1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
+		1C90420C2326E03C00BEF91E /* SelectionByWord.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C90420B2326E03C00BEF91E /* SelectionByWord.mm */; };
 		1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
 		1CACADA1230620AE0007D54C /* WKWebViewOpaque.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */; };
 		1CE6FAC32320267C00E48F6E /* rich-color-filtered.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1CE6FAC12320264F00E48F6E /* rich-color-filtered.html */; };
@@ -1524,6 +1525,7 @@
 		1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
 		1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
 		1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackgroundColor.mm; sourceTree = "<group>"; };
+		1C90420B2326E03C00BEF91E /* SelectionByWord.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SelectionByWord.mm; sourceTree = "<group>"; };
 		1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
 		1CACADA0230620AD0007D54C /* WKWebViewOpaque.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewOpaque.mm; sourceTree = "<group>"; };
 		1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
@@ -3068,6 +3070,7 @@
 				F464AF9120BB66EA007F9B18 /* RenderingProgressTests.mm */,
 				F4C8797E2059D8D3009CD00B /* ScrollViewInsetTests.mm */,
 				0FF1134D22D68679009A81DA /* ScrollViewScrollabilityTests.mm */,
+				1C90420B2326E03C00BEF91E /* SelectionByWord.mm */,
 				9B4B5EA422DEBE19001E3D5A /* SelectionModifyByParagraphBoundary.mm */,
 				CE6E819F20A6935F00E2C80F /* SetTimeoutFunction.mm */,
 				4433A395208044130091ED57 /* SynchronousTimeoutTests.mm */,
@@ -4684,6 +4687,7 @@
 				F4C8797F2059D8D3009CD00B /* ScrollViewInsetTests.mm in Sources */,
 				0FF1134E22D68679009A81DA /* ScrollViewScrollabilityTests.mm in Sources */,
 				CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */,
+				1C90420C2326E03C00BEF91E /* SelectionByWord.mm in Sources */,
 				9B4B5EA522DEBE19001E3D5A /* SelectionModifyByParagraphBoundary.mm in Sources */,
 				5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */,
 				51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/ios/SelectionByWord.mm (0 => 249701)


--- trunk/Tools/TestWebKitAPI/Tests/ios/SelectionByWord.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/SelectionByWord.mm	2019-09-10 03:50:04 UTC (rev 249701)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#include "config.h"
+
+#if PLATFORM(IOS_FAMILY)
+
+#import "PlatformUtilities.h"
+#import "TestInputDelegate.h"
+#import "TestWKWebView.h"
+#import "UIKitSPI.h"
+
+@interface WKContentView (Private)
+- (void)selectWordForReplacement;
+@end
+
+TEST(SelectionTests, ByWordAtEndOfDocument)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] init]);
+
+    [webView synchronouslyLoadHTMLString:@"<body><p>Paragraph One</p><p style='-webkit-user-select: none'>Paragraph Two</p><p>Paragraph Three</p><p></p></body>"];
+
+    [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(document.body.lastChild, 0)"];
+
+    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"getSelection().isCollapsed"].boolValue);
+
+    // This method triggers the wordRangeFromPosition() code to be tested.
+    [[webView wkContentView] selectWordForReplacement];
+
+    EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"getSelection().isCollapsed"].boolValue);
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getSelection().anchorNode.nodeValue"], "Paragraph Three");
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getSelection().anchorOffset"], "10");
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getSelection().focusNode.nodeValue"], "Paragraph Three");
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getSelection().focusOffset"], "15");
+
+    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getSelection().toString()"], "Three");
+}
+
+#endif // PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to