Title: [295062] trunk
Revision
295062
Author
wenson_hs...@apple.com
Date
2022-05-31 13:19:12 -0700 (Tue, 31 May 2022)

Log Message

[macOS] Include text context menu actions when right clicking on selected Live Text in a link
https://bugs.webkit.org/show_bug.cgi?id=241069
rdar://91606522

Reviewed by Devin Rousso.

Currently, when right clicking selected text inside of an image that's inside of a link, we only
show context menu actions for the link and image. While it's still possible to copy this selected
text using the Menu Bar (Edit > Copy), this should be reflected in the context menu as well.

To fix this, we adjust a bit of macOS-specific logic in `ContextMenuController` to include the set
of text actions as well, in this scenario.

* LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy-expected.txt: Added.
* LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy.html: Added.

Add a layout test to verify the change.

* Source/WebCore/page/ContextMenuController.cpp:
(WebCore::ContextMenuController::populate):

Always show selected text options for selected Live Text. Additionally, simplify a bit of nearby
code to take advantage of "if statements with initializers".

Canonical link: https://commits.webkit.org/251157@main

Modified Paths

Added Paths

Diff

Added: trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy-expected.txt (0 => 295062)


--- trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy-expected.txt	2022-05-31 20:19:12 UTC (rev 295062)
@@ -0,0 +1,8 @@
+PASS getCopyContextMenuItem() is null
+PASS Selected text in image
+PASS getCopyContextMenuItem() is non-null.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+

Added: trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy.html (0 => 295062)


--- trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy.html	                        (rev 0)
+++ trunk/LayoutTests/fast/images/text-recognition/mac/context-menu-for-image-in-link-contains-copy.html	2022-05-31 20:19:12 UTC (rev 295062)
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<style>
+img {
+    width: 400px;
+    height: 400px;
+}
+
+div[contenteditable] {
+    border: 1px solid tomato;
+}
+
+a {
+    display: block;
+    position: absolute;
+    top: 0;
+    left: 0;
+}
+</style>
+</head>
+<body>
+<a href=""
+    <img src=""
+</a>
+<div contenteditable></div>
+<script>
+function getCopyContextMenuItem()
+{
+    for (const item of eventSender.contextClick()) {
+        if (item.title === "Copy")
+            return item;
+    }
+    return null;
+}
+
+addEventListener("load", () => {
+    let image = document.querySelector("img");
+    internals.installImageOverlay(image, [
+        {
+            topLeft : new DOMPointReadOnly(0, 0),
+            topRight : new DOMPointReadOnly(1, 0),
+            bottomRight : new DOMPointReadOnly(1, 0.5),
+            bottomLeft : new DOMPointReadOnly(0, 0.5),
+            children: [
+                {
+                    text : "foobar",
+                    topLeft : new DOMPointReadOnly(0, 0),
+                    topRight : new DOMPointReadOnly(1, 0),
+                    bottomRight : new DOMPointReadOnly(1, 0.5),
+                    bottomLeft : new DOMPointReadOnly(0, 0.5),
+                }
+            ]
+        }
+    ]);
+
+    eventSender.mouseMoveTo(50, 150);
+
+    shouldBeNull("getCopyContextMenuItem()");
+    getSelection().selectAllChildren(internals.shadowRoot(image).getElementById("image-overlay"));
+    testPassed("Selected text in image");
+    shouldBeNonNull("getCopyContextMenuItem()");
+});
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (295061 => 295062)


--- trunk/Source/WebCore/page/ContextMenuController.cpp	2022-05-31 19:14:39 UTC (rev 295061)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp	2022-05-31 20:19:12 UTC (rev 295062)
@@ -967,21 +967,8 @@
 
         auto selectedRange = frame->selection().selection().range();
         bool selectionIsInsideImageOverlay = selectedRange && ImageOverlay::isInsideOverlay(*selectedRange);
-        bool shouldShowItemsForNonEditableText = ([&] {
-            if (!linkURL.isEmpty())
-                return false;
-
-            if (!mediaURL.isEmpty())
-                return false;
-
+        if (selectionIsInsideImageOverlay || (linkURL.isEmpty() && mediaURL.isEmpty() && imageURL.isEmpty())) {
             if (!imageURL.isEmpty())
-                return selectionIsInsideImageOverlay;
-
-            return true;
-        })();
-
-        if (shouldShowItemsForNonEditableText) {
-            if (!imageURL.isEmpty())
                 appendItem(*separatorItem(), m_contextMenu.get());
 
             if (m_context.hitTestResult().isSelected()) {
@@ -992,12 +979,10 @@
                 appendItem(*separatorItem(), m_contextMenu.get());
 
 #if ENABLE(APP_HIGHLIGHTS)
-                if (auto* page = frame->page()) {
-                    if (page->settings().appHighlightsEnabled() && !selectionIsInsideImageOverlay) {
-                        appendItem(AddHighlightToNewQuickNoteItem, m_contextMenu.get());
-                        appendItem(AddHighlightItem, m_contextMenu.get());
-                        appendItem(*separatorItem(), m_contextMenu.get());
-                    }
+                if (auto* page = frame->page(); page && page->settings().appHighlightsEnabled() && !selectionIsInsideImageOverlay) {
+                    appendItem(AddHighlightToNewQuickNoteItem, m_contextMenu.get());
+                    appendItem(AddHighlightItem, m_contextMenu.get());
+                    appendItem(*separatorItem(), m_contextMenu.get());
                 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to