| 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 "chrome/browser/autocomplete/bookmark_provider.h" | 5 #include "chrome/browser/autocomplete/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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // exact order to match. | 79 // exact order to match. |
| 80 // | 80 // |
| 81 // Please refer to the code for BookmarkIndex::GetBookmarksMatching for | 81 // Please refer to the code for BookmarkIndex::GetBookmarksMatching for |
| 82 // complete details of how searches are performed against the user's | 82 // complete details of how searches are performed against the user's |
| 83 // bookmarks. | 83 // bookmarks. |
| 84 bookmark_model_->GetBookmarksMatching(input.text(), | 84 bookmark_model_->GetBookmarksMatching(input.text(), |
| 85 kMaxBookmarkMatches, | 85 kMaxBookmarkMatches, |
| 86 &matches); | 86 &matches); |
| 87 if (matches.empty()) | 87 if (matches.empty()) |
| 88 return; // There were no matches. | 88 return; // There were no matches. |
| 89 AutocompleteInput fixed_up_input(input); | 89 base::string16 fixed_up_input(FixupUserInput(input, true)); |
| 90 FixupUserInput(&fixed_up_input); | |
| 91 for (BookmarkMatches::const_iterator i = matches.begin(); i != matches.end(); | 90 for (BookmarkMatches::const_iterator i = matches.begin(); i != matches.end(); |
| 92 ++i) { | 91 ++i) { |
| 93 // Create and score the AutocompleteMatch. If its score is 0 then the | 92 // Create and score the AutocompleteMatch. If its score is 0 then the |
| 94 // match is discarded. | 93 // match is discarded. |
| 95 AutocompleteMatch match(BookmarkMatchToACMatch(input, fixed_up_input, *i)); | 94 AutocompleteMatch match(BookmarkMatchToACMatch(input, fixed_up_input, *i)); |
| 96 if (match.relevance > 0) | 95 if (match.relevance > 0) |
| 97 matches_.push_back(match); | 96 matches_.push_back(match); |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Sort and clip the resulting matches. | 99 // Sort and clip the resulting matches. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 131 | 130 |
| 132 private: | 131 private: |
| 133 double title_length_; | 132 double title_length_; |
| 134 double scoring_factor_; | 133 double scoring_factor_; |
| 135 }; | 134 }; |
| 136 | 135 |
| 137 } // namespace | 136 } // namespace |
| 138 | 137 |
| 139 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch( | 138 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch( |
| 140 const AutocompleteInput& input, | 139 const AutocompleteInput& input, |
| 141 const AutocompleteInput& fixed_up_input, | 140 const base::string16& fixed_up_input_text, |
| 142 const BookmarkMatch& bookmark_match) { | 141 const BookmarkMatch& bookmark_match) { |
| 143 // The AutocompleteMatch we construct is non-deletable because the only | 142 // The AutocompleteMatch we construct is non-deletable because the only |
| 144 // way to support this would be to delete the underlying bookmark, which is | 143 // way to support this would be to delete the underlying bookmark, which is |
| 145 // unlikely to be what the user intends. | 144 // unlikely to be what the user intends. |
| 146 AutocompleteMatch match(this, 0, false, | 145 AutocompleteMatch match(this, 0, false, |
| 147 AutocompleteMatchType::BOOKMARK_TITLE); | 146 AutocompleteMatchType::BOOKMARK_TITLE); |
| 148 base::string16 title(bookmark_match.node->GetTitle()); | 147 base::string16 title(bookmark_match.node->GetTitle()); |
| 149 const GURL& url(bookmark_match.node->url()); | 148 const GURL& url(bookmark_match.node->url()); |
| 150 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec()); | 149 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec()); |
| 151 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset( | 150 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset( |
| 152 input, fixed_up_input, false, url_utf16); | 151 input.text(), fixed_up_input_text, false, url_utf16); |
| 153 match.destination_url = url; | 152 match.destination_url = url; |
| 154 const size_t match_start = bookmark_match.url_match_positions.empty() ? | 153 const size_t match_start = bookmark_match.url_match_positions.empty() ? |
| 155 0 : bookmark_match.url_match_positions[0].first; | 154 0 : bookmark_match.url_match_positions[0].first; |
| 156 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && | 155 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && |
| 157 ((match_start == base::string16::npos) || (match_start != 0)); | 156 ((match_start == base::string16::npos) || (match_start != 0)); |
| 158 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( | 157 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( |
| 159 bookmark_match.url_match_positions); | 158 bookmark_match.url_match_positions); |
| 160 // In addition to knowing how |offsets| is transformed, we need to know how | 159 // In addition to knowing how |offsets| is transformed, we need to know how |
| 161 // |inline_autocomplete_offset| is transformed. We add it to the end of | 160 // |inline_autocomplete_offset| is transformed. We add it to the end of |
| 162 // |offsets|, compute how everything is transformed, then remove it from the | 161 // |offsets|, compute how everything is transformed, then remove it from the |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 i != positions.end(); | 309 i != positions.end(); |
| 311 ++i) { | 310 ++i) { |
| 312 AutocompleteMatch::ACMatchClassifications new_class; | 311 AutocompleteMatch::ACMatchClassifications new_class; |
| 313 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, | 312 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, |
| 314 text_length, url_style, &new_class); | 313 text_length, url_style, &new_class); |
| 315 classifications = AutocompleteMatch::MergeClassifications( | 314 classifications = AutocompleteMatch::MergeClassifications( |
| 316 classifications, new_class); | 315 classifications, new_class); |
| 317 } | 316 } |
| 318 return classifications; | 317 return classifications; |
| 319 } | 318 } |
| OLD | NEW |