Title: [253399] trunk
Revision
253399
Author
dba...@webkit.org
Date
2019-12-11 15:43:48 -0800 (Wed, 11 Dec 2019)

Log Message

UIWKDocumentContext returns 0 character rects when caret is at beginning or end of text
https://bugs.webkit.org/show_bug.cgi?id=205135
<rdar://problem/56887914>

Reviewed by Wenson Hsieh.

Source/WebKit:

When the specified position to move from is at the beginning or end of the text then return
the position of the beginning or end of the nearest word based on the specified direction.

Currently we always return the null position. As a result we do not compute a valid
character range to convert to rectangles.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::moveByGranularityRespectingWordBoundary):

Tools:

Add tests that request rects when the insertion point is at the beginning or end of the text.

* TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (253398 => 253399)


--- trunk/Source/WebKit/ChangeLog	2019-12-11 23:19:08 UTC (rev 253398)
+++ trunk/Source/WebKit/ChangeLog	2019-12-11 23:43:48 UTC (rev 253399)
@@ -1,3 +1,20 @@
+2019-12-11  Daniel Bates  <daba...@apple.com>
+
+        UIWKDocumentContext returns 0 character rects when caret is at beginning or end of text
+        https://bugs.webkit.org/show_bug.cgi?id=205135
+        <rdar://problem/56887914>
+
+        Reviewed by Wenson Hsieh.
+
+        When the specified position to move from is at the beginning or end of the text then return
+        the position of the beginning or end of the nearest word based on the specified direction.
+
+        Currently we always return the null position. As a result we do not compute a valid
+        character range to convert to rectangles.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::moveByGranularityRespectingWordBoundary):
+
 2019-12-11  Jiewen Tan  <jiewen_...@apple.com>
 
         [WebAuthn] Combine AuthenticatorResponse and PublicKeyCredentialData

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (253398 => 253399)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-12-11 23:19:08 UTC (rev 253398)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2019-12-11 23:43:48 UTC (rev 253399)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-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
@@ -3872,7 +3872,7 @@
     bool backwards = direction == DirectionBackward;
     auto farthestPositionInDirection = backwards ? startOfEditableContent(position) : endOfEditableContent(position);
     if (position == farthestPositionInDirection)
-        return { };
+        return backwards ? startOfWord(position) : endOfWord(position);
 
     VisiblePosition currentPosition = position;
     VisiblePosition nextPosition;

Modified: trunk/Tools/ChangeLog (253398 => 253399)


--- trunk/Tools/ChangeLog	2019-12-11 23:19:08 UTC (rev 253398)
+++ trunk/Tools/ChangeLog	2019-12-11 23:43:48 UTC (rev 253399)
@@ -1,3 +1,16 @@
+2019-12-11  Daniel Bates  <daba...@apple.com>
+
+        UIWKDocumentContext returns 0 character rects when caret is at beginning or end of text
+        https://bugs.webkit.org/show_bug.cgi?id=205135
+        <rdar://problem/56887914>
+
+        Reviewed by Wenson Hsieh.
+
+        Add tests that request rects when the insertion point is at the beginning or end of the text.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
+        (TEST):
+
 2019-12-11  Jiewen Tan  <jiewen_...@apple.com>
 
         [WebAuthn] Combine AuthenticatorResponse and PublicKeyCredentialData

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (253398 => 253399)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2019-12-11 23:19:08 UTC (rev 253398)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2019-12-11 23:43:48 UTC (rev 253399)
@@ -395,4 +395,91 @@
     }
 }
 
