Title: [292898] trunk
Revision
292898
Author
wenson_hs...@apple.com
Date
2022-04-14 18:45:58 -0700 (Thu, 14 Apr 2022)

Log Message

Undo option after invoking "Markup Image" says "Undo Paste"
https://bugs.webkit.org/show_bug.cgi?id=239351
rdar://91647863

Reviewed by Darin Adler.

Source/WebCore:

Add plumbing to allow a caller of `Editor::replaceNodeFromPasteboard` to specify an `EditAction` for the editing
command that is not just `EditAction::Paste`, and use it to supply a more specific edit action type of
`MarkupImage` in the case where "Markup Image" is used to replace an image element with other image data. This
allows the undo/redo title to be more accurate than simply "Undo/Redo Paste".

Test: ImageAnalysisTests.PerformImageAnalysisMarkup

* dom/TextEvent.cpp:
(WebCore::TextEvent::createForPlainTextPaste):
(WebCore::TextEvent::createForFragmentPaste):
(WebCore::TextEvent::TextEvent):
* dom/TextEvent.h:
* dom/TextEventInputType.h:

Introduce TextEventInputMarkup. This is used to preserve the fact that a `TextEvent` was triggered via
"Markup Image" as opposed to a regular "Paste" command, when plumbing this event object through DOM event
propagation code. Once it reenters editing code, we consult this type to re-map this event to
`EditAction::MarkupImage` if appropriate.

I opted for this (slightly more roundabout) approach to prevent a potential layering violation, due to TextEvent
otherwise knowing about `EditAction`.

* editing/EditAction.cpp:
(WebCore::undoRedoLabel):
* editing/EditAction.h:

Introduce EditAction::MarkupImage. Additionally, alphabetically sort these enum types.

* editing/Editor.cpp:
(WebCore::Editor::handleTextEvent):
(WebCore::Editor::pasteAsFragment):
(WebCore::Editor::replaceSelectionWithFragment):
* editing/Editor.h:
* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::replaceNodeFromPasteboard):

Add an `EditAction` argument; by default, this is `EditAction::Paste`.

* en.lproj/Localizable.strings:

Add a new localized string to represent the name of the "Markup Image" item, for the purposes of setting the
Redo/Undo action title.

Source/WebKit:

Rename `replaceWithPasteboardData` to the more specific `replaceImageWithMarkupResults`. This method was
introduced (and is currently only used) to drive image replacement using "Markup Image"; giving this method a
more specific name allows us to hard-code `EditAction::MarkupImage` when calling into Editor to carry out the
replacement editing action in `WebPage::replaceImageWithMarkupResults`.

See WebCore/ChangeLog for additional details.

* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::replaceImageWithMarkupResults):
(WebKit::WebPageProxy::replaceWithPasteboardData): Deleted.
* UIProcess/WebPageProxy.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView imageAnalysisMarkupMenu]):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::applyMarkupToControlledImage):
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::replaceImageWithMarkupResults):
(WebKit::WebPage::replaceWithPasteboardData): Deleted.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Tools:

Augment an existing API test to verify that the resulting undo action title after invoking "Markup Image" is not
"Undo Paste".

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292897 => 292898)


