Chromium Code Reviews| 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 use the default provider if the user typed in the keyword. | |
| 144 const TemplateURL* default_url = url_service->GetDefaultSearchProvider(); | |
| 145 if (default_url && default_url->id() == match.template_url->id() && | |
|
Peter Kasting
2011/07/07 01:16:07
Nit: Slightly simpler conditionals by using else t
| |
| 146 autocomplete_controller()->input().text().compare( | |
|
Peter Kasting
2011/07/07 01:16:07
Nit: base::StartsWith()?
Do we need to worry abou
sky
2011/07/07 15:34:01
As far as I can tell no. keywords are always lower
| |
| 147 0u, default_url->keyword().size(), default_url->keyword()) == 0) { | |
| 148 keyword->assign(match.template_url->keyword()); | |
| 149 return false; | |
| 150 } | |
| 151 // If the current match is a keyword, return that as the selected keyword. | |
| 152 if ((!default_url || default_url->id() != match.template_url->id()) && | |
| 153 TemplateURL::SupportsReplacement(match.template_url)) { | |
| 154 keyword->assign(match.template_url->keyword()); | |
| 155 return false; | |
| 156 } | |
| 138 } | 157 } |
| 139 | 158 |
| 140 // See if the current match's fill_into_edit corresponds to a keyword. | 159 // See if the current match's fill_into_edit corresponds to a keyword. |
| 141 return GetKeywordForText(match.fill_into_edit, keyword); | 160 return GetKeywordForText(match.fill_into_edit, keyword); |
| 142 } | 161 } |
| 143 | 162 |
| 144 bool AutocompletePopupModel::GetKeywordForText(const string16& text, | 163 bool AutocompletePopupModel::GetKeywordForText(const string16& text, |
| 145 string16* keyword) const { | 164 string16* keyword) const { |
| 146 // Creates keyword_hint first in case |keyword| is a pointer to |text|. | 165 // Creates keyword_hint first in case |keyword| is a pointer to |text|. |
| 147 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); | 166 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()); | 261 CHECK((selected_line_ != kNoMatch) || result.empty()); |
| 243 manually_selected_match_.Clear(); | 262 manually_selected_match_.Clear(); |
| 244 // If we're going to trim the window size to no longer include the hovered | 263 // 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 | 264 // line, turn hover off. Practically, this shouldn't happen, but it |
| 246 // doesn't hurt to be defensive. | 265 // doesn't hurt to be defensive. |
| 247 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) | 266 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) |
| 248 SetHoveredLine(kNoMatch); | 267 SetHoveredLine(kNoMatch); |
| 249 | 268 |
| 250 view_->UpdatePopupAppearance(); | 269 view_->UpdatePopupAppearance(); |
| 251 } | 270 } |
| OLD | NEW |