- fix http://bugzilla.opendarwin.org/show_bug.cgi?id=3784
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2006 04:59:58 +0000 (04:59 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2006 04:59:58 +0000 (04:59 +0000)
          <rdar://problem/4483827> JavaScript save dialog disappears right away (sheet triggers blur event) (3784)

        * WebView/WebHTMLView.m:
        (-[WebHTMLView _updateFocusState]): Treat window as having focus if its sheet is key.
        (-[WebHTMLView addWindowObservers]): Observe all focus notifications, not just the ones involving this window.
        (-[WebHTMLView removeWindowObservers]): Ditto.
        (-[WebHTMLView windowDidBecomeKey:]): Add checks so that we call the methods only when appropriate,
        since this will now be called for all windows.
        (-[WebHTMLView windowDidResignKey:]): Ditto.

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

WebKit/ChangeLog
WebKit/WebView/WebHTMLView.m

index 40e1fbcaff02a8252f8ecbfdb58e569685ff7675..419de843a9d5eee56d3c40be502ac61a35d85646 100644 (file)
@@ -1,3 +1,16 @@
+2006-03-21  Darin Adler  <darin@apple.com>
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=3784
+          <rdar://problem/4483827> JavaScript save dialog disappears right away (sheet triggers blur event) (3784)
+
+        * WebView/WebHTMLView.m:
+        (-[WebHTMLView _updateFocusState]): Treat window as having focus if its sheet is key.
+        (-[WebHTMLView addWindowObservers]): Observe all focus notifications, not just the ones involving this window.
+        (-[WebHTMLView removeWindowObservers]): Ditto.
+        (-[WebHTMLView windowDidBecomeKey:]): Add checks so that we call the methods only when appropriate,
+        since this will now be called for all windows.
+        (-[WebHTMLView windowDidResignKey:]): Ditto.
+
 2006-03-21  Adele Peterson  <adele@apple.com>
 
         Reviewed by Darin.
index 4d6ffc08e04329b8dda4eab128742e12605196a4..672adbd6f9e8782146df98349313f52e42169b2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -1623,10 +1623,13 @@ static WebHTMLView *lastHitView = nil;
     // Also, this is responsible for letting the bridge know if the window has gained or lost focus
     // so we can send focus and blur events.
 
-    BOOL windowIsKey = [[self window] isKeyWindow];
+    NSWindow *window = [self window];
+    BOOL windowIsKey = [window isKeyWindow];
+    BOOL windowOrSheetIsKey = windowIsKey || [[window attachedSheet] isKeyWindow];
+
     BOOL displaysWithFocusAttributes = !_private->resigningFirstResponder && windowIsKey && [self _web_firstResponderCausesFocusDisplay];
     
-    [[self _bridge] setWindowHasFocus:windowIsKey];
+    [[self _bridge] setWindowHasFocus:windowOrSheetIsKey];
     [[self _bridge] setDisplaysWithFocusAttributes:displaysWithFocusAttributes];
 }
 
@@ -2139,9 +2142,9 @@ static WebHTMLView *lastHitView = nil;
     NSWindow *window = [self window];
     if (window) {
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:)
-            name:NSWindowDidBecomeKeyNotification object:window];
+            name:NSWindowDidBecomeKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:)
-            name:NSWindowDidResignKeyNotification object:window];
+            name:NSWindowDidResignKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillClose:)
             name:NSWindowWillCloseNotification object:window];
     }
@@ -2152,9 +2155,9 @@ static WebHTMLView *lastHitView = nil;
     NSWindow *window = [self window];
     if (window) {
         [[NSNotificationCenter defaultCenter] removeObserver:self
-            name:NSWindowDidBecomeKeyNotification object:window];
+            name:NSWindowDidBecomeKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] removeObserver:self
-            name:NSWindowDidResignKeyNotification object:window];
+            name:NSWindowDidResignKeyNotification object:nil];
         [[NSNotificationCenter defaultCenter] removeObserver:self
             name:NSWindowWillCloseNotification object:window];
     }
@@ -2556,17 +2559,26 @@ static WebHTMLView *lastHitView = nil;
 
 - (void)windowDidBecomeKey:(NSNotification *)notification
 {
-    ASSERT([notification object] == [self window]);
-    [self addMouseMovedObserver];
-    [self _updateFocusState];
+    NSWindow *keyWindow = [notification object];
+
+    if (keyWindow == [self window])
+        [self addMouseMovedObserver];
+
+    if (keyWindow == [self window] || keyWindow == [[self window] attachedSheet])
+        [self _updateFocusState];
 }
 
-- (void)windowDidResignKey: (NSNotification *)notification
+- (void)windowDidResignKey:(NSNotification *)notification
 {
-    ASSERT([notification object] == [self window]);
-    [_private->compController endRevertingChange:NO moveLeft:NO];
-    [self removeMouseMovedObserver];
-    [self _updateFocusState];
+    NSWindow *formerKeyWindow = [notification object];
+
+    if (formerKeyWindow == [self window])
+        [self removeMouseMovedObserver];
+
+    if (formerKeyWindow == [self window] || formerKeyWindow == [[self window] attachedSheet]) {
+        [self _updateFocusState];
+        [_private->compController endRevertingChange:NO moveLeft:NO];
+    }
 }
 
 - (void)windowWillClose:(NSNotification *)notification