⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277196 in webkit


Ignore:
Timestamp:
May 7, 2021, 1:28:04 PM (5 years ago)
Author:
Wenson Hsieh
Message:

[macOS] Set the -isSourceEditable property when presenting webpage translation popup
​https://bugs.webkit.org/show_bug.cgi?id=225515
<rdar://problem/77658040>

Reviewed by Tim Horton.

Source/WebCore:

Set -[LTUITranslationViewController isSourceEditable] to YES when showing the context menu for editable
content. Instead of plumbing another boolean flag through ContextMenuClient and into the client layers through
handleTranslation(), we roll all of the webpage translation context menu parameters into a single object
(TranslationContextMenuInfo), including a new flag indicating whether or not the translation controller should
be shown in "editable" mode.

  • Headers.cmake:
  • WebCore.xcodeproj/project.pbxproj:
  • loader/EmptyClients.cpp:
  • page/ContextMenuClient.h:
  • page/ContextMenuController.cpp:

(WebCore::ContextMenuController::contextMenuItemSelected):

  • page/TranslationContextMenuInfo.h: Added.

Pull the translated text string, selection bounds, menu location, and the new mode flag into a separate struct.

(WebCore::TranslationContextMenuInfo::encode const):
(WebCore::TranslationContextMenuInfo::decode):

Source/WebKit:

See WebCore/ChangeLog for more details.

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::handleContextMenuTranslation):

  • UIProcess/Cocoa/WebViewImpl.h:
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::handleContextMenuTranslation):

  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/mac/PageClientImplMac.h:
  • UIProcess/mac/PageClientImplMac.mm:

(WebKit::PageClientImpl::handleContextMenuTranslation):

  • 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:]):
(-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]): Deleted.

  • WebView/WebViewInternal.h:
