| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 AutocompleteMatch HistoryURLProvider::SuggestExactInput( | 249 AutocompleteMatch HistoryURLProvider::SuggestExactInput( |
| 250 const AutocompleteInput& input, | 250 const AutocompleteInput& input, |
| 251 bool trim_http) { | 251 bool trim_http) { |
| 252 AutocompleteMatch match(this, | 252 AutocompleteMatch match(this, |
| 253 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, | 253 CalculateRelevance(input.type(), WHAT_YOU_TYPED, 0), false, |
| 254 AutocompleteMatch::URL_WHAT_YOU_TYPED); | 254 AutocompleteMatch::URL_WHAT_YOU_TYPED); |
| 255 | 255 |
| 256 const GURL& url = input.canonicalized_url(); | 256 const GURL& url = input.canonicalized_url(); |
| 257 if (url.is_valid()) { | 257 if (url.is_valid()) { |
| 258 match.destination_url = url; | 258 match.destination_url = url; |
| 259 match.fill_into_edit = StringForURLDisplay(url, false, trim_http); | 259 match.fill_into_edit = StringForURLDisplay(url, false, false); |
| 260 // NOTE: Don't set match.input_location (to allow inline autocompletion) | 260 // NOTE: Don't set match.input_location (to allow inline autocompletion) |
| 261 // here, it's surprising and annoying. | 261 // here, it's surprising and annoying. |
| 262 // Trim off "http://" if the user didn't type it. |
| 263 // Double NOTE: we use TrimHttpPrefix here rather than StringForURLDisplay |
| 264 // to strip the http as we need to know the offset so we can adjust the |
| 265 // match_location below. StringForURLDisplay and TrimHttpPrefix have |
| 266 // slightly different behavior when stripping http as well. |
| 267 const size_t offset = trim_http ? TrimHttpPrefix(&match.fill_into_edit) : 0; |
| 262 | 268 |
| 263 // Try to highlight "innermost" match location. If we fix up "w" into | 269 // Try to highlight "innermost" match location. If we fix up "w" into |
| 264 // "www.w.com", we want to highlight the fifth character, not the first. | 270 // "www.w.com", we want to highlight the fifth character, not the first. |
| 265 // This relies on match.destination_url being the non-prefix-trimmed version | 271 // This relies on match.destination_url being the non-prefix-trimmed version |
| 266 // of match.contents. | 272 // of match.contents. |
| 267 match.contents = match.fill_into_edit; | 273 match.contents = match.fill_into_edit; |
| 268 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text()); | 274 const Prefix* best_prefix = BestPrefix(match.destination_url, input.text()); |
| 269 // Because of the vagaries of GURL, it's possible for match.destination_url | 275 // Because of the vagaries of GURL, it's possible for match.destination_url |
| 270 // to not contain the user's input at all. In this case don't mark anything | 276 // to not contain the user's input at all. In this case don't mark anything |
| 271 // as a match. | 277 // as a match. |
| 272 const size_t match_location = (best_prefix == NULL) ? | 278 const size_t match_location = (best_prefix == NULL) ? |
| 273 std::wstring::npos : best_prefix->prefix.length(); | 279 std::wstring::npos : best_prefix->prefix.length() - offset; |
| 274 AutocompleteMatch::ClassifyLocationInString(match_location, | 280 AutocompleteMatch::ClassifyLocationInString(match_location, |
| 275 input.text().length(), | 281 input.text().length(), |
| 276 match.contents.length(), | 282 match.contents.length(), |
| 277 ACMatchClassification::URL, | 283 ACMatchClassification::URL, |
| 278 &match.contents_class); | 284 &match.contents_class); |
| 279 | 285 |
| 280 match.is_history_what_you_typed_match = true; | 286 match.is_history_what_you_typed_match = true; |
| 281 } | 287 } |
| 282 | 288 |
| 283 return match; | 289 return match; |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 match.contents.length(), ACMatchClassification::URL, | 860 match.contents.length(), ACMatchClassification::URL, |
| 855 &match.contents_class); | 861 &match.contents_class); |
| 856 } | 862 } |
| 857 match.description = info.title(); | 863 match.description = info.title(); |
| 858 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 864 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
| 859 ACMatchClassification::NONE, | 865 ACMatchClassification::NONE, |
| 860 &match.description_class); | 866 &match.description_class); |
| 861 | 867 |
| 862 return match; | 868 return match; |
| 863 } | 869 } |
| OLD | NEW |