Changeset 276220 in webkit
- Timestamp:
- Apr 17, 2021, 9:24:59 PM (5 years ago)
- Location:
- trunk/Source
- Files:
-
- 13 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/page/ContextMenuController.cpp (modified) (4 diffs)
-
WebCore/platform/ContextMenuItem.cpp (modified) (1 diff)
-
WebCore/platform/ContextMenuItem.h (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/Shared/API/c/WKSharedAPICast.h (modified) (2 diffs)
-
WebKit/UIProcess/WebPageProxy.cpp (modified) (1 diff)
-
WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (modified) (2 diffs)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebHTMLView.mm (modified) (3 diffs)
-
WebKitLegacy/mac/WebView/WebUIDelegatePrivate.h (modified) (1 diff)
-
WebKitLegacy/mac/WebView/WebView.mm (modified) (3 diffs)
-
WebKitLegacy/mac/WebView/WebViewInternal.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r276219 r276220 1 2021-04-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Add some support for webpage translation in WebKitLegacy 4 https://bugs.webkit.org/show_bug.cgi?id=224683 5 <rdar://problem/75641882> 6 7 Reviewed by Darin Adler. 8 9 Remove compile-time guards around `ContextMenuItemTagAddHighlightToCurrentGroup` and 10 `ContextMenuItemTagAddHighlightToNewGroup`, so that we can keep these internal WebCore context menu tags in sync 11 with the SPI-exposed enum values in `WebUIDelegatePrivate.h`. See WebKitLegacy ChangeLog for more details. 12 13 * page/ContextMenuController.cpp: 14 (WebCore::ContextMenuController::contextMenuItemSelected): 15 (WebCore::ContextMenuController::checkOrEnableIfNeeded const): 16 * platform/ContextMenuItem.cpp: 17 (WebCore::isValidContextMenuAction): 18 * platform/ContextMenuItem.h: 19 1 20 2021-04-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 21 -
trunk/Source/WebCore/page/ContextMenuController.cpp
r276181 r276220 441 441 frame->editor().command("MakeTextWritingDirectionRightToLeft").execute(); 442 442 break; 443 #if ENABLE(APP_HIGHLIGHTS)444 443 case ContextMenuItemTagAddHighlightToCurrentGroup: 445 444 // FIXME: Add Highlight Logic … … 448 447 // FIXME: Add Highlight Logic 449 448 break; 450 #endif451 449 #if PLATFORM(COCOA) 452 450 case ContextMenuItemTagSearchInSpotlight: … … 1315 1313 shouldCheck = frame->editor().isContinuousSpellCheckingEnabled(); 1316 1314 break; 1317 #if ENABLE(APP_HIGHLIGHTS)1318 1315 case ContextMenuItemTagAddHighlightToCurrentGroup: 1319 1316 shouldEnable = frame->selection().isRange(); … … 1322 1319 shouldEnable = frame->selection().isRange(); 1323 1320 break; 1324 #endif1325 1321 #if PLATFORM(COCOA) 1326 1322 case ContextMenuItemTagSubstitutionsMenu: -
trunk/Source/WebCore/platform/ContextMenuItem.cpp
r274521 r276220 230 230 case ContextMenuAction::ContextMenuItemTagTextDirectionLeftToRight: 231 231 case ContextMenuAction::ContextMenuItemTagTextDirectionRightToLeft: 232 #if ENABLE(APP_HIGHLIGHTS)233 232 case ContextMenuAction::ContextMenuItemTagAddHighlightToCurrentGroup: 234 233 case ContextMenuAction::ContextMenuItemTagAddHighlightToNewGroup: 235 #endif236 234 #if PLATFORM(COCOA) 237 235 case ContextMenuAction::ContextMenuItemTagCorrectSpellingAutomatically: -
trunk/Source/WebCore/platform/ContextMenuItem.h
r274521 r276220 146 146 ContextMenuItemTagShareMenu, 147 147 ContextMenuItemTagToggleVideoEnhancedFullscreen, 148 #if ENABLE(APP_HIGHLIGHTS)149 148 ContextMenuItemTagAddHighlightToCurrentGroup, 150 149 ContextMenuItemTagAddHighlightToNewGroup, 151 #endif152 150 ContextMenuItemTagRevealImage, 153 151 ContextMenuItemTagTranslate, -
trunk/Source/WebKit/ChangeLog
r276219 r276220 1 2021-04-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Add some support for webpage translation in WebKitLegacy 4 https://bugs.webkit.org/show_bug.cgi?id=224683 5 <rdar://problem/75641882> 6 7 Reviewed by Darin Adler. 8 9 Remove some more compile-time guards, now that the WebCore enum is not conditional on `ENABLE(APP_HIGHLIGHT)`. 10 See WebCore/ChangeLog for more information. 11 12 * Shared/API/c/WKSharedAPICast.h: 13 (WebKit::toAPI): 14 (WebKit::toImpl): 15 * UIProcess/WebPageProxy.cpp: 16 (WebKit::WebPageProxy::contextMenuItemSelected): 17 * UIProcess/mac/WebContextMenuProxyMac.mm: 18 (WebKit::menuItemIdentifier): 19 1 20 2021-04-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 21 -
trunk/Source/WebKit/Shared/API/c/WKSharedAPICast.h
r274148 r276220 510 510 case WebCore::ContextMenuItemTagMediaMute: 511 511 return kWKContextMenuItemTagMediaMute; 512 #if ENABLE(APP_HIGHLIGHTS)513 512 case WebCore::ContextMenuItemTagAddHighlightToCurrentGroup: 514 513 return kWKContextMenuItemTagAddHighlightToCurrentGroup; 515 514 case WebCore::ContextMenuItemTagAddHighlightToNewGroup: 516 515 return kWKContextMenuItemTagAddHighlightToNewGroup; 517 #endif518 516 #if PLATFORM(COCOA) 519 517 case WebCore::ContextMenuItemTagCorrectSpellingAutomatically: … … 714 712 case kWKContextMenuItemTagMediaMute: 715 713 return WebCore::ContextMenuItemTagMediaMute; 716 #if ENABLE(APP_HIGHLIGHT)717 714 case kWKContextMenuItemTagAddHighlightToCurrentGroup: 718 715 return WebCore::ContextMenuItemTagAddHighlightToCurrentGroup; 719 716 case kWKContextMenuItemTagAddHighlightToNewGroup: 720 717 return WebCore::ContextMenuItemTagAddHighlightToNewGroup; 721 #endif722 718 #if PLATFORM(COCOA) 723 719 case kWKContextMenuItemTagCorrectSpellingAutomatically: -
trunk/Source/WebKit/UIProcess/WebPageProxy.cpp
r276181 r276220 6726 6726 return; 6727 6727 6728 case ContextMenuItemTagAddHighlightToNewGroup: 6728 6729 #if ENABLE(APP_HIGHLIGHTS) 6729 case ContextMenuItemTagAddHighlightToNewGroup:6730 6730 createAppHighlightInSelectedRange(CreateNewGroupForHighlight::Yes, HighlightRequestOriginatedInApp::No); 6731 #endif 6731 6732 return; 6732 6733 6733 6734 case ContextMenuItemTagAddHighlightToCurrentGroup: 6735 #if ENABLE(APP_HIGHLIGHTS) 6734 6736 createAppHighlightInSelectedRange(CreateNewGroupForHighlight::No, HighlightRequestOriginatedInApp::No); 6735 return; 6736 #endif 6737 #endif 6738 return; 6737 6739 6738 6740 case ContextMenuItemTagLearnSpelling: -
trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm
r275572 r276220 409 409 case ContextMenuItemTagLookUpInDictionary: 410 410 return _WKMenuItemIdentifierLookUp; 411 #if ENABLE(APP_HIGHLIGHTS) 411 412 412 case ContextMenuItemTagAddHighlightToCurrentGroup: 413 413 return _WKMenuItemIdentifierAddHighlightToCurrentGroup; … … 415 415 case ContextMenuItemTagAddHighlightToNewGroup: 416 416 return _WKMenuItemIdentifierAddHighlightToNewGroup; 417 #endif 417 418 418 case ContextMenuItemTagOpenFrameInNewWindow: 419 419 return _WKMenuItemIdentifierOpenFrameInNewWindow; -
trunk/Source/WebKitLegacy/mac/ChangeLog
r276209 r276220 1 2021-04-17 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 [macOS] Add some support for webpage translation in WebKitLegacy 4 https://bugs.webkit.org/show_bug.cgi?id=224683 5 <rdar://problem/75641882> 6 7 Reviewed by Darin Adler. 8 9 Add support for the webpage translation context menu item in WebKitLegacy. See below for more details. 10 11 * WebView/WebHTMLView.mm: 12 (toAction): 13 (toTag): 14 15 Introduce the `WebMenuItemTagTranslate` enum value, and use it as the tag value when creating an `NSMenuItem` 16 for the Translate action. 17 18 (createMenuItem): 19 * WebView/WebUIDelegatePrivate.h: 20 21 Unfortunately, in order to support a particular internal client of WebKitLegacy, we need to expose 22 `WebMenuItemTagTranslate` as an enum value in this existing enumeration of context menu item tags. This is 23 because the client's implementation of `-webView:contextMenuItemsForElement:defaultMenuItems:` rejects context 24 menu items by default, unless the item tag is within the set of item tags that they support. 25 26 This client will need to add the enum value of `WebMenuItemTagTranslate` into their allow-list. 27 28 * WebView/WebView.mm: 29 (+[WebView _canHandleContextMenuTranslation]): 30 31 Softlink against and check with `TranslationUIServices` to see if we should be showing the Translate menu item. 32 33 (-[WebView _handleContextMenuTranslation:selectionBounds:menuLocation:]): 34 35 Handle the menu action by creating and presenting a new `LTUITranslationViewController` using the given 36 information. 37 38 * WebView/WebViewInternal.h: 39 1 40 2021-04-17 Tyler Wilcock <twilco.o@protonmail.com> 2 41 -
trunk/Source/WebKitLegacy/mac/WebView/WebHTMLView.mm
r276191 r276220 427 427 case WebMenuItemTagDictationAlternative: 428 428 return ContextMenuItemTagDictationAlternative; 429 case WebMenuItemTagTranslate: 430 return ContextMenuItemTagTranslate; 429 431 } 430 432 return WTF::nullopt; … … 606 608 case ContextMenuItemTagToggleVideoFullscreen: 607 609 return WebMenuItemTagToggleVideoFullscreen; 608 #if ENABLE(APP_HIGHLIGHTS)609 610 case ContextMenuItemTagAddHighlightToCurrentGroup: 610 611 case ContextMenuItemTagAddHighlightToNewGroup: 611 612 return WTF::nullopt; 612 #endif613 613 case ContextMenuItemTagShareMenu: 614 614 return WebMenuItemTagShareMenu; 615 615 case ContextMenuItemTagToggleVideoEnhancedFullscreen: 616 616 return WebMenuItemTagToggleVideoEnhancedFullscreen; 617 case ContextMenuItemTagTranslate: 618 return WebMenuItemTagTranslate; 617 619 case ContextMenuItemTagRevealImage: 618 case ContextMenuItemTagTranslate:619 620 return WTF::nullopt; 620 621 … … 3633 3634 static RetainPtr<NSMenuItem> createMenuItem(const WebCore::HitTestResult& hitTestResult, const WebCore::ContextMenuItem& item) 3634 3635 { 3636 #if HAVE(TRANSLATION_UI_SERVICES) 3637 if (item.action() == WebCore::ContextMenuItemTagTranslate && !WebView._canHandleContextMenuTranslation) 3638 return nil; 3639 #endif 3640 3635 3641 if (item.action() == WebCore::ContextMenuItemTagShareMenu) 3636 3642 return createShareMenuItem(hitTestResult); -
trunk/Source/WebKitLegacy/mac/WebView/WebUIDelegatePrivate.h
r261138 r276220 108 108 WebMenuItemTagShareMenu, 109 109 WebMenuItemTagToggleVideoEnhancedFullscreen, 110 WebMenuItemTagAddHighlightToCurrentGroup, 111 WebMenuItemTagAddHighlightToNewGroup, 112 WebMenuItemTagRevealImage, 113 WebMenuItemTagTranslate, 110 114 }; 111 115 -
trunk/Source/WebKitLegacy/mac/WebView/WebView.mm
r276191 r276220 251 251 #import <wtf/Language.h> 252 252 #import <wtf/MainThread.h> 253 #import <wtf/MathExtras.h> 253 254 #import <wtf/ProcessPrivilege.h> 254 255 #import <wtf/RAMSize.h> … … 348 349 #import <WebCore/PlaybackSessionInterfaceMac.h> 349 350 #import <WebCore/PlaybackSessionModelMediaElement.h> 351 #endif 352 353 #if HAVE(TRANSLATION_UI_SERVICES) 354 #import <TranslationUIServices/LTUITranslationViewController.h> 355 356 SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(TranslationUIServices) 357 SOFT_LINK_CLASS_OPTIONAL(TranslationUIServices, LTUITranslationViewController) 350 358 #endif 351 359 … … 9630 9638 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 9631 9639 9640 + (BOOL)_canHandleContextMenuTranslation 9641 { 9642 return TranslationUIServicesLibrary() && [getLTUITranslationViewControllerClass() isAvailable]; 9643 } 9644 9632 9645 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)selectionBoundsInRootView menuLocation:(const WebCore::IntPoint&)locationInRootView 9633 9646 { 9634 // FIXME (224683): Not implemented yet. 9635 UNUSED_PARAM(text); 9636 UNUSED_PARAM(selectionBoundsInRootView); 9637 UNUSED_PARAM(locationInRootView); 9647 if (!WebView._canHandleContextMenuTranslation) { 9648 ASSERT_NOT_REACHED(); 9649 return; 9650 } 9651 9652 auto translationViewController = adoptNS([allocLTUITranslationViewControllerInstance() init]); 9653 [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:text]).get()]; 9654 9655 auto convertedSelectionBounds = [self _convertRectFromRootView:selectionBoundsInRootView]; 9656 auto convertedMenuLocation = [self _convertPointFromRootView:locationInRootView]; 9657 9658 auto popover = adoptNS([[NSPopover alloc] init]); 9659 [popover setBehavior:NSPopoverBehaviorTransient]; 9660 [popover setAppearance:self.effectiveAppearance]; 9661 [popover setAnimates:YES]; 9662 [popover setContentViewController:translationViewController.get()]; 9663 [popover setContentSize:[translationViewController preferredContentSize]]; 9664 9665 NSRectEdge preferredEdge; 9666 auto aim = convertedMenuLocation.x; 9667 auto highlight = NSMidX(convertedSelectionBounds); 9668 if (WTF::areEssentiallyEqual<CGFloat>(aim, highlight)) 9669 preferredEdge = self.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionRightToLeft ? NSRectEdgeMinX : NSRectEdgeMaxX; 9670 else 9671 preferredEdge = aim > highlight ? NSRectEdgeMaxX : NSRectEdgeMinX; 9672 9673 [popover showRelativeToRect:convertedSelectionBounds ofView:self preferredEdge:preferredEdge]; 9638 9674 } 9639 9675 -
trunk/Source/WebKitLegacy/mac/WebView/WebViewInternal.h
r276181 r276220 159 159 160 160 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS) 161 @property (class, nonatomic, readonly) BOOL _canHandleContextMenuTranslation; 161 162 - (void)_handleContextMenuTranslation:(const String&)text selectionBounds:(const WebCore::IntRect&)boundsInView menuLocation:(const WebCore::IntPoint&)menuLocation; 162 163 #endif
Note:
See TracChangeset
for help on using the changeset viewer.