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

Changeset 278414 in webkit


Ignore:
Timestamp:
Jun 3, 2021, 12:40:00 PM (5 years ago)
Author:
Wenson Hsieh
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):

Location:
trunk/Source/WebKit
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r278412 r278414  
     12021-06-03  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Image extraction preview panel should automatically close when the web view is unparented
     4        https://bugs.webkit.org/show_bug.cgi?id=226588
     5        rdar://77062762
     6
     7        Reviewed by Tim Horton.
     8
     9        Refactor some logic for presenting the preview panel. See below for more details.
     10
     11        * UIProcess/Cocoa/WebViewImpl.mm:
     12        (WebKit::WebViewImpl::handleProcessSwapOrExit):
     13        (WebKit::WebViewImpl::viewDidMoveToWindow):
     14
     15        When the web view is removed from the view hierarchy (i.e. when the view is moved to a `nil` window), call into
     16        `closeSharedPreviewPanelIfNecessary` to dismiss the shared preview panel if we're currently controlling its
     17        presentation for the purposes of image extraction.
     18
     19        (WebKit::WebViewImpl::beginPreviewPanelControl):
     20        (WebKit::WebViewImpl::endPreviewPanelControl):
     21
     22        Add more plumbing into WebPageProxy to begin and end preview panel control; this allows us to avoid having to
     23        expose a separate method to reset WebPageProxy's `m_imageExtractionPreviewController` and call it from
     24        WebViewImpl.
     25
     26        * UIProcess/WebPageProxy.cpp:
     27        (WebKit::WebPageProxy::didCommitLoadForFrame):
     28
     29        Additionally call into `closeSharedPreviewPanelIfNecessary` when committing main frame navigation. We also
     30        refactor a bit of logic here so that we fold several pieces of similar "reset" logic into a single if statement.
     31
     32        * UIProcess/WebPageProxy.h:
     33        * UIProcess/mac/WKImageExtractionPreviewController.h:
     34        * UIProcess/mac/WKImageExtractionPreviewController.mm:
     35        (-[WKImageExtractionPreviewController beginControl:]):
     36        (-[WKImageExtractionPreviewController endControl:]):
     37        (-[WKImageExtractionPreviewController closePanelIfNecessary]):
     38        (-[WKImageExtractionPreviewController isControlling:]):
     39
     40        Move logic for assigning, removing, and checking the QLPreviewPanel's `-delegate` and `-dataSource` into helper
     41        methods on WKImageExtractionPreviewController. Doing this allows us to consolidate more of the QuickLookUI-
     42        specific logic inside WKImageExtractionPreviewController and WebPageProxy, but also (and more importantly)
     43        prevents us from having to `#import <pal/spi/mac/QuickLookMacSPI.h>` inside `WebPageProxyMac.mm`, which results
     44        in nullability errors when calling into `-[NSApplication stopSpeaking:]`.
     45
     46        * UIProcess/mac/WebPageProxyMac.mm:
     47        (WebKit::WebPageProxy::beginPreviewPanelControl):
     48        (WebKit::WebPageProxy::endPreviewPanelControl):
     49        (WebKit::WebPageProxy::closeSharedPreviewPanelIfNecessary):
     50
    1512021-06-03  Chris Fleizach  <cfleizach@apple.com>
    252
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r278253 r278414  
    15181518{
    15191519    dismissContentRelativeChildWindowsWithAnimation(true);
     1520    m_page->closeSharedPreviewPanelIfNecessary();
    15201521
    15211522    notifyInputContextAboutDiscardedComposition();
    … …  
    23982399
    23992400        dismissContentRelativeChildWindowsWithAnimation(false);
     2401        m_page->closeSharedPreviewPanelIfNecessary();
    24002402
    24012403        if (m_immediateActionGestureRecognizer) {
    … …  
    57255727void WebViewImpl::beginPreviewPanelControl(QLPreviewPanel *panel)
    57265728{
    5727 #if ENABLE(IMAGE_EXTRACTION)
    5728     auto controller = m_page->imageExtractionPreviewController();
    5729     if (!controller)
    5730         return;
    5731 
    5732     panel.dataSource = controller;
    5733     panel.delegate = controller;
    5734 #else
    5735     UNUSED_PARAM(panel);
    5736 #endif
     5729    m_page->beginPreviewPanelControl(panel);
    57375730}
    57385731
    57395732void WebViewImpl::endPreviewPanelControl(QLPreviewPanel *panel)
    57405733{
    5741 #if ENABLE(IMAGE_EXTRACTION)
    5742     auto controller = m_page->imageExtractionPreviewController();
    5743     if (!controller)
    5744         return;
    5745 
    5746     if (panel.dataSource == controller)
    5747         panel.dataSource = nil;
    5748 
    5749     if (panel.delegate == controller)
    5750         panel.delegate = nil;
    5751 
    5752     m_page->resetImageExtractionPreview();
    5753 #else
    5754     UNUSED_PARAM(panel);
    5755 #endif
     5734    m_page->endPreviewPanelControl(panel);
    57565735}
    57575736
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r278394 r278414  
    48834883        m_navigationClient->didCommitLoadForFrame(*this, WTFMove(request), WTFMove(frameInfo));
    48844884    }
     4885    if (frame->isMainFrame()) {
    48854886#if ENABLE(ATTACHMENT_ELEMENT)
    4886     if (frame->isMainFrame())
    48874887        invalidateAllAttachments();
    48884888#endif
    4889 
    48904889#if ENABLE(REMOTE_INSPECTOR)
    4891     if (frame->isMainFrame())
    48924890        remoteInspectorInformationDidChange();
    48934891#endif
     4892#if USE(APPKIT)
     4893        closeSharedPreviewPanelIfNecessary();
     4894#endif
     4895    }
    48944896
    48954897#if ENABLE(MEDIA_SESSION_COORDINATOR)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r278394 r278414  
    230230OBJC_CLASS NSTextAlternatives;
    231231OBJC_CLASS NSView;
     232OBJC_CLASS QLPreviewPanel;
    232233OBJC_CLASS WKQLThumbnailLoadOperation;
    233234OBJC_CLASS WKWebView;
    … …  
    19131914#if ENABLE(IMAGE_EXTRACTION) && ENABLE(CONTEXT_MENUS)
    19141915    void handleContextMenuRevealImage();
    1915     void resetImageExtractionPreview();
     1916#endif
     1917
     1918#if USE(APPKIT)
     1919    void beginPreviewPanelControl(QLPreviewPanel *);
     1920    void endPreviewPanelControl(QLPreviewPanel *);
     1921    void closeSharedPreviewPanelIfNecessary();
    19161922#endif
    19171923
  • trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.h

    r277903 r278414  
    2828#if PLATFORM(MAC) && ENABLE(IMAGE_EXTRACTION)
    2929
    30 #import <pal/spi/mac/QuickLookMacSPI.h>
     30#import <Foundation/Foundation.h>
    3131
    3232namespace WebKit {
    … …  
    3434}
    3535
    36 @interface WKImageExtractionPreviewController : NSObject <QLPreviewPanelDelegate, QLPreviewPanelDataSource>
     36@class QLPreviewPanel;
     37
     38@interface WKImageExtractionPreviewController : NSObject
    3739- (instancetype)initWithPage:(WebKit::WebPageProxy&)page imageData:(NSData *)data title:(NSString *)title imageURL:(NSURL *)imageURL;
     40- (void)beginControl:(QLPreviewPanel *)panel;
     41- (BOOL)isControlling:(QLPreviewPanel *)panel;
     42- (void)endControl:(QLPreviewPanel *)panel;
     43- (void)closePanelIfNecessary;
    3844@end
    3945
  • trunk/Source/WebKit/UIProcess/mac/WKImageExtractionPreviewController.mm

    r277903 r278414  
    3333#import <wtf/RetainPtr.h>
    3434
     35@interface WKImageExtractionPreviewController () <QLPreviewPanelDelegate, QLPreviewPanelDataSource>
     36@end
     37
    3538@implementation WKImageExtractionPreviewController {
    3639    RetainPtr<QLItem> _item;
    … …  
    5558
    5659    return self;
     60}
     61
     62- (void)beginControl:(QLPreviewPanel *)panel
     63{
     64    panel.dataSource = self;
     65    panel.delegate = self;
     66}
     67
     68- (void)endControl:(QLPreviewPanel *)panel
     69{
     70    if (panel.dataSource == self)
     71        panel.dataSource = nil;
     72
     73    if (panel.delegate == self)
     74        panel.delegate = nil;
     75}
     76
     77- (void)closePanelIfNecessary
     78{
     79    if (!PAL::isQuickLookUIFrameworkAvailable() || ![PAL::getQLPreviewPanelClass() sharedPreviewPanelExists])
     80        return;
     81
     82    if (auto panel = [PAL::getQLPreviewPanelClass() sharedPreviewPanel]; [self isControlling:panel])
     83        [panel close];
     84}
     85
     86- (BOOL)isControlling:(QLPreviewPanel *)panel
     87{
     88    return panel.dataSource == self && panel.delegate == self;
    5789}
    5890
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r278253 r278414  
    4646#import "TextChecker.h"
    4747#import "WKBrowsingContextControllerInternal.h"
     48#import "WKImageExtractionPreviewController.h"
    4849#import "WKSharingServicePickerDelegate.h"
    4950#import "WebContextMenuProxyMac.h"
    … …  
    720721}
    721722
     723void WebPageProxy::beginPreviewPanelControl(QLPreviewPanel *panel)
     724{
     725#if ENABLE(IMAGE_EXTRACTION)
     726    [m_imageExtractionPreviewController beginControl:panel];
     727#endif
     728}
     729
     730void WebPageProxy::endPreviewPanelControl(QLPreviewPanel *panel)
     731{
     732#if ENABLE(IMAGE_EXTRACTION)
     733    if (auto controller = std::exchange(m_imageExtractionPreviewController, nil))
     734        [controller endControl:panel];
     735#endif
     736}
     737
     738void WebPageProxy::closeSharedPreviewPanelIfNecessary()
     739{
     740#if ENABLE(IMAGE_EXTRACTION)
     741    [m_imageExtractionPreviewController closePanelIfNecessary];
     742#endif
     743}
     744
    722745} // namespace WebKit
    723746
Note: See TracChangeset for help on using the changeset viewer.