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_contents_provider.h" | 5 #include "chrome/browser/autocomplete/history_contents_provider.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 size_t max_for_provider = std::min(kMaxMatches, result_refs.size()); | 195 size_t max_for_provider = std::min(kMaxMatches, result_refs.size()); |
196 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_provider, | 196 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_provider, |
197 result_refs.end(), &CompareMatchRelevance); | 197 result_refs.end(), &CompareMatchRelevance); |
198 matches_.clear(); | 198 matches_.clear(); |
199 for (size_t i = 0; i < max_for_provider; i++) { | 199 for (size_t i = 0; i < max_for_provider; i++) { |
200 matches_.push_back(ResultToMatch(*result_refs[i].result, | 200 matches_.push_back(ResultToMatch(*result_refs[i].result, |
201 result_refs[i].relevance)); | 201 result_refs[i].relevance)); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 static bool MatchInTitle(const history::URLResult& result) { | 205 // TODO(mrossetti): Remove MatchInTitle once body_only_ becomes permanent. |
206 return !result.title_match_positions().empty(); | 206 bool HistoryContentsProvider::MatchInTitle(const history::URLResult& result) { |
| 207 return !body_only_ && !result.title_match_positions().empty(); |
207 } | 208 } |
208 | 209 |
209 AutocompleteMatch HistoryContentsProvider::ResultToMatch( | 210 AutocompleteMatch HistoryContentsProvider::ResultToMatch( |
210 const history::URLResult& result, | 211 const history::URLResult& result, |
211 int score) { | 212 int score) { |
212 // TODO(sky): if matched title highlight matching words in title. | |
213 // Also show star in popup. | |
214 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? | 213 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? |
215 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); | 214 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); |
216 match.contents = StringForURLDisplay(result.url(), true, trim_http_); | 215 match.contents = StringForURLDisplay(result.url(), true, trim_http_); |
217 match.fill_into_edit = | 216 match.fill_into_edit = |
218 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), | 217 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), |
219 match.contents); | 218 match.contents); |
220 match.destination_url = result.url(); | 219 match.destination_url = result.url(); |
221 match.contents_class.push_back( | 220 match.contents_class.push_back( |
222 ACMatchClassification(0, ACMatchClassification::URL)); | 221 ACMatchClassification(0, ACMatchClassification::URL)); |
223 match.description = result.title(); | 222 match.description = result.title(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 279 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
281 TimeTicks::Now() - start_time); | 280 TimeTicks::Now() - start_time); |
282 } | 281 } |
283 | 282 |
284 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 283 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
285 const bookmark_utils::TitleMatch& match) { | 284 const bookmark_utils::TitleMatch& match) { |
286 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 285 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
287 url_result.set_title(match.node->GetTitle()); | 286 url_result.set_title(match.node->GetTitle()); |
288 results_.AppendURLBySwapping(&url_result); | 287 results_.AppendURLBySwapping(&url_result); |
289 } | 288 } |
OLD | NEW |