| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 CHECK(!result.empty()); | 125 CHECK(!result.empty()); |
| 126 SetSelectedLine(result.default_match() - result.begin(), true, false); | 126 SetSelectedLine(result.default_match() - result.begin(), true, false); |
| 127 view_->OnDragCanceled(); | 127 view_->OnDragCanceled(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, | 130 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, |
| 131 string16* keyword) const { | 131 string16* keyword) const { |
| 132 // Assume we have no keyword until we find otherwise. | 132 // Assume we have no keyword until we find otherwise. |
| 133 keyword->clear(); | 133 keyword->clear(); |
| 134 | 134 |
| 135 if (match.template_url) { | 135 if (match.template_url && |
| 136 TemplateURLService* url_service = | 136 TemplateURL::SupportsReplacement(match.template_url) && |
| 137 TemplateURLServiceFactory::GetForProfile(edit_model_->profile()); | 137 match.transition == PageTransition::KEYWORD) { |
| 138 if (!url_service) | 138 // The current match is a keyword, return that as the selected keyword. |
| 139 return false; | 139 keyword->assign(match.template_url->keyword()); |
| 140 | 140 return false; |
| 141 // Only show the keyword for the default provider if the user typed in | |
| 142 // the keyword and it isn't SEARCH_WHAT_YOU_TYPED. | |
| 143 const TemplateURL* default_url = url_service->GetDefaultSearchProvider(); | |
| 144 if (default_url && (default_url->id() == match.template_url->id())) { | |
| 145 if (StartsWith(autocomplete_controller()->input().text(), | |
| 146 default_url->keyword(), false) && | |
| 147 (match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) { | |
| 148 keyword->assign(match.template_url->keyword()); | |
| 149 return false; | |
| 150 } | |
| 151 } else if (TemplateURL::SupportsReplacement(match.template_url)) { | |
| 152 // The current match is a keyword, return that as the selected keyword. | |
| 153 keyword->assign(match.template_url->keyword()); | |
| 154 return false; | |
| 155 } | |
| 156 } | 141 } |
| 157 | 142 |
| 158 // See if the current match's fill_into_edit corresponds to a keyword. | 143 // See if the current match's fill_into_edit corresponds to a keyword. |
| 159 return GetKeywordForText(match.fill_into_edit, keyword); | 144 return GetKeywordForText(match.fill_into_edit, keyword); |
| 160 } | 145 } |
| 161 | 146 |
| 162 bool AutocompletePopupModel::GetKeywordForText(const string16& text, | 147 bool AutocompletePopupModel::GetKeywordForText(const string16& text, |
| 163 string16* keyword) const { | 148 string16* keyword) const { |
| 164 // Creates keyword_hint first in case |keyword| is a pointer to |text|. | 149 // Creates keyword_hint first in case |keyword| is a pointer to |text|. |
| 165 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); | 150 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 CHECK((selected_line_ != kNoMatch) || result.empty()); | 244 CHECK((selected_line_ != kNoMatch) || result.empty()); |
| 260 manually_selected_match_.Clear(); | 245 manually_selected_match_.Clear(); |
| 261 // If we're going to trim the window size to no longer include the hovered | 246 // If we're going to trim the window size to no longer include the hovered |
| 262 // line, turn hover off. Practically, this shouldn't happen, but it | 247 // line, turn hover off. Practically, this shouldn't happen, but it |
| 263 // doesn't hurt to be defensive. | 248 // doesn't hurt to be defensive. |
| 264 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) | 249 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) |
| 265 SetHoveredLine(kNoMatch); | 250 SetHoveredLine(kNoMatch); |
| 266 | 251 |
| 267 view_->UpdatePopupAppearance(); | 252 view_->UpdatePopupAppearance(); |
| 268 } | 253 } |
| OLD | NEW |