Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/autocomplete/search_provider.h

Issue 23164011: Omnibox: Reduce Bolding Flicker in SearchProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: even fancier solution Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 Search autocomplete provider. This provider is 5 // This file contains the Search autocomplete provider. This provider is
6 // responsible for all autocomplete entries that start with "Search <engine> 6 // responsible for all autocomplete entries that start with "Search <engine>
7 // for ...", including searching for the current input string, search 7 // for ...", including searching for the current input string, search
8 // history, and search suggestions. An instance of it gets created and 8 // history, and search suggestions. An instance of it gets created and
9 // managed by the autocomplete controller. 9 // managed by the autocomplete controller.
10 10
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 public net::URLFetcherDelegate { 53 public net::URLFetcherDelegate {
54 public: 54 public:
55 // ID used in creating URLFetcher for default provider's suggest results. 55 // ID used in creating URLFetcher for default provider's suggest results.
56 static const int kDefaultProviderURLFetcherID; 56 static const int kDefaultProviderURLFetcherID;
57 57
58 // ID used in creating URLFetcher for keyword provider's suggest results. 58 // ID used in creating URLFetcher for keyword provider's suggest results.
59 static const int kKeywordProviderURLFetcherID; 59 static const int kKeywordProviderURLFetcherID;
60 60
61 SearchProvider(AutocompleteProviderListener* listener, Profile* profile); 61 SearchProvider(AutocompleteProviderListener* listener, Profile* profile);
62 62
63 // Returns an AutocompleteMatch with the given |autocomplete_provider|,
64 // |relevance|, and |type|, which represents a search via |template_url| for
65 // |query_string|. If |template_url| is NULL, returns a match with an invalid
66 // destination URL.
67 //
68 // |input_text| is the original user input, which may differ from
69 // |query_string|; e.g. the user typed "foo" and got a search suggestion of
70 // "food", which we're now marking up. This is used to highlight portions of
71 // the match contents to distinguish locally-typed text from suggested text.
72 //
73 // |input| and |is_keyword| are necessary for various other details, like
74 // whether we should allow inline autocompletion and what the transition type
75 // should be. |accepted_suggestion| and |omnibox_start_margin| are used along
76 // with |input_text| to generate Assisted Query Stats.
77 // |append_extra_query_params| should be set if |template_url| is the default
78 // search engine, so the destination URL will contain any
79 // command-line-specified query params.
80 static AutocompleteMatch CreateSearchSuggestion(
81 AutocompleteProvider* autocomplete_provider,
82 int relevance,
83 AutocompleteMatch::Type type,
84 const TemplateURL* template_url,
85 const string16& query_string,
86 const string16& input_text,
87 const AutocompleteInput& input,
88 bool is_keyword,
89 int accepted_suggestion,
90 int omnibox_start_margin,
91 bool append_extra_query_params);
92
93 // AutocompleteProvider: 63 // AutocompleteProvider:
94 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; 64 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE;
95 virtual void ResetSession() OVERRIDE; 65 virtual void ResetSession() OVERRIDE;
96 66
97 bool field_trial_triggered_in_session() const { 67 bool field_trial_triggered_in_session() const {
98 return field_trial_triggered_in_session_; 68 return field_trial_triggered_in_session_;
99 } 69 }
100 70
101 private: 71 private:
102 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after 72 // TODO(hfung): Remove ZeroSuggestProvider as a friend class after
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool from_keyword_provider() const { return from_keyword_provider_; } 144 bool from_keyword_provider() const { return from_keyword_provider_; }
175 145
176 int relevance() const { return relevance_; } 146 int relevance() const { return relevance_; }
177 void set_relevance(int relevance) { relevance_ = relevance; } 147 void set_relevance(int relevance) { relevance_ = relevance; }
178 148
179 bool relevance_from_server() const { return relevance_from_server_; } 149 bool relevance_from_server() const { return relevance_from_server_; }
180 void set_relevance_from_server(bool relevance_from_server) { 150 void set_relevance_from_server(bool relevance_from_server) {
181 relevance_from_server_ = relevance_from_server; 151 relevance_from_server_ = relevance_from_server;
182 } 152 }
183 153
154 const string16& contents() const { return contents_; }
155 const ACMatchClassifications& contents_class() const {
156 return contents_class_;
157 }
158
184 // Returns if this result is inlineable against the current input |input|. 159 // Returns if this result is inlineable against the current input |input|.
185 // Non-inlineable results are stale. 160 // Non-inlineable results are stale.
186 virtual bool IsInlineable(const string16& input) const = 0; 161 virtual bool IsInlineable(const string16& input) const = 0;
187 162
188 // Returns the default relevance value for this result (which may 163 // Returns the default relevance value for this result (which may
189 // be left over from a previous omnibox input) given the current 164 // be left over from a previous omnibox input) given the current
190 // input and whether the current input caused a keyword provider 165 // input and whether the current input caused a keyword provider
191 // to be active. 166 // to be active.
192 virtual int CalculateRelevance(const AutocompleteInput& input, 167 virtual int CalculateRelevance(const AutocompleteInput& input,
193 bool keyword_provider_requested) const = 0; 168 bool keyword_provider_requested) const = 0;
194 169
195 protected: 170 protected:
196 // True if the result came from the keyword provider. 171 // True if the result came from the keyword provider.
197 bool from_keyword_provider_; 172 bool from_keyword_provider_;
198 173
199 // The relevance score. 174 // The relevance score.
200 int relevance_; 175 int relevance_;
201 176
177 // The main text displayed in the address bar dropdown.
178 string16 contents_;
179 ACMatchClassifications contents_class_;
180
202 private: 181 private:
203 // Whether this result's relevance score was fully or partly calculated 182 // Whether this result's relevance score was fully or partly calculated
204 // based on server information, and thus is assumed to be more accurate. 183 // based on server information, and thus is assumed to be more accurate.
205 // This is ultimately used in 184 // This is ultimately used in
206 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments 185 // SearchProvider::ConvertResultsToAutocompleteMatches(), see comments
207 // there. 186 // there.
208 bool relevance_from_server_; 187 bool relevance_from_server_;
209 }; 188 };
210 189
211 class SuggestResult : public Result { 190 class SuggestResult : public Result {
212 public: 191 public:
192 // Most parameters are self-explanatory. |input_text| is used to
193 // determine highlighting (i.e., populate |contents_| and
194 // |contents_class_|). We determine highlighting at the time
195 // the SuggestResult is created in order to reduce flicker as
196 // additional characters are typed or deleted.
213 SuggestResult(const string16& suggestion, 197 SuggestResult(const string16& suggestion,
214 bool from_keyword_provider, 198 bool from_keyword_provider,
215 int relevance, 199 int relevance,
216 bool relevance_from_server); 200 bool relevance_from_server,
201 const string16& input_text);
217 virtual ~SuggestResult(); 202 virtual ~SuggestResult();
218 203
219 const string16& suggestion() const { return suggestion_; } 204 const string16& suggestion() const { return suggestion_; }
220 205
206 // Fills in |contents_| and |contents_class_| to reflect how |contents_|
207 // should be displayed and bolded against the current |input_text|. If
208 // |allow_bolding_all| is false and the new |contents_class_| would have
209 // all of |contents_| bolded, do nothing.
210 void CalculateContents(bool allow_bolding_all,
211 const string16& input_text);
212
221 // Result: 213 // Result:
222 virtual bool IsInlineable(const string16& input) const OVERRIDE; 214 virtual bool IsInlineable(const string16& input) const OVERRIDE;
223 virtual int CalculateRelevance( 215 virtual int CalculateRelevance(
224 const AutocompleteInput& input, 216 const AutocompleteInput& input,
225 bool keyword_provider_requested) const OVERRIDE; 217 bool keyword_provider_requested) const OVERRIDE;
226 218
227 private: 219 private:
228 // The search suggestion string. 220 // The search suggestion string.
229 string16 suggestion_; 221 string16 suggestion_;
230 }; 222 };
231 223
232 class NavigationResult : public Result { 224 class NavigationResult : public Result {
233 public: 225 public:
234 // |provider| is necessary to use StringForURLDisplay() in order to 226 // |provider| is necessary to use StringForURLDisplay() in order to
235 // compute |formatted_url_|. 227 // compute |formatted_url_|.
228 // |input_text| and |languages| are used to determine
229 // highlighting (i.e., populate |contents_| and |contents_class_|).
230 // We determine highlighting at the time the NavigationResult is
231 // created in order to reduce flicker as additional characters are
232 // typed or deleted.
236 NavigationResult(const AutocompleteProvider& provider, 233 NavigationResult(const AutocompleteProvider& provider,
237 const GURL& url, 234 const GURL& url,
238 const string16& description, 235 const string16& description,
239 bool from_keyword_provider, 236 bool from_keyword_provider,
240 int relevance, 237 int relevance,
241 bool relevance_from_server); 238 bool relevance_from_server,
239 const string16& input_text,
240 const std::string& languages);
242 virtual ~NavigationResult(); 241 virtual ~NavigationResult();
243 242
244 const GURL& url() const { return url_; } 243 const GURL& url() const { return url_; }
245 const string16& description() const { return description_; } 244 const string16& description() const { return description_; }
246 const string16& formatted_url() const { return formatted_url_; } 245 const string16& formatted_url() const { return formatted_url_; }
247 246
247 // Fills in |contents_| and |contents_class_| to reflect how |contents_|
248 // should be displayed and bolded against the current |input_text| and
249 // user's |language|. If |allow_bolding_nothing| is false and
250 // overwriting |contents_| and |contents_class_| would result in an
251 // entirely unbolded |contents_|, do nothing.
252 void CalculateContents(bool allow_bolding_nothing,
253 const string16& input_text,
254 const std::string languages);
255
248 // Result: 256 // Result:
249 virtual bool IsInlineable(const string16& input) const OVERRIDE; 257 virtual bool IsInlineable(const string16& input) const OVERRIDE;
250 virtual int CalculateRelevance( 258 virtual int CalculateRelevance(
251 const AutocompleteInput& input, 259 const AutocompleteInput& input,
252 bool keyword_provider_requested) const OVERRIDE; 260 bool keyword_provider_requested) const OVERRIDE;
253 261
254 private: 262 private:
255 // The suggested url for navigation. 263 // The suggested url for navigation.
256 GURL url_; 264 GURL url_;
257 265
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 // indicate that there is no suggested score; a value of 0 305 // indicate that there is no suggested score; a value of 0
298 // suppresses the verbatim result. 306 // suppresses the verbatim result.
299 int verbatim_relevance; 307 int verbatim_relevance;
300 308
301 private: 309 private:
302 DISALLOW_COPY_AND_ASSIGN(Results); 310 DISALLOW_COPY_AND_ASSIGN(Results);
303 }; 311 };
304 312
305 virtual ~SearchProvider(); 313 virtual ~SearchProvider();
306 314
315 // Returns an AutocompleteMatch with the given |autocomplete_provider|,
316 // and |type| based on the search query suggestion represented in |result|
317 // The AutocompleteMatch represents a search via |template_url| for this
318 // suggestion. If |template_url| is NULL, returns a match with an invalid
319 // destination URL.
320 //
321 // |input_text| is the original user input, which may differ from
322 // |result.suggestion()|; e.g. the user typed "foo" and got a search
323 // suggestion of "food", which we're now marking up. This is used to
324 // decide whether the match returned is inlineable.
325 //
326 // |input| and |is_keyword| are necessary for various other details, like
327 // whether we should allow inline autocompletion and what the transition type
328 // should be. |accepted_suggestion| and |omnibox_start_margin| are used along
329 // with |input_text| to generate Assisted Query Stats.
330 // |append_extra_query_params| should be set if |template_url| is the default
331 // search engine, so the destination URL will contain any
332 // command-line-specified query params.
333 static AutocompleteMatch CreateSearchSuggestion(
Mark P 2013/08/16 23:25:58 This is both a move from its previous location and
334 AutocompleteProvider* autocomplete_provider,
335 const SuggestResult& result,
336 AutocompleteMatch::Type type,
337 const TemplateURL* template_url,
338 const string16& input_text,
339 const AutocompleteInput& input,
340 int accepted_suggestion,
341 int omnibox_start_margin,
342 bool append_extra_query_params);
343
307 // Removes non-inlineable results until either the top result can inline 344 // Removes non-inlineable results until either the top result can inline
308 // autocomplete the current input or verbatim outscores the top result. 345 // autocomplete the current input or verbatim outscores the top result.
309 static void RemoveStaleResults(const string16& input, 346 static void RemoveStaleResults(const string16& input,
310 int verbatim_relevance, 347 int verbatim_relevance,
311 SuggestResults* suggest_results, 348 SuggestResults* suggest_results,
312 NavigationResults* navigation_results); 349 NavigationResults* navigation_results);
313 350
351 // For every result in |results| (suggest or navigation), call
352 // CalculateContents(), which may replace its contents and bolding to
353 // better display against the current input.
354 static void RecalculateBolding(const string16& input_text,
355 const std::string languages,
356 Results* results);
357
314 // Calculates the relevance score for the keyword verbatim result (if the 358 // Calculates the relevance score for the keyword verbatim result (if the
315 // input matches one of the profile's keyword). 359 // input matches one of the profile's keyword).
316 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type, 360 static int CalculateRelevanceForKeywordVerbatim(AutocompleteInput::Type type,
317 bool prefer_keyword); 361 bool prefer_keyword);
318 362
319 // AutocompleteProvider: 363 // AutocompleteProvider:
320 virtual void Start(const AutocompleteInput& input, 364 virtual void Start(const AutocompleteInput& input,
321 bool minimal_changes) OVERRIDE; 365 bool minimal_changes) OVERRIDE;
322 virtual void Stop(bool clear_cached_results) OVERRIDE; 366 virtual void Stop(bool clear_cached_results) OVERRIDE;
323 367
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // scores. When using the aggressive method, scores may exceed 1300 482 // scores. When using the aggressive method, scores may exceed 1300
439 // unless |prevent_search_history_inlining| is set. 483 // unless |prevent_search_history_inlining| is set.
440 int CalculateRelevanceForHistory(const base::Time& time, 484 int CalculateRelevanceForHistory(const base::Time& time,
441 bool is_keyword, 485 bool is_keyword,
442 bool use_aggressive_method, 486 bool use_aggressive_method,
443 bool prevent_search_history_inlining) const; 487 bool prevent_search_history_inlining) const;
444 488
445 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with 489 // Creates an AutocompleteMatch for "Search <engine> for |query_string|" with
446 // the supplied relevance. Adds this match to |map|; if such a match already 490 // the supplied relevance. Adds this match to |map|; if such a match already
447 // exists, whichever one has lower relevance is eliminated. 491 // exists, whichever one has lower relevance is eliminated.
448 void AddMatchToMap(const string16& query_string, 492 void AddMatchToMap(const SuggestResult& result,
449 const string16& input_text, 493 const string16& input_text,
450 int relevance,
451 bool relevance_from_server,
452 AutocompleteMatch::Type type, 494 AutocompleteMatch::Type type,
453 int accepted_suggestion, 495 int accepted_suggestion,
454 bool is_keyword,
455 MatchMap* map); 496 MatchMap* map);
456 497
457 // Returns an AutocompleteMatch for a navigational suggestion. 498 // Returns an AutocompleteMatch for a navigational suggestion.
458 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation); 499 AutocompleteMatch NavigationToMatch(const NavigationResult& navigation);
459 500
460 // Resets the scores of all |keyword_navigation_results_| matches to 501 // Resets the scores of all |keyword_navigation_results_| matches to
461 // be below that of the top keyword query match (the verbatim match 502 // be below that of the top keyword query match (the verbatim match
462 // as expressed by |keyword_verbatim_relevance_| or keyword query 503 // as expressed by |keyword_verbatim_relevance_| or keyword query
463 // suggestions stored in |keyword_suggest_results_|). If there 504 // suggestions stored in |keyword_suggest_results_|). If there
464 // are no keyword suggestions and keyword verbatim is suppressed, 505 // are no keyword suggestions and keyword verbatim is suppressed,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 bool field_trial_triggered_in_session_; 567 bool field_trial_triggered_in_session_;
527 568
528 // If true, search history query suggestions will score low enough that 569 // If true, search history query suggestions will score low enough that
529 // they will not be inlined. 570 // they will not be inlined.
530 bool prevent_search_history_inlining_; 571 bool prevent_search_history_inlining_;
531 572
532 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 573 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
533 }; 574 };
534 575
535 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 576 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698