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 // The latter part of the test effectively asks "is the inline completion |
| 1070 // empty?" (i.e., is this match effectively the what-you-typed match?). |
| 1071 match.allowed_to_be_default_match = !params->prevent_inline_autocomplete || |
| 1072 ((inline_autocomplete_offset != string16::npos) && |
| 1073 (inline_autocomplete_offset >= match.fill_into_edit.length())); |
1068 | 1074 |
1069 size_t match_start = history_match.input_location; | 1075 size_t match_start = history_match.input_location; |
1070 match.contents = net::FormatUrl(info.url(), languages, | 1076 match.contents = net::FormatUrl(info.url(), languages, |
1071 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); | 1077 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); |
1072 if ((match_start != string16::npos) && | 1078 if ((match_start != string16::npos) && |
1073 (inline_autocomplete_offset != string16::npos) && | 1079 (inline_autocomplete_offset != string16::npos) && |
1074 (inline_autocomplete_offset != match_start)) { | 1080 (inline_autocomplete_offset != match_start)) { |
1075 DCHECK(inline_autocomplete_offset > match_start); | 1081 DCHECK(inline_autocomplete_offset > match_start); |
1076 AutocompleteMatch::ClassifyLocationInString(match_start, | 1082 AutocompleteMatch::ClassifyLocationInString(match_start, |
1077 inline_autocomplete_offset - match_start, match.contents.length(), | 1083 inline_autocomplete_offset - match_start, match.contents.length(), |
1078 ACMatchClassification::URL, &match.contents_class); | 1084 ACMatchClassification::URL, &match.contents_class); |
1079 } else { | 1085 } else { |
1080 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, | 1086 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, |
1081 match.contents.length(), ACMatchClassification::URL, | 1087 match.contents.length(), ACMatchClassification::URL, |
1082 &match.contents_class); | 1088 &match.contents_class); |
1083 } | 1089 } |
1084 match.description = info.title(); | 1090 match.description = info.title(); |
1085 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 1091 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
1086 info.title(), | 1092 info.title(), |
1087 ACMatchClassification::NONE, | 1093 ACMatchClassification::NONE, |
1088 &match.description_class); | 1094 &match.description_class); |
1089 RecordAdditionalInfoFromUrlRow(info, &match); | 1095 RecordAdditionalInfoFromUrlRow(info, &match); |
1090 return match; | 1096 return match; |
1091 } | 1097 } |
OLD | NEW |