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

Changeset 181866 in webkit


Ignore:
Timestamp:
Mar 23, 2015, 1:42:03 PM (11 years ago)
Author:
ap@apple.com
Message:

REGRESSION (Yosemite): WKView visibility notifications are messed up
https://bugs.webkit.org/show_bug.cgi?id=142945

Reviewed by Tim Horton.

As these notifications cannot be used by NSView subclasses, create a separate
object for observing them.

Source/WebKit/mac:

  • WebView/WebView.mm:

(-[WebView _commonInitializationWithFrameName:groupName:]):
(-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
(-[WebView addWindowObserversForWindow:]):
(-[WebView removeWindowObservers]):
(-[WebView viewWillMoveToWindow:]): Make sure that observers are removed even
if -[WebView close] is called manually.

  • WebView/WebViewData.h:
  • WebView/WebViewData.mm:

(-[WebWindowVisibilityObserver initWithView:]):
(-[WebWindowVisibilityObserver startObserving:]):
(-[WebWindowVisibilityObserver stopObserving:]):
(-[WebWindowVisibilityObserver _windowVisibilityChanged:]):

Source/WebKit2:

  • UIProcess/API/mac/WKView.mm:

(-[WKWindowVisibilityObserver initWithView:]):
(-[WKWindowVisibilityObserver startObserving:]):
(-[WKWindowVisibilityObserver stopObserving:]):
(-[WKWindowVisibilityObserver _windowDidOrderOnScreen:]):
(-[WKWindowVisibilityObserver _windowDidOrderOffScreen:]):
(-[WKView addWindowObserversForWindow:]):
(-[WKView removeWindowObservers]): Also, don't try to remove NSWindowWillOrderOffScreenNotification,
which we never start to observe.
(-[WKView initWithFrame:processPool:configuration:webView:]):

  • UIProcess/API/mac/WKViewInternal.h:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/mac/ChangeLog

    r181858 r181866  
     12015-03-23  Alexey Proskuryakov  <ap@apple.com>
     2
     3        REGRESSION (Yosemite): WKView visibility notifications are messed up
     4        https://bugs.webkit.org/show_bug.cgi?id=142945
     5
     6        Reviewed by Tim Horton.
     7
     8        As these notifications cannot be used by NSView subclasses, create a separate
     9        object for observing them.
     10
     11        * WebView/WebView.mm:
     12        (-[WebView _commonInitializationWithFrameName:groupName:]):
     13        (-[WebView initSimpleHTMLDocumentWithStyle:frame:preferences:groupName:]):
     14        (-[WebView addWindowObserversForWindow:]):
     15        (-[WebView removeWindowObservers]):
     16        (-[WebView viewWillMoveToWindow:]): Make sure that observers are removed even
     17        if -[WebView close] is called manually.
     18        * WebView/WebViewData.h:
     19        * WebView/WebViewData.mm:
     20        (-[WebWindowVisibilityObserver initWithView:]):
     21        (-[WebWindowVisibilityObserver startObserving:]):
     22        (-[WebWindowVisibilityObserver stopObserving:]):
     23        (-[WebWindowVisibilityObserver _windowVisibilityChanged:]):
     24
    1252015-03-23  Tim Horton  <timothy_horton@apple.com>
    226
  • trunk/Source/WebKit/mac/WebView/WebView.mm

    r181846 r181866  
    880880    _private->includesFlattenedCompositingLayersWhenDrawingToBitmap = YES;
    881881
     882#if PLATFORM(MAC)
     883    _private->windowVisibilityObserver = adoptNS([[WebWindowVisibilityObserver alloc] initWithView:self]);
     884#endif
     885
    882886    NSRect f = [self frame];
    883887    WebFrameView *frameView = [[WebFrameView alloc] initWithFrame: NSMakeRect(0,0,f.size.width,f.size.height)];
     
    11741178    _private->drawsBackground = YES;
    11751179    _private->backgroundColor = CGColorRetain(cachedCGColor(Color::white, ColorSpaceDeviceRGB));
    1176    
     1180
    11771181    WebFrameView *frameView = nil;
    11781182    frameView = [[WebFrameView alloc] initWithFrame: CGRectMake(0,0,frame.size.width,frame.size.height)];
     
    51875191        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
    51885192            name:NSWindowDidDeminiaturizeNotification object:window];
    5189         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
    5190             name:@"NSWindowDidOrderOffScreenNotification" object:window];
    5191         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
    5192             name:@"_NSWindowDidBecomeVisible" object:window];
     5193        [_private->windowVisibilityObserver startObserving:window];
    51935194    }
    51945195}
     
    52145215        [[NSNotificationCenter defaultCenter] removeObserver:self
    52155216            name:NSWindowDidDeminiaturizeNotification object:window];
    5216         [[NSNotificationCenter defaultCenter] removeObserver:self
    5217             name:@"NSWindowDidOrderOffScreenNotification" object:window];
    5218         [[NSNotificationCenter defaultCenter] removeObserver:self
    5219             name:@"_NSWindowDidBecomeVisible" object:window];
     5217        [_private->windowVisibilityObserver stopObserving:window];
    52205218    }
    52215219}
     
    52265224    // This happens when decoding a WebView in a nib.
    52275225    // FIXME: What sets up the observer of NSWindowWillCloseNotification in this case?
    5228     if (!_private || _private->closed)
    5229         return;
    5230    
     5226    if (!_private)
     5227        return;
     5228
    52315229    if ([self window] && [self window] != [self hostWindow])
    52325230        [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:[self window]];
     
    52405238        [window setAcceptsMouseMovedEvents:YES];
    52415239        WKSetNSWindowShouldPostEventNotifications(window, YES);
    5242     } else {
     5240    } else if (!_private->closed) {
    52435241        _private->page->setCanStartMedia(false);
    52445242        _private->page->setIsInWindow(false);
  • trunk/Source/WebKit/mac/WebView/WebViewData.h

    r181838 r181866  
    8585#endif
    8686
     87#if PLATFORM(MAC)
     88@class WebWindowVisibilityObserver;
     89#endif
     90
    8791extern BOOL applicationIsTerminating;
    8892extern int pluginDatabaseClientCount;
     
    125129    WebViewLayerFlushScheduler m_layerFlushScheduler;
    126130};
     131
     132@interface WebWindowVisibilityObserver : NSObject {
     133    WebView *_view;
     134}
     135
     136- (instancetype)initWithView:(WebView *)view;
     137- (void)startObserving:(NSWindow *)window;
     138- (void)stopObserving:(NSWindow *)window;
     139@end
    127140
    128141// FIXME: This should be renamed to WebViewData.
     
    160173    std::unique_ptr<WebCore::TextIndicatorWindow> textIndicatorWindow;
    161174    BOOL hasInitializedLookupObserver;
     175    RetainPtr<WebWindowVisibilityObserver> windowVisibilityObserver;
    162176#endif // PLATFORM(MAC)
    163177
  • trunk/Source/WebKit/mac/WebView/WebViewData.mm

    r181838 r181866  
    7878}
    7979
     80#if PLATFORM(MAC)
     81
     82@implementation WebWindowVisibilityObserver
     83
     84- (instancetype)initWithView:(WebView *)view
     85{
     86    self = [super init];
     87    if (!self)
     88        return nil;
     89
     90    _view = view;
     91    return self;
     92}
     93
     94- (void)startObserving:(NSWindow *)window
     95{
     96    // An NSView derived object such as WebView cannot observe these notifications, because NSView itself observes them.
     97    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
     98                                                 name:@"NSWindowDidOrderOffScreenNotification" object:window];
     99    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowVisibilityChanged:)
     100                                                 name:@"_NSWindowDidBecomeVisible" object:window];
     101}
     102
     103- (void)stopObserving:(NSWindow *)window
     104{
     105    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowDidOrderOffScreenNotification" object:window];
     106    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"_NSWindowDidBecomeVisible" object:window];
     107}
     108
     109- (void)_windowVisibilityChanged:(NSNotification *)notification
     110{
     111    [_view _windowVisibilityChanged:notification];
     112}
     113
     114@end
     115
     116#endif // PLATFORM(MAC)
     117
    80118@implementation WebViewPrivate
    81119
  • trunk/Source/WebKit2/ChangeLog

    r181864 r181866  
     12015-03-23  Alexey Proskuryakov  <ap@apple.com>
     2
     3        REGRESSION (Yosemite): WKView visibility notifications are messed up
     4        https://bugs.webkit.org/show_bug.cgi?id=142945
     5
     6        Reviewed by Tim Horton.
     7
     8        As these notifications cannot be used by NSView subclasses, create a separate
     9        object for observing them.
     10
     11        * UIProcess/API/mac/WKView.mm:
     12        (-[WKWindowVisibilityObserver initWithView:]):
     13        (-[WKWindowVisibilityObserver startObserving:]):
     14        (-[WKWindowVisibilityObserver stopObserving:]):
     15        (-[WKWindowVisibilityObserver _windowDidOrderOnScreen:]):
     16        (-[WKWindowVisibilityObserver _windowDidOrderOffScreen:]):
     17        (-[WKView addWindowObserversForWindow:]):
     18        (-[WKView removeWindowObservers]): Also, don't try to remove NSWindowWillOrderOffScreenNotification,
     19        which we never start to observe.
     20        (-[WKView initWithFrame:processPool:configuration:webView:]):
     21        * UIProcess/API/mac/WKViewInternal.h:
     22
    1232015-03-23  Anders Carlsson  <andersca@apple.com>
    224
  • trunk/Source/WebKit2/UIProcess/API/mac/WKView.mm

    r181836 r181866  
    171171#endif
    172172
     173@class WKWindowVisibilityObserver;
     174
    173175@interface WKViewData : NSObject {
    174176@public
     
    253255    BOOL _windowOcclusionDetectionEnabled;
    254256
     257    RetainPtr<WKWindowVisibilityObserver> _windowVisibilityObserver;
     258
    255259    std::unique_ptr<ViewGestureController> _gestureController;
    256260    BOOL _allowsMagnification;
     
    282286
    283287@implementation WKViewData
     288@end
     289
     290@interface WKWindowVisibilityObserver : NSObject {
     291    WKView *_view;
     292}
     293
     294- (instancetype)initWithView:(WKView *)view;
     295- (void)startObserving:(NSWindow *)window;
     296- (void)stopObserving:(NSWindow *)window;
     297@end
     298
     299@implementation WKWindowVisibilityObserver
     300
     301- (instancetype)initWithView:(WKView *)view
     302{
     303    self = [super init];
     304    if (!self)
     305        return nil;
     306
     307    _view = view;
     308    return self;
     309}
     310
     311- (void)startObserving:(NSWindow *)window
     312{
     313    // An NSView derived object such as WKView cannot observe these notifications, because NSView itself observes them.
     314    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidOrderOffScreen:)
     315                                                 name:@"NSWindowDidOrderOffScreenNotification" object:window];
     316    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidOrderOnScreen:)
     317                                                 name:@"_NSWindowDidBecomeVisible" object:window];
     318}
     319
     320- (void)stopObserving:(NSWindow *)window
     321{
     322    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowDidOrderOffScreenNotification" object:window];
     323    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"_NSWindowDidBecomeVisible" object:window];
     324}
     325
     326- (void)_windowDidOrderOnScreen:(NSNotification *)notification
     327{
     328    [_view _windowDidOrderOnScreen:notification];
     329}
     330
     331- (void)_windowDidOrderOffScreen:(NSNotification *)notification
     332{
     333    [_view _windowDidOrderOffScreen:notification];
     334}
     335
    284336@end
    285337
     
    25472599        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidResize:)
    25482600                                                     name:NSWindowDidResizeNotification object:window];
    2549         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidOrderOffScreen:)
    2550                                                      name:@"NSWindowDidOrderOffScreenNotification" object:window];
    2551         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidOrderOnScreen:)
    2552                                                      name:@"_NSWindowDidBecomeVisible" object:window];
    25532601        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidChangeBackingProperties:)
    25542602                                                     name:NSWindowDidChangeBackingPropertiesNotification object:window];
     
    25672615        [window addObserver:self forKeyPath:@"titlebarAppearsTransparent" options:NSKeyValueObservingOptionInitial context:keyValueObservingContext];
    25682616#endif
     2617        [_data->_windowVisibilityObserver startObserving:window];
    25692618    }
    25702619}
     
    25822631    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidMoveNotification object:window];
    25832632    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidResizeNotification object:window];
    2584     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowWillOrderOffScreenNotification" object:window];
    2585     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NSWindowDidOrderOffScreenNotification" object:window];
    2586     [[NSNotificationCenter defaultCenter] removeObserver:self name:@"_NSWindowDidBecomeVisible" object:window];
    25872633    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidChangeBackingPropertiesNotification object:window];
    25882634    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowDidChangeScreenNotification object:window];
     
    25942640    [window removeObserver:self forKeyPath:@"titlebarAppearsTransparent" context:keyValueObservingContext];
    25952641#endif
     2642    [_data->_windowVisibilityObserver stopObserving:window];
    25962643}
    25972644
     
    36973744    _data->_windowOcclusionDetectionEnabled = YES;
    36983745
     3746    _data->_windowVisibilityObserver = adoptNS([[WKWindowVisibilityObserver alloc] initWithView:self]);
     3747
    36993748    _data->_intrinsicContentSize = NSMakeSize(NSViewNoInstrinsicMetric, NSViewNoInstrinsicMetric);
    37003749
    37013750    _data->_needsViewFrameInWindowCoordinates = _data->_page->preferences().pluginsEnabled();
    3702    
     3751
    37033752    [self _registerDraggedTypes];
    37043753
  • trunk/Source/WebKit2/UIProcess/API/mac/WKViewInternal.h

    r181760 r181866  
    130130#endif
    131131
     132- (void)_windowDidOrderOnScreen:(NSNotification *)notification;
     133- (void)_windowDidOrderOffScreen:(NSNotification *)notification;
     134
    132135// FullScreen
    133136
Note: See TracChangeset for help on using the changeset viewer.