Title: [291347] trunk
Revision
291347
Author
[email protected]
Date
2022-03-16 08:06:35 -0700 (Wed, 16 Mar 2022)

Log Message

[iOS] Refactor some position information hit-testing logic related to data detectors in Live Text
https://bugs.webkit.org/show_bug.cgi?id=237927

Reviewed by Tim Horton.

Source/WebKit:

Pull the call to `dataDetectorImageOverlayPositionInformation()` out from `elementPositionInformation()`, and
into the top level in `WebPage::positionInformation()`. Since `dataDetectorImageOverlayPositionInformation` only
depends on the hit-tested inner node (rather than the element responding to click events), it doesn't make sense
to only populate the data detector results array only when we find an element that responds to clicks.

Test: fast/images/text-recognition/ios/show-data-detector-context-menu.html

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

LayoutTests:

Add a simple layout test that exercises context menu presentation when long pressing a data detector result
inside Live Text in an image. While this behavior isn't new, it's currently untested before this patch.

* fast/images/text-recognition/ios/show-data-detector-context-menu-expected.txt: Added.
* fast/images/text-recognition/ios/show-data-detector-context-menu.html:

Also add `-webkit-user-select: none;` to test that disabling text selection does not also disable the ability to
present the context menu over data detectors by long pressing on iOS.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291346 => 291347)


--- trunk/LayoutTests/ChangeLog	2022-03-16 14:41:56 UTC (rev 291346)
+++ trunk/LayoutTests/ChangeLog	2022-03-16 15:06:35 UTC (rev 291347)
@@ -1,3 +1,19 @@
+2022-03-16  Wenson Hsieh  <[email protected]>
+
+        [iOS] Refactor some position information hit-testing logic related to data detectors in Live Text
+        https://bugs.webkit.org/show_bug.cgi?id=237927
+
+        Reviewed by Tim Horton.
+
+        Add a simple layout test that exercises context menu presentation when long pressing a data detector result
+        inside Live Text in an image. While this behavior isn't new, it's currently untested before this patch.
+
+        * fast/images/text-recognition/ios/show-data-detector-context-menu-expected.txt: Added.
+        * fast/images/text-recognition/ios/show-data-detector-context-menu.html:
+
+        Also add `-webkit-user-select: none;` to test that disabling text selection does not also disable the ability to
+        present the context menu over data detectors by long pressing on iOS.
+
 2022-03-16  Youenn Fablet  <[email protected]>
 
         redirectCount returns 0 when using a Service Worker

Added: trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu-expected.txt (0 => 291347)


--- trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu-expected.txt	2022-03-16 15:06:35 UTC (rev 291347)
@@ -0,0 +1,5 @@
+PASS result?.contextMenu?.items?.includes('Open Link') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu.html (0 => 291347)


--- trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/ios/show-data-detector-context-menu.html	2022-03-16 15:06:35 UTC (rev 291347)
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+body, html {
+    margin: 0;
+}
+</style>
+<script src=""
+<script src=""
+</head>
+<body>
+<img src="" style="-webkit-user-select: none;"></img>
+<script>
+jsTestIsAsync = true;
+
+addEventListener("load", async () => {
+    internals.installImageOverlay(document.querySelector("img"), [
+        {
+            topLeft : new DOMPointReadOnly(0, 0),
+            topRight : new DOMPointReadOnly(1, 0),
+            bottomRight : new DOMPointReadOnly(1, 0.5),
+            bottomLeft : new DOMPointReadOnly(0, 0.5),
+            children: [{
+                text : "Link",
+                topLeft : new DOMPointReadOnly(0, 0),
+                topRight : new DOMPointReadOnly(1, 0),
+                bottomRight : new DOMPointReadOnly(1, 0.5),
+                bottomLeft : new DOMPointReadOnly(0, 0.5),
+            }],
+        },
+        {
+            topLeft : new DOMPointReadOnly(0, 0.5),
+            topRight : new DOMPointReadOnly(1, 0.5),
+            bottomRight : new DOMPointReadOnly(1, 1),
+            bottomLeft : new DOMPointReadOnly(0, 1),
+            children: [{
+                text : "webkit.org",
+                topLeft : new DOMPointReadOnly(0, 0.5),
+                topRight : new DOMPointReadOnly(1, 0.5),
+                bottomRight : new DOMPointReadOnly(1, 1),
+                bottomLeft : new DOMPointReadOnly(0, 1),
+            }],
+        }
+    ], [], [
+        {
+            topLeft : new DOMPointReadOnly(0, 0.5),
+            topRight : new DOMPointReadOnly(1, 0.5),
+            bottomRight : new DOMPointReadOnly(1, 1),
+            bottomLeft : new DOMPointReadOnly(0, 1),
+        }
+    ]);
+
+    result = await UIHelper.longPressAndGetContextMenuContentAt(200, 330);
+    shouldBeTrue("result?.contextMenu?.items?.includes('Open Link')");
+    finishJSTest();
+});
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebKit/ChangeLog (291346 => 291347)


