OLD | NEW |
---|---|
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 "components/omnibox/browser/titled_url_match_utils.h" | 5 #include "components/omnibox/browser/titled_url_match_utils.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "components/bookmarks/browser/titled_url_node.h" | 9 #include "components/bookmarks/browser/titled_url_node.h" |
10 #include "components/omnibox/browser/autocomplete_match.h" | 10 #include "components/omnibox/browser/autocomplete_match.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 const bool trim_http = | 78 const bool trim_http = |
79 !AutocompleteInput::HasHTTPScheme(input.text()) && | 79 !AutocompleteInput::HasHTTPScheme(input.text()) && |
80 ((match_start == base::string16::npos) || (match_start != 0)); | 80 ((match_start == base::string16::npos) || (match_start != 0)); |
81 std::vector<size_t> offsets = TitledUrlMatch::OffsetsFromMatchPositions( | 81 std::vector<size_t> offsets = TitledUrlMatch::OffsetsFromMatchPositions( |
82 titled_url_match.url_match_positions); | 82 titled_url_match.url_match_positions); |
83 // In addition to knowing how |offsets| is transformed, we need to know how | 83 // In addition to knowing how |offsets| is transformed, we need to know how |
84 // |inline_autocomplete_offset| is transformed. We add it to the end of | 84 // |inline_autocomplete_offset| is transformed. We add it to the end of |
85 // |offsets|, compute how everything is transformed, then remove it from the | 85 // |offsets|, compute how everything is transformed, then remove it from the |
86 // end. | 86 // end. |
87 offsets.push_back(inline_autocomplete_offset); | 87 offsets.push_back(inline_autocomplete_offset); |
88 match.contents = AutocompleteMatch::FormatUrlForSuggestionDisplayWithOffsets( | 88 base::OffsetAdjuster::Adjustments adjustments; |
89 url, trim_http, &offsets); | 89 match.contents = |
90 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( | |
91 url, trim_http, &adjustments); | |
92 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets, | |
93 match.contents.length()); | |
90 inline_autocomplete_offset = offsets.back(); | 94 inline_autocomplete_offset = offsets.back(); |
91 offsets.pop_back(); | 95 offsets.pop_back(); |
92 TitledUrlMatch::MatchPositions new_url_match_positions = | 96 TitledUrlMatch::MatchPositions new_url_match_positions = |
93 TitledUrlMatch::ReplaceOffsetsInMatchPositions( | 97 TitledUrlMatch::ReplaceOffsetsInMatchPositions( |
94 titled_url_match.url_match_positions, offsets); | 98 titled_url_match.url_match_positions, offsets); |
95 match.contents_class = ClassificationsFromMatchPositions( | 99 match.contents_class = ClassificationsFromMatchPositions( |
96 new_url_match_positions, match.contents.size(), true); | 100 new_url_match_positions, match.contents.size(), true); |
97 match.fill_into_edit = | 101 match.fill_into_edit = |
98 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 102 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
99 url, match.contents, scheme_classifier); | 103 url, match.contents, scheme_classifier); |
100 if (inline_autocomplete_offset != base::string16::npos) { | 104 if (inline_autocomplete_offset != base::string16::npos) { |
101 // |inline_autocomplete_offset| may be beyond the end of the | 105 // |inline_autocomplete_offset| may be beyond the end of the |
102 // |fill_into_edit| if the user has typed an URL with a scheme and the | 106 // |fill_into_edit| if the user has typed an URL with a scheme and the |
103 // last character typed is a slash. That slash is removed by the | 107 // last character typed is a slash. That slash is removed by the |
104 // FormatURLWithOffsets call above. | 108 // FormatURLWithOffsets call above. |
Justin Donnelly
2017/06/27 15:28:46
Fix this comment to refer to FormatUrlForSuggestio
tommycli
2017/07/07 19:27:10
Acknowledged.
| |
105 if (inline_autocomplete_offset < match.fill_into_edit.length()) { | 109 if (inline_autocomplete_offset < match.fill_into_edit.length()) { |
106 match.inline_autocompletion = | 110 match.inline_autocompletion = |
107 match.fill_into_edit.substr(inline_autocomplete_offset); | 111 match.fill_into_edit.substr(inline_autocomplete_offset); |
108 } | 112 } |
109 match.allowed_to_be_default_match = | 113 match.allowed_to_be_default_match = |
110 match.inline_autocompletion.empty() || | 114 match.inline_autocompletion.empty() || |
111 !HistoryProvider::PreventInlineAutocomplete(input); | 115 !HistoryProvider::PreventInlineAutocomplete(input); |
112 } | 116 } |
113 match.description = title; | 117 match.description = title; |
114 match.description_class = ClassificationsFromMatchPositions( | 118 match.description_class = ClassificationsFromMatchPositions( |
(...skipping 12 matching lines...) Expand all Loading... | |
127 return; | 131 return; |
128 for (TitledUrlMatch::MatchPositions::iterator it = | 132 for (TitledUrlMatch::MatchPositions::iterator it = |
129 title_match_positions->begin(); | 133 title_match_positions->begin(); |
130 it != title_match_positions->end(); ++it) { | 134 it != title_match_positions->end(); ++it) { |
131 it->first -= leading_whitespace_chars; | 135 it->first -= leading_whitespace_chars; |
132 it->second -= leading_whitespace_chars; | 136 it->second -= leading_whitespace_chars; |
133 } | 137 } |
134 } | 138 } |
135 | 139 |
136 } // namespace bookmarks | 140 } // namespace bookmarks |
OLD | NEW |