--- trunk/Source/WebCore/ChangeLog	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/ChangeLog	2022-04-15 01:45:58 UTC (rev 292898)
@@ -1,3 +1,54 @@
+2022-04-14  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Undo option after invoking "Markup Image" says "Undo Paste"
+        https://bugs.webkit.org/show_bug.cgi?id=239351
+        rdar://91647863
+
+        Reviewed by Darin Adler.
+
+        Add plumbing to allow a caller of `Editor::replaceNodeFromPasteboard` to specify an `EditAction` for the editing
+        command that is not just `EditAction::Paste`, and use it to supply a more specific edit action type of
+        `MarkupImage` in the case where "Markup Image" is used to replace an image element with other image data. This
+        allows the undo/redo title to be more accurate than simply "Undo/Redo Paste".
+
+        Test: ImageAnalysisTests.PerformImageAnalysisMarkup
+
+        * dom/TextEvent.cpp:
+        (WebCore::TextEvent::createForPlainTextPaste):
+        (WebCore::TextEvent::createForFragmentPaste):
+        (WebCore::TextEvent::TextEvent):
+        * dom/TextEvent.h:
+        * dom/TextEventInputType.h:
+
+        Introduce TextEventInputMarkup. This is used to preserve the fact that a `TextEvent` was triggered via
+        "Markup Image" as opposed to a regular "Paste" command, when plumbing this event object through DOM event
+        propagation code. Once it reenters editing code, we consult this type to re-map this event to
+        `EditAction::MarkupImage` if appropriate.
+
+        I opted for this (slightly more roundabout) approach to prevent a potential layering violation, due to TextEvent
+        otherwise knowing about `EditAction`.
+
+        * editing/EditAction.cpp:
+        (WebCore::undoRedoLabel):
+        * editing/EditAction.h:
+
+        Introduce EditAction::MarkupImage. Additionally, alphabetically sort these enum types.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::handleTextEvent):
+        (WebCore::Editor::pasteAsFragment):
+        (WebCore::Editor::replaceSelectionWithFragment):
+        * editing/Editor.h:
+        * editing/cocoa/EditorCocoa.mm:
+        (WebCore::Editor::replaceNodeFromPasteboard):
+
+        Add an `EditAction` argument; by default, this is `EditAction::Paste`.
+
+        * en.lproj/Localizable.strings:
+
+        Add a new localized string to represent the name of the "Markup Image" item, for the purposes of setting the
+        Redo/Undo action title.
+
 2022-04-14  Caitlin Potter  <ca...@igalia.com>
 
         [JSC] ShadowRealm global object has a mutable prototype

Modified: trunk/Source/WebCore/dom/TextEvent.cpp (292897 => 292898)


--- trunk/Source/WebCore/dom/TextEvent.cpp	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/dom/TextEvent.cpp	2022-04-15 01:45:58 UTC (rev 292898)
@@ -48,12 +48,12 @@
 
 Ref<TextEvent> TextEvent::createForPlainTextPaste(RefPtr<WindowProxy>&& view, const String& data, bool shouldSmartReplace)
 {
-    return adoptRef(*new TextEvent(WTFMove(view), data, nullptr, shouldSmartReplace, false, MailBlockquoteHandling::RespectBlockquote));
+    return adoptRef(*new TextEvent(WTFMove(view), data, nullptr, TextEventInputPaste, shouldSmartReplace, false, MailBlockquoteHandling::RespectBlockquote));
 }
 
