diff options
author | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 20:18:24 +0000 |
---|---|---|
committer | suzhe@chromium.org <suzhe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-09 20:18:24 +0000 |
commit | 4bb2c404e6f9fe9ce90f6164726ccc43adfb65b9 (patch) | |
tree | a858bb34fe56a253b4fdb308797e26022d742d78 | |
parent | 93066a119beb49642444df4111184212dd503398 (diff) | |
download | chromium_src-4bb2c404e6f9fe9ce90f6164726ccc43adfb65b9.zip chromium_src-4bb2c404e6f9fe9ce90f6164726ccc43adfb65b9.tar.gz chromium_src-4bb2c404e6f9fe9ce90f6164726ccc43adfb65b9.tar.bz2 |
Checks whether the autocomplete controller can accept keywords before the composition text of input methods sets in the omnibox. This will prevent committing the current composition text incorrectly.
BUG=61204
TEST=Enter the keyword of an extension and type space, and inserting text with an input method, then the composition text should not be committed.
Review URL: http://codereview.chromium.org/4103011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68761 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 19 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h index 06d5e09..d486cc5 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h @@ -74,6 +74,7 @@ class AutocompleteEditViewMac : public AutocompleteEditView, bool save_original_selection); virtual bool OnInlineAutocompleteTextMaybeChanged( const std::wstring& display_text, size_t user_text_length); + virtual void OnStartingIME(); virtual void OnRevertTemporaryText(); virtual void OnBeforePossibleChange(); virtual bool OnAfterPossibleChange(); diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm index 97981f9..15d0f97 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm +++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm @@ -627,6 +627,11 @@ void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged( [field_ clearUndoChain]; } +void AutocompleteEditViewMac::OnStartingIME() { + if (model_->is_keyword_hint() && !model_->keyword().empty()) + model_->AcceptKeyword(); +} + bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( const std::wstring& display_text, size_t user_text_length) { // TODO(shess): Make sure that this actually works. The round trip diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h index e731c2c..884df1b 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h @@ -77,6 +77,9 @@ class AutocompleteTextFieldObserver { virtual void OnDidChange() = 0; virtual void OnDidEndEditing() = 0; + // Called before input methods sets composition text in the field. + virtual void OnStartingIME() = 0; + // NSResponder translates certain keyboard actions into selectors // passed to -doCommandBySelector:. The selector is forwarded here, // return true if |cmd| is handled, false if the caller should diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm index 1b52e70..37b6029 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm @@ -264,6 +264,15 @@ } - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange { + if (![self hasMarkedText]) { + // Before input methods set composition text in the omnibox, we need to + // examine whether the autocompletion controller accepts the keyword to + // avoid committing the current composition text wrongly. + AutocompleteTextFieldObserver* observer = [self observer]; + if (observer) + observer->OnStartingIME(); + } + [super setMarkedText:aString selectedRange:selRange]; // Because the AutocompleteEditViewMac class treats marked text as content, diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest_helper.h b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest_helper.h index bccaae1..384337b 100644 --- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest_helper.h +++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_unittest_helper.h @@ -48,6 +48,7 @@ class MockAutocompleteTextFieldObserver : public AutocompleteTextFieldObserver { MOCK_METHOD0(OnDidBeginEditing, void()); MOCK_METHOD0(OnDidChange, void()); MOCK_METHOD0(OnDidEndEditing, void()); + MOCK_METHOD0(OnStartingIME, void()); MOCK_METHOD1(OnDoCommandBySelector, bool(SEL cmd)); MOCK_METHOD1(OnSetFocus, void(bool control_down)); MOCK_METHOD0(OnKillFocus, void()); |