Title: [276181] trunk/Source
Revision
276181
Author
[email protected]
Date
2021-04-16 16:53:19 -0700 (Fri, 16 Apr 2021)

Log Message

[macOS] Refactor some webpage translation code
https://bugs.webkit.org/show_bug.cgi?id=224680
Work towards <rdar://75641882>

Reviewed by Tim Horton.

Source/WebCore:

In preparation for fixing https://webkit.org/b/224683, refactor some codepaths for handling webpage translation
via the context menu on macOS, in WebKit2.

Currently, the context menu action for `ContextMenuItemTagTranslate` is fully handled in the client layer in
WebKit2, using state in `m_activeContextMenuContextData`. However, to make this action work in WebKitLegacy as
well, we need the ability to call back into the `ContextMenuController` to handle the action, since context menu
actions in WebKitLegacy only target the shared `WebMenuTarget` instance, which only knows about the context menu
controller rather than the `WebHTMLView` that vended the menu item.

Instead of adding logic in `WebMenuTarget` to dig the `WebHTMLView` corresponding to the focused frame out of
the context menu controller, it makes more sense to plumb this call through the (already-established)
`ContextMenuClient`. While this has the disadvantage of requiring an extra IPC hop on the WebKit2 case, it also
has the advantage that we can lazily compute the selection bounds and menu location in root view coordinates
only if the user has selected this menu action, which makes context menu data (slightly) cheaper to compute.

No change in behavior.

* loader/EmptyClients.cpp:
* page/ContextMenuClient.h:
* page/ContextMenuContext.h:
(WebCore::ContextMenuContext::setSelectionBounds): Deleted.
(WebCore::ContextMenuContext::selectionBounds const): Deleted.

Remove code for computing and setting selection bounds. This was only added in support of webpage translation;
instead of computing this up front, we can instead send this information only when the action is invoked.

* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):

Move logic for computing the selection bounds and menu location in root view coordinates out of `populate` and
into `contextMenuItemSelected`, only in the case where the action is `ContextMenuItemTagTranslate`.

(WebCore::ContextMenuController::populate):

Source/WebKit:

See WebCore ChangeLog for more details.

* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::encode const):
(WebKit::ContextMenuContextData::decode):
* Shared/ContextMenuContextData.h:

Remove `selectionBounds`. We don't need this anymore, because we'll instead compute the selection bounds only
when the Translate menu item is selected, instead of relying on `m_activeContextMenuContextData` being up to
date.

(WebKit::ContextMenuContextData::selectedText const):
(WebKit::ContextMenuContextData::selectionBounds const): Deleted.
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::handleContextMenuTranslation):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contextMenuItemSelected):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebContextMenuClient.h:
* WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
(WebKit::WebContextMenuClient::handleTranslation):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::handleContextMenuTranslation):
* WebProcess/WebPage/WebPage.h:

Source/WebKitLegacy/mac:

See WebCore ChangeLog for more details.

* WebCoreSupport/WebContextMenuClient.h:
* WebCoreSupport/WebContextMenuClient.mm:
(WebContextMenuClient::handleTranslation):
* WebView/WebView.mm:
(-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]):

Add an empty stub with a `FIXME` for the time being.

* WebView/WebViewInternal.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276180 => 276181)


