+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.
/*
- * 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
// 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];
}
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];
}
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];
}
- (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