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 // This file contains the keyword autocomplete provider. The keyword provider | 5 // This file contains the keyword autocomplete provider. The keyword provider |
6 // is responsible for remembering/suggesting user "search keyword queries" | 6 // is responsible for remembering/suggesting user "search keyword queries" |
7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An | 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An |
8 // instance of it gets created and managed by the autocomplete controller. | 8 // instance of it gets created and managed by the autocomplete controller. |
9 // KeywordProvider uses a TemplateURLService to find the set of keywords. | 9 // KeywordProvider uses a TemplateURLService to find the set of keywords. |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // Creates a fully marked-up AutocompleteMatch for a specific keyword. | 86 // Creates a fully marked-up AutocompleteMatch for a specific keyword. |
87 AutocompleteMatch CreateAutocompleteMatch(const string16& text, | 87 AutocompleteMatch CreateAutocompleteMatch(const string16& text, |
88 const string16& keyword, | 88 const string16& keyword, |
89 const AutocompleteInput& input); | 89 const AutocompleteInput& input); |
90 | 90 |
91 // AutocompleteProvider: | 91 // AutocompleteProvider: |
92 virtual void Start(const AutocompleteInput& input, | 92 virtual void Start(const AutocompleteInput& input, |
93 bool minimal_changes) OVERRIDE; | 93 bool minimal_changes) OVERRIDE; |
94 virtual void Stop(bool clear_cached_results) OVERRIDE; | 94 virtual void Stop(bool clear_cached_results) OVERRIDE; |
95 | 95 |
96 // Determines the relevance for some input, given its type, whether the user | |
Mark P
2013/01/21 20:18:17
This is an exact cut-and-paste.
| |
97 // typed the complete keyword, and whether the user is in "prefer keyword | |
98 // matches" mode, and whether the keyword supports replacement. | |
99 // If |allow_exact_keyword_match| is false, the relevance for complete | |
100 // keywords that support replacements is degraded. | |
101 static int CalculateRelevance(AutocompleteInput::Type type, | |
102 bool complete, | |
103 bool support_replacement, | |
104 bool prefer_keyword, | |
105 bool allow_exact_keyword_match); | |
106 | |
96 private: | 107 private: |
97 class ScopedEndExtensionKeywordMode; | 108 class ScopedEndExtensionKeywordMode; |
98 friend class ScopedEndExtensionKeywordMode; | 109 friend class ScopedEndExtensionKeywordMode; |
99 | 110 |
100 virtual ~KeywordProvider(); | 111 virtual ~KeywordProvider(); |
101 | 112 |
102 // Extracts the keyword from |input| into |keyword|. Any remaining characters | 113 // Extracts the keyword from |input| into |keyword|. Any remaining characters |
103 // after the keyword are placed in |remaining_input|. Returns true if |input| | 114 // after the keyword are placed in |remaining_input|. Returns true if |input| |
104 // is valid and has a keyword. This makes use of SplitKeywordFromInput to | 115 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
105 // extract the keyword and remaining string, and uses | 116 // extract the keyword and remaining string, and uses |
106 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. | 117 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. |
107 // In general use this instead of SplitKeywordFromInput. | 118 // In general use this instead of SplitKeywordFromInput. |
108 // Leading whitespace in |*remaining_input| will be trimmed. | 119 // Leading whitespace in |*remaining_input| will be trimmed. |
109 static bool ExtractKeywordFromInput(const AutocompleteInput& input, | 120 static bool ExtractKeywordFromInput(const AutocompleteInput& input, |
110 string16* keyword, | 121 string16* keyword, |
111 string16* remaining_input); | 122 string16* remaining_input); |
112 | 123 |
113 // Fills in the "destination_url" and "contents" fields of |match| with the | 124 // Fills in the "destination_url" and "contents" fields of |match| with the |
114 // provided user input and keyword data. | 125 // provided user input and keyword data. |
115 static void FillInURLAndContents(const string16& remaining_input, | 126 static void FillInURLAndContents(const string16& remaining_input, |
116 const TemplateURL* element, | 127 const TemplateURL* element, |
117 AutocompleteMatch* match); | 128 AutocompleteMatch* match); |
118 | 129 |
119 // Determines the relevance for some input, given its type, whether the user | |
120 // typed the complete keyword, and whether the user is in "prefer keyword | |
121 // matches" mode, and whether the keyword supports replacement. | |
122 // If |allow_exact_keyword_match| is false, the relevance for complete | |
123 // keywords that support replacements is degraded. | |
124 static int CalculateRelevance(AutocompleteInput::Type type, | |
125 bool complete, | |
126 bool support_replacement, | |
127 bool prefer_keyword, | |
128 bool allow_exact_keyword_match); | |
129 | |
130 // Creates a fully marked-up AutocompleteMatch from the user's input. | 130 // Creates a fully marked-up AutocompleteMatch from the user's input. |
131 // If |relevance| is negative, calculate a relevance based on heuristics. | 131 // If |relevance| is negative, calculate a relevance based on heuristics. |
132 AutocompleteMatch CreateAutocompleteMatch(TemplateURLService* model, | 132 AutocompleteMatch CreateAutocompleteMatch(TemplateURLService* model, |
133 const string16& keyword, | 133 const string16& keyword, |
134 const AutocompleteInput& input, | 134 const AutocompleteInput& input, |
135 size_t prefix_length, | 135 size_t prefix_length, |
136 const string16& remaining_input, | 136 const string16& remaining_input, |
137 int relevance); | 137 int relevance); |
138 | 138 |
139 void EnterExtensionKeywordMode(const std::string& extension_id); | 139 void EnterExtensionKeywordMode(const std::string& extension_id); |
(...skipping 26 matching lines...) Expand all Loading... | |
166 // If non-empty, holds the ID of the extension whose keyword is currently in | 166 // If non-empty, holds the ID of the extension whose keyword is currently in |
167 // the URL bar while the autocomplete popup is open. | 167 // the URL bar while the autocomplete popup is open. |
168 std::string current_keyword_extension_id_; | 168 std::string current_keyword_extension_id_; |
169 | 169 |
170 content::NotificationRegistrar registrar_; | 170 content::NotificationRegistrar registrar_; |
171 | 171 |
172 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 172 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
173 }; | 173 }; |
174 | 174 |
175 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 175 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
OLD | NEW |