OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "unicode/ubidi.h" | 9 #include "unicode/ubidi.h" |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 void AutocompletePopupModel::ResetToDefaultMatch() { | 125 void AutocompletePopupModel::ResetToDefaultMatch() { |
126 const AutocompleteResult& result = this->result(); | 126 const AutocompleteResult& result = this->result(); |
127 CHECK(!result.empty()); | 127 CHECK(!result.empty()); |
128 SetSelectedLine(result.default_match() - result.begin(), true, false); | 128 SetSelectedLine(result.default_match() - result.begin(), true, false); |
129 view_->OnDragCanceled(); | 129 view_->OnDragCanceled(); |
130 } | 130 } |
131 | 131 |
132 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, | 132 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, |
133 string16* keyword) const { | 133 string16* keyword) const { |
134 // If the current match is a keyword, return that as the selected keyword. | 134 // Assume we have no keyword until we find otherwise. |
135 if (TemplateURL::SupportsReplacement(match.template_url)) { | 135 keyword->clear(); |
136 keyword->assign(match.template_url->keyword()); | 136 |
137 return false; | 137 if (match.template_url) { |
| 138 TemplateURLService* url_service = |
| 139 TemplateURLServiceFactory::GetForProfile(profile_); |
| 140 if (!url_service) |
| 141 return false; |
| 142 |
| 143 // Only show the keyword for the default provider if the user typed in |
| 144 // the keyword and it isn't SEARCH_WHAT_YOU_TYPED. |
| 145 const TemplateURL* default_url = url_service->GetDefaultSearchProvider(); |
| 146 if (default_url && (default_url->id() == match.template_url->id())) { |
| 147 if (StartsWith(autocomplete_controller()->input().text(), |
| 148 default_url->keyword(), false) && |
| 149 (match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) { |
| 150 keyword->assign(match.template_url->keyword()); |
| 151 return false; |
| 152 } |
| 153 } else if (TemplateURL::SupportsReplacement(match.template_url)) { |
| 154 // The current match is a keyword, return that as the selected keyword. |
| 155 keyword->assign(match.template_url->keyword()); |
| 156 return false; |
| 157 } |
138 } | 158 } |
139 | 159 |
140 // See if the current match's fill_into_edit corresponds to a keyword. | 160 // See if the current match's fill_into_edit corresponds to a keyword. |
141 return GetKeywordForText(match.fill_into_edit, keyword); | 161 return GetKeywordForText(match.fill_into_edit, keyword); |
142 } | 162 } |
143 | 163 |
144 bool AutocompletePopupModel::GetKeywordForText(const string16& text, | 164 bool AutocompletePopupModel::GetKeywordForText(const string16& text, |
145 string16* keyword) const { | 165 string16* keyword) const { |
146 // Creates keyword_hint first in case |keyword| is a pointer to |text|. | 166 // Creates keyword_hint first in case |keyword| is a pointer to |text|. |
147 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); | 167 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 CHECK((selected_line_ != kNoMatch) || result.empty()); | 262 CHECK((selected_line_ != kNoMatch) || result.empty()); |
243 manually_selected_match_.Clear(); | 263 manually_selected_match_.Clear(); |
244 // If we're going to trim the window size to no longer include the hovered | 264 // If we're going to trim the window size to no longer include the hovered |
245 // line, turn hover off. Practically, this shouldn't happen, but it | 265 // line, turn hover off. Practically, this shouldn't happen, but it |
246 // doesn't hurt to be defensive. | 266 // doesn't hurt to be defensive. |
247 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) | 267 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) |
248 SetHoveredLine(kNoMatch); | 268 SetHoveredLine(kNoMatch); |
249 | 269 |
250 view_->UpdatePopupAppearance(); | 270 view_->UpdatePopupAppearance(); |
251 } | 271 } |
OLD | NEW |