Skip to content

Commit

Permalink
Make WebViews in NSPopovers render as they would in active windows.
Browse files Browse the repository at this point in the history
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.

Canonical link: https://commits.webkit.org/84381@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@95534 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
xeenon committed Sep 20, 2011
1 parent 80d0d06 commit 09bbc3d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/WebKit/mac/ChangeLog
@@ -1,3 +1,28 @@
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
Expand Down
28 changes: 28 additions & 0 deletions Source/WebKit/mac/WebView/WebHTMLView.mm
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
17 changes: 17 additions & 0 deletions Source/WebKit/mac/WebView/WebView.mm
Expand Up @@ -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];
}
Expand All @@ -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];
}
Expand Down Expand Up @@ -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])))
Expand Down

0 comments on commit 09bbc3d

Please sign in to comment.