| Index: chrome/browser/autocomplete/autocomplete_edit.cc
|
| ===================================================================
|
| --- chrome/browser/autocomplete/autocomplete_edit.cc (revision 95169)
|
| +++ chrome/browser/autocomplete/autocomplete_edit.cc (working copy)
|
| @@ -397,6 +397,8 @@
|
| void AutocompleteEditModel::StartAutocomplete(
|
| bool has_selected_text,
|
| bool prevent_inline_autocomplete) const {
|
| + ClearPopupKeywordMode();
|
| +
|
| bool keyword_is_selected = KeywordIsSelected();
|
| popup_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
|
| // We don't explicitly clear AutocompletePopupModel::manually_selected_match,
|
| @@ -560,28 +562,44 @@
|
| bool AutocompleteEditModel::AcceptKeyword() {
|
| DCHECK(is_keyword_hint_ && !keyword_.empty());
|
|
|
| - view_->OnBeforePossibleChange();
|
| - view_->SetWindowTextAndCaretPos(string16(), 0);
|
| + autocomplete_controller_->Stop(false);
|
| 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_->SetSelectedMatch(AutocompletePopupModel::KEYWORD);
|
| +
|
| + view_->SetUserText(string16(), string16(), false);
|
| +
|
| UserMetrics::RecordAction(UserMetricsAction("AcceptedKeywordHint"));
|
| return true;
|
| }
|
|
|
| void AutocompleteEditModel::ClearKeyword(const string16& visible_text) {
|
| - view_->OnBeforePossibleChange();
|
| + autocomplete_controller_->Stop(false);
|
| + ClearPopupKeywordMode();
|
| +
|
| 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();
|
| + }
|
| }
|
|
|
| const AutocompleteResult& AutocompleteEditModel::result() const {
|
| @@ -866,8 +884,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);
|
| @@ -900,6 +922,12 @@
|
| return !is_keyword_hint_ && !keyword_.empty();
|
| }
|
|
|
| +void AutocompleteEditModel::ClearPopupKeywordMode() const {
|
| + if (popup_->IsOpen() &&
|
| + popup_->selected_match() == AutocompletePopupModel::KEYWORD)
|
| + popup_->SetSelectedMatch(AutocompletePopupModel::RESULT);
|
| +}
|
| +
|
| string16 AutocompleteEditModel::DisplayTextFromUserText(
|
| const string16& text) const {
|
| return KeywordIsSelected() ?
|
| @@ -1011,7 +1039,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
|
|
|