Chromium Code Reviews| Index: chrome/browser/autocomplete/autocomplete_edit.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/autocomplete_edit.cc (revision 94623) |
| +++ chrome/browser/autocomplete/autocomplete_edit.cc (working copy) |
| @@ -397,6 +397,8 @@ |
| void AutocompleteEditModel::StartAutocomplete( |
| bool has_selected_text, |
| bool prevent_inline_autocomplete) const { |
| + ResetCurrentMatchKeywordMode(); |
| + |
| bool keyword_is_selected = KeywordIsSelected(); |
| popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch); |
| // We don't explicitly clear AutocompletePopupModel::manually_selected_match, |
| @@ -560,30 +562,51 @@ |
| bool AutocompleteEditModel::AcceptKeyword() { |
| DCHECK(is_keyword_hint_ && !keyword_.empty()); |
| - view_->OnBeforePossibleChange(); |
| - view_->SetWindowTextAndCaretPos(string16(), 0); |
| + autocomplete_controller_->Stop(false); |
|
sky
2011/08/01 16:02:15
I'm pretty sure this results in not running the qu
|
| is_keyword_hint_ = false; |
| - view_->OnAfterPossibleChange(); |
| - just_deleted_text_ = false; // OnAfterPossibleChange() erroneously sets this |
| - // since the edit contents have disappeared. It |
| - // doesn't really matter, but we clear it to be |
| - // consistent. |
| + |
| + if (popup_->IsOpen()) |
| + popup_->SelectKeyword(true); |
| + |
| + view_->SetUserText(string16(), string16(), false); |
| + |
| UserMetrics::RecordAction(UserMetricsAction("AcceptedKeywordHint")); |
| return true; |
| } |
| void AutocompleteEditModel::ClearKeyword(const string16& visible_text) { |
| - view_->OnBeforePossibleChange(); |
| + autocomplete_controller_->Stop(false); |
| + ResetCurrentMatchKeywordMode(); |
| + |
| const string16 window_text(keyword_ + visible_text); |
| - view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length()); |
| - keyword_.clear(); |
| - is_keyword_hint_ = false; |
| - view_->OnAfterPossibleChange(); |
| - just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this |
| - // since the edit contents have actually grown |
| - // longer. |
| + |
| + // Only reset the result if the edit text has changed since the |
| + // keyword was accepted. |
| + if (just_deleted_text_) { |
| + view_->OnBeforePossibleChange(); |
| + view_->SetWindowTextAndCaretPos(window_text.c_str(), keyword_.length()); |
| + keyword_.clear(); |
| + is_keyword_hint_ = false; |
| + view_->OnAfterPossibleChange(); |
| + just_deleted_text_ = true; // OnAfterPossibleChange() fails to clear this |
| + // since the edit contents have actually grown |
| + // longer. |
| + } else { |
| + view_->SetUserText(window_text, window_text, false); |
| + |
| + is_keyword_hint_ = visible_text.empty(); |
| + if (!is_keyword_hint_) |
| + keyword_.clear(); |
| + |
| + OnChanged(); |
| + } |
| } |
| +void AutocompleteEditModel::ResetCurrentMatchKeywordMode() const { |
|
sky
2011/08/01 16:02:15
Doesn't match position in header.
sky
2011/08/01 16:02:15
Maybe this should be called ExitKeywordMode(), or
|
| + if (popup_->IsOpen() && popup_->keyword_selected()) |
| + popup_->SelectKeyword(false); |
| +} |
| + |
| const AutocompleteResult& AutocompleteEditModel::result() const { |
| return autocomplete_controller_->result(); |
| } |
| @@ -868,8 +891,12 @@ |
| // can be many of these as a user types an initial series of characters, |
| // the OS DNS cache could suffer eviction problems for minimal gain. |
| - is_keyword_hint = popup_->GetKeywordForMatch(*match, &keyword); |
| + keyword = match->keyword; |
| + is_keyword_hint = match->associated_keyword.get() != NULL; |
| + if (is_keyword_hint) |
| + keyword = match->associated_keyword->keyword; |
| } |
| + |
| popup_->OnResultChanged(); |
| OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, |
| is_keyword_hint); |
| @@ -1013,7 +1040,9 @@ |
| TRIM_LEADING, &keyword); |
| // Only allow exact keyword match if |keyword| represents a keyword hint. |
| - return keyword.length() && popup_->GetKeywordForText(keyword, &keyword); |
| + return keyword.length() && |
| + !autocomplete_controller_->keyword_provider()-> |
| + GetKeywordForText(keyword).empty(); |
| } |
| // static |