Index: chrome/browser/autocomplete/autocomplete_edit.cc |
=================================================================== |
--- chrome/browser/autocomplete/autocomplete_edit.cc (revision 81359) |
+++ chrome/browser/autocomplete/autocomplete_edit.cc (working copy) |
@@ -382,6 +382,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, |
@@ -515,9 +517,9 @@ |
current_match : result().match_at(index); |
// Strip the keyword + leading space off the input. |
- size_t prefix_length = match.template_url->keyword().size() + 1; |
+ size_t prefix_length = match.keyword_url->keyword().size() + 1; |
ExtensionOmniboxEventRouter::OnInputEntered( |
- profile_, match.template_url->GetExtensionId(), |
+ profile_, match.keyword_url->GetExtensionId(), |
UTF16ToUTF8(match.fill_into_edit.substr(prefix_length))); |
view_->RevertAll(); |
return; |
@@ -548,30 +550,63 @@ |
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()) { |
+ AutocompleteMatch& match = const_cast<AutocompleteMatch&>(result(). |
+ match_at(popup_->selected_line())); |
+ |
+ match.keyword_state = AutocompleteMatch::DUAL_SHOWING_KEYWORD; |
+ popup_->view()->InvalidateLine(popup_->selected_line()); |
+ } |
+ |
+ view_->SetUserText(string16(), string16(), false); |
+ |
UserMetrics::RecordAction(UserMetricsAction("AcceptedKeywordHint"), profile_); |
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 { |
+ if (popup_->IsOpen()) { |
+ AutocompleteMatch& match = const_cast<AutocompleteMatch&>(result(). |
+ match_at(popup_->selected_line())); |
+ |
+ if (match.keyword_state == AutocompleteMatch::DUAL_SHOWING_KEYWORD) { |
+ match.keyword_state = AutocompleteMatch::DUAL_SHOWING_NON_KEYWORD; |
+ popup_->view()->InvalidateLine(popup_->selected_line()); |
+ } |
+ } |
+} |
+ |
const AutocompleteResult& AutocompleteEditModel::result() const { |
return autocomplete_controller_->result(); |
} |
@@ -668,6 +703,13 @@ |
} else { |
// The popup is open, so the user should be able to interact with it |
// normally. |
+ if (popup_->IsOpen()) { |
+ AutocompleteMatch match = CurrentMatch(); |
+ |
+ if (match.keyword_state == AutocompleteMatch::DUAL_SHOWING_KEYWORD) |
+ ClearKeyword(string16()); |
+ } |
+ |
popup_->Move(count); |
} |
} |
@@ -853,8 +895,10 @@ |
// 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->has_keyword_hint(); |
} |
+ |
popup_->OnResultChanged(); |
OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, |
is_keyword_hint); |
@@ -998,7 +1042,8 @@ |
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_->GetKeywordForText(keyword).empty(); |
} |
// static |