diff options
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()); |