--- trunk/Source/WebKit/ChangeLog	2022-03-16 14:41:56 UTC (rev 291346)
+++ trunk/Source/WebKit/ChangeLog	2022-03-16 15:06:35 UTC (rev 291347)
@@ -1,3 +1,21 @@
+2022-03-16  Wenson Hsieh  <[email protected]>
+
+        [iOS] Refactor some position information hit-testing logic related to data detectors in Live Text
+        https://bugs.webkit.org/show_bug.cgi?id=237927
+
+        Reviewed by Tim Horton.
+
+        Pull the call to `dataDetectorImageOverlayPositionInformation()` out from `elementPositionInformation()`, and
+        into the top level in `WebPage::positionInformation()`. Since `dataDetectorImageOverlayPositionInformation` only
+        depends on the hit-tested inner node (rather than the element responding to click events), it doesn't make sense
+        to only populate the data detector results array only when we find an element that responds to clicks.
+
+        Test: fast/images/text-recognition/ios/show-data-detector-context-menu.html
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::elementPositionInformation):
+        (WebKit::WebPage::positionInformation):
+
 2022-03-16  Youenn Fablet  <[email protected]>
 
         Make MIMETypeRegistry::mimeTypeForPath take a StringView

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


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-03-16 14:41:56 UTC (rev 291346)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-03-16 15:06:35 UTC (rev 291347)
@@ -2963,13 +2963,6 @@
         boundsPositionInformation(*renderer, info);
     }
 
-#if ENABLE(DATA_DETECTION)
-    if (info.isImageOverlayText && innerNonSharedNode->shadowHost() == &element && is<HTMLElement>(element)) {
-        if (Ref htmlElement = downcast<HTMLElement>(element); ImageOverlay::hasOverlay(htmlElement.get()))
-            dataDetectorImageOverlayPositionInformation(htmlElement.get(), request, info);
-    }
-#endif
-
     info.elementContext = page.contextForElement(element);
 }
     
@@ -3198,6 +3191,26 @@
             info.image = shareableBitmapSnapshotForNode(element);
     }
 
+#if ENABLE(DATA_DETECTION)
+    auto hitTestedImageOverlayHost = ([&]() -> RefPtr<HTMLElement> {
+        if (!hitTestNode || !info.isImageOverlayText)
+            return nullptr;
+
+        RefPtr shadowHost = hitTestNode->shadowHost();
+        if (!is<HTMLElement>(shadowHost.get()))
+            return nullptr;
+
+        RefPtr htmlElement = downcast<HTMLElement>(shadowHost.get());
+        if (!ImageOverlay::hasOverlay(*htmlElement))
+            return nullptr;
+
+        return htmlElement;
+    })();
+
+    if (hitTestedImageOverlayHost)
+        dataDetectorImageOverlayPositionInformation(*hitTestedImageOverlayHost, request, info);
+#endif // ENABLE(DATA_DETECTION)
+
     if (!info.isImage && request.includeImageData && hitTestNode) {
         if (auto video = hostVideoElementIgnoringImageOverlay(*hitTestNode))
             videoPositionInformation(*this, *video, request, info);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to