Title: [278414] trunk/Source/WebKit
Revision
278414
Author
[email protected]
Date
2021-06-03 12:40:00 -0700 (Thu, 03 Jun 2021)

Log Message

[macOS] Image extraction preview panel should automatically close when the web view is unparented
https://bugs.webkit.org/show_bug.cgi?id=226588
rdar://77062762

Reviewed by Tim Horton.

Refactor some logic for presenting the preview panel. See below for more details.

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::handleProcessSwapOrExit):
(WebKit::WebViewImpl::viewDidMoveToWindow):

When the web view is removed from the view hierarchy (i.e. when the view is moved to a `nil` window), call into
`closeSharedPreviewPanelIfNecessary` to dismiss the shared preview panel if we're currently controlling its
presentation for the purposes of image extraction.

(WebKit::WebViewImpl::beginPreviewPanelControl):
(WebKit::WebViewImpl::endPreviewPanelControl):

Add more plumbing into WebPageProxy to begin and end preview panel control; this allows us to avoid having to
expose a separate method to reset WebPageProxy's `m_imageExtractionPreviewController` and call it from
WebViewImpl.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::didCommitLoadForFrame):

Additionally call into `closeSharedPreviewPanelIfNecessary` when committing main frame navigation. We also
refactor a bit of logic here so that we fold several pieces of similar "reset" logic into a single if statement.

* UIProcess/WebPageProxy.h:
* UIProcess/mac/WKImageExtractionPreviewController.h:
* UIProcess/mac/WKImageExtractionPreviewController.mm:
(-[WKImageExtractionPreviewController beginControl:]):
(-[WKImageExtractionPreviewController endControl:]):
(-[WKImageExtractionPreviewController closePanelIfNecessary]):
(-[WKImageExtractionPreviewController isControlling:]):

Move logic for assigning, removing, and checking the QLPreviewPanel's `-delegate` and `-dataSource` into helper
methods on WKImageExtractionPreviewController. Doing this allows us to consolidate more of the QuickLookUI-
specific logic inside WKImageExtractionPreviewController and WebPageProxy, but also (and more importantly)
prevents us from having to `#import <pal/spi/mac/QuickLookMacSPI.h>` inside `WebPageProxyMac.mm`, which results
in nullability errors when calling into `-[NSApplication stopSpeaking:]`.

* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::beginPreviewPanelControl):
(WebKit::WebPageProxy::endPreviewPanelControl):
(WebKit::WebPageProxy::closeSharedPreviewPanelIfNecessary):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (278413 => 278414)


