Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to | 342 // NOTE: We use TrimHttpPrefix() here rather than StringForURLDisplay() to |
| 343 // strip the scheme as we need to know the offset so we can adjust the | 343 // strip the scheme as we need to know the offset so we can adjust the |
| 344 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have | 344 // |match_location| below. StringForURLDisplay() and TrimHttpPrefix() have |
| 345 // slightly different behavior as well (the latter will strip even without | 345 // slightly different behavior as well (the latter will strip even without |
| 346 // two slashes after the scheme). | 346 // two slashes after the scheme). |
| 347 string16 display_string(provider->StringForURLDisplay(url, false, false)); | 347 string16 display_string(provider->StringForURLDisplay(url, false, false)); |
| 348 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; | 348 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; |
| 349 match.fill_into_edit = | 349 match.fill_into_edit = |
| 350 AutocompleteInput::FormattedStringWithEquivalentMeaning(url, | 350 AutocompleteInput::FormattedStringWithEquivalentMeaning(url, |
| 351 display_string); | 351 display_string); |
| 352 match.allowed_to_be_default_match = true; | |
| 352 // NOTE: Don't set match.inline_autocompletion to something non-empty here; | 353 // NOTE: Don't set match.inline_autocompletion to something non-empty here; |
| 353 // it's surprising and annoying. | 354 // it's surprising and annoying. |
| 354 | 355 |
| 355 // Try to highlight "innermost" match location. If we fix up "w" into | 356 // Try to highlight "innermost" match location. If we fix up "w" into |
| 356 // "www.w.com", we want to highlight the fifth character, not the first. | 357 // "www.w.com", we want to highlight the fifth character, not the first. |
| 357 // This relies on match.destination_url being the non-prefix-trimmed version | 358 // This relies on match.destination_url being the non-prefix-trimmed version |
| 358 // of match.contents. | 359 // of match.contents. |
| 359 match.contents = display_string; | 360 match.contents = display_string; |
| 360 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( | 361 const URLPrefix* best_prefix = URLPrefix::BestURLPrefix( |
| 361 UTF8ToUTF16(match.destination_url.spec()), input.text()); | 362 UTF8ToUTF16(match.destination_url.spec()), input.text()); |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), | 1059 AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), |
| 1059 net::FormatUrl(info.url(), languages, format_types, | 1060 net::FormatUrl(info.url(), languages, format_types, |
| 1060 net::UnescapeRule::SPACES, NULL, NULL, | 1061 net::UnescapeRule::SPACES, NULL, NULL, |
| 1061 &inline_autocomplete_offset)); | 1062 &inline_autocomplete_offset)); |
| 1062 if (!params->prevent_inline_autocomplete && | 1063 if (!params->prevent_inline_autocomplete && |
| 1063 (inline_autocomplete_offset != string16::npos)) { | 1064 (inline_autocomplete_offset != string16::npos)) { |
| 1064 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1065 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1065 match.inline_autocompletion = | 1066 match.inline_autocompletion = |
| 1066 match.fill_into_edit.substr(inline_autocomplete_offset); | 1067 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1067 } | 1068 } |
| 1069 match.allowed_to_be_default_match = !params->prevent_inline_autocomplete ? | |
|
Peter Kasting
2013/08/06 22:56:16
Nit: Simpler:
match.allowed_to_be_default_match
Mark P
2013/08/07 00:44:31
Nice. Done.
| |
| 1070 true : | |
| 1071 ((inline_autocomplete_offset != string16::npos) && | |
| 1072 (inline_autocomplete_offset >= match.fill_into_edit.length())); | |
| 1068 | 1073 |
| 1069 size_t match_start = history_match.input_location; | 1074 size_t match_start = history_match.input_location; |
| 1070 match.contents = net::FormatUrl(info.url(), languages, | 1075 match.contents = net::FormatUrl(info.url(), languages, |
| 1071 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); | 1076 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); |
| 1072 if ((match_start != string16::npos) && | 1077 if ((match_start != string16::npos) && |
| 1073 (inline_autocomplete_offset != string16::npos) && | 1078 (inline_autocomplete_offset != string16::npos) && |
| 1074 (inline_autocomplete_offset != match_start)) { | 1079 (inline_autocomplete_offset != match_start)) { |
| 1075 DCHECK(inline_autocomplete_offset > match_start); | 1080 DCHECK(inline_autocomplete_offset > match_start); |
| 1076 AutocompleteMatch::ClassifyLocationInString(match_start, | 1081 AutocompleteMatch::ClassifyLocationInString(match_start, |
| 1077 inline_autocomplete_offset - match_start, match.contents.length(), | 1082 inline_autocomplete_offset - match_start, match.contents.length(), |
| 1078 ACMatchClassification::URL, &match.contents_class); | 1083 ACMatchClassification::URL, &match.contents_class); |
| 1079 } else { | 1084 } else { |
| 1080 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, | 1085 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, |
| 1081 match.contents.length(), ACMatchClassification::URL, | 1086 match.contents.length(), ACMatchClassification::URL, |
| 1082 &match.contents_class); | 1087 &match.contents_class); |
| 1083 } | 1088 } |
| 1084 match.description = info.title(); | 1089 match.description = info.title(); |
| 1085 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 1090 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
| 1086 info.title(), | 1091 info.title(), |
| 1087 ACMatchClassification::NONE, | 1092 ACMatchClassification::NONE, |
| 1088 &match.description_class); | 1093 &match.description_class); |
| 1089 RecordAdditionalInfoFromUrlRow(info, &match); | 1094 RecordAdditionalInfoFromUrlRow(info, &match); |
| 1090 return match; | 1095 return match; |
| 1091 } | 1096 } |
| OLD | NEW |