diff options
author | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 20:45:32 +0000 |
---|---|---|
committer | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-30 20:45:32 +0000 |
commit | 7cd363601dfdaad7d3c9a36f4a4085e5e039fa05 (patch) | |
tree | 9fd4c27c057573c6de4c359d74914e4b96426bb4 /chrome/browser/cocoa | |
parent | ed0047bec1d0de1f668daf6a35af62f4d377b399 (diff) | |
download | chromium_src-7cd363601dfdaad7d3c9a36f4a4085e5e039fa05.zip chromium_src-7cd363601dfdaad7d3c9a36f4a4085e5e039fa05.tar.gz chromium_src-7cd363601dfdaad7d3c9a36f4a4085e5e039fa05.tar.bz2 |
[Mac]Fix issue 34343: "Tab to search" hint on omnibox disappears on drag dropped tab.
This CL is just a clone of http://codereview.chromium.org/1519005. As I just rebuilt my working environment.
BUG=34343
TEST=Input www.google.com to trigger "tab to search" hint, then drag the tab into a new window, then check if "tab to search" hint is still there.
Review URL: http://codereview.chromium.org/1523016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
6 files changed, 29 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h index 8e16705..f07289c 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.h +++ b/chrome/browser/cocoa/autocomplete_text_field.h @@ -78,6 +78,12 @@ class AutocompleteTextFieldObserver { // clearly relevent to expose here. But consider pulling more of // the AutocompleteEditViewMac calls up to here. virtual bool OnDoCommandBySelector(SEL cmd) = 0; + + // Called whenever the autocomplete text field gets focused. + virtual void OnSetFocus(bool control_down) = 0; + + // Called whenever the autocomplete text field is losing focus. + virtual void OnKillFocus() = 0; }; @interface AutocompleteTextField : StyledTextField<NSTextViewDelegate, diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm index a4242bb..f24cfa5 100644 --- a/chrome/browser/cocoa/autocomplete_text_field.mm +++ b/chrome/browser/cocoa/autocomplete_text_field.mm @@ -320,6 +320,17 @@ if (doAccept) { [[BrowserWindowController browserWindowControllerForView:self] lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; + + // Tells the observer that we get the focus. + // But we can't call observer_->OnKillFocus() in resignFirstResponder:, + // because the first responder will be immediately set to the field editor + // when calling [super becomeFirstResponder], thus we won't receive + // resignFirstResponder: anymore when losing focus. + if (observer_) { + NSEvent* theEvent = [NSApp currentEvent]; + const bool controlDown = ([theEvent modifierFlags]&NSControlKeyMask) != 0; + observer_->OnSetFocus(controlDown); + } } return doAccept; } diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm index 936b013..5bbc40b 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm @@ -202,6 +202,9 @@ class Extension; // Give the text field ownership of the visibility lock. [[BrowserWindowController browserWindowControllerForView:field] releaseBarVisibilityForOwner:field withAnimation:YES delay:YES]; + + if ([field observer]) + [field observer]->OnKillFocus(); } return doResign; } diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm index 1d0ae49..1f3ecd3 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm @@ -300,12 +300,12 @@ TEST_F(AutocompleteTextFieldObserverTest, FlagsChanged) { // field catches -flagsChanged: because it's on the responder chain, // the field editor doesn't implement it. TEST_F(AutocompleteTextFieldObserverTest, FieldEditorFlagsChanged) { + InSequence dummy; // Call mock in exactly the order specified. + EXPECT_CALL(field_observer_, OnSetFocus(false)); [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; NSResponder* firstResponder = [[field_ window] firstResponder]; EXPECT_EQ(firstResponder, [field_ currentEditor]); - InSequence dummy; // Call mock in exactly the order specified. - // Test without Control key down, but some other modifier down. EXPECT_CALL(field_observer_, OnControlKeyChanged(false)); [firstResponder flagsChanged:KeyDownEventWithFlags(NSShiftKeyMask)]; @@ -422,6 +422,7 @@ TEST_F(AutocompleteTextFieldTest, ResetFieldEditorKeywordHint) { // Test that resetting the field editor bounds does not cause untoward // messages to the field's observer. TEST_F(AutocompleteTextFieldObserverTest, ResetFieldEditorContinuesEditing) { + EXPECT_CALL(field_observer_, OnSetFocus(false)); // Becoming first responder doesn't begin editing. [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); @@ -826,6 +827,7 @@ TEST_F(AutocompleteTextFieldTest, EditorGetsCorrectUndoManager) { } TEST_F(AutocompleteTextFieldObserverTest, SendsEditingMessages) { + EXPECT_CALL(field_observer_, OnSetFocus(false)); // Becoming first responder doesn't begin editing. [test_window() makePretendKeyWindowAndSetFirstResponder:field_]; NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); @@ -850,6 +852,7 @@ TEST_F(AutocompleteTextFieldObserverTest, SendsEditingMessages) { [editor doCommandBySelector:cmd]; // Finished with the changes. + EXPECT_CALL(field_observer_, OnKillFocus()); EXPECT_CALL(field_observer_, OnDidEndEditing()); [test_window() clearPretendKeyWindowAndFirstResponder]; } diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h index 4997171..373ea36 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h +++ b/chrome/browser/cocoa/autocomplete_text_field_unittest_helper.h @@ -46,6 +46,8 @@ class MockAutocompleteTextFieldObserver : public AutocompleteTextFieldObserver { MOCK_METHOD0(OnDidChange, void()); MOCK_METHOD0(OnDidEndEditing, void()); MOCK_METHOD1(OnDoCommandBySelector, bool(SEL cmd)); + MOCK_METHOD1(OnSetFocus, void(bool control_down)); + MOCK_METHOD0(OnKillFocus, void()); }; } // namespace diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm index 26a7fc9..807c400 100644 --- a/chrome/browser/cocoa/location_bar_view_mac.mm +++ b/chrome/browser/cocoa/location_bar_view_mac.mm @@ -343,7 +343,8 @@ void LocationBarViewMac::OnInputInProgress(bool in_progress) { } void LocationBarViewMac::OnSetFocus() { - // Do nothing. + // Update the keyword and search hint states. + OnChanged(); } void LocationBarViewMac::OnKillFocus() { |