summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-20 17:33:06 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-20 17:33:06 +0000
commit08aafa686ea3f3121936f8d4159a8c8069c98738 (patch)
tree467f0987e0443269c2b66f2ebb1462d5de717ae9 /chrome
parent84bdb30018ecc91f9fd04497699ebf0cd861c780 (diff)
downloadchromium_src-08aafa686ea3f3121936f8d4159a8c8069c98738.zip
chromium_src-08aafa686ea3f3121936f8d4159a8c8069c98738.tar.gz
chromium_src-08aafa686ea3f3121936f8d4159a8c8069c98738.tar.bz2
Mac: Modify Omnibox to notice when the window loses key, too.
http://crbug.com/12252 TEST=Type "word" in omnibox. Click on some other window. Popup should dissappear. Review URL: http://codereview.chromium.org/115573 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16488 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm32
2 files changed, 34 insertions, 2 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index ff394de..e8d00fb 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -80,9 +80,11 @@ class AutocompleteEditViewMac : public AutocompleteEditView {
virtual void OnBeforePossibleChange();
virtual bool OnAfterPossibleChange();
- // Helper functions which forward to our private: model_.
+ // Helper functions which forward to |model_|, for use from
+ // AutocompleteEditHelper Objective-C class.
void OnUpOrDownKeyPressed(bool up, bool by_page);
void OnEscapeKeyPressed();
+ // Only forwards to |model_| if the field_ has focus.
void OnSetFocus(bool f);
void OnKillFocus();
void AcceptInput(WindowOpenDisposition disposition, bool for_drop);
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index d0d1db4..c86fa29 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