Location:
trunk/Source
Files:
1 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r277177 r277196  
     12021-05-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Set the -isSourceEditable property when presenting webpage translation popup
     4        https://bugs.webkit.org/show_bug.cgi?id=225515
     5        <rdar://problem/77658040>
     6
     7        Reviewed by Tim Horton.
     8
     9        Set `-[LTUITranslationViewController isSourceEditable]` to `YES` when showing the context menu for editable
     10        content. Instead of plumbing another boolean flag through `ContextMenuClient` and into the client layers through
     11        `handleTranslation()`, we roll all of the webpage translation context menu parameters into a single object
     12        (`TranslationContextMenuInfo`), including a new flag indicating whether or not the translation controller should
     13        be shown in "editable" mode.
     14
     15        * Headers.cmake:
     16        * WebCore.xcodeproj/project.pbxproj:
     17        * loader/EmptyClients.cpp:
     18        * page/ContextMenuClient.h:
     19        * page/ContextMenuController.cpp:
     20        (WebCore::ContextMenuController::contextMenuItemSelected):
     21        * page/TranslationContextMenuInfo.h: Added.
     22
     23        Pull the translated text string, selection bounds, menu location, and the new mode flag into a separate struct.
     24
     25        (WebCore::TranslationContextMenuInfo::encode const):
     26        (WebCore::TranslationContextMenuInfo::decode):
     27
    1282021-05-07  Chris Dumez  <cdumez@apple.com>
    229
  • trunk/Source/WebCore/Headers.cmake

    r276951 r277196  
    946946    page/TextDirectionSubmenuInclusionBehavior.h
    947947    page/TextIndicator.h
     948    page/TranslationContextMenuInfo.h
    948949    page/UserContentController.h
    949950    page/UserContentProvider.h
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r277024 r277196  
    53395339                F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; settings = {ATTRIBUTES = (Private, ); }; };
    53405340                F482434B260C33060022497C /* ImageOverlayController.h in Headers */ = {isa = PBXBuildFile; fileRef = F4824348260C32F10022497C /* ImageOverlayController.h */; };
     5341                F48570A52644C76D00C05F71 /* TranslationContextMenuInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = F48570A42644C76D00C05F71 /* TranslationContextMenuInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
    53415342                F48B7D5325C341E6009E75DD /* ImageExtractionResult.h in Headers */ = {isa = PBXBuildFile; fileRef = F48B7D5225C341E6009E75DD /* ImageExtractionResult.h */; settings = {ATTRIBUTES = (Private, ); }; };
    53425343                F48D2A6C215623B400C6752B /* FontShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = F48D2A6A215623B400C6752B /* FontShadow.h */; settings = {ATTRIBUTES = (Private, ); }; };
    … …  
    1679716798                F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; };
    1679816799                F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; };
     16800                F48570A42644C76D00C05F71 /* TranslationContextMenuInfo.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TranslationContextMenuInfo.h; sourceTree = "<group>"; };
    1679916801                F48B7D5225C341E6009E75DD /* ImageExtractionResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ImageExtractionResult.h; sourceTree = "<group>"; };
    1680016802                F48D2A6A215623B400C6752B /* FontShadow.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontShadow.h; sourceTree = "<group>"; };
    … …  
    2251822520                                2D4F96F11A1ECC240098BF88 /* TextIndicator.cpp */,
    2251922521                                2D4F96F21A1ECC240098BF88 /* TextIndicator.h */,
     22522                                F48570A42644C76D00C05F71 /* TranslationContextMenuInfo.h */,
    2252022523                                F4E1965F21F26E4E00285078 /* UndoItem.cpp */,
    2252122524                                2ECDBAD521D8906300F00ECD /* UndoItem.h */,
    … …  
    3142731430                                49E912AB0EFAC906009D0CAF /* Animation.h in Headers */,
    3142831431                                71EFCEDC202B38A900D7C411 /* AnimationEffect.h in Headers */,
    31429                                 449D864F2640C9C5000122DE /* HighlightVisibility.h in Headers */,
    3143031432                                71E2C42621C935280024F8C8 /* AnimationEffectPhase.h in Headers */,
    3143131433                                319848011A1D817B00A13318 /* AnimationEvent.h in Headers */,
    … …  
    3264632648                                CDCFABBD18C0AF78006F8450 /* HighlightData.h in Headers */,
    3264732649                                4430D00D2575A8A50046D401 /* HighlightRegister.h in Headers */,
     32650                                449D864F2640C9C5000122DE /* HighlightVisibility.h in Headers */,
    3264832651                                BC94D1540C275C8B006BC617 /* History.h in Headers */,
    3264932652                                97DCE20210807C750057D394 /* HistoryController.h in Headers */,
    … …  
    3488434887                                4998AED213FB224D0090B1AA /* ScriptedAnimationController.h in Headers */,
    3488534888                                08A484780E5272C500C3FE76 /* ScriptElement.h in Headers */,
    34886                                 E4D86E6D2640394C00B62425 /* StyleScopeOrdinal.h in Headers */,
    3488734889                                E3E4E2A81E3B17100023BB8A /* ScriptElementCachedScriptFetcher.h in Headers */,
    3488834890                                E11C9D9B0EB3681200E409DB /* ScriptExecutionContext.h in Headers */,
    … …  
    3520035202                                0F94F37E23661626003AA5C7 /* StyleRuleType.h in Headers */,
    3520135203                                E461D65F1BB0C80D00CB5645 /* StyleScope.h in Headers */,
     35204                                E4D86E6D2640394C00B62425 /* StyleScopeOrdinal.h in Headers */,
    3520235205                                4A4F48AA16B0DFC000EDBB29 /* StyleScopeRuleSets.h in Headers */,
    3520335206                                F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */,
    … …  
    3553835541                                E17B491616A9B094001C8839 /* TransitionEvent.h in Headers */,
    3553935542                                49E911D20EF86D47009D0CAF /* TranslateTransformOperation.h in Headers */,
     35543                                F48570A52644C76D00C05F71 /* TranslationContextMenuInfo.h in Headers */,
    3554035544                                854FE7370A2297BE0058D7AD /* Traversal.h in Headers */,
    3554135545                                37FD4298118368460093C029 /* TreeDepthLimit.h in Headers */,
  • trunk/Source/WebCore/loader/EmptyClients.cpp

    r276448 r277196  
    121121
    122122#if HAVE(TRANSLATION_UI_SERVICES)
    123     void handleTranslation(const String&, const IntRect&, const IntPoint&) final { }
     123    void handleTranslation(const TranslationContextMenuInfo&) final { }
    124124#endif
    125125
  • trunk/Source/WebCore/page/ContextMenuClient.h

    r276252 r277196  
    3636class IntRect;
    3737
     38#if HAVE(TRANSLATION_UI_SERVICES)
     39struct TranslationContextMenuInfo;
     40#endif
     41
    3842class ContextMenuClient {
    3943public:
    … …  
    4953
    5054#if HAVE(TRANSLATION_UI_SERVICES)
    51     virtual void handleTranslation(const String&, const IntRect&, const IntPoint&) = 0;
     55    virtual void handleTranslation(const TranslationContextMenuInfo&) = 0;
    5256#endif
    5357
  • trunk/Source/WebCore/page/ContextMenuController.cpp

    r276871 r277196  
    6464#include "Settings.h"
    6565#include "TextIterator.h"
     66#include "TranslationContextMenuInfo.h"
    6667#include "TypingCommand.h"
    6768#include "UserTypingGestureIndicator.h"
    … …  
    528529#if HAVE(TRANSLATION_UI_SERVICES)
    529530        if (auto view = makeRefPtr(frame->view())) {
    530             auto selectionBounds = view->contentsToRootView(enclosingIntRect(frame->selection().selectionBounds()));
    531             auto location = view->contentsToRootView(m_context.hitTestResult().roundedPointInInnerNodeFrame());
    532             m_client.handleTranslation(m_context.hitTestResult().selectedText(), selectionBounds, location);
     531            m_client.handleTranslation({
     532                m_context.hitTestResult().selectedText(),
     533                view->contentsToRootView(enclosingIntRect(frame->selection().selectionBounds())),
     534                view->contentsToRootView(m_context.hitTestResult().roundedPointInInnerNodeFrame()),
     535                m_context.hitTestResult().isContentEditable() ? TranslationContextMenuMode::Editable : TranslationContextMenuMode::NonEditable,
     536            });
    533537        }
    534538#endif
  • trunk/Source/WebKit/ChangeLog

    r277172 r277196  
     12021-05-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Set the -isSourceEditable property when presenting webpage translation popup
     4        https://bugs.webkit.org/show_bug.cgi?id=225515
     5        <rdar://problem/77658040>
     6
     7        Reviewed by Tim Horton.
     8
     9        See WebCore/ChangeLog for more details.
     10
     11        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     12        (WebKit::WebPageProxy::handleContextMenuTranslation):
     13        * UIProcess/Cocoa/WebViewImpl.h:
     14        * UIProcess/Cocoa/WebViewImpl.mm:
     15        (WebKit::WebViewImpl::handleContextMenuTranslation):
     16        * UIProcess/PageClient.h:
     17        * UIProcess/WebPageProxy.h:
     18        * UIProcess/WebPageProxy.messages.in:
     19        * UIProcess/mac/PageClientImplMac.h:
     20        * UIProcess/mac/PageClientImplMac.mm:
     21        (WebKit::PageClientImpl::handleContextMenuTranslation):
     22        * WebProcess/WebCoreSupport/WebContextMenuClient.h:
     23        * WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm:
     24        (WebKit::WebContextMenuClient::handleTranslation):
     25        * WebProcess/WebPage/WebPage.cpp:
     26        (WebKit::WebPage::handleContextMenuTranslation):
     27        * WebProcess/WebPage/WebPage.h:
     28
    1292021-05-07  Carlos Garnacho  <carlosg@gnome.org>
    230
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r276947 r277196  
    627627}
    628628
    629 void WebPageProxy::handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView)
    630 {
    631     return pageClient().handleContextMenuTranslation(text, boundsInView, locationInView);
     629void WebPageProxy::handleContextMenuTranslation(const TranslationContextMenuInfo& info)
     630{
     631    return pageClient().handleContextMenuTranslation(info);
    632632}
    633633
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r276621 r277196  
    9797struct ShareDataWithParsedURL;
    9898
     99#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     100struct TranslationContextMenuInfo;
     101#endif
     102
    99103#if ENABLE(IMAGE_EXTRACTION)
    100104struct ImageExtractionResult;
    … …  
    649653#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    650654    bool canHandleContextMenuTranslation() const;
    651     void handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& menuLocation);
     655    void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&);
    652656#endif
    653657
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r276621 r277196  
    108108#import <WebCore/TextAlternativeWithRange.h>
    109109#import <WebCore/TextUndoInsertionMarkupMac.h>
     110#import <WebCore/TranslationContextMenuInfo.h>
    110111#import <WebCore/WebActionDisablingCALayerDelegate.h>
    111112#import <WebCore/WebCoreCALayerExtras.h>
    … …  
    146147#import <TranslationUIServices/LTUITranslationViewController.h>
    147148
     149@interface LTUITranslationViewController (Staging_77660675)
     150@property (nonatomic, copy) void(^replacementHandler)(NSAttributedString *);
     151@end
     152
    148153SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(TranslationUIServices)
    149154SOFT_LINK_CLASS_OPTIONAL(TranslationUIServices, LTUITranslationViewController)
    … …  
    55875592}
    55885593
    5589 void WebViewImpl::handleContextMenuTranslation(const String& text, const IntRect& boundsInView, const IntPoint& menuLocation)
     5594void WebViewImpl::handleContextMenuTranslation(const TranslationContextMenuInfo& info)
    55905595{
    55915596    if (!canHandleContextMenuTranslation()) {
    … …  
    55965601    auto view = m_view.get();
    55975602    auto translationViewController = adoptNS([allocLTUITranslationViewControllerInstance() init]);
    5598     auto textToTranslate = adoptNS([[NSAttributedString alloc] initWithString:text]);
    5599     [translationViewController setText:textToTranslate.get()];
     5603    [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:info.text]).get()];
     5604    if (info.mode == WebCore::TranslationContextMenuMode::Editable && [translationViewController respondsToSelector:@selector(setReplacementHandler:)]) {
     5605        [translationViewController setIsSourceEditable:YES];
     5606        [translationViewController setReplacementHandler:[this, weakThis = makeWeakPtr(*this)](NSAttributedString *string) {
     5607            if (weakThis)
     5608                insertText(string.string);
     5609        }];
     5610    }
     5611
    56005612    if (NSEqualSizes([translationViewController preferredContentSize], NSZeroSize))
    56015613        [translationViewController setPreferredContentSize:NSMakeSize(400, 400)];
    … …  
    56095621
    56105622    NSRectEdge preferredEdge;
    5611     auto aim = menuLocation.x();
    5612     auto highlight = boundsInView.center().x();
     5623    auto aim = info.locationInRootView.x();
     5624    auto highlight = info.selectionBoundsInRootView.center().x();
    56135625    if (aim == highlight)
    56145626        preferredEdge = [view userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft ? NSRectEdgeMinX : NSRectEdgeMaxX;
    … …  
    56165628        preferredEdge = aim > highlight ? NSRectEdgeMaxX : NSRectEdgeMinX;
    56175629
    5618     [popover showRelativeToRect:boundsInView ofView:view.get() preferredEdge:preferredEdge];
     5630    [popover showRelativeToRect:info.selectionBoundsInRootView ofView:view.get() preferredEdge:preferredEdge];
    56195631}
    56205632
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r277097 r277196  
    127127struct PromisedAttachmentInfo;
    128128#endif
     129
     130#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     131struct TranslationContextMenuInfo;
     132#endif
    129133}
    130134
    … …  
    618622#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    619623    virtual bool canHandleContextMenuTranslation() const = 0;
    620     virtual void handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& menuLocation) = 0;
     624    virtual void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&) = 0;
    621625#endif
    622626};
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r277097 r277196  
    109109#include <WebCore/TextGranularity.h>
    110110#include <WebCore/TextManipulationController.h>
     111#include <WebCore/TranslationContextMenuInfo.h>
    111112#include <WebCore/UserInterfaceLayoutDirection.h>
    112113#include <WebCore/ViewportArguments.h>
    … …  
    19121913#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    19131914    bool canHandleContextMenuTranslation() const;
    1914     void handleContextMenuTranslation(const String& text, const WebCore::IntRect& boundsInView, const WebCore::IntPoint& locationInView);
     1915    void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&);
    19151916#endif
    19161917
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r277045 r277196  
    229229
    230230#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    231     HandleContextMenuTranslation(String text, WebCore::IntRect boundsInView, WebCore::IntPoint locationInView)
     231    HandleContextMenuTranslation(struct WebCore::TranslationContextMenuInfo info)
    232232#endif
    233233
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h

    r275491 r277196  
    284284#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    285285    bool canHandleContextMenuTranslation() const override;
    286     void handleContextMenuTranslation(const String&, const WebCore::IntRect&, const WebCore::IntPoint&) override;
     286    void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&) override;
    287287#endif
    288288
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r275491 r277196  
    10231023}
    10241024
    1025 void PageClientImpl::handleContextMenuTranslation(const String& text, const IntRect& boundsInView, const WebCore::IntPoint& menuLocation)
    1026 {
    1027     m_impl->handleContextMenuTranslation(text, boundsInView, menuLocation);
     1025void PageClientImpl::handleContextMenuTranslation(const TranslationContextMenuInfo& info)
     1026{
     1027    m_impl->handleContextMenuTranslation(info);
    10281028}
    10291029
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebContextMenuClient.h

    r276181 r277196  
    5858
    5959#if HAVE(TRANSLATION_UI_SERVICES)
    60     void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final;
     60    void handleTranslation(const WebCore::TranslationContextMenuInfo&) final;
    6161#endif
    6262
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebContextMenuClientMac.mm

    r276181 r277196  
    3838#import <WebCore/Page.h>
    3939#import <WebCore/TextIndicator.h>
     40#import <WebCore/TranslationContextMenuInfo.h>
    4041#import <wtf/text/WTFString.h>
    4142
    … …  
    9798#if HAVE(TRANSLATION_UI_SERVICES)
    9899
    99 void WebContextMenuClient::handleTranslation(const String& text, const IntRect& bounds, const IntPoint& location)
     100void WebContextMenuClient::handleTranslation(const WebCore::TranslationContextMenuInfo& info)
    100101{
    101     m_page->send(Messages::WebPageProxy::HandleContextMenuTranslation(text, bounds, location));
     102    m_page->send(Messages::WebPageProxy::HandleContextMenuTranslation(info));
    102103}
    103104
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r277045 r277196  
    245245#include <WebCore/SubstituteData.h>
    246246#include <WebCore/TextIterator.h>
     247#include <WebCore/TranslationContextMenuInfo.h>
    247248#include <WebCore/UserContentURLPattern.h>
    248249#include <WebCore/UserGestureIndicator.h>
    … …  
    75727573#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    75737574
    7574 void WebPage::handleContextMenuTranslation(const String& text, const IntRect& boundsInView, const IntPoint& locationInView)
    7575 {
    7576     send(Messages::WebPageProxy::HandleContextMenuTranslation(text, boundsInView, locationInView));
     7575void WebPage::handleContextMenuTranslation(const TranslationContextMenuInfo& info)
     7576{
     7577    send(Messages::WebPageProxy::HandleContextMenuTranslation(info));
    75777578}
    75787579
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r277097 r277196  
    248248class HTMLAttachmentElement;
    249249#endif
     250
     251#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     252struct TranslationContextMenuInfo;
     253#endif
    250254}
    251255
    … …  
    13971401
    13981402#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    1399     void handleContextMenuTranslation(const String& text, const WebCore::IntRect& selectionBoundsInView, const WebCore::IntPoint& menuLocationInView);
     1403    void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&);
    14001404#endif
    14011405
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r276982 r277196  
     12021-05-07  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Set the -isSourceEditable property when presenting webpage translation popup
     4        https://bugs.webkit.org/show_bug.cgi?id=225515
     5        <rdar://problem/77658040>
     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:]):
     16        (-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]): Deleted.
     17        * WebView/WebViewInternal.h:
     18
    1192021-05-04  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.h

    r276181 r277196  
    6969
    7070#if HAVE(TRANSLATION_UI_SERVICES)
    71     void handleTranslation(const String&, const WebCore::IntRect& selectionBoundsInRootView, const WebCore::IntPoint& locationInRootView) final;
     71    void handleTranslation(const WebCore::TranslationContextMenuInfo&) final;
    7272#endif
    7373
  • trunk/Source/WebKitLegacy/mac/WebCoreSupport/WebContextMenuClient.mm

    r276899 r277196  
    150150#if HAVE(TRANSLATION_UI_SERVICES)
    151151
    152 void WebContextMenuClient::handleTranslation(const String& text, const IntRect& selectionBoundsInRootView, const IntPoint& locationInRootView)
    153 {
    154     [m_webView _handleContextMenuTranslation:text selectionBounds:selectionBoundsInRootView menuLocation:locationInRootView];
     152void WebContextMenuClient::handleTranslation(const TranslationContextMenuInfo& info)
     153{
     154    [m_webView _handleContextMenuTranslation:info];
    155155}
    156156
  • trunk/Source/WebKitLegacy/mac/WebView/WebView.mm

    r276982 r277196  
    216216#import <WebCore/TextResourceDecoder.h>
    217217#import <WebCore/ThreadCheck.h>
     218#import <WebCore/TranslationContextMenuInfo.h>
    218219#import <WebCore/UTIRegistry.h>
    219220#import <WebCore/UserAgent.h>
    … …  
    352353#if HAVE(TRANSLATION_UI_SERVICES)
    353354#import <TranslationUIServices/LTUITranslationViewController.h>
     355
     356@interface LTUITranslationViewController (Staging_77660675)
     357@property (nonatomic, copy) void(^replacementHandler)(NSAttributedString *);
     358@end
    354359
    355360SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(TranslationUIServices)
    … …  
    96399644}
    96409645
    9641 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)selectionBoundsInRootView menuLocation:(const WebCore::IntPoint&)locationInRootView
     9646- (void)_handleContextMenuTranslation:(const WebCore::TranslationContextMenuInfo&)info
    96429647{
    96439648    if (!WebView._canHandleContextMenuTranslation) {
    … …  
    96479652
    96489653    auto translationViewController = adoptNS([allocLTUITranslationViewControllerInstance() init]);
    9649     [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:text]).get()];
    9650 
    9651     auto convertedSelectionBounds = [self _convertRectFromRootView:selectionBoundsInRootView];
    9652     auto convertedMenuLocation = [self _convertPointFromRootView:locationInRootView];
     9654    [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:info.text]).get()];
     9655    if (info.mode == WebCore::TranslationContextMenuMode::Editable && [translationViewController respondsToSelector:@selector(setReplacementHandler:)]) {
     9656        [translationViewController setIsSourceEditable:YES];
     9657        [translationViewController setReplacementHandler:[weakSelf = WeakObjCPtr<WebView>(self)](NSAttributedString *string) {
     9658            auto strongSelf = weakSelf.get();
     9659            [strongSelf insertText:string.string];
     9660        }];
     9661    }
     9662
     9663    auto convertedSelectionBounds = [self _convertRectFromRootView:info.selectionBoundsInRootView];
     9664    auto convertedMenuLocation = [self _convertPointFromRootView:info.locationInRootView];
    96539665
    96549666    auto popover = adoptNS([[NSPopover alloc] init]);
  • trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h

    r276220 r277196  
    6666struct DictationAlternative;
    6767struct DictionaryPopupInfo;
     68
     69#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     70struct TranslationContextMenuInfo;
     71#endif
    6872}
    6973
    … …  
    160164#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
    161165@property (class, nonatomic, readonly) BOOL _canHandleContextMenuTranslation;
    162 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)boundsInView menuLocation:(const WebCore::IntPoint&)menuLocation;
     166- (void)_handleContextMenuTranslation:(const WebCore::TranslationContextMenuInfo&)info;
    163167#endif
    164168
Note: See TracChangeset for help on using the changeset viewer.