Title: [259013] trunk
Revision
259013
Author
dba...@webkit.org
Date
2020-03-25 14:56:03 -0700 (Wed, 25 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 (259012 => 259013)


--- trunk/Source/WebKit/ChangeLog	2020-03-25 21:36:05 UTC (rev 259012)
+++ trunk/Source/WebKit/ChangeLog	2020-03-25 21:56:03 UTC (rev 259013)
@@ -1,3 +1,17 @@
+2020-03-25  Daniel Bates  <daba...@apple.com>
+
+        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-25  Wenson Hsieh  <wenson_hs...@apple.com>
 
         Rename "data interaction pasteboard" to "drag and drop pasteboard"

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-25 21:36:05 UTC (rev 259012)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2020-03-25 21:56:03 UTC (rev 259013)
@@ -4252,8 +4252,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 (259012 => 259013)


--- trunk/Tools/ChangeLog	2020-03-25 21:36:05 UTC (rev 259012)
+++ trunk/Tools/ChangeLog	2020-03-25 21:56:03 UTC (rev 259013)
@@ -1,3 +1,16 @@
+2020-03-25  Daniel Bates  <daba...@apple.com>
+
+        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-25  Doug Kelly  <do...@apple.com>
 
         Unreviewed, add new committer to contributors.json

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm (259012 => 259013)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2020-03-25 21:36:05 UTC (rev 259012)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm	2020-03-25 21:56:03 UTC (rev 259013)
@@ -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.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); /* Place caret at the beginning of the field. */ 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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to