-Ref<TextEvent> TextEvent::createForFragmentPaste(RefPtr<WindowProxy>&& view, RefPtr<DocumentFragment>&& data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
+Ref<TextEvent> TextEvent::createForFragmentPaste(RefPtr<WindowProxy>&& view, RefPtr<DocumentFragment>&& data, TextEventInputType inputType, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
 {
-    return adoptRef(*new TextEvent(WTFMove(view), emptyString(), WTFMove(data), shouldSmartReplace, shouldMatchStyle, mailBlockquoteHandling));
+    return adoptRef(*new TextEvent(WTFMove(view), emptyString(), WTFMove(data), inputType, shouldSmartReplace, shouldMatchStyle, mailBlockquoteHandling));
 }
 
 Ref<TextEvent> TextEvent::createForDrop(RefPtr<WindowProxy>&& view, const String& data)
@@ -84,9 +84,9 @@
 {
 }
 
-TextEvent::TextEvent(RefPtr<WindowProxy>&& view, const String& data, RefPtr<DocumentFragment>&& pastingFragment, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
+TextEvent::TextEvent(RefPtr<WindowProxy>&& view, const String& data, RefPtr<DocumentFragment>&& pastingFragment, TextEventInputType inputType, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling mailBlockquoteHandling)
     : UIEvent(eventNames().textInputEvent, CanBubble::Yes, IsCancelable::Yes, IsComposed::Yes, WTFMove(view), 0)
-    , m_inputType(TextEventInputPaste)
+    , m_inputType(inputType)
     , m_data(data)
     , m_pastingFragment(WTFMove(pastingFragment))
     , m_shouldSmartReplace(shouldSmartReplace)

Modified: trunk/Source/WebCore/dom/TextEvent.h (292897 => 292898)


--- trunk/Source/WebCore/dom/TextEvent.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/dom/TextEvent.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -42,7 +42,7 @@
         static Ref<TextEvent> create(RefPtr<WindowProxy>&&, const String& data, TextEventInputType = TextEventInputKeyboard);
         static Ref<TextEvent> createForBindings();
         static Ref<TextEvent> createForPlainTextPaste(RefPtr<WindowProxy>&&, const String& data, bool shouldSmartReplace);
-        static Ref<TextEvent> createForFragmentPaste(RefPtr<WindowProxy>&&, RefPtr<DocumentFragment>&& data, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
+        static Ref<TextEvent> createForFragmentPaste(RefPtr<WindowProxy>&&, RefPtr<DocumentFragment>&& data, TextEventInputType, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
         static Ref<TextEvent> createForDrop(RefPtr<WindowProxy>&&, const String& data);
         static Ref<TextEvent> createForDictation(RefPtr<WindowProxy>&&, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
 
@@ -62,6 +62,7 @@
         bool isDictation() const { return m_inputType == TextEventInputDictation; }
         bool isAutocompletion() const { return m_inputType == TextEventInputAutocompletion; }
         bool isKeyboard() const { return m_inputType == TextEventInputKeyboard; }
+        bool isMarkup() const { return m_inputType == TextEventInputMarkup; }
 
         bool shouldSmartReplace() const { return m_shouldSmartReplace; }
         bool shouldMatchStyle() const { return m_shouldMatchStyle; }
@@ -73,7 +74,7 @@
         TextEvent();
 
         TextEvent(RefPtr<WindowProxy>&&, const String& data, TextEventInputType = TextEventInputKeyboard);
-        TextEvent(RefPtr<WindowProxy>&&, const String& data, RefPtr<DocumentFragment>&&, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
+        TextEvent(RefPtr<WindowProxy>&&, const String& data, RefPtr<DocumentFragment>&&, TextEventInputType, bool shouldSmartReplace, bool shouldMatchStyle, MailBlockquoteHandling);
         TextEvent(RefPtr<WindowProxy>&&, const String& data, const Vector<DictationAlternative>& dictationAlternatives);
 
         bool isTextEvent() const override;

Modified: trunk/Source/WebCore/dom/TextEventInputType.h (292897 => 292898)


--- trunk/Source/WebCore/dom/TextEventInputType.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/dom/TextEventInputType.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -36,6 +36,7 @@
     TextEventInputPaste,
     TextEventInputDrop,
     TextEventInputDictation,
+    TextEventInputMarkup,
     TextEventInputOther,
 };
 

Modified: trunk/Source/WebCore/editing/EditAction.cpp (292897 => 292898)


--- trunk/Source/WebCore/editing/EditAction.cpp	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/editing/EditAction.cpp	2022-04-15 01:45:58 UTC (rev 292898)
@@ -142,6 +142,8 @@
         return WEB_UI_STRING_KEY("Convert to Ordered List", "Convert to Ordered List (Undo action name)", "Undo action name");
     case EditAction::ConvertToUnorderedList:
         return WEB_UI_STRING_KEY("Convert to Unordered List", "Convert to Unordered List (Undo action name)", "Undo action name");
+    case EditAction::MarkupImage:
+        return WEB_UI_STRING_KEY("Markup Image", "Image analysis markup menu item (Undo action name)", "Undo action name");
     }
     return { };
 }

Modified: trunk/Source/WebCore/editing/EditAction.h (292897 => 292898)


--- trunk/Source/WebCore/editing/EditAction.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/editing/EditAction.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -32,68 +32,69 @@
 namespace WebCore {
 
 enum class EditAction : uint8_t {
-    Unspecified,
-    Insert,
-    InsertReplacement,
-    InsertFromDrop,
-    SetColor,
-    SetBackgroundColor,
-    TurnOffKerning,
-    TightenKerning,
-    LoosenKerning,
-    UseStandardKerning,
-    TurnOffLigatures,
-    UseStandardLigatures,
-    UseAllLigatures,
-    RaiseBaseline,
-    LowerBaseline,
-    SetTraditionalCharacterShape,
-    SetFont,
-    ChangeAttributes,
     AlignLeft,
     AlignRight,
+    Bold,
     Center,
-    Justify,
-    SetInlineWritingDirection,
-    SetBlockWritingDirection,
-    Subscript,
-    Superscript,
-    Underline,
-    StrikeThrough,
-    Outline,
-    Unscript,
-    DeleteByDrag,
+    ChangeAttributes,
+    ConvertToOrderedList,
+    ConvertToUnorderedList,
+    CreateLink,
     Cut,
-    Bold,
-    Italics,
     Delete,
+    DeleteByDrag,
     Dictation,
+    FormatBlock,
+    Indent,
+    Insert,
+    InsertFromDrop,
+    InsertOrderedList,
+    InsertReplacement,
+    InsertUnorderedList,
+    Italics,
+    Justify,
+    LoosenKerning,
+    LowerBaseline,
+    MarkupImage,
+    Outdent,
+    Outline,
     Paste,
     PasteFont,
     PasteRuler,
-    TypingDeleteSelection,
+    RaiseBaseline,
+    SetBackgroundColor,
+    SetBlockWritingDirection,
+    SetColor,
+    SetFont,
+    SetInlineWritingDirection,
+    SetTraditionalCharacterShape,
+    StrikeThrough,
+    Subscript,
+    Superscript,
+    TightenKerning,
+    TurnOffKerning,
+    TurnOffLigatures,
     TypingDeleteBackward,
+    TypingDeleteFinalComposition,
     TypingDeleteForward,
-    TypingDeleteWordBackward,
-    TypingDeleteWordForward,
     TypingDeleteLineBackward,
     TypingDeleteLineForward,
     TypingDeletePendingComposition,
-    TypingDeleteFinalComposition,
-    TypingInsertText,
+    TypingDeleteSelection,
+    TypingDeleteWordBackward,
+    TypingDeleteWordForward,
+    TypingInsertFinalComposition,
     TypingInsertLineBreak,
     TypingInsertParagraph,
     TypingInsertPendingComposition,
-    TypingInsertFinalComposition,
-    CreateLink,
+    TypingInsertText,
+    Underline,
     Unlink,
-    FormatBlock,
-    InsertOrderedList,
-    InsertUnorderedList,
-    ConvertToOrderedList,
-    ConvertToUnorderedList,
-    Indent,
-    Outdent
+    Unscript,
+    Unspecified,
+    UseAllLigatures,
+    UseStandardKerning,
+    UseStandardLigatures,
 };
 
 WTF::String undoRedoLabel(EditAction);

Modified: trunk/Source/WebCore/editing/Editor.cpp (292897 => 292898)


--- trunk/Source/WebCore/editing/Editor.cpp	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/editing/Editor.cpp	2022-04-15 01:45:58 UTC (rev 292898)
@@ -337,15 +337,16 @@
     if (event.isDrop())
         return false;
 
-    if (event.isPaste()) {
+    if (event.isPaste() || event.isMarkup()) {
+        auto action = "" ? EditAction::MarkupImage : EditAction::Paste;
         if (event.pastingFragment()) {
 #if PLATFORM(IOS_FAMILY)
             if (client()->performsTwoStepPaste(event.pastingFragment()))
                 return true;
 #endif
-            replaceSelectionWithFragment(*event.pastingFragment(), SelectReplacement::No, event.shouldSmartReplace() ? SmartReplace::Yes : SmartReplace::No, event.shouldMatchStyle() ? MatchStyle::Yes : MatchStyle::No, EditAction::Paste, event.mailBlockquoteHandling());
+            replaceSelectionWithFragment(*event.pastingFragment(), SelectReplacement::No, event.shouldSmartReplace() ? SmartReplace::Yes : SmartReplace::No, event.shouldMatchStyle() ? MatchStyle::Yes : MatchStyle::No, action, event.mailBlockquoteHandling());
         } else
-            replaceSelectionWithText(event.data(), SelectReplacement::No, event.shouldSmartReplace() ? SmartReplace::Yes : SmartReplace::No, EditAction::Paste);
+            replaceSelectionWithText(event.data(), SelectReplacement::No, event.shouldSmartReplace() ? SmartReplace::Yes : SmartReplace::No, action);
         return true;
     }
 
@@ -626,12 +627,15 @@
     target->dispatchEvent(TextEvent::createForPlainTextPaste(document().windowProxy(), pastingText, smartReplace));
 }
 
-void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote)
+void Editor::pasteAsFragment(Ref<DocumentFragment>&& pastingFragment, bool smartReplace, bool matchStyle, MailBlockquoteHandling respectsMailBlockquote, EditAction action)
 {
     auto target = findEventTargetFromSelection();
     if (!target)
         return;
-    target->dispatchEvent(TextEvent::createForFragmentPaste(document().windowProxy(), WTFMove(pastingFragment), smartReplace, matchStyle, respectsMailBlockquote));
+
+    ASSERT(action == EditAction::MarkupImage || action == EditAction::Paste);
+    auto type = action == EditAction::MarkupImage ? TextEventInputMarkup : TextEventInputPaste;
+    target->dispatchEvent(TextEvent::createForFragmentPaste(document().windowProxy(), WTFMove(pastingFragment), type, smartReplace, matchStyle, respectsMailBlockquote));
 }
 
 void Editor::pasteAsPlainTextBypassingDHTML()
@@ -686,7 +690,7 @@
         return;
 
     AccessibilityReplacedText replacedText;
-    if (AXObjectCache::accessibilityEnabled() && (editingAction == EditAction::Paste || editingAction == EditAction::Insert))
+    if (AXObjectCache::accessibilityEnabled() && (editingAction == EditAction::Paste || editingAction == EditAction::Insert || editingAction == EditAction::MarkupImage))
         replacedText = AccessibilityReplacedText(selection);
 
     OptionSet<ReplaceSelectionCommand::CommandOption> options { ReplaceSelectionCommand::PreventNesting, ReplaceSelectionCommand::SanitizeFragment };

Modified: trunk/Source/WebCore/editing/Editor.h (292897 => 292898)


--- trunk/Source/WebCore/editing/Editor.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/editing/Editor.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -444,7 +444,7 @@
     WEBCORE_EXPORT void handleAlternativeTextUIResult(const String& correction);
     void dismissCorrectionPanelAsIgnored();
 
-    WEBCORE_EXPORT void pasteAsFragment(Ref<DocumentFragment>&&, bool smartReplace, bool matchStyle, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
+    WEBCORE_EXPORT void pasteAsFragment(Ref<DocumentFragment>&&, bool smartReplace, bool matchStyle, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote, EditAction = EditAction::Paste);
     WEBCORE_EXPORT void pasteAsPlainText(const String&, bool smartReplace);
 
     // This is only called on the mac where paste is implemented primarily at the WebKit level.
@@ -537,7 +537,7 @@
     void takeFindStringFromSelection();
     WEBCORE_EXPORT void replaceSelectionWithAttributedString(NSAttributedString *, MailBlockquoteHandling = MailBlockquoteHandling::RespectBlockquote);
     WEBCORE_EXPORT void readSelectionFromPasteboard(const String& pasteboardName);
-    WEBCORE_EXPORT void replaceNodeFromPasteboard(Node&, const String& pasteboardName);
+    WEBCORE_EXPORT void replaceNodeFromPasteboard(Node&, const String& pasteboardName, EditAction = EditAction::Paste);
 #endif
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm (292897 => 292898)


--- trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/editing/cocoa/EditorCocoa.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -346,7 +346,7 @@
     }
 }
 
-void Editor::replaceNodeFromPasteboard(Node& node, const String& pasteboardName)
+void Editor::replaceNodeFromPasteboard(Node& node, const String& pasteboardName, EditAction action)
 {
     if (node.document() != m_document)
         return;
@@ -377,7 +377,7 @@
     if (auto fragment = webContentFromPasteboard(pasteboard, *range, true, chosePlainText)) {
         maybeCopyNodeAttributesToFragment(node, *fragment);
         if (shouldInsertFragment(*fragment, *range, EditorInsertAction::Pasted))
-            pasteAsFragment(fragment.releaseNonNull(), false, false, MailBlockquoteHandling::IgnoreBlockquote);
+            pasteAsFragment(fragment.releaseNonNull(), false, false, MailBlockquoteHandling::IgnoreBlockquote, action);
     }
 
 #if PLATFORM(MAC)

Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (292897 => 292898)


--- trunk/Source/WebCore/en.lproj/Localizable.strings	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings	2022-04-15 01:45:58 UTC (rev 292898)
@@ -548,6 +548,9 @@
 "Ignore Spelling" = "Ignore Spelling";
 
 /* Undo action name */
+"Image analysis markup menu item (Undo action name)" = "Markup Image";
+
+/* Undo action name */
 "Indent (Undo action name)" = "Indent";
 
 /* Undo action name */

Modified: trunk/Source/WebKit/ChangeLog (292897 => 292898)


--- trunk/Source/WebKit/ChangeLog	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/ChangeLog	2022-04-15 01:45:58 UTC (rev 292898)
@@ -1,5 +1,34 @@
 2022-04-14  Wenson Hsieh  <wenson_hs...@apple.com>
 
+        Undo option after invoking "Markup Image" says "Undo Paste"
+        https://bugs.webkit.org/show_bug.cgi?id=239351
+        rdar://91647863
+
+        Reviewed by Darin Adler.
+
+        Rename `replaceWithPasteboardData` to the more specific `replaceImageWithMarkupResults`. This method was
+        introduced (and is currently only used) to drive image replacement using "Markup Image"; giving this method a
+        more specific name allows us to hard-code `EditAction::MarkupImage` when calling into Editor to carry out the
+        replacement editing action in `WebPage::replaceImageWithMarkupResults`.
+
+        See WebCore/ChangeLog for additional details.
+
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::replaceImageWithMarkupResults):
+        (WebKit::WebPageProxy::replaceWithPasteboardData): Deleted.
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView imageAnalysisMarkupMenu]):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::applyMarkupToControlledImage):
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::replaceImageWithMarkupResults):
+        (WebKit::WebPage::replaceWithPasteboardData): Deleted.
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
+2022-04-14  Wenson Hsieh  <wenson_hs...@apple.com>
+
         Unreviewed, fix the Catalyst build after r292888
 
         `MCProfileConnection` is not available on Mac Catalyst.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (292897 => 292898)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -915,9 +915,9 @@
     send(Messages::WebPage::ReplaceSelectionWithPasteboardData(types, data));
 }
 
