OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 // TODO(mrossetti): Implement this function. (Will happen in next CL.) | 85 // TODO(mrossetti): Implement this function. (Will happen in next CL.) |
86 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} | 86 void HistoryQuickProvider::DeleteMatch(const AutocompleteMatch& match) {} |
87 | 87 |
88 void HistoryQuickProvider::DoAutocomplete() { | 88 void HistoryQuickProvider::DoAutocomplete() { |
89 // Get the matching URLs from the DB. | 89 // Get the matching URLs from the DB. |
90 string16 term_string = autocomplete_input_.text(); | 90 string16 term_string = autocomplete_input_.text(); |
91 term_string = net::UnescapeURLComponent(term_string, | 91 term_string = net::UnescapeURLComponent(term_string, |
92 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); | 92 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); |
93 history::String16Vector terms( | 93 history::String16Vector terms( |
94 history::String16VectorFromString16(term_string, false)); | 94 history::String16VectorFromString16(term_string, false)); |
95 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(terms); | 95 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(terms); |
96 if (matches.empty()) | 96 if (matches.empty()) |
97 return; | 97 return; |
98 | 98 |
99 // Artificially reduce the score of high-scoring matches which should not be | 99 // Artificially reduce the score of high-scoring matches which should not be |
100 // inline autocompletd. Each such result gets the next available | 100 // inline autocompletd. Each such result gets the next available |
101 // |max_match_score|. Upon use of |max_match_score| it is decremented. | 101 // |max_match_score|. Upon use of |max_match_score| it is decremented. |
102 // All subsequent matches must be clamped to retain match results ordering. | 102 // All subsequent matches must be clamped to retain match results ordering. |
(...skipping 22 matching lines...) Expand all Loading... |
125 int score = CalculateRelevance(history_match, max_match_score); | 125 int score = CalculateRelevance(history_match, max_match_score); |
126 AutocompleteMatch match(this, score, !!info.visit_count(), | 126 AutocompleteMatch match(this, score, !!info.visit_count(), |
127 history_match.url_matches.empty() ? | 127 history_match.url_matches.empty() ? |
128 AutocompleteMatch::HISTORY_URL : AutocompleteMatch::HISTORY_TITLE); | 128 AutocompleteMatch::HISTORY_URL : AutocompleteMatch::HISTORY_TITLE); |
129 match.destination_url = info.url(); | 129 match.destination_url = info.url(); |
130 DCHECK(match.destination_url.is_valid()); | 130 DCHECK(match.destination_url.is_valid()); |
131 | 131 |
132 // Format the URL autocomplete presentation. | 132 // Format the URL autocomplete presentation. |
133 std::vector<size_t> offsets = | 133 std::vector<size_t> offsets = |
134 OffsetsFromTermMatches(history_match.url_matches); | 134 OffsetsFromTermMatches(history_match.url_matches); |
135 match.contents = | 135 match.contents = net::FormatUrlWithOffsets(info.url(), languages_, |
136 net::FormatUrlWithOffsets(info.url(), languages_, net::kFormatUrlOmitAll, | 136 net::kFormatUrlOmitAll, net::UnescapeRule::SPACES, NULL, NULL, &offsets); |
137 UnescapeRule::SPACES, NULL, NULL, &offsets); | |
138 history::TermMatches new_matches = | 137 history::TermMatches new_matches = |
139 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); | 138 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); |
140 match.contents_class = | 139 match.contents_class = |
141 SpansFromTermMatch(new_matches, match.contents.length(), true); | 140 SpansFromTermMatch(new_matches, match.contents.length(), true); |
142 match.fill_into_edit = match.contents; | 141 match.fill_into_edit = match.contents; |
143 | 142 |
144 if (prevent_inline_autocomplete || !history_match.can_inline) { | 143 if (prevent_inline_autocomplete || !history_match.can_inline) { |
145 match.inline_autocomplete_offset = string16::npos; | 144 match.inline_autocomplete_offset = string16::npos; |
146 } else { | 145 } else { |
147 match.inline_autocomplete_offset = | 146 match.inline_autocomplete_offset = |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 do { | 208 do { |
210 offset += matches[i].length; | 209 offset += matches[i].length; |
211 ++i; | 210 ++i; |
212 } while ((i < match_count) && (offset == matches[i].offset)); | 211 } while ((i < match_count) && (offset == matches[i].offset)); |
213 if (offset < text_length) | 212 if (offset < text_length) |
214 spans.push_back(ACMatchClassification(offset, url_style)); | 213 spans.push_back(ACMatchClassification(offset, url_style)); |
215 } | 214 } |
216 | 215 |
217 return spans; | 216 return spans; |
218 } | 217 } |
OLD | NEW |