Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1104)

Unified Diff: chrome/browser/autocomplete/autocomplete_edit_view_mac.mm

Issue 115573: Mac: Modify Omnibox to notice when the window loses key, too. (Closed)
Patch Set: Unregister notifications before releasing edit_helper_. Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index d0d1db4421de04f419b2a30d3ee1ef747ae6e007..c86fa29cc7aeacf7e614be016a01df795a9e3d8f 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -97,6 +97,8 @@ NSRange ComponentToNSRange(const url_parse::Component& component) {
AutocompleteEditViewMac* edit_view_; // weak, owns us.
}
- initWithEditView:(AutocompleteEditViewMac*)view;
+- (void)windowDidResignKey:(NSNotification*)notification;
+- (void)windowDidBecomeKey:(NSNotification*)notification;
@end
AutocompleteEditViewMac::AutocompleteEditViewMac(
@@ -122,6 +124,18 @@ AutocompleteEditViewMac::AutocompleteEditViewMac(
// Needed so that editing doesn't lose the styling.
[field_ setAllowsEditingTextAttributes:YES];
+
+ // Track the window's key status for signalling focus changes to
+ // |model_|.
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ [nc addObserver:edit_helper_
+ selector:@selector(windowDidResignKey:)
+ name:NSWindowDidResignKeyNotification
+ object:[field_ window]];
+ [nc addObserver:edit_helper_
+ selector:@selector(windowDidBecomeKey:)
+ name:NSWindowDidBecomeKeyNotification
+ object:[field_ window]];
}
AutocompleteEditViewMac::~AutocompleteEditViewMac() {
@@ -137,6 +151,9 @@ AutocompleteEditViewMac::~AutocompleteEditViewMac() {
// Disconnect field_ from edit_helper_ so that we don't get calls
// after destruction.
[field_ setDelegate:nil];
+
+ // Disconnect notifications so they don't signal a dead object.
+ [[NSNotificationCenter defaultCenter] removeObserver:edit_helper_];
}
void AutocompleteEditViewMac::SaveStateToTab(TabContents* tab) {
@@ -440,7 +457,10 @@ void AutocompleteEditViewMac::OnEscapeKeyPressed() {
model_->OnEscapeKeyPressed();
}
void AutocompleteEditViewMac::OnSetFocus(bool f) {
- model_->OnSetFocus(f);
+ // Only forward if we actually do have the focus.
+ if ([field_ currentEditor]) {
+ model_->OnSetFocus(f);
+ }
}
void AutocompleteEditViewMac::OnKillFocus() {
// TODO(shess): This would seem to be a job for |model_|.
@@ -537,4 +557,14 @@ void AutocompleteEditViewMac::FocusLocation() {
// it's set to the start of the text.
}
+// Signal that we've lost focus when the window resigns key.
+- (void)windowDidResignKey:(NSNotification*)notification {
+ edit_view_->OnKillFocus();
+}
+
+// Signal that we may have regained focus.
+- (void)windowDidBecomeKey:(NSNotification*)notification {
+ edit_view_->OnSetFocus(false);
+}
+
@end
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698