diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 20:50:47 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 20:50:47 +0000 |
commit | fe0ecbe4c6b2a4b7422c65be1967fcb019f49342 (patch) | |
tree | eb9b5ceb8640801f0b80b433da331dad4a2f40b5 /chrome/browser/cocoa/autocomplete_text_field.mm | |
parent | 6cd3a5ffeb3b3707bee1b95374e03762d29a2711 (diff) | |
download | chromium_src-fe0ecbe4c6b2a4b7422c65be1967fcb019f49342.zip chromium_src-fe0ecbe4c6b2a4b7422c65be1967fcb019f49342.tar.gz chromium_src-fe0ecbe4c6b2a4b7422c65be1967fcb019f49342.tar.bz2 |
[Mac] Route edit-state messages via observer rather than delegate.
AutocompleteTextField routes messages to AutocompleteEditViewMac via a
Cocoa-style delegate and also a C++ observer class. The Cocoa-style
delegate has been gradually being pruned down in favor of the
observer, this CL completes the transformation.
The noted bugs occur because some bit of Cocoa code was sending
spurious delegate notifications. Since this code no longer depends on
those notifications, the spurious notifications are no longer a
problem for this case.
BUG=19116, 17803
TEST=Login to gmail, select a message, j, k, and other keys should work (and not send you to the omnibox). Bring up the Print panel and cancel. Bring up a new tab and close it. gmail's accelerator keys should still work right (not send focus to omnibox).
Review URL: http://codereview.chromium.org/391025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33853 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/autocomplete_text_field.mm')
-rw-r--r-- | chrome/browser/cocoa/autocomplete_text_field.mm | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm index 1fb8aa5..d0b61dd 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.mm +++ b/chrome/browser/cocoa/autocomplete_text_field.mm @@ -15,13 +15,20 @@ return [AutocompleteTextFieldCell class]; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (void)awakeFromNib { DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); } - (void)flagsChanged:(NSEvent*)theEvent { - bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; - observer_->OnControlKeyChanged(controlFlag); + if (observer_) { + const bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; + observer_->OnControlKeyChanged(controlFlag); + } } - (AutocompleteTextFieldCell*)autocompleteTextFieldCell { @@ -170,4 +177,65 @@ [undoManager_ removeAllActions]; } +// NOTE(shess): http://crbug.com/19116 describes a weird bug which +// happens when the user runs a Print panel on Leopard. After that, +// spurious -controlTextDidBeginEditing notifications are sent when an +// NSTextField is firstResponder, even though -currentEditor on that +// field returns nil. That notification caused significant problems +// in AutocompleteEditViewMac. -textDidBeginEditing: was NOT being +// sent in those cases, so this approach doesn't have the problem. +- (void)textDidBeginEditing:(NSNotification*)aNotification { + [super textDidBeginEditing:aNotification]; + if (observer_) { + observer_->OnDidBeginEditing(); + } +} + +- (void)textDidChange:(NSNotification *)aNotification { + [super textDidChange:aNotification]; + if (observer_) { + observer_->OnDidChange(); + } +} + +- (void)textDidEndEditing:(NSNotification *)aNotification { + [super textDidEndEditing:aNotification]; + if (observer_) { + observer_->OnDidEndEditing(); + } +} + +- (BOOL)textView:(NSTextView*)textView doCommandBySelector:(SEL)cmd { + if (observer_ && observer_->OnDoCommandBySelector(cmd)) { + return YES; + } + return [super textView:textView doCommandBySelector:cmd]; +} + +- (void)windowDidResignKey:(NSNotification*)notification { + DCHECK_EQ([self window], [notification object]); + if (observer_) { + observer_->OnDidResignKey(); + } +} + +- (void)viewWillMoveToWindow:(NSWindow*)newWindow { + if ([self window]) { + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + [nc removeObserver:self + name:NSWindowDidResignKeyNotification + object:[self window]]; + } +} + +- (void)viewDidMoveToWindow { + if ([self window]) { + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self + selector:@selector(windowDidResignKey:) + name:NSWindowDidResignKeyNotification + object:[self window]]; + } +} + @end |