+TEST(WebKit, DocumentEditingContextCaretAtStartOfText)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView synchronouslyLoadHTMLString:applyStyle(@"<p id='text' contenteditable>The quick brown fox jumps over the lazy dog.</p>")];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus <p>.
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NULL(context.contextBefore);
+    EXPECT_NULL(context.selectedText);
+    EXPECT_NSSTRING_EQ("The quick", context.contextAfter);
+
+    auto *textRects = context.textRects;
+    ASSERT_EQ(9U, textRects.count);
+    EXPECT_EQ(CGRectMake(0, 0, 10, 19), textRects[0].CGRectValue); // T
+    EXPECT_EQ(CGRectMake(9, 0, 9, 19), textRects[1].CGRectValue); // h
+    EXPECT_EQ(CGRectMake(17, 0, 8, 19), textRects[2].CGRectValue); // e
+    EXPECT_EQ(CGRectMake(24, 0, 5, 19), textRects[3].CGRectValue); //
+    EXPECT_EQ(CGRectMake(28, 0, 9, 19), textRects[4].CGRectValue); // q
+    EXPECT_EQ(CGRectMake(36, 0, 9, 19), textRects[5].CGRectValue); // u
+    EXPECT_EQ(CGRectMake(44, 0, 6, 19), textRects[6].CGRectValue); // i
+    EXPECT_EQ(CGRectMake(49, 0, 8, 19), textRects[7].CGRectValue); // c
+    EXPECT_EQ(CGRectMake(56, 0, 9, 19), textRects[8].CGRectValue); // k
+}
+
+TEST(WebKit, DocumentEditingContextCaretAtStartOfTextWithLeadingNonBreakableSpace)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView synchronouslyLoadHTMLString:applyStyle(@"<p id='text' contenteditable>&nbsp;The quick brown fox jumps over the lazy dog.</p>")];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus <p>.
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NULL(context.contextBefore);
+    EXPECT_NULL(context.selectedText);
+    EXPECT_NSSTRING_EQ(" The", context.contextAfter);
+
+    auto *textRects = context.textRects;
+    ASSERT_EQ(4U, textRects.count);
+    EXPECT_EQ(CGRectMake(0, 0, 4, 19), textRects[0].CGRectValue); //
+    EXPECT_EQ(CGRectMake(4, 0, 10, 19), textRects[1].CGRectValue); // T
+    EXPECT_EQ(CGRectMake(13, 0, 9, 19), textRects[2].CGRectValue); // h
+    EXPECT_EQ(CGRectMake(21, 0, 8, 19), textRects[3].CGRectValue); // e
+}
+
+
+TEST(WebKit, DocumentEditingContextCaretAtEndOfText)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView synchronouslyLoadHTMLString:applyStyle(@"<p id='text' contenteditable>The quick brown fox jumps over the lazy dog.</p>")];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus <p>.
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NSSTRING_EQ("dog.", context.contextBefore);
+    EXPECT_NULL(context.selectedText);
+    EXPECT_NULL(context.contextAfter);
+
+    auto *textRects = context.textRects;
+    ASSERT_EQ(4U, textRects.count);
+    EXPECT_EQ(CGRectMake(268, 0, 9, 19), textRects[0].CGRectValue); // d
+    EXPECT_EQ(CGRectMake(276, 0, 9, 19), textRects[1].CGRectValue); // o
+    EXPECT_EQ(CGRectMake(284, 0, 9, 19), textRects[2].CGRectValue); // g
+    EXPECT_EQ(CGRectMake(292, 0, 5, 19), textRects[3].CGRectValue); // .
+}
+
+TEST(WebKit, DocumentEditingContextCaretAtEndOfTextWithTrailingNonBreakableSpace)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView synchronouslyLoadHTMLString:applyStyle(@"<p id='text' contenteditable>The quick brown fox jumps over the lazy dog.&nbsp;</p>")];
+    [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus <p>.
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NSSTRING_EQ("dog. ", context.contextBefore);
+    EXPECT_NULL(context.selectedText);
+    EXPECT_NULL(context.contextAfter);
+
+    auto *textRects = context.textRects;
+    ASSERT_EQ(5U, textRects.count);
+    EXPECT_EQ(CGRectMake(268, 0, 9, 19), textRects[0].CGRectValue); // d
+    EXPECT_EQ(CGRectMake(276, 0, 9, 19), textRects[1].CGRectValue); // o
+    EXPECT_EQ(CGRectMake(284, 0, 9, 19), textRects[2].CGRectValue); // g
+    EXPECT_EQ(CGRectMake(292, 0, 5, 19), textRects[3].CGRectValue); // .
+    EXPECT_EQ(CGRectMake(296, 0, 5, 19), textRects[4].CGRectValue); //
+}
+
 #endif // PLATFORM(IOS_FAMILY) && HAVE(UI_WK_DOCUMENT_CONTEXT)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to