summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 23:05:26 +0000
committerscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-27 23:05:26 +0000
commit9ac400986952037b777600f720f79215ee685037 (patch)
tree8dd6978836c25394560b1941015180f305f592d8 /chrome
parent5a484224887687a7d46d9aa0094c544b6e4518a8 (diff)
downloadchromium_src-9ac400986952037b777600f720f79215ee685037.zip
chromium_src-9ac400986952037b777600f720f79215ee685037.tar.gz
chromium_src-9ac400986952037b777600f720f79215ee685037.tar.bz2
[GTK] Added unit tests for omnibox highlighting
BUG=55418 TEST=unit_tests --gtest_filter=AutocompletePopupViewGtkTest.\* should run tests on GTK but not Windows or Mac. Review URL: http://codereview.chromium.org/4082002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@64169 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc212
-rw-r--r--chrome/browser/autocomplete/autocomplete.h207
-rw-r--r--chrome/browser/autocomplete/autocomplete_browsertest.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_classifier.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm1
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_win.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_match.cc188
-rw-r--r--chrome/browser/autocomplete/autocomplete_match.h208
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_model.cc1
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc121
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc418
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.h1
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm1
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc1
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/history_quick_provider.cc2
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc1
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc1
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc1
-rw-r--r--chrome/browser/autocomplete/search_provider.cc1
-rw-r--r--chrome/browser/autocomplete/search_provider.h1
-rw-r--r--chrome/browser/autocomplete/search_provider_unittest.cc1
-rw-r--r--chrome/browser/automation/automation_provider_json.cc2
-rw-r--r--chrome/browser/automation/testing_automation_provider.cc2
-rw-r--r--chrome/browser/extensions/extension_omnibox_api.h2
-rw-r--r--chrome/browser/extensions/extension_omnibox_apitest.cc1
-rw-r--r--chrome/browser/gtk/gtk_util.cc1
-rw-r--r--chrome/browser/instant/instant_controller.cc2
-rw-r--r--chrome/browser/metrics/metrics_log.cc1
-rw-r--r--chrome/browser/omnibox_search_hint.cc2
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu.cc1
-rw-r--r--chrome/browser/toolbar_model.cc1
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc1
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h1
-rw-r--r--chrome/browser/views/frame/browser_root_view.cc1
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/automation/autocomplete_edit_proxy.h1
46 files changed, 970 insertions, 447 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index d5b6cc6..007fd2b 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -13,6 +13,7 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/history_quick_provider.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/autocomplete/history_contents_provider.h"
@@ -406,187 +407,6 @@ void AutocompleteInput::Clear() {
prefer_keyword_ = false;
}
-// AutocompleteMatch ----------------------------------------------------------
-
-AutocompleteMatch::AutocompleteMatch()
- : provider(NULL),
- relevance(0),
- deletable(false),
- inline_autocomplete_offset(std::wstring::npos),
- transition(PageTransition::GENERATED),
- is_history_what_you_typed_match(false),
- type(SEARCH_WHAT_YOU_TYPED),
- template_url(NULL),
- starred(false) {
-}
-
-AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
- int relevance,
- bool deletable,
- Type type)
- : provider(provider),
- relevance(relevance),
- deletable(deletable),
- inline_autocomplete_offset(std::wstring::npos),
- transition(PageTransition::TYPED),
- is_history_what_you_typed_match(false),
- type(type),
- template_url(NULL),
- starred(false) {
-}
-
-AutocompleteMatch::~AutocompleteMatch() {
-}
-
-// static
-std::string AutocompleteMatch::TypeToString(Type type) {
- const char* strings[NUM_TYPES] = {
- "url-what-you-typed",
- "history-url",
- "history-title",
- "history-body",
- "history-keyword",
- "navsuggest",
- "search-what-you-typed",
- "search-history",
- "search-suggest",
- "search-other-engine",
- "open-history-page",
- };
- DCHECK(arraysize(strings) == NUM_TYPES);
- return strings[type];
-}
-
-// static
-int AutocompleteMatch::TypeToIcon(Type type) {
- int icons[NUM_TYPES] = {
- IDR_OMNIBOX_HTTP,
- IDR_OMNIBOX_HTTP,
- IDR_OMNIBOX_HISTORY,
- IDR_OMNIBOX_HISTORY,
- IDR_OMNIBOX_HISTORY,
- IDR_OMNIBOX_HTTP,
- IDR_OMNIBOX_SEARCH,
- IDR_OMNIBOX_SEARCH,
- IDR_OMNIBOX_SEARCH,
- IDR_OMNIBOX_SEARCH,
- IDR_OMNIBOX_MORE,
- };
- DCHECK(arraysize(icons) == NUM_TYPES);
- return icons[type];
-}
-
-// static
-bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2) {
- // For equal-relevance matches, we sort alphabetically, so that providers
- // who return multiple elements at the same priority get a "stable" sort
- // across multiple updates.
- if (elem1.relevance == elem2.relevance)
- return elem1.contents > elem2.contents;
-
- // A negative relevance indicates the real relevance can be determined by
- // negating the value. If both relevances are negative, negate the result
- // so that we end up with positive relevances, then negative relevances with
- // the negative relevances sorted by absolute values.
- const bool result = elem1.relevance > elem2.relevance;
- return (elem1.relevance < 0 && elem2.relevance < 0) ? !result : result;
-}
-
-// static
-bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2) {
- // Sort identical destination_urls together. Place the most relevant matches
- // first, so that when we call std::unique(), these are the ones that get
- // preserved.
- return (elem1.destination_url != elem2.destination_url) ?
- (elem1.destination_url < elem2.destination_url) :
- MoreRelevant(elem1, elem2);
-}
-
-// static
-bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2) {
- return elem1.destination_url == elem2.destination_url;
-}
-
-// static
-void AutocompleteMatch::ClassifyMatchInString(
- const std::wstring& find_text,
- const std::wstring& text,
- int style,
- ACMatchClassifications* classification) {
- ClassifyLocationInString(text.find(find_text), find_text.length(),
- text.length(), style, classification);
-}
-
-void AutocompleteMatch::ClassifyLocationInString(
- size_t match_location,
- size_t match_length,
- size_t overall_length,
- int style,
- ACMatchClassifications* classification) {
- classification->clear();
-
- // Don't classify anything about an empty string
- // (AutocompleteMatch::Validate() checks this).
- if (overall_length == 0)
- return;
-
- // Mark pre-match portion of string (if any).
- if (match_location != 0) {
- classification->push_back(ACMatchClassification(0, style));
- }
-
- // Mark matching portion of string.
- if (match_location == std::wstring::npos) {
- // No match, above classification will suffice for whole string.
- return;
- }
- // Classifying an empty match makes no sense and will lead to validation
- // errors later.
- DCHECK(match_length > 0);
- classification->push_back(ACMatchClassification(match_location,
- (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
-
- // Mark post-match portion of string (if any).
- const size_t after_match(match_location + match_length);
- if (after_match < overall_length) {
- classification->push_back(ACMatchClassification(after_match, style));
- }
-}
-
-#ifndef NDEBUG
-void AutocompleteMatch::Validate() const {
- ValidateClassifications(contents, contents_class);
- ValidateClassifications(description, description_class);
-}
-
-void AutocompleteMatch::ValidateClassifications(
- const std::wstring& text,
- const ACMatchClassifications& classifications) const {
- if (text.empty()) {
- DCHECK(classifications.size() == 0);
- return;
- }
-
- // The classifications should always cover the whole string.
- DCHECK(classifications.size() > 0) << "No classification for text";
- DCHECK(classifications[0].offset == 0) << "Classification misses beginning";
- if (classifications.size() == 1)
- return;
-
- // The classifications should always be sorted.
- size_t last_offset = classifications[0].offset;
- for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
- i != classifications.end(); ++i) {
- DCHECK(i->offset > last_offset) << "Classification unsorted";
- DCHECK(i->offset < text.length()) << "Classification out of bounds";
- last_offset = i->offset;
- }
-}
-#endif
-
// AutocompleteProvider -------------------------------------------------------
// static
@@ -752,6 +572,36 @@ void AutocompleteResult::SortAndCull(const AutocompleteInput& input) {
alternate_nav_url_ = input.canonicalized_url();
}
+size_t AutocompleteResult::size() const {
+ return matches_.size();
+}
+
+bool AutocompleteResult::empty() const {
+ return matches_.empty();
+}
+
+AutocompleteResult::const_iterator AutocompleteResult::begin() const {
+ return matches_.begin();
+}
+
+AutocompleteResult::iterator AutocompleteResult::begin() {
+ return matches_.begin();
+}
+
+AutocompleteResult::const_iterator AutocompleteResult::end() const {
+ return matches_.end();
+}
+
+AutocompleteResult::iterator AutocompleteResult::end() {
+ return matches_.end();
+}
+
+// Returns the match at the given index.
+const AutocompleteMatch& AutocompleteResult::match_at(size_t index) const {
+ DCHECK(index < matches_.size());
+ return matches_[index];
+}
+
void AutocompleteResult::Reset() {
matches_.clear();
default_match_ = end();
diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h
index 23bd053..25c8341 100644
--- a/chrome/browser/autocomplete/autocomplete.h
+++ b/chrome/browser/autocomplete/autocomplete.h
@@ -12,7 +12,6 @@
#include "base/logging.h"
#include "base/ref_counted.h"
#include "base/timer.h"
-#include "chrome/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_parse.h"
@@ -271,195 +270,6 @@ class AutocompleteInput {
bool synchronous_only_;
};
-// AutocompleteMatch ----------------------------------------------------------
-
-// A single result line with classified spans. The autocomplete popup displays
-// the 'contents' and the 'description' (the description is optional) in the
-// autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when
-// that line is selected. fill_into_edit may be the same as 'description' for
-// things like URLs, but may be different for searches or other providers. For
-// example, a search result may say "Search for asdf" as the description, but
-// "asdf" should appear in the box.
-struct AutocompleteMatch {
- // Autocomplete matches contain strings that are classified according to a
- // separate vector of styles. This vector associates flags with particular
- // string segments, and must be in sorted order. All text must be associated
- // with some kind of classification. Even if a match has no distinct
- // segments, its vector should contain an entry at offset 0 with no flags.
- //
- // Example: The user typed "goog"
- // http://www.google.com/ Google
- // ^ ^ ^ ^ ^
- // 0, | 15, | 4,
- // 11,match 0,match
- //
- // This structure holds the classification information for each span.
- struct ACMatchClassification {
- // The values in here are not mutually exclusive -- use them like a
- // bitfield. This also means we use "int" instead of this enum type when
- // passing the values around, so the compiler doesn't complain.
- enum Style {
- NONE = 0,
- URL = 1 << 0, // A URL
- MATCH = 1 << 1, // A match for the user's search term
- DIM = 1 << 2, // "Helper text"
- };
-
- ACMatchClassification(size_t offset, int style)
- : offset(offset),
- style(style) {
- }
-
- // Offset within the string that this classification starts
- size_t offset;
-
- int style;
- };
-
- typedef std::vector<ACMatchClassification> ACMatchClassifications;
-
- // The type of this match.
- enum Type {
- URL_WHAT_YOU_TYPED = 0, // The input as a URL.
- HISTORY_URL, // A past page whose URL contains the input.
- HISTORY_TITLE, // A past page whose title contains the input.
- HISTORY_BODY, // A past page whose body contains the input.
- HISTORY_KEYWORD, // A past page whose keyword contains the input.
- NAVSUGGEST, // A suggested URL.
- SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default
- // engine).
- SEARCH_HISTORY, // A past search (with the default engine)
- // containing the input.
- SEARCH_SUGGEST, // A suggested search (with the default engine).
- SEARCH_OTHER_ENGINE, // A search with a non-default engine.
- OPEN_HISTORY_PAGE, // A synthetic result that opens the history page
- // to search for the input.
- NUM_TYPES,
- };
-
- AutocompleteMatch();
- AutocompleteMatch(AutocompleteProvider* provider,
- int relevance,
- bool deletable,
- Type type);
- ~AutocompleteMatch();
-
- // Converts |type| to a string representation. Used in logging.
- static std::string TypeToString(Type type);
-
- // Converts |type| to a resource identifier for the appropriate icon for this
- // type.
- static int TypeToIcon(Type type);
-
- // Comparison function for determining when one match is better than another.
- static bool MoreRelevant(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2);
-
- // Comparison functions for removing matches with duplicate destinations.
- static bool DestinationSortFunc(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2);
- static bool DestinationsEqual(const AutocompleteMatch& elem1,
- const AutocompleteMatch& elem2);
-
- // Helper functions for classes creating matches:
- // Fills in the classifications for |text|, using |style| as the base style
- // and marking the first instance of |find_text| as a match. (This match
- // will also not be dimmed, if |style| has DIM set.)
- static void ClassifyMatchInString(const std::wstring& find_text,
- const std::wstring& text,
- int style,
- ACMatchClassifications* classifications);
-
- // Similar to ClassifyMatchInString(), but for cases where the range to mark
- // as matching is already known (avoids calling find()). This can be helpful
- // when find() would be misleading (e.g. you want to mark the second match in
- // a string instead of the first).
- static void ClassifyLocationInString(size_t match_location,
- size_t match_length,
- size_t overall_length,
- int style,
- ACMatchClassifications* classifications);
-
- // The provider of this match, used to remember which provider the user had
- // selected when the input changes. This may be NULL, in which case there is
- // no provider (or memory of the user's selection).
- AutocompleteProvider* provider;
-
- // The relevance of this match. See table above for scores returned by
- // various providers. This is used to rank matches among all responding
- // providers, so different providers must be carefully tuned to supply
- // matches with appropriate relevance.
- //
- // If the relevance is negative, it will only be displayed if there are not
- // enough non-negative items in all the providers to max out the popup. In
- // this case, the relevance of the additional items will be inverted so they
- // can be mixed in with the rest of the relevances. This allows a provider
- // to group its matches, having the added items appear intermixed with its
- // other matches.
- //
- // TODO(pkasting): http://b/1111299 This should be calculated algorithmically,
- // rather than being a fairly fixed value defined by the table above.
- int relevance;
-
- // True if the user should be able to delete this match.
- bool deletable;
-
- // This string is loaded into the location bar when the item is selected
- // by pressing the arrow keys. This may be different than a URL, for example,
- // for search suggestions, this would just be the search terms.
- std::wstring fill_into_edit;
-
- // The position within fill_into_edit from which we'll display the inline
- // autocomplete string. This will be std::wstring::npos if this match should
- // not be inline autocompleted.
- size_t inline_autocomplete_offset;
-
- // The URL to actually load when the autocomplete item is selected. This URL
- // should be canonical so we can compare URLs with strcmp to avoid dupes.
- // It may be empty if there is no possible navigation.
- GURL destination_url;
-
- // The main text displayed in the address bar dropdown.
- std::wstring contents;
- ACMatchClassifications contents_class;
-
- // Additional helper text for each entry, such as a title or description.
- std::wstring description;
- ACMatchClassifications description_class;
-
- // The transition type to use when the user opens this match. By default
- // this is TYPED. Providers whose matches do not look like URLs should set
- // it to GENERATED.
- PageTransition::Type transition;
-
- // True when this match is the "what you typed" match from the history
- // system.
- bool is_history_what_you_typed_match;
-
- // Type of this match.
- Type type;
-
- // If this match corresponds to a keyword, this is the TemplateURL the
- // keyword was obtained from.
- const TemplateURL* template_url;
-
- // True if the user has starred the destination URL.
- bool starred;
-
-#ifndef NDEBUG
- // Does a data integrity check on this match.
- void Validate() const;
-
- // Checks one text/classifications pair for valid values.
- void ValidateClassifications(
- const std::wstring& text,
- const ACMatchClassifications& classifications) const;
-#endif
-};
-
-typedef AutocompleteMatch::ACMatchClassification ACMatchClassification;
-typedef std::vector<ACMatchClassification> ACMatchClassifications;
-
// AutocompleteProvider -------------------------------------------------------
// A single result provider for the autocomplete system. Given user input, the
@@ -642,18 +452,15 @@ class AutocompleteResult {
void SortAndCull(const AutocompleteInput& input);
// Vector-style accessors/operators.
- size_t size() const { return matches_.size(); }
- bool empty() const { return matches_.empty(); }
- const_iterator begin() const { return matches_.begin(); }
- iterator begin() { return matches_.begin(); }
- const_iterator end() const { return matches_.end(); }
- iterator end() { return matches_.end(); }
+ size_t size() const;
+ bool empty() const;
+ const_iterator begin() const;
+ iterator begin();
+ const_iterator end() const;
+ iterator end();
// Returns the match at the given index.
- const AutocompleteMatch& match_at(size_t index) const {
- DCHECK(index < matches_.size());
- return matches_[index];
- }
+ const AutocompleteMatch& match_at(size_t index) const;
// Get the default match for the query (not necessarily the first). Returns
// end() if there is no default match.
diff --git a/chrome/browser/autocomplete/autocomplete_browsertest.cc b/chrome/browser/autocomplete/autocomplete_browsertest.cc
index e14f004..f44191d 100644
--- a/chrome/browser/autocomplete/autocomplete_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_browsertest.cc
@@ -7,6 +7,7 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
diff --git a/chrome/browser/autocomplete/autocomplete_classifier.cc b/chrome/browser/autocomplete/autocomplete_classifier.cc
index 3e96ff5..88dc89c 100644
--- a/chrome/browser/autocomplete/autocomplete_classifier.cc
+++ b/chrome/browser/autocomplete/autocomplete_classifier.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "googleurl/src/gurl.h"
AutocompleteClassifier::AutocompleteClassifier(Profile* profile)
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index d5faec3..6505e6d 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -13,6 +13,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/browser_list.h"
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index a9cdf1a..99f5e80 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_
#pragma once
-#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/page_transition_types.h"
@@ -21,6 +21,7 @@ class SkBitmap;
class AutocompleteEditController;
class AutocompleteEditModel;
class AutocompleteEditView;
+class AutocompleteResult;
namespace gfx {
class Rect;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
index 2890fdd..7a808ad 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc
@@ -13,6 +13,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
index 1d645b3..0249c6b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc
@@ -16,6 +16,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/browser_process.h"
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index d902b85..aa4b9a6 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -14,6 +14,7 @@
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
#include "chrome/browser/browser_process.h"
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
index 5f26caa..328d55b 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_win.cc
@@ -31,6 +31,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_accessibility.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/browser_process.h"
diff --git a/chrome/browser/autocomplete/autocomplete_match.cc b/chrome/browser/autocomplete/autocomplete_match.cc
new file mode 100644
index 0000000..57d57cd
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_match.cc
@@ -0,0 +1,188 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "grit/theme_resources.h"
+
+// AutocompleteMatch ----------------------------------------------------------
+
+AutocompleteMatch::AutocompleteMatch()
+ : provider(NULL),
+ relevance(0),
+ deletable(false),
+ inline_autocomplete_offset(std::wstring::npos),
+ transition(PageTransition::GENERATED),
+ is_history_what_you_typed_match(false),
+ type(SEARCH_WHAT_YOU_TYPED),
+ template_url(NULL),
+ starred(false) {
+}
+
+AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
+ int relevance,
+ bool deletable,
+ Type type)
+ : provider(provider),
+ relevance(relevance),
+ deletable(deletable),
+ inline_autocomplete_offset(std::wstring::npos),
+ transition(PageTransition::TYPED),
+ is_history_what_you_typed_match(false),
+ type(type),
+ template_url(NULL),
+ starred(false) {
+}
+
+AutocompleteMatch::~AutocompleteMatch() {
+}
+
+// static
+std::string AutocompleteMatch::TypeToString(Type type) {
+ const char* strings[NUM_TYPES] = {
+ "url-what-you-typed",
+ "history-url",
+ "history-title",
+ "history-body",
+ "history-keyword",
+ "navsuggest",
+ "search-what-you-typed",
+ "search-history",
+ "search-suggest",
+ "search-other-engine",
+ "open-history-page",
+ };
+ DCHECK(arraysize(strings) == NUM_TYPES);
+ return strings[type];
+}
+
+// static
+int AutocompleteMatch::TypeToIcon(Type type) {
+ int icons[NUM_TYPES] = {
+ IDR_OMNIBOX_HTTP,
+ IDR_OMNIBOX_HTTP,
+ IDR_OMNIBOX_HISTORY,
+ IDR_OMNIBOX_HISTORY,
+ IDR_OMNIBOX_HISTORY,
+ IDR_OMNIBOX_HTTP,
+ IDR_OMNIBOX_SEARCH,
+ IDR_OMNIBOX_SEARCH,
+ IDR_OMNIBOX_SEARCH,
+ IDR_OMNIBOX_SEARCH,
+ IDR_OMNIBOX_MORE,
+ };
+ DCHECK(arraysize(icons) == NUM_TYPES);
+ return icons[type];
+}
+
+// static
+bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2) {
+ // For equal-relevance matches, we sort alphabetically, so that providers
+ // who return multiple elements at the same priority get a "stable" sort
+ // across multiple updates.
+ if (elem1.relevance == elem2.relevance)
+ return elem1.contents > elem2.contents;
+
+ // A negative relevance indicates the real relevance can be determined by
+ // negating the value. If both relevances are negative, negate the result
+ // so that we end up with positive relevances, then negative relevances with
+ // the negative relevances sorted by absolute values.
+ const bool result = elem1.relevance > elem2.relevance;
+ return (elem1.relevance < 0 && elem2.relevance < 0) ? !result : result;
+}
+
+// static
+bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2) {
+ // Sort identical destination_urls together. Place the most relevant matches
+ // first, so that when we call std::unique(), these are the ones that get
+ // preserved.
+ return (elem1.destination_url != elem2.destination_url) ?
+ (elem1.destination_url < elem2.destination_url) :
+ MoreRelevant(elem1, elem2);
+}
+
+// static
+bool AutocompleteMatch::DestinationsEqual(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2) {
+ return elem1.destination_url == elem2.destination_url;
+}
+
+// static
+void AutocompleteMatch::ClassifyMatchInString(
+ const std::wstring& find_text,
+ const std::wstring& text,
+ int style,
+ ACMatchClassifications* classification) {
+ ClassifyLocationInString(text.find(find_text), find_text.length(),
+ text.length(), style, classification);
+}
+
+void AutocompleteMatch::ClassifyLocationInString(
+ size_t match_location,
+ size_t match_length,
+ size_t overall_length,
+ int style,
+ ACMatchClassifications* classification) {
+ classification->clear();
+
+ // Don't classify anything about an empty string
+ // (AutocompleteMatch::Validate() checks this).
+ if (overall_length == 0)
+ return;
+
+ // Mark pre-match portion of string (if any).
+ if (match_location != 0) {
+ classification->push_back(ACMatchClassification(0, style));
+ }
+
+ // Mark matching portion of string.
+ if (match_location == std::wstring::npos) {
+ // No match, above classification will suffice for whole string.
+ return;
+ }
+ // Classifying an empty match makes no sense and will lead to validation
+ // errors later.
+ DCHECK(match_length > 0);
+ classification->push_back(ACMatchClassification(match_location,
+ (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM));
+
+ // Mark post-match portion of string (if any).
+ const size_t after_match(match_location + match_length);
+ if (after_match < overall_length) {
+ classification->push_back(ACMatchClassification(after_match, style));
+ }
+}
+
+#ifndef NDEBUG
+void AutocompleteMatch::Validate() const {
+ ValidateClassifications(contents, contents_class);
+ ValidateClassifications(description, description_class);
+}
+
+void AutocompleteMatch::ValidateClassifications(
+ const std::wstring& text,
+ const ACMatchClassifications& classifications) const {
+ if (text.empty()) {
+ DCHECK(classifications.size() == 0);
+ return;
+ }
+
+ // The classifications should always cover the whole string.
+ DCHECK(classifications.size() > 0) << "No classification for text";
+ DCHECK(classifications[0].offset == 0) << "Classification misses beginning";
+ if (classifications.size() == 1)
+ return;
+
+ // The classifications should always be sorted.
+ size_t last_offset = classifications[0].offset;
+ for (ACMatchClassifications::const_iterator i(classifications.begin() + 1);
+ i != classifications.end(); ++i) {
+ DCHECK(i->offset > last_offset) << "Classification unsorted";
+ DCHECK(i->offset < text.length()) << "Classification out of bounds";
+ last_offset = i->offset;
+ }
+}
+#endif
diff --git a/chrome/browser/autocomplete/autocomplete_match.h b/chrome/browser/autocomplete/autocomplete_match.h
new file mode 100644
index 0000000..4ad4a6e
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_match.h
@@ -0,0 +1,208 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
+#pragma once
+
+#include <vector>
+#include <string>
+
+#include "chrome/common/page_transition_types.h"
+#include "googleurl/src/gurl.h"
+
+class AutocompleteProvider;
+class PageTransition;
+class TemplateURL;
+
+// AutocompleteMatch ----------------------------------------------------------
+
+// A single result line with classified spans. The autocomplete popup displays
+// the 'contents' and the 'description' (the description is optional) in the
+// autocomplete dropdown, and fills in 'fill_into_edit' into the textbox when
+// that line is selected. fill_into_edit may be the same as 'description' for
+// things like URLs, but may be different for searches or other providers. For
+// example, a search result may say "Search for asdf" as the description, but
+// "asdf" should appear in the box.
+struct AutocompleteMatch {
+ // Autocomplete matches contain strings that are classified according to a
+ // separate vector of styles. This vector associates flags with particular
+ // string segments, and must be in sorted order. All text must be associated
+ // with some kind of classification. Even if a match has no distinct
+ // segments, its vector should contain an entry at offset 0 with no flags.
+ //
+ // Example: The user typed "goog"
+ // http://www.google.com/ Google
+ // ^ ^ ^ ^ ^
+ // 0, | 15, | 4,
+ // 11,match 0,match
+ //
+ // This structure holds the classification information for each span.
+ struct ACMatchClassification {
+ // The values in here are not mutually exclusive -- use them like a
+ // bitfield. This also means we use "int" instead of this enum type when
+ // passing the values around, so the compiler doesn't complain.
+ enum Style {
+ NONE = 0,
+ URL = 1 << 0, // A URL
+ MATCH = 1 << 1, // A match for the user's search term
+ DIM = 1 << 2, // "Helper text"
+ };
+
+ ACMatchClassification(size_t offset, int style)
+ : offset(offset),
+ style(style) {
+ }
+
+ // Offset within the string that this classification starts
+ size_t offset;
+
+ int style;
+ };
+
+ typedef std::vector<ACMatchClassification> ACMatchClassifications;
+
+ // The type of this match.
+ enum Type {
+ URL_WHAT_YOU_TYPED = 0, // The input as a URL.
+ HISTORY_URL, // A past page whose URL contains the input.
+ HISTORY_TITLE, // A past page whose title contains the input.
+ HISTORY_BODY, // A past page whose body contains the input.
+ HISTORY_KEYWORD, // A past page whose keyword contains the input.
+ NAVSUGGEST, // A suggested URL.
+ SEARCH_WHAT_YOU_TYPED, // The input as a search query (with the default
+ // engine).
+ SEARCH_HISTORY, // A past search (with the default engine)
+ // containing the input.
+ SEARCH_SUGGEST, // A suggested search (with the default engine).
+ SEARCH_OTHER_ENGINE, // A search with a non-default engine.
+ OPEN_HISTORY_PAGE, // A synthetic result that opens the history page
+ // to search for the input.
+ NUM_TYPES,
+ };
+
+ AutocompleteMatch();
+ AutocompleteMatch(AutocompleteProvider* provider,
+ int relevance,
+ bool deletable,
+ Type type);
+ ~AutocompleteMatch();
+
+ // Converts |type| to a string representation. Used in logging.
+ static std::string TypeToString(Type type);
+
+ // Converts |type| to a resource identifier for the appropriate icon for this
+ // type.
+ static int TypeToIcon(Type type);
+
+ // Comparison function for determining when one match is better than another.
+ static bool MoreRelevant(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2);
+
+ // Comparison functions for removing matches with duplicate destinations.
+ static bool DestinationSortFunc(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2);
+ static bool DestinationsEqual(const AutocompleteMatch& elem1,
+ const AutocompleteMatch& elem2);
+
+ // Helper functions for classes creating matches:
+ // Fills in the classifications for |text|, using |style| as the base style
+ // and marking the first instance of |find_text| as a match. (This match
+ // will also not be dimmed, if |style| has DIM set.)
+ static void ClassifyMatchInString(const std::wstring& find_text,
+ const std::wstring& text,
+ int style,
+ ACMatchClassifications* classifications);
+
+ // Similar to ClassifyMatchInString(), but for cases where the range to mark
+ // as matching is already known (avoids calling find()). This can be helpful
+ // when find() would be misleading (e.g. you want to mark the second match in
+ // a string instead of the first).
+ static void ClassifyLocationInString(size_t match_location,
+ size_t match_length,
+ size_t overall_length,
+ int style,
+ ACMatchClassifications* classifications);
+
+ // The provider of this match, used to remember which provider the user had
+ // selected when the input changes. This may be NULL, in which case there is
+ // no provider (or memory of the user's selection).
+ AutocompleteProvider* provider;
+
+ // The relevance of this match. See table above for scores returned by
+ // various providers. This is used to rank matches among all responding
+ // providers, so different providers must be carefully tuned to supply
+ // matches with appropriate relevance.
+ //
+ // If the relevance is negative, it will only be displayed if there are not
+ // enough non-negative items in all the providers to max out the popup. In
+ // this case, the relevance of the additional items will be inverted so they
+ // can be mixed in with the rest of the relevances. This allows a provider
+ // to group its matches, having the added items appear intermixed with its
+ // other matches.
+ //
+ // TODO(pkasting): http://b/1111299 This should be calculated algorithmically,
+ // rather than being a fairly fixed value defined by the table above.
+ int relevance;
+
+ // True if the user should be able to delete this match.
+ bool deletable;
+
+ // This string is loaded into the location bar when the item is selected
+ // by pressing the arrow keys. This may be different than a URL, for example,
+ // for search suggestions, this would just be the search terms.
+ std::wstring fill_into_edit;
+
+ // The position within fill_into_edit from which we'll display the inline
+ // autocomplete string. This will be std::wstring::npos if this match should
+ // not be inline autocompleted.
+ size_t inline_autocomplete_offset;
+
+ // The URL to actually load when the autocomplete item is selected. This URL
+ // should be canonical so we can compare URLs with strcmp to avoid dupes.
+ // It may be empty if there is no possible navigation.
+ GURL destination_url;
+
+ // The main text displayed in the address bar dropdown.
+ std::wstring contents;
+ ACMatchClassifications contents_class;
+
+ // Additional helper text for each entry, such as a title or description.
+ std::wstring description;
+ ACMatchClassifications description_class;
+
+ // The transition type to use when the user opens this match. By default
+ // this is TYPED. Providers whose matches do not look like URLs should set
+ // it to GENERATED.
+ PageTransition::Type transition;
+
+ // True when this match is the "what you typed" match from the history
+ // system.
+ bool is_history_what_you_typed_match;
+
+ // Type of this match.
+ Type type;
+
+ // If this match corresponds to a keyword, this is the TemplateURL the
+ // keyword was obtained from.
+ const TemplateURL* template_url;
+
+ // True if the user has starred the destination URL.
+ bool starred;
+
+#ifndef NDEBUG
+ // Does a data integrity check on this match.
+ void Validate() const;
+
+ // Checks one text/classifications pair for valid values.
+ void ValidateClassifications(
+ const std::wstring& text,
+ const ACMatchClassifications& classifications) const;
+#endif
+};
+
+typedef AutocompleteMatch::ACMatchClassification ACMatchClassification;
+typedef std::vector<ACMatchClassification> ACMatchClassifications;
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_MATCH_H_
diff --git a/chrome/browser/autocomplete/autocomplete_popup_model.cc b/chrome/browser/autocomplete/autocomplete_popup_model.cc
index a92d0d8..5b8f814 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_model.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_model.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/extensions/extensions_service.h"
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
index 9c8c1b8..088c9ad 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/defaults.h"
#include "chrome/browser/gtk/gtk_theme_provider.h"
@@ -109,7 +110,66 @@ size_t GetUTF8Offset(const std::wstring& wide_text, size_t wide_text_offset) {
return WideToUTF8(wide_text.substr(0, wide_text_offset)).size();
}
-void SetupLayoutForMatch(PangoLayout* layout,
+// Generates the normal URL color, a green color used in unhighlighted URL
+// text. It is a mix of |kURLTextColor| and the current text color. Unlike the
+// selected text color, it is more important to match the qualities of the
+// foreground typeface color instead of taking the background into account.
+GdkColor NormalURLColor(GdkColor foreground) {
+ color_utils::HSL fg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
+
+ color_utils::HSL hue_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
+
+ // Only allow colors that have a fair amount of saturation in them (color vs
+ // white). This means that our output color will always be fairly green.
+ double s = std::max(0.5, fg_hsl.s);
+
+ // Make sure the luminance is at least as bright as the |kURLTextColor| green
+ // would be if we were to use that.
+ double l;
+ if (fg_hsl.l < hue_hsl.l)
+ l = hue_hsl.l;
+ else
+ l = (fg_hsl.l + hue_hsl.l) / 2;
+
+ color_utils::HSL output = { hue_hsl.h, s, l };
+ return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
+}
+
+// Generates the selected URL color, a green color used on URL text in the
+// currently highlighted entry in the autocomplete popup. It's a mix of
+// |kURLTextColor|, the current text color, and the background color (the
+// select highlight). It is more important to contrast with the background
+// saturation than to look exactly like the foreground color.
+GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) {
+ color_utils::HSL fg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
+
+ color_utils::HSL bg_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(background), &bg_hsl);
+
+ color_utils::HSL hue_hsl;
+ color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
+
+ // The saturation of the text should be opposite of the background, clamped
+ // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but
+ // less than 0.8 so it's not the oversaturated neon-color.
+ double opposite_s = 1 - bg_hsl.s;
+ double s = std::max(0.2, std::min(0.8, opposite_s));
+
+ // The luminance should match the luminance of the foreground text. Again,
+ // we clamp so as to have at some amount of color (green) in the text.
+ double opposite_l = fg_hsl.l;
+ double l = std::max(0.1, std::min(0.9, opposite_l));
+
+ color_utils::HSL output = { hue_hsl.h, s, l };
+ return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
+}
+} // namespace
+
+void AutocompletePopupViewGtk::SetupLayoutForMatch(
+ PangoLayout* layout,
const std::wstring& text,
const AutocompleteMatch::ACMatchClassifications& classifications,
const GdkColor* base_color,
@@ -195,65 +255,6 @@ void SetupLayoutForMatch(PangoLayout* layout,
pango_attr_list_unref(attrs);
}
-// Generates the normal URL color, a green color used in unhighlighted URL
-// text. It is a mix of |kURLTextColor| and the current text color. Unlike the
-// selected text color, It is more important to match the qualities of the
-// foreground typeface color instead of taking the background into account.
-GdkColor NormalURLColor(GdkColor foreground) {
- color_utils::HSL fg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
-
- color_utils::HSL hue_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
-
- // Only allow colors that have a fair amount of saturation in them (color vs
- // white). This means that our output color will always be fairly green.
- double s = std::max(0.5, fg_hsl.s);
-
- // Make sure the luminance is at least as bright as the |kURLTextColor| green
- // would be if we were to use that.
- double l;
- if (fg_hsl.l < hue_hsl.l)
- l = hue_hsl.l;
- else
- l = (fg_hsl.l + hue_hsl.l) / 2;
-
- color_utils::HSL output = { hue_hsl.h, s, l };
- return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
-}
-
-// Generates the selected URL color, a green color used on URL text in the
-// currently highlighted entry in the autocomplete popup. It's a mix of
-// |kURLTextColor|, the current text color, and the background color (the
-// select highlight). It is more important to contrast with the background
-// saturation than to look exactly like the foreground color.
-GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) {
- color_utils::HSL fg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(foreground), &fg_hsl);
-
- color_utils::HSL bg_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(background), &bg_hsl);
-
- color_utils::HSL hue_hsl;
- color_utils::SkColorToHSL(gfx::GdkColorToSkColor(kURLTextColor), &hue_hsl);
-
- // The saturation of the text should be opposite of the background, clamped
- // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but
- // less than 0.8 so it's not the oversaturated neon-color.
- double opposite_s = 1 - bg_hsl.s;
- double s = std::max(0.2, std::min(0.8, opposite_s));
-
- // The luminance should match the luminance of the foreground text. Again,
- // we clamp so as to have at some amount of color (green) in the text.
- double opposite_l = fg_hsl.l;
- double l = std::max(0.1, std::min(0.9, opposite_l));
-
- color_utils::HSL output = { hue_hsl.h, s, l };
- return gfx::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255));
-}
-
-} // namespace
-
AutocompletePopupViewGtk::AutocompletePopupViewGtk(
AutocompleteEditView* edit_view,
AutocompleteEditModel* edit_model,
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
index 89bd697..590cc41 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk.h
@@ -8,9 +8,11 @@
#include <gtk/gtk.h>
#include <map>
+#include <string>
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
@@ -18,7 +20,6 @@
class AutocompleteEditModel;
class AutocompleteEditView;
-struct AutocompleteMatch;
class AutocompletePopupModel;
class GtkThemeProvider;
class Profile;
@@ -48,6 +49,17 @@ class AutocompletePopupViewGtk : public AutocompletePopupView,
const NotificationDetails& details);
private:
+ // Be friendly for unit tests.
+ friend class AutocompletePopupViewGtkTest;
+ static void SetupLayoutForMatch(
+ PangoLayout* layout,
+ const std::wstring& text,
+ const AutocompleteMatch::ACMatchClassifications& classifications,
+ const GdkColor* base_color,
+ const GdkColor* dim_color,
+ const GdkColor* url_color,
+ const std::string& prefix_text);
+
void Show(size_t num_results);
void Hide();
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc b/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc
new file mode 100644
index 0000000..a133b26
--- /dev/null
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc
@@ -0,0 +1,418 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h"
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "gfx/gtk_util.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+static const float kLargeWidth = 10000;
+
+const GdkColor kContentTextColor = GDK_COLOR_RGB(0x00, 0x00, 0x00);
+const GdkColor kDimContentTextColor = GDK_COLOR_RGB(0x80, 0x80, 0x80);
+const GdkColor kURLTextColor = GDK_COLOR_RGB(0x00, 0x88, 0x00);
+
+} // namespace
+
+class AutocompletePopupViewGtkTest : public PlatformTest {
+ public:
+ AutocompletePopupViewGtkTest() { }
+
+ virtual void SetUp() {
+ PlatformTest::SetUp();
+
+ window_ = gtk_window_new(GTK_WINDOW_POPUP);
+ layout_ = gtk_widget_create_pango_layout(window_, NULL);
+ }
+
+ virtual void TearDown() {
+ g_object_unref(layout_);
+ gtk_widget_destroy(window_);
+
+ PlatformTest::TearDown();
+ }
+
+ // The google C++ Testing Framework documentation suggests making
+ // accessors in the fixture so that each test doesn't need to be a
+ // friend of the class being tested. This method just proxies the
+ // call through after adding the fixture's layout_.
+ void SetupLayoutForMatch(
+ const std::wstring& text,
+ const AutocompleteMatch::ACMatchClassifications& classifications,
+ const GdkColor* base_color,
+ const GdkColor* dim_color,
+ const GdkColor* url_color,
+ const std::string& prefix_text) {
+ AutocompletePopupViewGtk::SetupLayoutForMatch(layout_,
+ text,
+ classifications,
+ base_color,
+ dim_color,
+ url_color,
+ prefix_text);
+ }
+
+ struct RunInfo {
+ PangoAttribute* attr_;
+ guint length_;
+ RunInfo() : attr_(NULL), length_(0) { }
+ };
+
+ RunInfo RunInfoForAttrType(guint location,
+ guint end_location,
+ PangoAttrType type) {
+ RunInfo retval;
+
+ PangoAttrList* attrs = pango_layout_get_attributes(layout_);
+ if (!attrs)
+ return retval;
+
+ PangoAttrIterator* attr_iter = pango_attr_list_get_iterator(attrs);
+ if (!attr_iter)
+ return retval;
+
+ for (gboolean more = true, findNextStart = false;
+ more;
+ more = pango_attr_iterator_next(attr_iter)) {
+ PangoAttribute* attr = pango_attr_iterator_get(attr_iter, type);
+
+ // This iterator segment doesn't have any elements of the
+ // desired type; keep looking.
+ if (!attr)
+ continue;
+
+ // Skip attribute ranges before the desired start point.
+ if (attr->end_index <= location)
+ continue;
+
+ // If the matching type went past the iterator segment, then set
+ // the length to the next start - location.
+ if (findNextStart) {
+ // If the start is still less than the location, then reset
+ // the match. Otherwise, check that the new attribute is, in
+ // fact different before shortening the run length.
+ if (attr->start_index <= location) {
+ findNextStart = false;
+ } else if (!pango_attribute_equal(retval.attr_, attr)) {
+ retval.length_ = attr->start_index - location;
+ break;
+ }
+ }
+
+ gint start_range, end_range;
+ pango_attr_iterator_range(attr_iter,
+ &start_range,
+ &end_range);
+
+ // Now we have a match. May need to keep going to shorten
+ // length if we reach a new item of the same type.
+ retval.attr_ = attr;
+ if (attr->end_index > (guint)end_range) {
+ retval.length_ = end_location - location;
+ findNextStart = true;
+ } else {
+ retval.length_ = attr->end_index - location;
+ break;
+ }
+ }
+
+ pango_attr_iterator_destroy(attr_iter);
+ return retval;
+ }
+
+ guint RunLengthForAttrType(guint location,
+ guint end_location,
+ PangoAttrType type) {
+ RunInfo info = RunInfoForAttrType(location,
+ end_location,
+ type);
+ return info.length_;
+ }
+
+ gboolean RunHasAttribute(guint location,
+ guint end_location,
+ PangoAttribute* attribute) {
+ RunInfo info = RunInfoForAttrType(location,
+ end_location,
+ attribute->klass->type);
+
+ return info.attr_ && pango_attribute_equal(info.attr_, attribute);
+ }
+
+ gboolean RunHasColor(guint location,
+ guint end_location,
+ const GdkColor& color) {
+ PangoAttribute* attribute =
+ pango_attr_foreground_new(color.red,
+ color.green,
+ color.blue);
+
+ gboolean retval = RunHasAttribute(location,
+ end_location,
+ attribute);
+
+ pango_attribute_destroy(attribute);
+
+ return retval;
+ }
+
+ gboolean RunHasWeight(guint location,
+ guint end_location,
+ PangoWeight weight) {
+ PangoAttribute* attribute = pango_attr_weight_new(weight);
+
+ gboolean retval = RunHasAttribute(location,
+ end_location,
+ attribute);
+
+ pango_attribute_destroy(attribute);
+
+ return retval;
+ }
+
+ GtkWidget* window_;
+ PangoLayout* layout_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AutocompletePopupViewGtkTest);
+};
+
+// Simple inputs with no matches should result in styled output who's
+// text matches the input string, with the passed-in color, and
+// nothing bolded.
+TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringNoMatch) {
+ const std::wstring kContents = L"This is a test";
+
+ AutocompleteMatch::ACMatchClassifications classifications;
+
+ SetupLayoutForMatch(kContents,
+ classifications,
+ &kContentTextColor,
+ &kDimContentTextColor,
+ &kURLTextColor,
+ std::string());
+
+ EXPECT_EQ(kContents.size(),
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+
+ EXPECT_TRUE(RunHasColor(0U,
+ kContents.size(),
+ kContentTextColor));
+
+ // This part's a little wacky - either we don't have a weight, or
+ // the weight run is the entire string and is NORMAL
+ guint weightLength = RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT);
+ if (weightLength) {
+ EXPECT_EQ(kContents.size(), weightLength);
+ EXPECT_TRUE(RunHasWeight(0U,
+ kContents.size(),
+ PANGO_WEIGHT_NORMAL));
+ }
+}
+
+// Identical to DecorateMatchedStringNoMatch, except test that URL
+// style gets a different color than we passed in.
+TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLNoMatch) {
+ const std::wstring kContents = L"This is a test";
+ AutocompleteMatch::ACMatchClassifications classifications;
+
+ classifications.push_back(
+ ACMatchClassification(0U, ACMatchClassification::URL));
+
+ SetupLayoutForMatch(kContents,
+ classifications,
+ &kContentTextColor,
+ &kDimContentTextColor,
+ &kURLTextColor,
+ std::string());
+
+ EXPECT_EQ(kContents.size(),
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(0U,
+ kContents.size(),
+ kURLTextColor));
+
+ // This part's a little wacky - either we don't have a weight, or
+ // the weight run is the entire string and is NORMAL
+ guint weightLength = RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT);
+ if (weightLength) {
+ EXPECT_EQ(kContents.size(), weightLength);
+ EXPECT_TRUE(RunHasWeight(0U,
+ kContents.size(),
+ PANGO_WEIGHT_NORMAL));
+ }
+}
+
+// Test that DIM works as expected.
+TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringDimNoMatch) {
+ const std::wstring kContents = L"This is a test";
+ // Dim "is".
+ const guint runLength1 = 5, runLength2 = 2, runLength3 = 7;
+ // Make sure nobody messed up the inputs.
+ EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
+
+ // Push each run onto classifications.
+ AutocompleteMatch::ACMatchClassifications classifications;
+ classifications.push_back(
+ ACMatchClassification(0U, ACMatchClassification::NONE));
+ classifications.push_back(
+ ACMatchClassification(runLength1, ACMatchClassification::DIM));
+ classifications.push_back(
+ ACMatchClassification(runLength1 + runLength2,
+ ACMatchClassification::NONE));
+
+ SetupLayoutForMatch(kContents,
+ classifications,
+ &kContentTextColor,
+ &kDimContentTextColor,
+ &kURLTextColor,
+ std::string());
+
+ // Check the runs have expected color and length.
+ EXPECT_EQ(runLength1,
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(0U,
+ kContents.size(),
+ kContentTextColor));
+ EXPECT_EQ(runLength2,
+ RunLengthForAttrType(runLength1,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(runLength1,
+ kContents.size(),
+ kDimContentTextColor));
+ EXPECT_EQ(runLength3,
+ RunLengthForAttrType(runLength1 + runLength2,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(runLength1 + runLength2,
+ kContents.size(),
+ kContentTextColor));
+
+ // This part's a little wacky - either we don't have a weight, or
+ // the weight run is the entire string and is NORMAL
+ guint weightLength = RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT);
+ if (weightLength) {
+ EXPECT_EQ(kContents.size(), weightLength);
+ EXPECT_TRUE(RunHasWeight(0U,
+ kContents.size(),
+ PANGO_WEIGHT_NORMAL));
+ }
+}
+
+// Test that the matched run gets bold-faced, but keeps the same
+// color.
+TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringMatch) {
+ const std::wstring kContents = L"This is a test";
+ // Match "is".
+ const guint runLength1 = 5, runLength2 = 2, runLength3 = 7;
+ // Make sure nobody messed up the inputs.
+ EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
+
+ // Push each run onto classifications.
+ AutocompleteMatch::ACMatchClassifications classifications;
+ classifications.push_back(
+ ACMatchClassification(0U, ACMatchClassification::NONE));
+ classifications.push_back(
+ ACMatchClassification(runLength1, ACMatchClassification::MATCH));
+ classifications.push_back(
+ ACMatchClassification(runLength1 + runLength2,
+ ACMatchClassification::NONE));
+
+ SetupLayoutForMatch(kContents,
+ classifications,
+ &kContentTextColor,
+ &kDimContentTextColor,
+ &kURLTextColor,
+ std::string());
+
+ // Check the runs have expected weight and length.
+ EXPECT_EQ(runLength1,
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT));
+ EXPECT_TRUE(RunHasWeight(0U,
+ kContents.size(),
+ PANGO_WEIGHT_NORMAL));
+ EXPECT_EQ(runLength2,
+ RunLengthForAttrType(runLength1,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT));
+ EXPECT_TRUE(RunHasWeight(runLength1,
+ kContents.size(),
+ PANGO_WEIGHT_BOLD));
+ EXPECT_EQ(runLength3,
+ RunLengthForAttrType(runLength1 + runLength2,
+ kContents.size(),
+ PANGO_ATTR_WEIGHT));
+ EXPECT_TRUE(RunHasWeight(runLength1 + runLength2,
+ kContents.size(),
+ PANGO_WEIGHT_NORMAL));
+
+ // The entire string should be the same, normal color.
+ EXPECT_EQ(kContents.size(),
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(0U,
+ kContents.size(),
+ kContentTextColor));
+}
+
+// Just like DecorateMatchedStringURLMatch, this time with URL style.
+TEST_F(AutocompletePopupViewGtkTest, DecorateMatchedStringURLMatch) {
+ const std::wstring kContents = L"http://hello.world/";
+ // Match "hello".
+ const guint runLength1 = 7, runLength2 = 5, runLength3 = 7;
+ // Make sure nobody messed up the inputs.
+ EXPECT_EQ(runLength1 + runLength2 + runLength3, kContents.size());
+
+ // Push each run onto classifications.
+ AutocompleteMatch::ACMatchClassifications classifications;
+ classifications.push_back(
+ ACMatchClassification(0U, ACMatchClassification::URL));
+ const int kURLMatch =
+ ACMatchClassification::URL | ACMatchClassification::MATCH;
+ classifications.push_back(
+ ACMatchClassification(runLength1,
+ kURLMatch));
+ classifications.push_back(
+ ACMatchClassification(runLength1 + runLength2,
+ ACMatchClassification::URL));
+
+ SetupLayoutForMatch(kContents,
+ classifications,
+ &kContentTextColor,
+ &kDimContentTextColor,
+ &kURLTextColor,
+ std::string());
+
+ // One color for the entire string, and it's not the one we passed
+ // in.
+ EXPECT_EQ(kContents.size(),
+ RunLengthForAttrType(0U,
+ kContents.size(),
+ PANGO_ATTR_FOREGROUND));
+ EXPECT_TRUE(RunHasColor(0U,
+ kContents.size(),
+ kURLTextColor));
+}
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
index 70a1ba4..20af4f0 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
@@ -14,6 +14,7 @@
#include "base/scoped_ptr.h"
#include "base/scoped_nsobject.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_view.h"
#include "gfx/font.h"
#include "webkit/glue/window_open_disposition.h"
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index 1e4f42f..6f26248 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -13,6 +13,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/cocoa/event_utils.h"
#include "chrome/browser/cocoa/image_utils.h"
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index fd0ebda..d78611c 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index 06e46d2..1d0c828 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -8,6 +8,7 @@
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/history/query_parser.h"
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index 4a76f26..9f1119b 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -7,6 +7,7 @@
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/history_contents_provider.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_thread.h"
diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc
index 04d1c7e1..236c1c4 100644
--- a/chrome/browser/autocomplete/history_quick_provider.cc
+++ b/chrome/browser/autocomplete/history_quick_provider.cc
@@ -9,6 +9,7 @@
#include "base/string_util.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
@@ -192,4 +193,3 @@ int HistoryQuickProvider::CalculateRelevance(int raw_score,
return 900 + static_cast<int>(match_number);
}
}
-
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index 4344a2e..6de941a 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -13,6 +13,7 @@
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/url_database.h"
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 30d63fb..0f75347 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -11,6 +11,7 @@
#include "base/metrics/histogram.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_database.h"
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index f330798..19f3053 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -7,6 +7,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/history/history.h"
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index 4f3ee5e..8bc133e 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -10,6 +10,7 @@
#include "app/l10n_util.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/extensions/extension_omnibox_api.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index 5583519..e63d548 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/message_loop.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index a13ef3e..71336bf 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -14,6 +14,7 @@
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/keyword_provider.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/history/history.h"
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 73b70fe..9cf52fc 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -22,6 +22,7 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/cancelable_request.h"
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/search_engines/template_url.h"
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc
index 595b688..3bf63c9 100644
--- a/chrome/browser/autocomplete/search_provider_unittest.cc
+++ b/chrome/browser/autocomplete/search_provider_unittest.cc
@@ -6,6 +6,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "build/build_config.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/search_provider.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/browser/history/history.h"
diff --git a/chrome/browser/automation/automation_provider_json.cc b/chrome/browser/automation/automation_provider_json.cc
index 2ffbeaa..c58b622 100644
--- a/chrome/browser/automation/automation_provider_json.cc
+++ b/chrome/browser/automation/automation_provider_json.cc
@@ -6,6 +6,7 @@
#include "base/json/json_writer.h"
#include "base/json/string_escape.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/test/automation/automation_messages.h"
@@ -53,4 +54,3 @@ void AutomationJSONReply::SendError(const std::string& error_message) {
provider_->Send(message_);
message_ = NULL;
}
-
diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc
index e62caae..1db722b 100644
--- a/chrome/browser/automation/testing_automation_provider.cc
+++ b/chrome/browser/automation/testing_automation_provider.cc
@@ -15,7 +15,9 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/app_modal_dialog.h"
#include "chrome/browser/app_modal_dialog_queue.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autofill/autofill_manager.h"
#include "chrome/browser/automation/automation_autocomplete_edit_tracker.h"
#include "chrome/browser/automation/automation_browser_tracker.h"
diff --git a/chrome/browser/extensions/extension_omnibox_api.h b/chrome/browser/extensions/extension_omnibox_api.h
index 538ce85..9d0dc99 100644
--- a/chrome/browser/extensions/extension_omnibox_api.h
+++ b/chrome/browser/extensions/extension_omnibox_api.h
@@ -7,7 +7,7 @@
#pragma once
#include "base/string16.h"
-#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/extensions/extension_function.h"
// Event router class for events related to the omnibox API.
diff --git a/chrome/browser/extensions/extension_omnibox_apitest.cc b/chrome/browser/extensions/extension_omnibox_apitest.cc
index f48d9a1..9f9c6a0 100644
--- a/chrome/browser/extensions/extension_omnibox_apitest.cc
+++ b/chrome/browser/extensions/extension_omnibox_apitest.cc
@@ -8,6 +8,7 @@
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
diff --git a/chrome/browser/gtk/gtk_util.cc b/chrome/browser/gtk/gtk_util.cc
index 005c3b9..c03e5ba 100644
--- a/chrome/browser/gtk/gtk_util.cc
+++ b/chrome/browser/gtk/gtk_util.cc
@@ -21,6 +21,7 @@
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/gtk/cairo_cached_surface.h"
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index d534cef..a790b96 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/instant/instant_controller.h"
#include "base/command_line.h"
-#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/instant/instant_delegate.h"
#include "chrome/browser/instant/instant_loader.h"
#include "chrome/browser/instant/instant_loader_manager.h"
diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc
index 7d602e6..5a7db76 100644
--- a/chrome/browser/metrics/metrics_log.cc
+++ b/chrome/browser/metrics/metrics_log.cc
@@ -17,6 +17,7 @@
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/gpu_process_host.h"
#include "chrome/browser/prefs/pref_service.h"
diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc
index e1ab84c..42cbe63 100644
--- a/chrome/browser/omnibox_search_hint.cc
+++ b/chrome/browser/omnibox_search_hint.cc
@@ -9,8 +9,10 @@
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/task.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
#include "chrome/browser/location_bar.h"
diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc
index d7aebcd..2d85f69 100644
--- a/chrome/browser/tab_contents/render_view_context_menu.cc
+++ b/chrome/browser/tab_contents/render_view_context_menu.cc
@@ -17,6 +17,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/debugger/devtools_manager.h"
diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc
index e8cdaaf..fb6d050 100644
--- a/chrome/browser/toolbar_model.cc
+++ b/chrome/browser/toolbar_model.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/toolbar_model.h"
#include "base/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_edit.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/cert_store.h"
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 807ee00..bfd7321 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -13,6 +13,7 @@
#include "base/i18n/rtl.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/instant/instant_opt_in.h"
#include "chrome/browser/views/bubble_border.h"
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
index 2924ce2..9a3e2bc 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
@@ -22,6 +22,7 @@
class AutocompleteEditModel;
class AutocompleteEditViewWin;
+struct AutocompleteMatch;
class BubbleBorder;
class Profile;
diff --git a/chrome/browser/views/frame/browser_root_view.cc b/chrome/browser/views/frame/browser_root_view.cc
index d2985dd..e423603 100644
--- a/chrome/browser/views/frame/browser_root_view.cc
+++ b/chrome/browser/views/frame/browser_root_view.cc
@@ -9,6 +9,7 @@
#include "app/os_exchange_data.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/frame/browser_view.h"
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 808cc86..d0c480b 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -117,6 +117,8 @@
'browser/autocomplete/autocomplete_edit_view_mac.mm',
'browser/autocomplete/autocomplete_edit_view_win.cc',
'browser/autocomplete/autocomplete_edit_view_win.h',
+ 'browser/autocomplete/autocomplete_match.cc',
+ 'browser/autocomplete/autocomplete_match.h',
'browser/autocomplete/autocomplete_popup_model.cc',
'browser/autocomplete/autocomplete_popup_model.h',
'browser/autocomplete/autocomplete_popup_view.h',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 841b631..0d6d79a 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -981,6 +981,7 @@
'browser/autocomplete_history_manager_unittest.cc',
'browser/autocomplete/autocomplete_edit_unittest.cc',
'browser/autocomplete/autocomplete_edit_view_mac_unittest.mm',
+ 'browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc',
'browser/autocomplete/autocomplete_popup_view_mac_unittest.mm',
'browser/autocomplete/autocomplete_unittest.cc',
'browser/autocomplete/history_contents_provider_unittest.cc',
@@ -1641,6 +1642,7 @@
}],
['toolkit_views==1', {
'sources!': [
+ 'browser/autocomplete/autocomplete_popup_view_gtk_unittest.cc',
'browser/gtk/bookmark_bar_gtk_unittest.cc',
'browser/gtk/bookmark_editor_gtk_unittest.cc',
'browser/gtk/gtk_chrome_shrinkable_hbox_unittest.cc',
diff --git a/chrome/test/automation/autocomplete_edit_proxy.h b/chrome/test/automation/autocomplete_edit_proxy.h
index d9af03d..e33824a 100644
--- a/chrome/test/automation/autocomplete_edit_proxy.h
+++ b/chrome/test/automation/autocomplete_edit_proxy.h
@@ -11,6 +11,7 @@
#include "base/string_number_conversions.h"
#include "chrome/browser/autocomplete/autocomplete.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/test/automation/automation_handle_tracker.h"
#include "googleurl/src/gurl.h"
#include "ipc/ipc_message.h"