-void WebPageProxy::replaceWithPasteboardData(const ElementContext& elementContext, const Vector<String>& types, const IPC::DataReference& data)
+void WebPageProxy::replaceImageWithMarkupResults(const ElementContext& elementContext, const Vector<String>& types, const IPC::DataReference& data)
 {
-    send(Messages::WebPage::ReplaceWithPasteboardData(elementContext, types, data));
+    send(Messages::WebPage::ReplaceImageWithMarkupResults(elementContext, types, data));
 }
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (292897 => 292898)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -267,6 +267,7 @@
 enum class CreateNewGroupForHighlight : bool;
 enum class DOMPasteAccessCategory : uint8_t;
 enum class DOMPasteAccessResponse : uint8_t;
+enum class EditAction : uint8_t;
 enum class EventMakesGamepadsVisible : bool;
 enum class LockBackForwardList : bool;
 enum class HasInsecureContent : bool;
@@ -1194,7 +1195,7 @@
     void registerWebProcessAccessibilityToken(const IPC::DataReference&);
     // Called by the UI process when it is ready to send its tokens to the web process.
     void registerUIProcessAccessibilityTokens(const IPC::DataReference& elemenToken, const IPC::DataReference& windowToken);
-    void replaceWithPasteboardData(const WebCore::ElementContext&, const Vector<String>& types, const IPC::DataReference&);
+    void replaceImageWithMarkupResults(const WebCore::ElementContext&, const Vector<String>& types, const IPC::DataReference&);
     void replaceSelectionWithPasteboardData(const Vector<String>& types, const IPC::DataReference&);
     bool readSelectionFromPasteboard(const String& pasteboardName);
     String stringSelectionForPasteboard();

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (292897 => 292898)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -4734,7 +4734,7 @@
 
         auto [elementContext, image, preferredMIMEType] = *view->_imageAnalysisMarkupData;
         if (auto [data, type] = WebKit::transcodeWithPreferredMIMEType(image.get(), preferredMIMEType.createCFString().get(), (__bridge CFStringRef)UTTypeTIFF.identifier); data)
