Changeset 276181 in webkit
- Timestamp:
- Apr 16, 2021, 4:53:19 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 21 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/loader/EmptyClients.cpp (modified) (1 diff)
-
WebCore/page/ContextMenuClient.h (modified) (1 diff)
-
WebCore/page/ContextMenuContext.h (modified) (2 diffs)
-
WebCore/page/ContextMenuController.cpp (modified) (2 diffs)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Shared/ContextMenuContextData.cpp (modified) (3 diffs)
-
WebKit/Shared/ContextMenuContextData.h (modified) (2 diffs)
-
WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (modified) (1 diff)
-
WebKit/UIProcess/WebPageProxy.cpp (modified) (1 diff)
-
WebKit/UIProcess/WebPageProxy.h (modified) (1 diff)
-
WebKit/UIProcess/WebPageProxy.messages.in (modified) (1 diff)
-
WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h (modified) (1 diff)
-
WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.cpp (modified) (1 diff)
-
WebKit/WebProcess/WebPage/WebPage.h (modified) (1 diff)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h (modified) (1 diff)
-
WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebView.mm (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebViewInternal.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r276180 r276181 1 2021-04-16 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Refactor some webpage translation code 4 https://bugs.webkit.org/show_bug.cgi?id=224680 5 Work towards <rdar://75641882> 6 7 Reviewed by Tim Horton. 8 9 In preparation for fixing https://webkit.org/b/224683, refactor some codepaths for handling webpage translation 10 via the context menu on macOS, in WebKit2. 11 12 Currently, the context menu action for `ContextMenuItemTagTranslate` is fully handled in the client layer in 13 WebKit2, using state in `m_activeContextMenuContextData`. However, to make this action work in WebKitLegacy as 14 well, we need the ability to call back into the `ContextMenuController` to handle the action, since context menu 15 actions in WebKitLegacy only target the shared `WebMenuTarget` instance, which only knows about the context menu 16 controller rather than the `WebHTMLView` that vended the menu item. 17 18 Instead of adding logic in `WebMenuTarget` to dig the `WebHTMLView` corresponding to the focused frame out of 19 the context menu controller, it makes more sense to plumb this call through the (already-established) 20 `ContextMenuClient`. While this has the disadvantage of requiring an extra IPC hop on the WebKit2 case, it also 21 has the advantage that we can lazily compute the selection bounds and menu location in root view coordinates 22 only if the user has selected this menu action, which makes context menu data (slightly) cheaper to compute. 23 24 No change in behavior. 25 26 * loader/EmptyClients.cpp: 27 * page/ContextMenuClient.h: 28 * page/ContextMenuContext.h: 29 (WebCore::ContextMenuContext::setSelectionBounds): Deleted. 30 (WebCore::ContextMenuContext::selectionBounds const): Deleted. 31 32 Remove code for computing and setting selection bounds. This was only added in support of webpage translation; 33 instead of computing this up front, we can instead send this information only when the action is invoked. 34 35 * page/ContextMenuController.cpp: 36 (WebCore::ContextMenuController::contextMenuItemSelected): 37 38 Move logic for computing the selection bounds and menu location in root view coordinates out of `populate` and 39 into `contextMenuItemSelected`, only in the case where the action is `ContextMenuItemTagTranslate`. 40 41 (WebCore::ContextMenuController::populate): 42 1 43 2021-04-16 Jiewen Tan <jiewen_tan@apple.com> 2 44 -
trunk/Source/WebCore/loader/EmptyClients.cpp
r275163 r276181 116 116 #endif 117 117 118 #if HAVE(TRANSLATION_UI_SERVICES) 119 void handleTranslation(const String&, const IntRect&, const IntPoint&) final { } 120 #endif 121 118 122 #if PLATFORM(GTK) 119 123 void insertEmoji(Frame&) final { } -
trunk/Source/WebCore/page/ContextMenuClient.h
r245460 r276181 46 46 virtual void stopSpeaking() = 0; 47 47 48 #if HAVE(TRANSLATION_UI_SERVICES) 49 virtual void handleTranslation(const String&, const IntRect&, const IntPoint&) = 0; 50 #endif 51 48 52 #if PLATFORM(COCOA) 49 53 virtual void searchWithSpotlight() = 0; -
trunk/Source/WebCore/page/ContextMenuContext.h
r274521 r276181 56 56 const String& selectedText() const { return m_selectedText; } 57 57 58 void setSelectionBounds(const IntRect& bounds) { m_selectionBounds = bounds; }59 const IntRect& selectionBounds() const { return m_selectionBounds; }60 61 58 #if ENABLE(SERVICE_CONTROLS) 62 59 void setControlledImage(Image* controlledImage) { m_controlledImage = controlledImage; } … … 68 65 HitTestResult m_hitTestResult; 69 66 String m_selectedText; 70 IntRect m_selectionBounds;71 67 72 68 #if ENABLE(SERVICE_CONTROLS) -
trunk/Source/WebCore/page/ContextMenuController.cpp
r276084 r276181 524 524 break; 525 525 case ContextMenuItemTagRevealImage: 526 case ContextMenuItemTagTranslate:527 526 // This should be handled at the client layer. 528 527 ASSERT_NOT_REACHED(); 528 break; 529 case ContextMenuItemTagTranslate: 530 #if HAVE(TRANSLATION_UI_SERVICES) 531 if (auto view = makeRefPtr(frame->view())) { 532 auto selectionBounds = view->contentsToRootView(enclosingIntRect(frame->selection().selectionBounds())); 533 auto location = view->contentsToRootView(m_context.hitTestResult().roundedPointInInnerNodeFrame()); 534 m_client.handleTranslation(m_context.hitTestResult().selectedText(), selectionBounds, location); 535 } 536 #endif 529 537 break; 530 538 default: … … 869 877 870 878 auto selectedText = m_context.hitTestResult().selectedText(); 871 if (!selectedText.isEmpty()) { 872 m_context.setSelectedText(selectedText); 873 if (auto view = makeRefPtr(frame->view())) { 874 auto selectionBoundsInContentCoordinates = enclosingIntRect(frame->selection().selectionBounds()); 875 if (!selectionBoundsInContentCoordinates.isEmpty()) 876 m_context.setSelectionBounds(view->contentsToRootView(selectionBoundsInContentCoordinates)); 877 } 878 } 879 m_context.setSelectedText(selectedText); 879 880 880 881 if (!m_context.hitTestResult().isContentEditable()) { -
trunk/Source/WebKit/ChangeLog
r276180 r276181 1 2021-04-16 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Refactor some webpage translation code 4 https://bugs.webkit.org/show_bug.cgi?id=224680 5 Work towards <rdar://75641882> 6 7 Reviewed by Tim Horton. 8 9 See WebCore ChangeLog for more details. 10 11 * Shared/ContextMenuContextData.cpp: 12 (WebKit::ContextMenuContextData::ContextMenuContextData): 13 (WebKit::ContextMenuContextData::encode const): 14 (WebKit::ContextMenuContextData::decode): 15 * Shared/ContextMenuContextData.h: 16 17 Remove `selectionBounds`. We don't need this anymore, because we'll instead compute the selection bounds only 18 when the Translate menu item is selected, instead of relying on `m_activeContextMenuContextData` being up to 19 date. 20 21 (WebKit::ContextMenuContextData::selectedText const): 22 (WebKit::ContextMenuContextData::selectionBounds const): Deleted. 23 * UIProcess/Cocoa/WebPageProxyCocoa.mm: 24 (WebKit::WebPageProxy::handleContextMenuTranslation): 25 * UIProcess/WebPageProxy.cpp: 26 (WebKit::WebPageProxy::contextMenuItemSelected): 27 * UIProcess/WebPageProxy.h: 28 * UIProcess/WebPageProxy.messages.in: 29 * WebProcess/WebCoreSupport/WebContextMenuClient.h: 30 * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm: 31 (WebKit::WebContextMenuClient::handleTranslation): 32 * WebProcess/WebPage/WebPage.cpp: 33 (WebKit::WebPage::handleContextMenuTranslation): 34 * WebProcess/WebPage/WebPage.h: 35 1 36 2021-04-16 Jiewen Tan <jiewen_tan@apple.com> 2 37 -
trunk/Source/WebKit/Shared/ContextMenuContextData.cpp
r274521 r276181 54 54 , m_webHitTestResultData(context.hitTestResult(), true) 55 55 , m_selectedText(context.selectedText()) 56 , m_selectionBounds(context.selectionBounds())57 56 #if ENABLE(SERVICE_CONTROLS) 58 57 , m_selectionIsEditable(false) … … 80 79 encoder << m_webHitTestResultData; 81 80 encoder << m_selectedText; 82 encoder << m_selectionBounds;83 81 84 82 #if ENABLE(SERVICE_CONTROLS) … … 108 106 109 107 if (!decoder.decode(result.m_selectedText)) 110 return false;111 112 if (!decoder.decode(result.m_selectionBounds))113 108 return false; 114 109 -
trunk/Source/WebKit/Shared/ContextMenuContextData.h
r274521 r276181 55 55 const WebHitTestResultData& webHitTestResultData() const { return m_webHitTestResultData; } 56 56 const String& selectedText() const { return m_selectedText; } 57 const WebCore::IntRect& selectionBounds() const { return m_selectionBounds; }58 57 59 58 #if ENABLE(SERVICE_CONTROLS) … … 86 85 WebHitTestResultData m_webHitTestResultData; 87 86 String m_selectedText; 88 WebCore::IntRect m_selectionBounds;89 87 90 88 #if ENABLE(SERVICE_CONTROLS) -
trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm
r275768 r276181 616 616 } 617 617 618 void WebPageProxy::handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView) 619 { 620 return pageClient().handleContextMenuTranslation(text, boundsInView, locationInView); 621 } 622 618 623 #endif // HAVE(TRANSLATION_UI_SERVICES) 619 624 #endif // ENABLE(CONTEXT_MENUS) -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r276177 r276181 6747 6747 return; 6748 6748 6749 case ContextMenuItemTagTranslate:6750 #if HAVE(TRANSLATION_UI_SERVICES)6751 pageClient().handleContextMenuTranslation(m_activeContextMenuContextData.selectedText(), m_activeContextMenuContextData.selectionBounds(), m_activeContextMenuContextData.menuLocation());6752 #endif6753 return;6754 6755 6749 default: 6756 6750 break; -
trunk/Source/WebKit/UIProcess/WebPageProxy.h
r276177 r276181 1905 1905 #endif 1906 1906 1907 #if HAVE(TRANSLATION_UI_SERVICES) 1907 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 1908 1908 bool canHandleContextMenuTranslation() const; 1909 void handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView); 1909 1910 #endif 1910 1911 -
trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in
r276177 r276181 226 226 #endif 227 227 228 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 229 HandleContextMenuTranslation(String text, WebCore::IntRect boundsInView, WebCore::IntPoint locationInView) 230 #endif 231 228 232 #if ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU) 229 233 ShowMediaControlsContextMenu(WebCore::FloatRect targetFrame, Vector<WebCore::MediaControlsContextMenuItem> items) -> (WebCore::MediaControlsContextMenuItem::ID selectedItemID) Async -
trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h
r248762 r276181 57 57 #endif 58 58 59 #if HAVE(TRANSLATION_UI_SERVICES) 60 void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final; 61 #endif 62 59 63 #if PLATFORM(GTK) 60 64 void insertEmoji(WebCore::Frame&) override; -
trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm
r235205 r276181 95 95 } 96 96 97 #if HAVE(TRANSLATION_UI_SERVICES) 98 99 void WebContextMenuClient::handleTranslation(const String& text, const IntRect& bounds, const IntPoint& location) 100 { 101 m_page->send(Messages::WebPageProxy::HandleContextMenuTranslation(text, bounds, location)); 102 } 103 104 #endif // HAVE(TRANSLATION_UI_SERVICES) 105 97 106 } // namespace WebKit 98 107 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp
r275921 r276181 7529 7529 } 7530 7530 7531 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 7532 7533 void WebPage::handleContextMenuTranslation(const String& text, const IntRect& boundsInView, const IntPoint& locationInView) 7534 { 7535 send(Messages::WebPageProxy::HandleContextMenuTranslation(text, boundsInView, locationInView)); 7536 } 7537 7538 #endif 7539 7531 7540 } // namespace WebKit 7532 7541 -
trunk/Source/WebKit/WebProcess/WebPage/WebPage.h
r276177 r276181 1392 1392 #endif 1393 1393 1394 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 1395 void handleContextMenuTranslation(const String& text, const WebCore::IntRect& selectionBoundsInView, const WebCore::IntPoint& menuLocationInView); 1396 #endif 1397 1394 1398 #if ENABLE(MEDIA_CONTROLS_CONTEXT_MENUS) && USE(UICONTEXTMENU) 1395 1399 void showMediaControlsContextMenu(WebCore::FloatRect&&, Vector<WebCore::MediaControlsContextMenuItem>&&, CompletionHandler<void(WebCore::MediaControlsContextMenuItem::ID)>&&); -
trunk/Source/WebKitLegacy/mac/ChangeLog
r276177 r276181 1 2021-04-16 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Refactor some webpage translation code 4 https://bugs.webkit.org/show_bug.cgi?id=224680 5 Work towards <rdar://75641882> 6 7 Reviewed by Tim Horton. 8 9 See WebCore ChangeLog for more details. 10 11 * WebCoreSupport/WebContextMenuClient.h: 12 * WebCoreSupport/WebContextMenuClient.mm: 13 (WebContextMenuClient::handleTranslation): 14 * WebView/WebView.mm: 15 (-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]): 16 17 Add an empty stub with a `FIXME` for the time being. 18 19 * WebView/WebViewInternal.h: 20 1 21 2021-04-16 Peng Liu <peng.liu6@apple.com> 2 22 -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h
r248762 r276181 68 68 #endif 69 69 70 #if HAVE(TRANSLATION_UI_SERVICES) 71 void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final; 72 #endif 73 70 74 private: 71 75 NSMenu *contextMenuForEvent(NSEvent *, NSView *, bool& isServicesMenu); -
trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm
r260753 r276181 148 148 } 149 149 150 #if HAVE(TRANSLATION_UI_SERVICES) 151 152 void WebContextMenuClient::handleTranslation(const String& text, const IntRect& selectionBoundsInRootView, const IntPoint& locationInRootView) 153 { 154 [m_webView _handleContextMenuTranslation:text selectionBounds:selectionBoundsInRootView menuLocation:locationInRootView]; 155 } 156 157 #endif 158 150 159 #if ENABLE(SERVICE_CONTROLS) 151 160 -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r276177 r276181 9628 9628 } 9629 9629 9630 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 9631 9632 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)selectionBoundsInRootView menuLocation:(const WebCore::IntPoint&)locationInRootView 9633 { 9634 // FIXME (224683): Not implemented yet. 9635 UNUSED_PARAM(text); 9636 UNUSED_PARAM(selectionBoundsInRootView); 9637 UNUSED_PARAM(locationInRootView); 9638 } 9639 9640 #endif // HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 9641 9630 9642 @end 9631 9643 -
trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h
r276177 r276181 158 158 #endif 159 159 160 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 161 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)boundsInView menuLocation:(const WebCore::IntPoint&)menuLocation; 162 #endif 163 160 164 - (void)_windowVisibilityChanged:(NSNotification *)notification; 161 165
Note:
See TracChangeset
for help on using the changeset viewer.