--- trunk/Source/WebCore/ChangeLog	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebCore/ChangeLog	2021-04-16 23:53:19 UTC (rev 276181)
@@ -1,3 +1,45 @@
+2021-04-16  Wenson Hsieh  <[email protected]>
+
+        [macOS] Refactor some webpage translation code
+        https://bugs.webkit.org/show_bug.cgi?id=224680
+        Work towards <rdar://75641882>
+
+        Reviewed by Tim Horton.
+
+        In preparation for fixing https://webkit.org/b/224683, refactor some codepaths for handling webpage translation
+        via the context menu on macOS, in WebKit2.
+
+        Currently, the context menu action for `ContextMenuItemTagTranslate` is fully handled in the client layer in
+        WebKit2, using state in `m_activeContextMenuContextData`. However, to make this action work in WebKitLegacy as
+        well, we need the ability to call back into the `ContextMenuController` to handle the action, since context menu
+        actions in WebKitLegacy only target the shared `WebMenuTarget` instance, which only knows about the context menu
+        controller rather than the `WebHTMLView` that vended the menu item.
+
+        Instead of adding logic in `WebMenuTarget` to dig the `WebHTMLView` corresponding to the focused frame out of
+        the context menu controller, it makes more sense to plumb this call through the (already-established)
+        `ContextMenuClient`. While this has the disadvantage of requiring an extra IPC hop on the WebKit2 case, it also
+        has the advantage that we can lazily compute the selection bounds and menu location in root view coordinates
+        only if the user has selected this menu action, which makes context menu data (slightly) cheaper to compute.
+
+        No change in behavior.
+
+        * loader/EmptyClients.cpp:
+        * page/ContextMenuClient.h:
+        * page/ContextMenuContext.h:
+        (WebCore::ContextMenuContext::setSelectionBounds): Deleted.
+        (WebCore::ContextMenuContext::selectionBounds const): Deleted.
+
+        Remove code for computing and setting selection bounds. This was only added in support of webpage translation;
+        instead of computing this up front, we can instead send this information only when the action is invoked.
+
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::contextMenuItemSelected):
+
+        Move logic for computing the selection bounds and menu location in root view coordinates out of `populate` and
+        into `contextMenuItemSelected`, only in the case where the action is `ContextMenuItemTagTranslate`.
+
+        (WebCore::ContextMenuController::populate):
+
 2021-04-16  Jiewen Tan  <[email protected]>
 
         Allow using the platform authenticator on non-Touch ID Macs according to Internal requirements

Modified: trunk/Source/WebCore/loader/EmptyClients.cpp (276180 => 276181)


--- trunk/Source/WebCore/loader/EmptyClients.cpp	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebCore/loader/EmptyClients.cpp	2021-04-16 23:53:19 UTC (rev 276181)
@@ -115,6 +115,10 @@
     void searchWithSpotlight() final { }
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+    void handleTranslation(const String&, const IntRect&, const IntPoint&) final { }
+#endif
+
 #if PLATFORM(GTK)
     void insertEmoji(Frame&) final { }
 #endif

Modified: trunk/Source/WebCore/page/ContextMenuClient.h (276180 => 276181)


--- trunk/Source/WebCore/page/ContextMenuClient.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebCore/page/ContextMenuClient.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -45,6 +45,10 @@
     virtual void speak(const String&) = 0;
     virtual void stopSpeaking() = 0;
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+    virtual void handleTranslation(const String&, const IntRect&, const IntPoint&) = 0;
+#endif
+
 #if PLATFORM(COCOA)
     virtual void searchWithSpotlight() = 0;
 #endif

Modified: trunk/Source/WebCore/page/ContextMenuContext.h (276180 => 276181)


--- trunk/Source/WebCore/page/ContextMenuContext.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebCore/page/ContextMenuContext.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -55,9 +55,6 @@
     void setSelectedText(const String& selectedText) { m_selectedText = selectedText; }
     const String& selectedText() const { return m_selectedText; }
 
-    void setSelectionBounds(const IntRect& bounds) { m_selectionBounds = bounds; }
-    const IntRect& selectionBounds() const { return m_selectionBounds; }
-
 #if ENABLE(SERVICE_CONTROLS)
     void setControlledImage(Image* controlledImage) { m_controlledImage = controlledImage; }
     Image* controlledImage() const { return m_controlledImage.get(); }
@@ -67,7 +64,6 @@
     Type m_type { Type::ContextMenu };
     HitTestResult m_hitTestResult;
     String m_selectedText;
-    IntRect m_selectionBounds;
 
 #if ENABLE(SERVICE_CONTROLS)
     RefPtr<Image> m_controlledImage;

Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (276180 => 276181)


--- trunk/Source/WebCore/page/ContextMenuController.cpp	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp	2021-04-16 23:53:19 UTC (rev 276181)
@@ -523,10 +523,18 @@
         frame->editor().applyDictationAlternative(title);
         break;
     case ContextMenuItemTagRevealImage:
-    case ContextMenuItemTagTranslate:
         // This should be handled at the client layer.
         ASSERT_NOT_REACHED();
         break;
