Title: [280690] trunk/Source/WebKit
Revision
280690
Author
[email protected]
Date
2021-08-05 09:03:34 -0700 (Thu, 05 Aug 2021)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (280689 => 280690)


--- trunk/Source/WebKit/ChangeLog	2021-08-05 15:27:03 UTC (rev 280689)
+++ trunk/Source/WebKit/ChangeLog	2021-08-05 16:03:34 UTC (rev 280690)
@@ -1,3 +1,24 @@
+2021-08-05  Wenson Hsieh  <[email protected]>
+
+        [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.
+
 2021-08-05  Michael Catanzaro  <[email protected]>
 
         GCC 11 builds should use -Wno-array-bounds, -Wno-nonnull

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (280689 => 280690)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-08-05 15:27:03 UTC (rev 280689)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-08-05 16:03:34 UTC (rev 280690)
@@ -52,6 +52,7 @@
 OBJC_CLASS NSAccessibilityRemoteUIElement;
 OBJC_CLASS NSImmediateActionGestureRecognizer;
 OBJC_CLASS NSMenu;
+OBJC_CLASS NSPopover;
 OBJC_CLASS NSTextInputContext;
 OBJC_CLASS NSView;
 OBJC_CLASS QLPreviewPanel;
@@ -907,6 +908,10 @@
     RefPtr<WorkQueue> m_imageAnalyzerQueue;
     RetainPtr<VKImageAnalyzer> m_imageAnalyzer;
 #endif
+
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+    WeakObjCPtr<NSPopover> m_lastContextMenuTranslationPopover;
+#endif
 };
     
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (280689 => 280690)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-08-05 15:27:03 UTC (rev 280689)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-08-05 16:03:34 UTC (rev 280690)
@@ -150,10 +150,6 @@
 #if HAVE(TRANSLATION_UI_SERVICES)
 #import <TranslationUIServices/LTUITranslationViewController.h>
 
-@interface LTUITranslationViewController (Staging_77660675)
-@property (nonatomic, copy) void(^replacementHandler)(NSAttributedString *);
-@end
-
 SOFT_LINK_PRIVATE_FRAMEWORK_OPTIONAL(TranslationUIServices)
 SOFT_LINK_CLASS_OPTIONAL(TranslationUIServices, LTUITranslationViewController)
 #endif
@@ -3720,6 +3716,10 @@
     [m_immediateActionController dismissContentRelativeChildWindows];
 
     m_pageClient->dismissCorrectionPanel(WebCore::ReasonForDismissingAlternativeTextIgnored);
+
+#if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
+    [std::exchange(m_lastContextMenuTranslationPopover, nil) close];
+#endif
 }
 
 void WebViewImpl::hideWordDefinitionWindow()
@@ -5779,7 +5779,7 @@
     auto view = m_view.get();
     auto translationViewController = adoptNS([allocLTUITranslationViewControllerInstance() init]);
     [translationViewController setText:adoptNS([[NSAttributedString alloc] initWithString:info.text]).get()];
-    if (info.mode == WebCore::TranslationContextMenuMode::Editable && [translationViewController respondsToSelector:@selector(setReplacementHandler:)]) {
+    if (info.mode == WebCore::TranslationContextMenuMode::Editable) {
         [translationViewController setIsSourceEditable:YES];
         [translationViewController setReplacementHandler:[this, weakThis = makeWeakPtr(*this)](NSAttributedString *string) {
             if (weakThis)
@@ -5805,6 +5805,7 @@
     else
         preferredEdge = aim > highlight ? NSRectEdgeMaxX : NSRectEdgeMinX;
 
+    m_lastContextMenuTranslationPopover = popover.get();
     [popover showRelativeToRect:info.selectionBoundsInRootView ofView:view.get() preferredEdge:preferredEdge];
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to