| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 AutocompletePopupModel::~AutocompletePopupModel() { | 42 AutocompletePopupModel::~AutocompletePopupModel() { |
| 43 } | 43 } |
| 44 | 44 |
| 45 void AutocompletePopupModel::SetProfile(Profile* profile) { | 45 void AutocompletePopupModel::SetProfile(Profile* profile) { |
| 46 DCHECK(profile); | 46 DCHECK(profile); |
| 47 profile_ = profile; | 47 profile_ = profile; |
| 48 controller_->SetProfile(profile); | 48 controller_->SetProfile(profile); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void AutocompletePopupModel::StartAutocomplete( | 51 void AutocompletePopupModel::StartAutocomplete( |
| 52 const string16& text, | 52 const std::wstring& text, |
| 53 const string16& desired_tld, | 53 const std::wstring& desired_tld, |
| 54 bool prevent_inline_autocomplete, | 54 bool prevent_inline_autocomplete, |
| 55 bool prefer_keyword, | 55 bool prefer_keyword, |
| 56 bool allow_exact_keyword_match) { | 56 bool allow_exact_keyword_match) { |
| 57 // The user is interacting with the edit, so stop tracking hover. | 57 // The user is interacting with the edit, so stop tracking hover. |
| 58 SetHoveredLine(kNoMatch); | 58 SetHoveredLine(kNoMatch); |
| 59 | 59 |
| 60 manually_selected_match_.Clear(); | 60 manually_selected_match_.Clear(); |
| 61 | 61 |
| 62 controller_->Start(text, desired_tld, prevent_inline_autocomplete, | 62 controller_->Start(text, desired_tld, prevent_inline_autocomplete, |
| 63 prefer_keyword, allow_exact_keyword_match, false); | 63 prefer_keyword, allow_exact_keyword_match, false); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // selected line. | 127 // selected line. |
| 128 CHECK(selected_line_ != kNoMatch); | 128 CHECK(selected_line_ != kNoMatch); |
| 129 GURL current_destination(result.match_at(selected_line_).destination_url); | 129 GURL current_destination(result.match_at(selected_line_).destination_url); |
| 130 view_->InvalidateLine(selected_line_); | 130 view_->InvalidateLine(selected_line_); |
| 131 selected_line_ = line; | 131 selected_line_ = line; |
| 132 view_->InvalidateLine(selected_line_); | 132 view_->InvalidateLine(selected_line_); |
| 133 | 133 |
| 134 // Update the edit with the new data for this match. | 134 // Update the edit with the new data for this match. |
| 135 // TODO(pkasting): If |selected_line_| moves to the controller, this can be | 135 // TODO(pkasting): If |selected_line_| moves to the controller, this can be |
| 136 // eliminated and just become a call to the observer on the edit. | 136 // eliminated and just become a call to the observer on the edit. |
| 137 string16 keyword; | 137 std::wstring keyword; |
| 138 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); | 138 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); |
| 139 if (reset_to_default) { | 139 if (reset_to_default) { |
| 140 string16 inline_autocomplete_text; | 140 std::wstring inline_autocomplete_text; |
| 141 if ((match.inline_autocomplete_offset != string16::npos) && | 141 if ((match.inline_autocomplete_offset != std::wstring::npos) && |
| 142 (match.inline_autocomplete_offset < match.fill_into_edit.length())) { | 142 (match.inline_autocomplete_offset < match.fill_into_edit.length())) { |
| 143 inline_autocomplete_text = | 143 inline_autocomplete_text = |
| 144 match.fill_into_edit.substr(match.inline_autocomplete_offset); | 144 match.fill_into_edit.substr(match.inline_autocomplete_offset); |
| 145 } | 145 } |
| 146 edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL, | 146 edit_model_->OnPopupDataChanged(inline_autocomplete_text, NULL, |
| 147 keyword, is_keyword_hint); | 147 keyword, is_keyword_hint); |
| 148 } else { | 148 } else { |
| 149 edit_model_->OnPopupDataChanged(match.fill_into_edit, ¤t_destination, | 149 edit_model_->OnPopupDataChanged(match.fill_into_edit, ¤t_destination, |
| 150 keyword, is_keyword_hint); | 150 keyword, is_keyword_hint); |
| 151 } | 151 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 // called instead. | 195 // called instead. |
| 196 CHECK(!result->empty()); | 196 CHECK(!result->empty()); |
| 197 CHECK(selected_line_ < result->size()); | 197 CHECK(selected_line_ < result->size()); |
| 198 *match = result->match_at(selected_line_); | 198 *match = result->match_at(selected_line_); |
| 199 } | 199 } |
| 200 if (alternate_nav_url && manually_selected_match_.empty()) | 200 if (alternate_nav_url && manually_selected_match_.empty()) |
| 201 *alternate_nav_url = result->alternate_nav_url(); | 201 *alternate_nav_url = result->alternate_nav_url(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, | 204 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, |
| 205 string16* keyword) const { | 205 std::wstring* keyword) const { |
| 206 // Assume we have no keyword until we find otherwise. | 206 // Assume we have no keyword until we find otherwise. |
| 207 keyword->clear(); | 207 keyword->clear(); |
| 208 | 208 |
| 209 // If the current match is a keyword, return that as the selected keyword. | 209 // If the current match is a keyword, return that as the selected keyword. |
| 210 if (TemplateURL::SupportsReplacement(match.template_url)) { | 210 if (TemplateURL::SupportsReplacement(match.template_url)) { |
| 211 keyword->assign(match.template_url->keyword()); | 211 keyword->assign(UTF16ToWideHack(match.template_url->keyword())); |
| 212 return false; | 212 return false; |
| 213 } | 213 } |
| 214 | 214 |
| 215 // See if the current match's fill_into_edit corresponds to a keyword. | 215 // See if the current match's fill_into_edit corresponds to a keyword. |
| 216 if (!profile_->GetTemplateURLModel()) | 216 if (!profile_->GetTemplateURLModel()) |
| 217 return false; | 217 return false; |
| 218 profile_->GetTemplateURLModel()->Load(); | 218 profile_->GetTemplateURLModel()->Load(); |
| 219 const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword( | 219 const string16 keyword_hint(TemplateURLModel::CleanUserInputKeyword( |
| 220 match.fill_into_edit)); | 220 WideToUTF16Hack(match.fill_into_edit))); |
| 221 if (keyword_hint.empty()) | 221 if (keyword_hint.empty()) |
| 222 return false; | 222 return false; |
| 223 | 223 |
| 224 // Don't provide a hint if this keyword doesn't support replacement. | 224 // Don't provide a hint if this keyword doesn't support replacement. |
| 225 const TemplateURL* const template_url = | 225 const TemplateURL* const template_url = |
| 226 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint); | 226 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword_hint); |
| 227 if (!TemplateURL::SupportsReplacement(template_url)) | 227 if (!TemplateURL::SupportsReplacement(template_url)) |
| 228 return false; | 228 return false; |
| 229 | 229 |
| 230 // Don't provide a hint for inactive/disabled extension keywords. | 230 // Don't provide a hint for inactive/disabled extension keywords. |
| 231 if (template_url->IsExtensionKeyword()) { | 231 if (template_url->IsExtensionKeyword()) { |
| 232 const Extension* extension = profile_->GetExtensionService()-> | 232 const Extension* extension = profile_->GetExtensionService()-> |
| 233 GetExtensionById(template_url->GetExtensionId(), false); | 233 GetExtensionById(template_url->GetExtensionId(), false); |
| 234 if (!extension || | 234 if (!extension || |
| 235 (profile_->IsOffTheRecord() && | 235 (profile_->IsOffTheRecord() && |
| 236 !profile_->GetExtensionService()->IsIncognitoEnabled(extension))) | 236 !profile_->GetExtensionService()->IsIncognitoEnabled(extension))) |
| 237 return false; | 237 return false; |
| 238 } | 238 } |
| 239 | 239 |
| 240 keyword->assign(keyword_hint); | 240 keyword->assign(UTF16ToWideHack(keyword_hint)); |
| 241 return true; | 241 return true; |
| 242 } | 242 } |
| 243 | 243 |
| 244 void AutocompletePopupModel::FinalizeInstantQuery( | 244 void AutocompletePopupModel::FinalizeInstantQuery( |
| 245 const string16& input_text, | 245 const std::wstring& input_text, |
| 246 const string16& suggest_text) { | 246 const std::wstring& suggest_text) { |
| 247 if (IsOpen()) { | 247 if (IsOpen()) { |
| 248 SearchProvider* search_provider = controller_->search_provider(); | 248 SearchProvider* search_provider = controller_->search_provider(); |
| 249 search_provider->FinalizeInstantQuery(input_text, suggest_text); | 249 search_provider->FinalizeInstantQuery(input_text, suggest_text); |
| 250 } | 250 } |
| 251 } | 251 } |
| 252 | 252 |
| 253 AutocompleteLog* AutocompletePopupModel::GetAutocompleteLog() { | 253 AutocompleteLog* AutocompletePopupModel::GetAutocompleteLog() { |
| 254 return new AutocompleteLog(controller_->input().text(), | 254 return new AutocompleteLog(controller_->input().text(), |
| 255 controller_->input().type(), selected_line_, 0, controller_->result()); | 255 controller_->input().type(), selected_line_, 0, controller_->result()); |
| 256 } | 256 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 | 323 |
| 324 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( | 324 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( |
| 325 const AutocompleteMatch& match) const { | 325 const AutocompleteMatch& match) const { |
| 326 if (!match.template_url || !match.template_url->IsExtensionKeyword()) | 326 if (!match.template_url || !match.template_url->IsExtensionKeyword()) |
| 327 return NULL; | 327 return NULL; |
| 328 | 328 |
| 329 return &profile_->GetExtensionService()->GetOmniboxPopupIcon( | 329 return &profile_->GetExtensionService()->GetOmniboxPopupIcon( |
| 330 match.template_url->GetExtensionId()); | 330 match.template_url->GetExtensionId()); |
| 331 } | 331 } |
| OLD | NEW |