Title: [258945] trunk
Revision
258945
Author
[email protected]
Date
2020-03-24 15:08:58 -0700 (Tue, 24 Mar 2020)

Log Message

Element context character rects may be in wrong coordinate system
https://bugs.webkit.org/show_bug.cgi?id=209493
<rdar://problem/60840261>

Reviewed by Wenson Hsieh.

Source/WebKit:

Convert the character rects from content view coordinates to root view coordinates
as that is the coordinate system callers of -requestDocumentContext expect.

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

Tools:

Add some tests.

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (258944 => 258945)


--- trunk/Source/WebKit/ChangeLog	2020-03-24 22:05:53 UTC (rev 258944)
+++ trunk/Source/WebKit/ChangeLog	2020-03-24 22:08:58 UTC (rev 258945)
@@ -1,5 +1,19 @@
 2020-03-24  Daniel Bates  <[email protected]>
 
+        Element context character rects may be in wrong coordinate system
+        https://bugs.webkit.org/show_bug.cgi?id=209493
+        <rdar://problem/60840261>
+
+        Reviewed by Wenson Hsieh.
+
+        Convert the character rects from content view coordinates to root view coordinates
+        as that is the coordinate system callers of -requestDocumentContext expect.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::requestDocumentEditingContext):
+
+2020-03-24  Daniel Bates  <[email protected]>
+
         Use SimpleRange in characterRectsForRange()
         https://bugs.webkit.org/show_bug.cgi?id=209495
 

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-24 22:05:53 UTC (rev 258944)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-24 22:08:58 UTC (rev 258945)
@@ -4242,8 +4242,11 @@
         unsigned offsetSoFar = startOffset;
         const int stride = 1;
         while (!iterator.atEnd()) {
-            if (!iterator.text().isEmpty())
-                rects.append({ createLiveRange(iterator.range())->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections), { offsetSoFar++, stride } });
+            if (!iterator.text().isEmpty()) {
+                auto currentRange = createLiveRange(iterator.range());
+                auto absoluteBoundingBox = currentRange->absoluteBoundingBox(Range::BoundingRectBehavior::IgnoreEmptyTextSelections);
+                rects.append({ currentRange->ownerDocument().view()->contentsToRootView(absoluteBoundingBox), { offsetSoFar++, stride } });
+            }
             iterator.advance(stride);
         }
         return rects;

Modified: trunk/Tools/ChangeLog (258944 => 258945)


--- trunk/Tools/ChangeLog	2020-03-24 22:05:53 UTC (rev 258944)
+++ trunk/Tools/ChangeLog	2020-03-24 22:08:58 UTC (rev 258945)
@@ -1,3 +1,16 @@
+2020-03-24  Daniel Bates  <[email protected]>
+
+        Element context character rects may be in wrong coordinate system
+        https://bugs.webkit.org/show_bug.cgi?id=209493
+        <rdar://problem/60840261>
+
+        Reviewed by Wenson Hsieh.
+
+        Add some tests.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
+        (TEST):
+
 2020-03-24  Aakash Jain  <[email protected]>
 
         [ews] position in queue shown in status-bubble is larger than actual position

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (258944 => 258945)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2020-03-24 22:05:53 UTC (rev 258944)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2020-03-24 22:08:58 UTC (rev 258945)
@@ -513,6 +513,64 @@
     }
 }
 
+TEST(DocumentEditingContext, RequestRectsInTextAreaInsideIFrame)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    // Use "padding: 0" for the <textarea> as the default user-agent stylesheet can effect text wrapping.
+    [webView synchronouslyLoadHTMLString:applyAhemStyle([NSString stringWithFormat:@"<iframe srcdoc=\"%@\" style='position: absolute; left: 1em; top: 1em; border: none'></iframe>", applyAhemStyle(@"<textarea id='test' style='padding: 0'>The quick brown fox jumps over the lazy dog.</textarea><script>let textarea = document.querySelector('iframe').contentDocument.getElementById('test'); textarea.focus(); textarea.setSelectionRange(0, 0); /* Place caret at the beginning of the field. */</script>")])];
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NULL(context.contextBefore);
+    EXPECT_NSSTRING_EQ("The", context.contextAfter);
+    auto *textRects = [context textRects];
+    EXPECT_EQ(3U, textRects.count);
+
+#if PLATFORM(MACCATALYST)
+    const size_t yPos = 27;
+    const size_t height = 26;
+#else
+    const size_t yPos = 28;
+    const size_t height = 25;
+#endif
+
+    if (textRects.count >= 3) {
+        CGFloat x = 28;
+        EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T
+        EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h
+        EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e
+    }
+}
+
+TEST(DocumentEditingContext, RequestRectsInTextAreaInsideScrolledIFrame)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    // Use "padding: 0" for the <textarea> as the default user-agent stylesheet can effect text wrapping.
+    [webView synchronouslyLoadHTMLString:applyAhemStyle([NSString stringWithFormat:@"<iframe srcdoc=\"%@\" style='position: absolute; left: 1em; top: 1em; border: none' height='200'></iframe>", applyAhemStyle(@"<body style='height: 1000px'><div style='width: 200px; height: 200px'></div><textarea id='test' style='padding: 0'>The quick brown fox jumps over the lazy dog.</textarea><script>let textarea = document.getElementById('test'); textarea.focus(); textarea.setSelectionRange(0, 0); window.scrollTo(0, 200); /* Scroll <textarea> to the top. */</script></body>")])];
+
+    auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)];
+    EXPECT_NOT_NULL(context);
+    EXPECT_NULL(context.contextBefore);
+    EXPECT_NSSTRING_EQ("The", context.contextAfter);
+    auto *textRects = [context textRects];
+    EXPECT_EQ(3U, textRects.count);
+
+#if PLATFORM(MACCATALYST)
+    const size_t yPos = 27;
+    const size_t height = 26;
+#else
+    const size_t yPos = 28;
+    const size_t height = 25;
+#endif
+
+    if (textRects.count >= 3) {
+        CGFloat x = 28;
+        EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T
+        EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h
+        EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e
+    }
+}
+
 // MARK: Tests using word granularity
 
 TEST(DocumentEditingContext, RequestFirstTwoWords)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to