Index: chrome/browser/autocomplete/autocomplete_edit.cc |
=================================================================== |
--- chrome/browser/autocomplete/autocomplete_edit.cc (revision 80868) |
+++ 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, |
@@ -548,30 +550,62 @@ |
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_->selected_line() != AutocompletePopupModel::kNoMatch) { |
Peter Kasting
2011/04/11 23:17:33
Nit: Ask if the popup is open instead (if it's ope
|
+ AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2011/04/11 23:17:33
This function does not exist.
|
+ |
+ match.keyword->is_keyword_mode = true; |
+ 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_->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_->selected_line() != AutocompletePopupModel::kNoMatch) { |
Peter Kasting
2011/04/11 23:17:33
Nit: Ask if the popup is open instead.
|
+ AutocompleteMatch match; |
+ InfoForCurrentSelection(&match, NULL); |
+ |
+ if (match.keyword.get() && match.keyword->is_keyword_hint && |
+ match.keyword->is_keyword_mode) { |
+ match.keyword->is_keyword_mode = false; |
+ popup_->view()->InvalidateLine(popup_->selected_line()); |
+ } |
+ } |
+} |
+ |
const AutocompleteResult& AutocompleteEditModel::result() const { |
return autocomplete_controller_->result(); |
} |
@@ -668,6 +702,14 @@ |
} else { |
// The popup is open, so the user should be able to interact with it |
// normally. |
+ if (popup_->selected_line() != AutocompletePopupModel::kNoMatch) { |
Peter Kasting
2011/04/11 23:17:33
Nit: Ask if the popup is open instead.
|
+ AutocompleteMatch match = CurrentMatch(); |
Peter Kasting
2011/04/11 23:17:33
This function does not exist.
|
+ |
+ if (match.keyword.get() && match.keyword->is_keyword_hint && |
+ match.keyword->is_keyword_mode) |
+ ClearKeyword(string16()); |
+ } |
+ |
popup_->Move(count); |
} |
} |
@@ -853,8 +895,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); |
+ if (match->keyword.get()) { |
+ is_keyword_hint = match->keyword->is_keyword_hint; |
+ keyword = match->keyword->text; |
+ } |
} |
+ |
popup_->OnResultChanged(); |
OnPopupDataChanged(inline_autocomplete_text, NULL, keyword, |
is_keyword_hint); |
@@ -998,7 +1044,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 |