Index: chrome/browser/autocomplete/autocomplete_popup_model.cc |
=================================================================== |
--- chrome/browser/autocomplete/autocomplete_popup_model.cc (revision 95169) |
+++ chrome/browser/autocomplete/autocomplete_popup_model.cc (working copy) |
@@ -31,7 +31,8 @@ |
edit_model_(edit_model), |
profile_(profile), |
hovered_line_(kNoMatch), |
- selected_line_(kNoMatch) { |
+ selected_line_(kNoMatch), |
+ match_state_(NORMAL) { |
edit_model->set_popup_model(this); |
} |
@@ -94,6 +95,7 @@ |
// selected line. |
CHECK(selected_line_ != kNoMatch); |
GURL current_destination(result.match_at(selected_line_).destination_url); |
+ match_state_ = NORMAL; |
view_->InvalidateLine(selected_line_); |
selected_line_ = line; |
view_->InvalidateLine(selected_line_); |
@@ -101,8 +103,11 @@ |
// Update the edit with the new data for this match. |
// TODO(pkasting): If |selected_line_| moves to the controller, this can be |
// eliminated and just become a call to the observer on the edit. |
- string16 keyword; |
- const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); |
+ string16 keyword = match.keyword; |
+ const bool is_keyword_hint = match.associated_keyword.get() != NULL; |
+ if (is_keyword_hint) |
+ keyword = match.associated_keyword->keyword; |
+ |
if (reset_to_default) { |
string16 inline_autocomplete_text; |
if ((match.inline_autocomplete_offset != string16::npos) && |
@@ -129,75 +134,6 @@ |
view_->OnDragCanceled(); |
} |
-bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, |
- string16* keyword) const { |
- // Assume we have no keyword until we find otherwise. |
- keyword->clear(); |
- |
- if (match.template_url) { |
- TemplateURLService* url_service = |
- TemplateURLServiceFactory::GetForProfile(profile_); |
- if (!url_service) |
- return false; |
- |
- // Only show the keyword for the default provider if the user typed in |
- // the keyword and it isn't SEARCH_WHAT_YOU_TYPED. |
- const TemplateURL* default_url = url_service->GetDefaultSearchProvider(); |
- if (default_url && (default_url->id() == match.template_url->id())) { |
- if (StartsWith(autocomplete_controller()->input().text(), |
- default_url->keyword(), false) && |
- (match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) { |
- keyword->assign(match.template_url->keyword()); |
- return false; |
- } |
- } else if (TemplateURL::SupportsReplacement(match.template_url)) { |
- // The current match is a keyword, return that as the selected keyword. |
- keyword->assign(match.template_url->keyword()); |
- return false; |
- } |
- } |
- |
- // See if the current match's fill_into_edit corresponds to a keyword. |
- return GetKeywordForText(match.fill_into_edit, keyword); |
-} |
- |
-bool AutocompletePopupModel::GetKeywordForText(const string16& text, |
- string16* keyword) const { |
- // Creates keyword_hint first in case |keyword| is a pointer to |text|. |
- const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); |
- |
- // Assume we have no keyword until we find otherwise. |
- keyword->clear(); |
- |
- if (keyword_hint.empty()) |
- return false; |
- TemplateURLService* url_service = |
- TemplateURLServiceFactory::GetForProfile(profile_); |
- if (!url_service) |
- return false; |
- url_service->Load(); |
- |
- // Don't provide a hint if this keyword doesn't support replacement. |
- const TemplateURL* const template_url = |
- url_service->GetTemplateURLForKeyword(keyword_hint); |
- if (!TemplateURL::SupportsReplacement(template_url)) |
- return false; |
- |
- // Don't provide a hint for inactive/disabled extension keywords. |
- if (template_url->IsExtensionKeyword()) { |
- const Extension* extension = profile_->GetExtensionService()-> |
- GetExtensionById(template_url->GetExtensionId(), false); |
- if (!extension || |
- (profile_->IsOffTheRecord() && |
- !profile_->GetExtensionService()-> |
- IsIncognitoEnabled(extension->id()))) |
- return false; |
- } |
- |
- keyword->assign(keyword_hint); |
- return true; |
-} |
- |
void AutocompletePopupModel::Move(int count) { |
const AutocompleteResult& result = this->result(); |
if (result.empty()) |
@@ -213,6 +149,17 @@ |
false, false); |
} |
+void AutocompletePopupModel::SetSelectedMatch(MatchState state) { |
+ DCHECK(!result().empty()); |
+ DCHECK_NE(selected_line_, kNoMatch); |
+ |
+ const AutocompleteMatch& match = result().match_at(selected_line_); |
+ DCHECK(match.associated_keyword.get()); |
+ |
+ match_state_ = state; |
+ view_->InvalidateLine(selected_line_); |
+} |
+ |
void AutocompletePopupModel::TryDeletingCurrentItem() { |
// We could use InfoForCurrentSelection() here, but it seems better to try |
// and shift-delete the actual selection, rather than any "in progress, not |
@@ -261,6 +208,7 @@ |
// There had better not be a nonempty result set with no default match. |
CHECK((selected_line_ != kNoMatch) || result.empty()); |
manually_selected_match_.Clear(); |
+ match_state_ = NORMAL; |
// If we're going to trim the window size to no longer include the hovered |
// line, turn hover off. Practically, this shouldn't happen, but it |
// doesn't hurt to be defensive. |