diff --git a/Source/WebKit/mac/ChangeLog b/Source/WebKit/mac/ChangeLog index 72f017895a03..9710d5d18af5 100644 --- a/Source/WebKit/mac/ChangeLog +++ b/Source/WebKit/mac/ChangeLog @@ -1,3 +1,28 @@ +2011-09-19 Timothy Hatcher + + Make WebViews in NSPopovers render as they would in active windows. + + The NSWindowDid{Become,Resign}KeyNotifications are not fired when NSPopovers + are shown or hidden since they share key with the parent window. So WebView + and WebHTMLView need to also observe the will order on/off screen notifications. + + https://webkit.org/b/68402 + rdar://problem/9754099 + + Reviewed by John Sullivan. + + * WebView/WebHTMLView.mm: + (-[WebHTMLView _removeWindowObservers]): Remove order on/off screen notification obversers. + (-[WebHTMLView addWindowObservers]): Add order on/off screen notification obversers. + (-[WebHTMLView windowWillOrderOnScreen:]): Check if the window is already a key window, + which can be the case for NSPopovers. + (-[WebHTMLView windowWillOrderOffScreen:]): Remove the mouse moved observer. + * WebView/WebView.mm: + (-[WebView addWindowObserversForWindow:]): Add order off screen notification obverser. + (-[WebView removeWindowObservers]): Remove order off screen notification obverser. + (-[WebView _windowWillOrderOnScreen:]): Call _updateActiveState. + (-[WebView _windowWillOrderOffScreen:]): Ditto. + 2011-09-19 Mark Rowe Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect diff --git a/Source/WebKit/mac/WebView/WebHTMLView.mm b/Source/WebKit/mac/WebView/WebHTMLView.mm index 5773924b12a4..090f000ab6a7 100644 --- a/Source/WebKit/mac/WebView/WebHTMLView.mm +++ b/Source/WebKit/mac/WebView/WebHTMLView.mm @@ -932,6 +932,8 @@ - (void)_removeWindowObservers NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter removeObserver:self name:NSWindowDidBecomeKeyNotification object:nil]; [notificationCenter removeObserver:self name:NSWindowDidResignKeyNotification object:nil]; + [notificationCenter removeObserver:self name:WKWindowWillOrderOnScreenNotification() object:window]; + [notificationCenter removeObserver:self name:WKWindowWillOrderOffScreenNotification() object:window]; [notificationCenter removeObserver:self name:NSWindowWillCloseNotification object:window]; _private->observingWindowNotifications = false; @@ -2859,6 +2861,8 @@ - (void)addWindowObservers NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; [notificationCenter addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:nil]; [notificationCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:nil]; + [notificationCenter addObserver:self selector:@selector(windowWillOrderOnScreen:) name:WKWindowWillOrderOnScreenNotification() object:window]; + [notificationCenter addObserver:self selector:@selector(windowWillOrderOffScreen:) name:WKWindowWillOrderOffScreenNotification() object:window]; [notificationCenter addObserver:self selector:@selector(windowWillClose:) name:NSWindowWillCloseNotification object:window]; _private->observingWindowNotifications = true; @@ -3378,6 +3382,30 @@ - (void)windowDidResignKey:(NSNotification *)notification } } +- (void)windowWillOrderOnScreen:(NSNotification *)notification +{ + if (!pthread_main_np()) { + [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO]; + return; + } + + // Check if the window is already a key window, which can be the case for NSPopovers. + if ([[self window] isKeyWindow]) + [self addMouseMovedObserver]; +} + +- (void)windowWillOrderOffScreen:(NSNotification *)notification +{ + if (!pthread_main_np()) { + [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO]; + return; + } + + // When the WebView is in a NSPopover the NSWindowDidResignKeyNotification isn't sent + // unless the parent window loses key. So we need to remove the mouse moved observer. + [self removeMouseMovedObserver]; +} + - (void)windowWillClose:(NSNotification *)notification { if (!pthread_main_np()) { diff --git a/Source/WebKit/mac/WebView/WebView.mm b/Source/WebKit/mac/WebView/WebView.mm index 58f7fc7e856e..b740335522da 100644 --- a/Source/WebKit/mac/WebView/WebView.mm +++ b/Source/WebKit/mac/WebView/WebView.mm @@ -3194,6 +3194,8 @@ - (void)addWindowObserversForWindow:(NSWindow *)window name:NSWindowDidResignKeyNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowWillOrderOnScreen:) name:WKWindowWillOrderOnScreenNotification() object:window]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowWillOrderOffScreen:) + name:WKWindowWillOrderOffScreenNotification() object:window]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidChangeResolution:) name:windowDidChangeResolutionNotification object:window]; } @@ -3209,6 +3211,8 @@ - (void)removeWindowObservers name:NSWindowDidResignKeyNotification object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:WKWindowWillOrderOnScreenNotification() object:window]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:WKWindowWillOrderOffScreenNotification() object:window]; [[NSNotificationCenter defaultCenter] removeObserver:self name:windowDidChangeResolutionNotification object:window]; } @@ -3279,10 +3283,23 @@ - (void)_windowDidResignKey:(NSNotification *)notification - (void)_windowWillOrderOnScreen:(NSNotification *)notification { + // Update the active state here so WebViews in NSPopovers get the active state. + // This is needed because the normal NSWindowDidBecomeKeyNotification is not fired + // for NSPopover windows since they share key with their parent window. + [self _updateActiveState]; + if (![self shouldUpdateWhileOffscreen]) [self setNeedsDisplay:YES]; } +- (void)_windowWillOrderOffScreen:(NSNotification *)notification +{ + // Update the active state here so WebViews in NSPopovers get the inactive state. + // This is needed because the normal NSWindowDidResignKeyNotification is not fired + // for NSPopover windows since they share key with their parent window. + [self _updateActiveState]; +} + - (void)_windowWillClose:(NSNotification *)notification { if ([self shouldCloseWithWindow] && ([self window] == [self hostWindow] || ([self window] && ![self hostWindow]) || (![self window] && [self hostWindow])))