| 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 "components/omnibox/browser/bookmark_provider.h" | 5 #include "components/omnibox/browser/bookmark_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch( | 159 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch( |
| 160 const AutocompleteInput& input, | 160 const AutocompleteInput& input, |
| 161 const base::string16& fixed_up_input_text, | 161 const base::string16& fixed_up_input_text, |
| 162 const BookmarkMatch& bookmark_match) { | 162 const BookmarkMatch& bookmark_match) { |
| 163 // The AutocompleteMatch we construct is non-deletable because the only | 163 // The AutocompleteMatch we construct is non-deletable because the only |
| 164 // way to support this would be to delete the underlying bookmark, which is | 164 // way to support this would be to delete the underlying bookmark, which is |
| 165 // unlikely to be what the user intends. | 165 // unlikely to be what the user intends. |
| 166 AutocompleteMatch match(this, 0, false, | 166 AutocompleteMatch match(this, 0, false, |
| 167 AutocompleteMatchType::BOOKMARK_TITLE); | 167 AutocompleteMatchType::BOOKMARK_TITLE); |
| 168 base::string16 title(bookmark_match.node->GetTitle()); | 168 base::string16 title(bookmark_match.node->GetTitledUrlNodeTitle()); |
| 169 BookmarkMatch::MatchPositions new_title_match_positions = | 169 BookmarkMatch::MatchPositions new_title_match_positions = |
| 170 bookmark_match.title_match_positions; | 170 bookmark_match.title_match_positions; |
| 171 CorrectTitleAndMatchPositions(&title, &new_title_match_positions); | 171 CorrectTitleAndMatchPositions(&title, &new_title_match_positions); |
| 172 const GURL& url(bookmark_match.node->url()); | 172 const GURL& url(bookmark_match.node->GetTitledUrlNodeUrl()); |
| 173 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec()); | 173 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec()); |
| 174 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset( | 174 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset( |
| 175 input.text(), fixed_up_input_text, false, url_utf16); | 175 input.text(), fixed_up_input_text, false, url_utf16); |
| 176 match.destination_url = url; | 176 match.destination_url = url; |
| 177 const size_t match_start = bookmark_match.url_match_positions.empty() ? | 177 const size_t match_start = bookmark_match.url_match_positions.empty() ? |
| 178 0 : bookmark_match.url_match_positions[0].first; | 178 0 : bookmark_match.url_match_positions[0].first; |
| 179 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && | 179 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && |
| 180 ((match_start == base::string16::npos) || (match_start != 0)); | 180 ((match_start == base::string16::npos) || (match_start != 0)); |
| 181 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( | 181 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( |
| 182 bookmark_match.url_match_positions); | 182 bookmark_match.url_match_positions); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 // Pretend empty titles are identical to the URL. | 274 // Pretend empty titles are identical to the URL. |
| 275 if (title.empty()) | 275 if (title.empty()) |
| 276 title = base::ASCIIToUTF16(url.spec()); | 276 title = base::ASCIIToUTF16(url.spec()); |
| 277 ScoringFunctor title_position_functor = | 277 ScoringFunctor title_position_functor = |
| 278 for_each(bookmark_match.title_match_positions.begin(), | 278 for_each(bookmark_match.title_match_positions.begin(), |
| 279 bookmark_match.title_match_positions.end(), | 279 bookmark_match.title_match_positions.end(), |
| 280 ScoringFunctor(title.size())); | 280 ScoringFunctor(title.size())); |
| 281 ScoringFunctor url_position_functor = | 281 ScoringFunctor url_position_functor = |
| 282 for_each(bookmark_match.url_match_positions.begin(), | 282 for_each(bookmark_match.url_match_positions.begin(), |
| 283 bookmark_match.url_match_positions.end(), | 283 bookmark_match.url_match_positions.end(), |
| 284 ScoringFunctor(bookmark_match.node->url().spec().length())); | 284 ScoringFunctor( |
| 285 bookmark_match.node->GetTitledUrlNodeUrl().spec().length())); |
| 285 const double title_match_strength = title_position_functor.ScoringFactor(); | 286 const double title_match_strength = title_position_functor.ScoringFactor(); |
| 286 const double summed_factors = title_match_strength + | 287 const double summed_factors = title_match_strength + |
| 287 url_position_functor.ScoringFactor(); | 288 url_position_functor.ScoringFactor(); |
| 288 const double normalized_sum = | 289 const double normalized_sum = |
| 289 std::min(summed_factors / (title.size() + 10), 1.0); | 290 std::min(summed_factors / (title.size() + 10), 1.0); |
| 290 // Bookmarks with javascript scheme ("bookmarklets") that do not have title | 291 // Bookmarks with javascript scheme ("bookmarklets") that do not have title |
| 291 // matches get a lower base and lower maximum score because returning them | 292 // matches get a lower base and lower maximum score because returning them |
| 292 // for matches in their (often very long) URL looks stupid and is often not | 293 // for matches in their (often very long) URL looks stupid and is often not |
| 293 // intended by the user. | 294 // intended by the user. |
| 294 const bool bookmarklet_without_title_match = | 295 const bool bookmarklet_without_title_match = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 i != positions.end(); | 334 i != positions.end(); |
| 334 ++i) { | 335 ++i) { |
| 335 AutocompleteMatch::ACMatchClassifications new_class; | 336 AutocompleteMatch::ACMatchClassifications new_class; |
| 336 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, | 337 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, |
| 337 text_length, url_style, &new_class); | 338 text_length, url_style, &new_class); |
| 338 classifications = AutocompleteMatch::MergeClassifications( | 339 classifications = AutocompleteMatch::MergeClassifications( |
| 339 classifications, new_class); | 340 classifications, new_class); |
| 340 } | 341 } |
| 341 return classifications; | 342 return classifications; |
| 342 } | 343 } |
| OLD | NEW |