Changeset 280690 in webkit


Ignore:
Timestamp:
Aug 5, 2021 9:03:34 AM (12 months ago)
Author:
Wenson Hsieh
Message:

[macOS Monterey] Translate popover becomes detached from webpage after scrolling
https://bugs.webkit.org/show_bug.cgi?id=228807
rdar://81540115

Reviewed by Sam Weinig.

Close the context menu translation popover in WebViewImpl::dismissContentRelativeChildWindowsFromViewOnly
(along with all other content-relative UI) to prevent the popover from being detached from its translated text
upon scrolling or zooming.

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

(WebKit::WebViewImpl::dismissContentRelativeChildWindowsFromViewOnly):
(WebKit::WebViewImpl::handleContextMenuTranslation):

Save a weak pointer to the current translation popover when we're about to present it, and use it to force the
popover to -close when dismissing content-relative child windows. Also take this opportunity to remove some
staging declarations on LTUITranslationViewController that have long since landed in the macOS 12 SDK.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r280689 r280690  
     12021-08-05  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS Monterey] Translate popover becomes detached from webpage after scrolling
     4        https://bugs.webkit.org/show_bug.cgi?id=228807
     5        rdar://81540115
     6
     7        Reviewed by Sam Weinig.
     8
     9        Close the context menu translation popover in `WebViewImpl::dismissContentRelativeChildWindowsFromViewOnly`
     10        (along with all other content-relative UI) to prevent the popover from being detached from its translated text
     11        upon scrolling or zooming.
     12
     13        * UIProcess/Cocoa/WebViewImpl.h:
     14        * UIProcess/Cocoa/WebViewImpl.mm:
     15        (WebKit::WebViewImpl::dismissContentRelativeChildWindowsFromViewOnly):
     16        (WebKit::WebViewImpl::handleContextMenuTranslation):
     17
     18        Save a weak pointer to the current translation popover when we're about to present it, and use it to force the
     19        popover to `-close` when dismissing content-relative child windows. Also take this opportunity to remove some
     20        staging declarations on LTUITranslationViewController that have long since landed in the macOS 12 SDK.
     21
    1222021-08-05  Michael Catanzaro  <mcatanzaro@gnome.org>
    223
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r279988 r280690  
    5353OBJC_CLASS NSImmediateActionGestureRecognizer;
    5454OBJC_CLASS NSMenu;
     55OBJC_CLASS NSPopover;
    5556OBJC_CLASS NSTextInputContext;
    5657OBJC_CLASS NSView;
     
    908909    RetainPtr<VKImageAnalyzer> m_imageAnalyzer;
    909910#endif
     911
     912#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     913    WeakObjCPtr<NSPopover> m_lastContextMenuTranslationPopover;
     914#endif
    910915};
    911916   
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r280336 r280690  
    151151#import <TranslationUIServices/LTUITranslationViewController.h>
    152152
    153 @interface LTUITranslationViewController (Staging_77660675)
    154 @property (nonatomic, copy) void(^replacementHandler)(NSAttributedString *);
    155 @end
    156 
    157153SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(TranslationUIServices)
    158154SOFT_LINK_CLASS_OPTIONAL(TranslationUIServices, LTUITranslationViewController)
     
    37213717
    37223718    m_pageClient->dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeTextIgnored);
     3719
     3720#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     3721    [std::exchange(m_lastContextMenuTranslationPopover, nil) close];
     3722#endif
    37233723}
    37243724
     
    57805780    auto translationViewController = adoptNS([allocLTUITranslationViewControllerInstance() init]);
    57815781    [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:info.text]).get()];
    5782     if (info.mode == WebCore::TranslationContextMenuMode::Editable && [translationViewController respondsToSelector:@selector(setReplacementHandler:)]) {
     5782    if (info.mode == WebCore::TranslationContextMenuMode::Editable) {
    57835783        [translationViewController setIsSourceEditable:YES];
    57845784        [translationViewController setReplacementHandler:[this, weakThis = makeWeakPtr(*this)](NSAttributedString *string) {
     
    58065806        preferredEdge = aim > highlight ? NSRectEdgeMaxX : NSRectEdgeMinX;
    58075807
     5808    m_lastContextMenuTranslationPopover = popover.get();
    58085809    [popover showRelativeToRect:info.selectionBoundsInRootView ofView:view.get() preferredEdge:preferredEdge];
    58095810}
Note: See TracChangeset for help on using the changeset viewer.