diff options
Diffstat (limited to 'chrome/browser/autocomplete')
6 files changed, 71 insertions, 48 deletions
diff --git a/chrome/browser/autocomplete/history_provider.cc b/chrome/browser/autocomplete/history_provider.cc index 64d7063..efd6bb9 100644 --- a/chrome/browser/autocomplete/history_provider.cc +++ b/chrome/browser/autocomplete/history_provider.cc @@ -13,6 +13,7 @@ #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/history/in_memory_url_index_types.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/net/url_fixer_upper.h" #include "chrome/common/url_constants.h" @@ -157,3 +158,36 @@ bool HistoryProvider::PreventInlineAutocomplete( (!input.text().empty() && IsWhitespace(input.text()[input.text().length() - 1])); } + +// static +ACMatchClassifications HistoryProvider::SpansFromTermMatch( + const history::TermMatches& matches, + size_t text_length, + bool is_url) { + ACMatchClassification::Style url_style = + is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; + ACMatchClassifications spans; + if (matches.empty()) { + if (text_length) + spans.push_back(ACMatchClassification(0, url_style)); + return spans; + } + if (matches[0].offset) + spans.push_back(ACMatchClassification(0, url_style)); + size_t match_count = matches.size(); + for (size_t i = 0; i < match_count;) { + size_t offset = matches[i].offset; + spans.push_back(ACMatchClassification(offset, + ACMatchClassification::MATCH | url_style)); + // Skip all adjacent matches. + do { + offset += matches[i].length; + ++i; + } while ((i < match_count) && (offset == matches[i].offset)); + if (offset < text_length) + spans.push_back(ACMatchClassification(offset, url_style)); + } + + return spans; +} + diff --git a/chrome/browser/autocomplete/history_provider.h b/chrome/browser/autocomplete/history_provider.h index 6be0e2b..9a72b86 100644 --- a/chrome/browser/autocomplete/history_provider.h +++ b/chrome/browser/autocomplete/history_provider.h @@ -7,6 +7,7 @@ #include "base/compiler_specific.h" #include "chrome/browser/autocomplete/autocomplete_provider.h" +#include "chrome/browser/history/in_memory_url_index_types.h" class AutocompleteInput; struct AutocompleteMatch; @@ -53,6 +54,13 @@ class HistoryProvider : public AutocompleteProvider { // |input.prevent_inline_autocomplete()| is true or the input text contains // trailing whitespace. bool PreventInlineAutocomplete(const AutocompleteInput& input); + + // Fill and return an ACMatchClassifications structure given the |matches| + // to highlight. + static ACMatchClassifications SpansFromTermMatch( + const history::TermMatches& matches, + size_t text_length, + bool is_url); }; #endif // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_ diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc index 5982a71..0ae6b11 100644 --- a/chrome/browser/autocomplete/history_quick_provider.cc +++ b/chrome/browser/autocomplete/history_quick_provider.cc @@ -316,35 +316,3 @@ history::InMemoryURLIndex* HistoryQuickProvider::GetIndex() { return history_service->InMemoryIndex(); } - -// static -ACMatchClassifications HistoryQuickProvider::SpansFromTermMatch( - const history::TermMatches& matches, - size_t text_length, - bool is_url) { - ACMatchClassification::Style url_style = - is_url ? ACMatchClassification::URL : ACMatchClassification::NONE; - ACMatchClassifications spans; - if (matches.empty()) { - if (text_length) - spans.push_back(ACMatchClassification(0, url_style)); - return spans; - } - if (matches[0].offset) - spans.push_back(ACMatchClassification(0, url_style)); - size_t match_count = matches.size(); - for (size_t i = 0; i < match_count;) { - size_t offset = matches[i].offset; - spans.push_back(ACMatchClassification(offset, - ACMatchClassification::MATCH | url_style)); - // Skip all adjacent matches. - do { - offset += matches[i].length; - ++i; - } while ((i < match_count) && (offset == matches[i].offset)); - if (offset < text_length) - spans.push_back(ACMatchClassification(offset, url_style)); - } - - return spans; -} diff --git a/chrome/browser/autocomplete/history_quick_provider.h b/chrome/browser/autocomplete/history_quick_provider.h index 470e7b9..7d2c5cd 100644 --- a/chrome/browser/autocomplete/history_quick_provider.h +++ b/chrome/browser/autocomplete/history_quick_provider.h @@ -16,7 +16,6 @@ #include "chrome/browser/history/in_memory_url_index.h" class Profile; -class TermMatches; namespace history { class ScoredHistoryMatch; @@ -64,13 +63,6 @@ class HistoryQuickProvider : public HistoryProvider { // Returns the index that should be used for history lookups. history::InMemoryURLIndex* GetIndex(); - // Fill and return an ACMatchClassifications structure given the term - // matches (|matches|) to highlight where terms were found. - static ACMatchClassifications SpansFromTermMatch( - const history::TermMatches& matches, - size_t text_length, - bool is_url); - // Only for use in unittests. Takes ownership of |index|. void set_index(history::InMemoryURLIndex* index) { index_for_testing_.reset(index); diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index d28038a..45c660b 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -21,6 +21,8 @@ #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/history_types.h" +#include "chrome/browser/history/in_memory_url_index_types.h" +#include "chrome/browser/history/scored_history_match.h" #include "chrome/browser/omnibox/omnibox_field_trial.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url_service.h" @@ -771,10 +773,8 @@ bool HistoryURLProvider::FixupExactSuggestion( match->deletable = true; match->description = classifier.url_row().title(); RecordAdditionalInfoFromUrlRow(classifier.url_row(), match); - AutocompleteMatch::ClassifyMatchInString( - input.text(), - classifier.url_row().title(), - ACMatchClassification::NONE, &match->description_class); + match->description_class = + ClassifyDescription(input.text(), match->description); if (!classifier.url_row().typed_count()) { // If we reach here, we must be in the second pass, and we must not have // this row's data available during the first pass. That means we @@ -1087,10 +1087,25 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( &match.contents_class); } match.description = info.title(); - AutocompleteMatch::ClassifyMatchInString(params.input.text(), - info.title(), - ACMatchClassification::NONE, - &match.description_class); + match.description_class = + ClassifyDescription(params.input.text(), match.description); RecordAdditionalInfoFromUrlRow(info, &match); return match; } + +// static +ACMatchClassifications HistoryURLProvider::ClassifyDescription( + const string16& input_text, + const string16& description) { + string16 clean_description = history::CleanUpTitleForMatching(description); + history::TermMatches description_matches(SortAndDeoverlapMatches( + history::MatchTermInString(input_text, clean_description, 0))); + history::WordStarts description_word_starts; + history::String16VectorFromString16( + clean_description, false, &description_word_starts); + description_matches = + history::ScoredHistoryMatch::FilterTermMatchesByWordStarts( + description_matches, description_word_starts, 0); + return SpansFromTermMatch( + description_matches, clean_description.length(), false); +} diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h index b42faf3..610d35b 100644 --- a/chrome/browser/autocomplete/history_url_provider.h +++ b/chrome/browser/autocomplete/history_url_provider.h @@ -291,6 +291,12 @@ class HistoryURLProvider : public HistoryProvider { MatchType match_type, int relevance); + // Returns a set of classifications that highlight all the occurrences + // of |input_text| at word breaks in |description|. + static ACMatchClassifications ClassifyDescription( + const string16& input_text, + const string16& description); + // Params for the current query. The provider should not free this directly; // instead, it is passed as a parameter through the history backend, and the // parameter itself is freed once it's no longer needed. The only reason we |