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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@95534
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2011-09-19 Timothy Hatcher <timothy@apple.com>
+
+ 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 <mrowe@apple.com>
<http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect
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;
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;
}
}
+- (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()) {
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];
}
[[NSNotificationCenter defaultCenter] removeObserver:self
name:WKWindowWillOrderOnScreenNotification() object:window];
[[NSNotificationCenter defaultCenter] removeObserver:self
+ name:WKWindowWillOrderOffScreenNotification() object:window];
+ [[NSNotificationCenter defaultCenter] removeObserver:self
name:windowDidChangeResolutionNotification object:window];
}
}
- (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])))