Title: [95534] trunk/Source/WebKit/mac
Revision
95534
Author
timo...@apple.com
Date
2011-09-20 06:37:35 -0700 (Tue, 20 Sep 2011)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebKit/mac/ChangeLog (95533 => 95534)


--- trunk/Source/WebKit/mac/ChangeLog	2011-09-20 12:45:42 UTC (rev 95533)
+++ trunk/Source/WebKit/mac/ChangeLog	2011-09-20 13:37:35 UTC (rev 95534)
@@ -1,3 +1,28 @@
+2011-09-19  Timothy Hatcher  <timo...@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  <mr...@apple.com>
 
         <http://webkit.org/b/68421> Stop calling UpdateSystemActivity in places where we hold power assertions that achieve the same effect

Modified: trunk/Source/WebKit/mac/WebView/WebHTMLView.mm (95533 => 95534)


--- trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2011-09-20 12:45:42 UTC (rev 95533)
+++ trunk/Source/WebKit/mac/WebView/WebHTMLView.mm	2011-09-20 13:37:35 UTC (rev 95534)
@@ -932,6 +932,8 @@
     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 @@
     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)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()) {

Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (95533 => 95534)


--- trunk/Source/WebKit/mac/WebView/WebView.mm	2011-09-20 12:45:42 UTC (rev 95533)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm	2011-09-20 13:37:35 UTC (rev 95534)
@@ -3194,6 +3194,8 @@
             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];
     }
@@ -3210,6 +3212,8 @@
         [[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)_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])))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to