<rdar://problem/10328474> Text highlight changes to gray selection color when menu...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2011 18:48:43 +0000 (18:48 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Dec 2011 18:48:43 +0000 (18:48 +0000)
Reviewed by John Sullivan.

* WebView/WebView.mm:
(-[WebView _updateActiveState]): Changed to use -[NSWindow _hasKeyAppearance] instead
of -isKeyWindow. The former also returns YES when a menu extra is open.
(-[WebView addWindowObserversForWindow:]): Removed code to observe
NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification.
(-[WebView removeWindowObservers]): Removed code to stop observing the above.
(-[WebView _windowChangedKeyState]): Overridden this to call _updateActiveState.
This is called when the result of -_hasKeyAppearance changes.
(-[WebView _windowWillOrderOnScreen:]): Removed call to _updateActiveState,
previously needed for popovers, because _windowChangedKeyState is invoked
at the right time for them.
(-[WebView _windowWillOrderOffScreen:]): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@102605 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm

index ab956e7ad421227d25ff6bf99789337da0d54e2d..f3bcaa5efde756b6bcd2915b2da319a1124b8e6c 100644 (file)
@@ -1,3 +1,22 @@
+2011-12-12  Dan Bernstein  <mitz@apple.com>
+
+        <rdar://problem/10328474> Text highlight changes to gray selection color when menu extra is shown
+
+        Reviewed by John Sullivan.
+
+        * WebView/WebView.mm:
+        (-[WebView _updateActiveState]): Changed to use -[NSWindow _hasKeyAppearance] instead
+        of -isKeyWindow. The former also returns YES when a menu extra is open.
+        (-[WebView addWindowObserversForWindow:]): Removed code to observe
+        NSWindowDidBecomeKeyNotification and NSWindowDidResignKeyNotification.
+        (-[WebView removeWindowObservers]): Removed code to stop observing the above.
+        (-[WebView _windowChangedKeyState]): Overridden this to call _updateActiveState.
+        This is called when the result of -_hasKeyAppearance changes.
+        (-[WebView _windowWillOrderOnScreen:]): Removed call to _updateActiveState,
+        previously needed for popovers, because _windowChangedKeyState is invoked
+        at the right time for them.
+        (-[WebView _windowWillOrderOffScreen:]): Ditto.
+
 2011-12-07  Mark Rowe  <mrowe@apple.com>
 
         Fix the 32-bit build.
index 0c5ce6fb3eef5528ea3fd76c9b3be94ee343013b..e046ca05e9c09d758f0a9baffa773da6e44b6b0d 100644 (file)
 - (BOOL)_shouldAutoscrollForDraggingInfo:(id)dragInfo;
 @end
 
-@interface NSWindow (WebNSWindowDetails) 
+@interface NSWindow (WebNSWindowDetails)
 - (id)_oldFirstResponderBeforeBecoming;
 - (void)_enableScreenUpdatesIfNeeded;
 - (BOOL)_wrapsCarbonWindow;
+- (BOOL)_hasKeyAppearance;
 @end
 
 using namespace WebCore;
@@ -2508,7 +2509,7 @@ static inline IMP getMethod(id o, SEL s)
 - (void)_updateActiveState
 {
     if (_private && _private->page)
-        _private->page->focusController()->setActive([[self window] isKeyWindow]);
+        _private->page->focusController()->setActive([[self window] _hasKeyAppearance]);
 }
 
 static PassOwnPtr<Vector<String> > toStringVector(NSArray* patterns)
@@ -3348,10 +3349,6 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
 - (void)addWindowObserversForWindow:(NSWindow *)window
 {
     if (window) {
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidBecomeKey:)
-            name:NSWindowDidBecomeKeyNotification object:nil];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowDidResignKey:)
-            name:NSWindowDidResignKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowWillOrderOnScreen:)
             name:WKWindowWillOrderOnScreenNotification() object:window];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_windowWillOrderOffScreen:)
@@ -3367,10 +3364,6 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
 {
     NSWindow *window = [self window];
     if (window) {
-        [[NSNotificationCenter defaultCenter] removeObserver:self
-            name:NSWindowDidBecomeKeyNotification object:nil];
-        [[NSNotificationCenter defaultCenter] removeObserver:self
-            name:NSWindowDidResignKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] removeObserver:self
             name:WKWindowWillOrderOnScreenNotification() object:window];
         [[NSNotificationCenter defaultCenter] removeObserver:self
@@ -3437,27 +3430,13 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
         _private->page->windowScreenDidChange((PlatformDisplayID)[[[[[self window] screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue]);
 }
 
-- (void)_windowDidBecomeKey:(NSNotification *)notification
-{
-    NSWindow *keyWindow = [notification object];
-    if (keyWindow == [self window] || keyWindow == [[self window] attachedSheet])
-        [self _updateActiveState];
-}
-
-- (void)_windowDidResignKey:(NSNotification *)notification
+- (void)_windowChangedKeyState
 {
-    NSWindow *formerKeyWindow = [notification object];
-    if (formerKeyWindow == [self window] || formerKeyWindow == [[self window] attachedSheet])
-        [self _updateActiveState];
+    [self _updateActiveState];
 }
 
 - (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];
 
@@ -3475,11 +3454,6 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
 
 - (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];
-    
     if (_private && _private->page)
         _private->page->suspendScriptedAnimations();    
 }