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 = url_formatter::FormatUrlWithOffsets( | 88 base::OffsetAdjuster::Adjustments adjustments; |
89 url, url_formatter::kFormatUrlOmitAll & | 89 match.contents = |
90 ~(trim_http ? 0 : url_formatter::kFormatUrlOmitHTTP), | 90 AutocompleteMatch::FormatUrlForSuggestionDisplayWithAdjustments( |
Justin Donnelly
2017/06/20 17:31:02
If it's worth having a convenience version of this
tommycli
2017/06/20 22:51:21
Done. Hmm... well after this there's now some non-
| |
91 net::UnescapeRule::SPACES, nullptr, nullptr, &offsets); | 91 url, trim_http, &adjustments); |
92 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); | |
92 inline_autocomplete_offset = offsets.back(); | 93 inline_autocomplete_offset = offsets.back(); |
93 offsets.pop_back(); | 94 offsets.pop_back(); |
94 TitledUrlMatch::MatchPositions new_url_match_positions = | 95 TitledUrlMatch::MatchPositions new_url_match_positions = |
95 TitledUrlMatch::ReplaceOffsetsInMatchPositions( | 96 TitledUrlMatch::ReplaceOffsetsInMatchPositions( |
96 titled_url_match.url_match_positions, offsets); | 97 titled_url_match.url_match_positions, offsets); |
97 match.contents_class = ClassificationsFromMatchPositions( | 98 match.contents_class = ClassificationsFromMatchPositions( |
98 new_url_match_positions, match.contents.size(), true); | 99 new_url_match_positions, match.contents.size(), true); |
99 match.fill_into_edit = | 100 match.fill_into_edit = |
100 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 101 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
101 url, match.contents, scheme_classifier); | 102 url, match.contents, scheme_classifier); |
(...skipping 27 matching lines...) Expand all Loading... | |
129 return; | 130 return; |
130 for (TitledUrlMatch::MatchPositions::iterator it = | 131 for (TitledUrlMatch::MatchPositions::iterator it = |
131 title_match_positions->begin(); | 132 title_match_positions->begin(); |
132 it != title_match_positions->end(); ++it) { | 133 it != title_match_positions->end(); ++it) { |
133 it->first -= leading_whitespace_chars; | 134 it->first -= leading_whitespace_chars; |
134 it->second -= leading_whitespace_chars; | 135 it->second -= leading_whitespace_chars; |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 } // namespace bookmarks | 139 } // namespace bookmarks |
OLD | NEW |