-            view->_page->replaceWithPasteboardData(elementContext, { String { type.get() } }, { static_cast<const uint8_t*>([data bytes]), [data length] });
+            view->_page->replaceImageWithMarkupResults(elementContext, { String { type.get() } }, { static_cast<const uint8_t*>([data bytes]), [data length] });
     }];
 }
 

Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (292897 => 292898)


--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -349,7 +349,7 @@
         if (!data)
             return;
 
-        protectedPage->replaceWithPasteboardData(elementContext, { String(type.get()) }, IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length]));
+        protectedPage->replaceImageWithMarkupResults(elementContext, { String(type.get()) }, IPC::DataReference(static_cast<const uint8_t*>([data bytes]), [data length]));
     });
 #endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (292897 => 292898)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -566,7 +566,7 @@
     Vector<String> m_types;
 };
 
-void WebPage::replaceWithPasteboardData(const ElementContext& elementContext, const Vector<String>& types, const IPC::DataReference& data)
+void WebPage::replaceImageWithMarkupResults(const ElementContext& elementContext, const Vector<String>& types, const IPC::DataReference& data)
 {
     Ref frame = CheckedRef(m_page->focusController())->focusedOrMainFrame();
     auto element = elementForContext(elementContext);
@@ -594,7 +594,7 @@
     {
         OverridePasteboardForSelectionReplacement overridePasteboard { types, data };
         IgnoreSelectionChangeForScope ignoreSelectionChanges { frame.get() };
-        frame->editor().replaceNodeFromPasteboard(*element, replaceSelectionPasteboardName());
+        frame->editor().replaceNodeFromPasteboard(*element, replaceSelectionPasteboardName(), EditAction::MarkupImage);
     }
 
     constexpr auto restoreSelectionOptions = FrameSelection::defaultSetSelectionOptions(UserTriggered);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (292897 => 292898)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-04-15 01:45:58 UTC (rev 292898)
@@ -977,7 +977,7 @@
 #endif
 
 #if PLATFORM(COCOA)
-    void replaceWithPasteboardData(const WebCore::ElementContext&, const Vector<String>& types, const IPC::DataReference&);
+    void replaceImageWithMarkupResults(const WebCore::ElementContext&, const Vector<String>& types, const IPC::DataReference&);
     void replaceSelectionWithPasteboardData(const Vector<String>& types, const IPC::DataReference&);
 #endif
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (292897 => 292898)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-04-15 01:45:58 UTC (rev 292898)
@@ -470,7 +470,7 @@
     GetStringSelectionForPasteboard() -> (String stringValue) Synchronous
     GetDataSelectionForPasteboard(String pasteboardType) -> (WebKit::SharedMemory::IPCHandle ipcHandle) Synchronous
     ReadSelectionFromPasteboard(String pasteboardName) -> (bool result) Synchronous
-    ReplaceWithPasteboardData(struct WebCore::ElementContext context, Vector<String> types, IPC::DataReference data)
+    ReplaceImageWithMarkupResults(struct WebCore::ElementContext context, Vector<String> types, IPC::DataReference data)
     ReplaceSelectionWithPasteboardData(Vector<String> types, IPC::DataReference data)
 
     ShouldDelayWindowOrderingEvent(WebKit::WebMouseEvent event) -> (bool result) Synchronous

Modified: trunk/Tools/ChangeLog (292897 => 292898)


--- trunk/Tools/ChangeLog	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Tools/ChangeLog	2022-04-15 01:45:58 UTC (rev 292898)
@@ -1,3 +1,17 @@
+2022-04-14  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Undo option after invoking "Markup Image" says "Undo Paste"
+        https://bugs.webkit.org/show_bug.cgi?id=239351
+        rdar://91647863
+
+        Reviewed by Darin Adler.
+
+        Augment an existing API test to verify that the resulting undo action title after invoking "Markup Image" is not
+        "Undo Paste".
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm:
+        (TestWebKitAPI::TEST):
+
 2022-04-14  Robert Jenner  <jen...@apple.com>
 
         Add an additional system to unsafe-merge queue

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm (292897 => 292898)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm	2022-04-15 00:27:35 UTC (rev 292897)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ImageAnalysisTests.mm	2022-04-15 01:45:58 UTC (rev 292898)
@@ -341,6 +341,10 @@
     Util::waitForConditionWithLogging([&] {
         return [[webView objectByEvaluatingJavaScript:@"document.images[0].getBoundingClientRect().width"] intValue] == 215;
     }, 3, @"Expected bounding client rect to become 215.");
+
+    NSString *undoTitle = [webView undoManager].undoMenuItemTitle;
+    EXPECT_GT(undoTitle.length, 0U);
+    EXPECT_FALSE([undoTitle containsString:@"Paste"]);
 }
 
 #endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS) && PLATFORM(IOS_FAMILY)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to