+    case ContextMenuItemTagTranslate:
+#if HAVE(TRANSLATION_UI_SERVICES)
+        if (auto view = makeRefPtr(frame->view())) {
+            auto selectionBounds = view->contentsToRootView(enclosingIntRect(frame->selection().selectionBounds()));
+            auto location = view->contentsToRootView(m_context.hitTestResult().roundedPointInInnerNodeFrame());
+            m_client.handleTranslation(m_context.hitTestResult().selectedText(), selectionBounds, location);
+        }
+#endif
+        break;
     default:
         break;
     }
@@ -868,14 +876,7 @@
     };
 
     auto selectedText = m_context.hitTestResult().selectedText();
-    if (!selectedText.isEmpty()) {
-        m_context.setSelectedText(selectedText);
-        if (auto view = makeRefPtr(frame->view())) {
-            auto selectionBoundsInContentCoordinates = enclosingIntRect(frame->selection().selectionBounds());
-            if (!selectionBoundsInContentCoordinates.isEmpty())
-                m_context.setSelectionBounds(view->contentsToRootView(selectionBoundsInContentCoordinates));
-        }
-    }
+    m_context.setSelectedText(selectedText);
 
     if (!m_context.hitTestResult().isContentEditable()) {
         FrameLoader& loader = frame->loader();

Modified: trunk/Source/WebKit/ChangeLog (276180 => 276181)


--- trunk/Source/WebKit/ChangeLog	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/ChangeLog	2021-04-16 23:53:19 UTC (rev 276181)
@@ -1,3 +1,38 @@
+2021-04-16  Wenson Hsieh  <[email protected]>
+
+        [macOS] Refactor some webpage translation code
+        https://bugs.webkit.org/show_bug.cgi?id=224680
+        Work towards <rdar://75641882>
+
+        Reviewed by Tim Horton.
+
+        See WebCore ChangeLog for more details.
+
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::ContextMenuContextData::encode const):
+        (WebKit::ContextMenuContextData::decode):
+        * Shared/ContextMenuContextData.h:
+
+        Remove `selectionBounds`. We don't need this anymore, because we'll instead compute the selection bounds only
+        when the Translate menu item is selected, instead of relying on `m_activeContextMenuContextData` being up to
+        date.
+
+        (WebKit::ContextMenuContextData::selectedText const):
+        (WebKit::ContextMenuContextData::selectionBounds const): Deleted.
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::handleContextMenuTranslation):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::contextMenuItemSelected):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebContextMenuClient.h:
+        * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
+        (WebKit::WebContextMenuClient::handleTranslation):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::handleContextMenuTranslation):
+        * WebProcess/WebPage/WebPage.h:
+
 2021-04-16  Jiewen Tan  <[email protected]>
 
         Allow using the platform authenticator on non-Touch ID Macs according to Internal requirements

Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.cpp (276180 => 276181)


--- trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.cpp	2021-04-16 23:53:19 UTC (rev 276181)
@@ -53,7 +53,6 @@
     , m_menuItems(menuItems)
     , m_webHitTestResultData(context.hitTestResult(), true)
     , m_selectedText(context.selectedText())
-    , m_selectionBounds(context.selectionBounds())
 #if ENABLE(SERVICE_CONTROLS)
     , m_selectionIsEditable(false)
 #endif
@@ -79,7 +78,6 @@
     encoder << m_menuItems;
     encoder << m_webHitTestResultData;
     encoder << m_selectedText;
-    encoder << m_selectionBounds;
 
 #if ENABLE(SERVICE_CONTROLS)
     ShareableBitmap::Handle handle;
@@ -109,9 +107,6 @@
     if (!decoder.decode(result.m_selectedText))
         return false;
 
-    if (!decoder.decode(result.m_selectionBounds))
-        return false;
-
 #if ENABLE(SERVICE_CONTROLS)
     ShareableBitmap::Handle handle;
     if (!decoder.decode(handle))

Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.h (276180 => 276181)


--- trunk/Source/WebKit/Shared/ContextMenuContextData.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -54,7 +54,6 @@
     WebHitTestResultData& webHitTestResultData() { return m_webHitTestResultData; }
     const WebHitTestResultData& webHitTestResultData() const { return m_webHitTestResultData; }
     const String& selectedText() const { return m_selectedText; }