--- trunk/Source/WebKit/ChangeLog	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/ChangeLog	2021-06-03 19:40:00 UTC (rev 278414)
@@ -1,3 +1,53 @@
+2021-06-03  Wenson Hsieh  <[email protected]>
+
+        [macOS] Image extraction preview panel should automatically close when the web view is unparented
+        https://bugs.webkit.org/show_bug.cgi?id=226588
+        rdar://77062762
+
+        Reviewed by Tim Horton.
+
+        Refactor some logic for presenting the preview panel. See below for more details.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::handleProcessSwapOrExit):
+        (WebKit::WebViewImpl::viewDidMoveToWindow):
+
+        When the web view is removed from the view hierarchy (i.e. when the view is moved to a `nil` window), call into
+        `closeSharedPreviewPanelIfNecessary` to dismiss the shared preview panel if we're currently controlling its
+        presentation for the purposes of image extraction.
+
+        (WebKit::WebViewImpl::beginPreviewPanelControl):
+        (WebKit::WebViewImpl::endPreviewPanelControl):
+
+        Add more plumbing into WebPageProxy to begin and end preview panel control; this allows us to avoid having to
+        expose a separate method to reset WebPageProxy's `m_imageExtractionPreviewController` and call it from
+        WebViewImpl.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::didCommitLoadForFrame):
+
+        Additionally call into `closeSharedPreviewPanelIfNecessary` when committing main frame navigation. We also
+        refactor a bit of logic here so that we fold several pieces of similar "reset" logic into a single if statement.
+
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/mac/WKImageExtractionPreviewController.h:
+        * UIProcess/mac/WKImageExtractionPreviewController.mm:
+        (-[WKImageExtractionPreviewController beginControl:]):
+        (-[WKImageExtractionPreviewController endControl:]):
+        (-[WKImageExtractionPreviewController closePanelIfNecessary]):
+        (-[WKImageExtractionPreviewController isControlling:]):
+
+        Move logic for assigning, removing, and checking the QLPreviewPanel's `-delegate` and `-dataSource` into helper
+        methods on WKImageExtractionPreviewController. Doing this allows us to consolidate more of the QuickLookUI-
+        specific logic inside WKImageExtractionPreviewController and WebPageProxy, but also (and more importantly)
+        prevents us from having to `#import <pal/spi/mac/QuickLookMacSPI.h>` inside `WebPageProxyMac.mm`, which results
+        in nullability errors when calling into `-[NSApplication stopSpeaking:]`.
+
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::beginPreviewPanelControl):
+        (WebKit::WebPageProxy::endPreviewPanelControl):
+        (WebKit::WebPageProxy::closeSharedPreviewPanelIfNecessary):
+
 2021-06-03  Chris Fleizach  <[email protected]>
 
         AX: macOS WebContent can't read prefs from com.apple.Accessibility

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-06-03 19:40:00 UTC (rev 278414)
@@ -1517,6 +1517,7 @@
 void WebViewImpl::handleProcessSwapOrExit()
 {
     dismissContentRelativeChildWindowsWithAnimation(true);
+    m_page->closeSharedPreviewPanelIfNecessary();
 
     notifyInputContextAboutDiscardedComposition();
 
@@ -2397,6 +2398,7 @@
         m_flagsChangedEventMonitor = nil;
 
         dismissContentRelativeChildWindowsWithAnimation(false);
+        m_page->closeSharedPreviewPanelIfNecessary();
 
         if (m_immediateActionGestureRecognizer) {
             // Work around <rdar://problem/22646404> by explicitly cancelling the animation.
@@ -5724,35 +5726,12 @@
 
 void WebViewImpl::beginPreviewPanelControl(QLPreviewPanel *panel)
 {
-#if ENABLE(IMAGE_EXTRACTION)
-    auto controller = m_page->imageExtractionPreviewController();
-    if (!controller)
-        return;
-
-    panel.dataSource = controller;
-    panel.delegate = controller;
-#else
-    UNUSED_PARAM(panel);
-#endif
+    m_page->beginPreviewPanelControl(panel);
 }
 
 void WebViewImpl::endPreviewPanelControl(QLPreviewPanel *panel)
 {
-#if ENABLE(IMAGE_EXTRACTION)
-    auto controller = m_page->imageExtractionPreviewController();
-    if (!controller)
-        return;
-
-    if (panel.dataSource == controller)
-        panel.dataSource = nil;
-
-    if (panel.delegate == controller)
-        panel.delegate = nil;
-
-    m_page->resetImageExtractionPreview();
-#else
-    UNUSED_PARAM(panel);
-#endif
+    m_page->endPreviewPanelControl(panel);
 }
 
 #if ENABLE(DATA_DETECTION)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-06-03 19:40:00 UTC (rev 278414)
@@ -4882,15 +4882,17 @@
             m_navigationClient->didCommitNavigation(*this, navigation.get(), m_process->transformHandlesToObjects(userData.object()).get());
         m_navigationClient->didCommitLoadForFrame(*this, WTFMove(request), WTFMove(frameInfo));
     }
+    if (frame->isMainFrame()) {
 #if ENABLE(ATTACHMENT_ELEMENT)
-    if (frame->isMainFrame())
         invalidateAllAttachments();
 #endif
-
 #if ENABLE(REMOTE_INSPECTOR)
-    if (frame->isMainFrame())
         remoteInspectorInformationDidChange();
 #endif
+#if USE(APPKIT)
+        closeSharedPreviewPanelIfNecessary();
+#endif
+    }
 
 #if ENABLE(MEDIA_SESSION_COORDINATOR)
     WEBPAGEPROXY_DIDCOMMITLOADFORFRAME_WKCOORDINATOR_ADDITIONS

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-06-03 19:40:00 UTC (rev 278414)
@@ -229,6 +229,7 @@
 OBJC_CLASS NSMenu;
 OBJC_CLASS NSTextAlternatives;
 OBJC_CLASS NSView;
+OBJC_CLASS QLPreviewPanel;
 OBJC_CLASS WKQLThumbnailLoadOperation;
 OBJC_CLASS WKWebView;
 OBJC_CLASS _WKRemoteObjectRegistry;
@@ -1912,9 +1913,14 @@
 
 #if ENABLE(IMAGE_EXTRACTION) && ENABLE(CONTEXT_MENUS)
     void handleContextMenuRevealImage();
-    void resetImageExtractionPreview();
 #endif
 
+#if USE(APPKIT)
+    void beginPreviewPanelControl(QLPreviewPanel *);
+    void endPreviewPanelControl(QLPreviewPanel *);
+    void closeSharedPreviewPanelIfNecessary();
+#endif
+
 #if HAVE(TRANSLATION_UI_SERVICES) && ENABLE(CONTEXT_MENUS)
     bool canHandleContextMenuTranslation() const;
     void handleContextMenuTranslation(const WebCore::TranslationContextMenuInfo&);

Modified: trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.h (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.h	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.h	2021-06-03 19:40:00 UTC (rev 278414)
@@ -27,14 +27,20 @@
 
 #if PLATFORM(MAC) && ENABLE(IMAGE_EXTRACTION)
 
-#import <pal/spi/mac/QuickLookMacSPI.h>
+#import <Foundation/Foundation.h>
 
 namespace WebKit {
 class WebPageProxy;
 }
 
-@interface WKImageExtractionPreviewController : NSObject <QLPreviewPanelDelegate, QLPreviewPanelDataSource>
+@class QLPreviewPanel;
+
+@interface WKImageExtractionPreviewController : NSObject
 - (instancetype)initWithPage:(WebKit::WebPageProxy&)page imageData:(NSData *)data title:(NSString *)title imageURL:(NSURL *)imageURL;
+- (void)beginControl:(QLPreviewPanel *)panel;
+- (BOOL)isControlling:(QLPreviewPanel *)panel;
+- (void)endControl:(QLPreviewPanel *)panel;
+- (void)closePanelIfNecessary;
 @end
 
 #endif // PLATFORM(MAC) && ENABLE(IMAGE_EXTRACTION)

Modified: trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.mm (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.mm	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.mm	2021-06-03 19:40:00 UTC (rev 278414)
@@ -32,6 +32,9 @@
 #import <pal/mac/QuickLookUISoftLink.h>
 #import <wtf/RetainPtr.h>
 
+@interface WKImageExtractionPreviewController () <QLPreviewPanelDelegate, QLPreviewPanelDataSource>
+@end
+
 @implementation WKImageExtractionPreviewController {
     RetainPtr<QLItem> _item;
     RetainPtr<NSData> _imageData;
@@ -56,6 +59,35 @@
     return self;
 }
 
+- (void)beginControl:(QLPreviewPanel *)panel
+{
+    panel.dataSource = self;
+    panel.delegate = self;
+}
+
+- (void)endControl:(QLPreviewPanel *)panel
+{
+    if (panel.dataSource == self)
+        panel.dataSource = nil;
+
+    if (panel.delegate == self)
+        panel.delegate = nil;
+}
+
+- (void)closePanelIfNecessary
+{
+    if (!PAL::isQuickLookUIFrameworkAvailable() || ![PAL::getQLPreviewPanelClass() sharedPreviewPanelExists])
+        return;
+
+    if (auto panel = [PAL::getQLPreviewPanelClass() sharedPreviewPanel]; [self isControlling:panel])
+        [panel close];
+}
+
+- (BOOL)isControlling:(QLPreviewPanel *)panel
+{
+    return panel.dataSource == self && panel.delegate == self;
+}
+
 #pragma mark - QLPreviewItemDataProvider
 
 - (NSData *)provideDataForItem:(QLItem *)item

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (278413 => 278414)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-06-03 19:32:22 UTC (rev 278413)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2021-06-03 19:40:00 UTC (rev 278414)
@@ -45,6 +45,7 @@
 #import "StringUtilities.h"
 #import "TextChecker.h"
 #import "WKBrowsingContextControllerInternal.h"
+#import "WKImageExtractionPreviewController.h"
 #import "WKSharingServicePickerDelegate.h"
 #import "WebContextMenuProxyMac.h"
 #import "WebPageMessages.h"
@@ -719,6 +720,28 @@
 #endif
 }
 
+void WebPageProxy::beginPreviewPanelControl(QLPreviewPanel *panel)
+{
+#if ENABLE(IMAGE_EXTRACTION)
+    [m_imageExtractionPreviewController beginControl:panel];
+#endif
+}
+
+void WebPageProxy::endPreviewPanelControl(QLPreviewPanel *panel)
+{
+#if ENABLE(IMAGE_EXTRACTION)
+    if (auto controller = std::exchange(m_imageExtractionPreviewController, nil))
+        [controller endControl:panel];
+#endif
+}
+
+void WebPageProxy::closeSharedPreviewPanelIfNecessary()
+{
+#if ENABLE(IMAGE_EXTRACTION)
+    [m_imageExtractionPreviewController closePanelIfNecessary];
+#endif
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to