-    const WebCore::IntRect& selectionBounds() const { return m_selectionBounds; }
 
 #if ENABLE(SERVICE_CONTROLS)
     ContextMenuContextData(const WebCore::IntPoint& menuLocation, const Vector<uint8_t>& selectionData, const Vector<String>& selectedTelephoneNumbers, bool isEditable)
@@ -85,7 +84,6 @@
 
     WebHitTestResultData m_webHitTestResultData;
     String m_selectedText;
-    WebCore::IntRect m_selectionBounds;
 
 #if ENABLE(SERVICE_CONTROLS)
     RefPtr<ShareableBitmap> m_controlledImage;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (276180 => 276181)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-04-16 23:53:19 UTC (rev 276181)
@@ -615,6 +615,11 @@
     return pageClient().canHandleContextMenuTranslation();
 }
 
+void WebPageProxy::handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView)
+{
+    return pageClient().handleContextMenuTranslation(text, boundsInView, locationInView);
+}
+
 #endif // HAVE(TRANSLATION_UI_SERVICES)
 #endif // ENABLE(CONTEXT_MENUS)
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (276180 => 276181)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-04-16 23:53:19 UTC (rev 276181)
@@ -6746,12 +6746,6 @@
 #endif
         return;
 
-    case ContextMenuItemTagTranslate:
-#if HAVE(TRANSLATION_UI_SERVICES)
-        pageClient().handleContextMenuTranslation(m_activeContextMenuContextData.selectedText(), m_activeContextMenuContextData.selectionBounds(), m_activeContextMenuContextData.menuLocation());
-#endif
-        return;
-
     default:
         break;
     }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (276180 => 276181)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -1904,8 +1904,9 @@
     void resetImageExtractionPreview();
 #endif
 
-#if HAVE(TRANSLATION_UI_SERVICES)
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     bool canHandleContextMenuTranslation() const;
+    void handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView);
 #endif
 
 #if ENABLE(MEDIA_SESSION_COORDINATOR)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (276180 => 276181)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-04-16 23:53:19 UTC (rev 276181)
@@ -225,6 +225,10 @@
     RequestImageExtraction(URL imageURL, WebKit::ShareableBitmap::Handle imageData) -> (struct WebCore::ImageExtractionResult result) Async
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+    HandleContextMenuTranslation(String text, WebCore::IntRect boundsInView, WebCore::IntPoint locationInView)
+#endif
+
 #if ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)
     ShowMediaControlsContextMenu(WebCore::FloatRect targetFrame, Vector<WebCore::MediaControlsContextMenuItem> items) -> (WebCore::MediaControlsContextMenuItem::ID selectedItemID) Async
 #endif // ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h (276180 => 276181)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -56,6 +56,10 @@
     void searchWithSpotlight() override;
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+    void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final;
+#endif
+
 #if PLATFORM(GTK)
     void insertEmoji(WebCore::Frame&) override;
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm (276180 => 276181)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm	2021-04-16 23:53:19 UTC (rev 276181)
@@ -94,6 +94,15 @@
     m_page->send(Messages::WebPageProxy::SearchWithSpotlight(selectedString));
 }
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+
+void WebContextMenuClient::handleTranslation(const String& text, const IntRect& bounds, const IntPoint& location)
+{
+    m_page->send(Messages::WebPageProxy::HandleContextMenuTranslation(text, bounds, location));
+}
+
+#endif // HAVE(TRANSLATION_UI_SERVICES)
+
 } // namespace WebKit
 
 #endif // ENABLE(CONTEXT_MENUS)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (276180 => 276181)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-04-16 23:53:19 UTC (rev 276181)
@@ -7528,6 +7528,15 @@
     completionHandler(mainFrame()->document()->loader()->lastNavigationWasAppBound());
 }
 
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+
+void WebPage::handleContextMenuTranslation(const String& text, const IntRect& boundsInView, const IntPoint& locationInView)
+{
+    send(Messages::WebPageProxy::HandleContextMenuTranslation(text, boundsInView, locationInView));
+}
+
+#endif
+
 } // namespace WebKit
 
 #undef RELEASE_LOG_IF_ALLOWED

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (276180 => 276181)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -1391,6 +1391,10 @@
     void updateWithImageExtractionResult(WebCore::ImageExtractionResult&&, const WebCore::ElementContext&, const WebCore::FloatPoint& location, CompletionHandler<void(bool)>&&);
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+    void handleContextMenuTranslation(const String& text, const WebCore::IntRect& selectionBoundsInView, const WebCore::IntPoint& menuLocationInView);
+#endif
+
 #if ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)
     void showMediaControlsContextMenu(WebCore::FloatRect&&, Vector<WebCore::MediaControlsContextMenuItem>&&, CompletionHandler<void(WebCore::MediaControlsContextMenuItem::ID)>&&);
 #endif // ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU)

Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (276180 => 276181)


--- trunk/Source/WebKitLegacy/mac/ChangeLog	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog	2021-04-16 23:53:19 UTC (rev 276181)
@@ -1,3 +1,23 @@
+2021-04-16  Wenson Hsieh  <[email protected]>
+
+        [macOS] Refactor some webpage translation code
+        https://bugs.webkit.org/show_bug.cgi?id=224680
+        Work towards <rdar://75641882>
+
+        Reviewed by Tim Horton.
+
+        See WebCore ChangeLog for more details.
+
+        * WebCoreSupport/WebContextMenuClient.h:
+        * WebCoreSupport/WebContextMenuClient.mm:
+        (WebContextMenuClient::handleTranslation):
+        * WebView/WebView.mm:
+        (-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]):
+
+        Add an empty stub with a `FIXME` for the time being.
+
+        * WebView/WebViewInternal.h:
+
 2021-04-16  Peng Liu  <[email protected]>
 
         [GPUP] WebContent process should not create AVOutputContext instances when media in GPU Process is enabled

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h (276180 => 276181)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -67,6 +67,10 @@
     RetainPtr<NSImage> imageForCurrentSharingServicePickerItem(WebSharingServicePickerController &) override;
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+    void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final;
+#endif
+
 private:
     NSMenu *contextMenuForEvent(NSEvent *, NSView *, bool& isServicesMenu);
 

Modified: trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm (276180 => 276181)


--- trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm	2021-04-16 23:53:19 UTC (rev 276181)
@@ -147,6 +147,15 @@
     return true;
 }
 
+#if HAVE(TRANSLATION_UI_SERVICES)
+
+void WebContextMenuClient::handleTranslation(const String& text, const IntRect& selectionBoundsInRootView, const IntPoint& locationInRootView)
+{
+    [m_webView _handleContextMenuTranslation:text selectionBounds:selectionBoundsInRootView menuLocation:locationInRootView];
+}
+
+#endif
+
 #if ENABLE(SERVICE_CONTROLS)
 
 void WebContextMenuClient::sharingServicePickerWillBeDestroyed(WebSharingServicePickerController &)

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebView.mm (276180 => 276181)


--- trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebView.mm	2021-04-16 23:53:19 UTC (rev 276181)
@@ -9627,6 +9627,18 @@
     [[self _UIDelegateForwarder] webViewClose:self];
 }
 
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+
+- (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)selectionBoundsInRootView menuLocation:(const WebCore::IntPoint&)locationInRootView
+{
+    // FIXME (224683): Not implemented yet.
+    UNUSED_PARAM(text);
+    UNUSED_PARAM(selectionBoundsInRootView);
+    UNUSED_PARAM(locationInRootView);
+}
+
+#endif // HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+
 @end
 
 @implementation WebView (WebViewDeviceOrientation)

Modified: trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h (276180 => 276181)


--- trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h	2021-04-16 23:52:30 UTC (rev 276180)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h	2021-04-16 23:53:19 UTC (rev 276181)
@@ -157,6 +157,10 @@
 - (WebSelectionServiceController&)_selectionServiceController;
 #endif
 
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+- (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)boundsInView menuLocation:(const WebCore::IntPoint&)menuLocation;
+#endif
+
 - (void)_windowVisibilityChanged:(NSNotification *)notification;
 
 - (void)_closeWindow;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to