OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 enum Type { | 166 enum Type { |
167 INVALID, // Empty input | 167 INVALID, // Empty input |
168 UNKNOWN, // Valid input whose type cannot be determined | 168 UNKNOWN, // Valid input whose type cannot be determined |
169 REQUESTED_URL, // Input autodetected as UNKNOWN, which the user wants to | 169 REQUESTED_URL, // Input autodetected as UNKNOWN, which the user wants to |
170 // treat as an URL by specifying a desired_tld | 170 // treat as an URL by specifying a desired_tld |
171 URL, // Input autodetected as a URL | 171 URL, // Input autodetected as a URL |
172 QUERY, // Input autodetected as a query | 172 QUERY, // Input autodetected as a query |
173 FORCED_QUERY, // Input forced to be a query by an initial '?' | 173 FORCED_QUERY, // Input forced to be a query by an initial '?' |
174 }; | 174 }; |
175 | 175 |
176 AutocompleteInput() | 176 AutocompleteInput(); |
177 : type_(INVALID), | |
178 prevent_inline_autocomplete_(false), | |
179 prefer_keyword_(false), | |
180 synchronous_only_(false) { | |
181 } | |
182 | |
183 AutocompleteInput(const std::wstring& text, | 177 AutocompleteInput(const std::wstring& text, |
184 const std::wstring& desired_tld, | 178 const std::wstring& desired_tld, |
185 bool prevent_inline_autocomplete, | 179 bool prevent_inline_autocomplete, |
186 bool prefer_keyword, | 180 bool prefer_keyword, |
187 bool synchronous_only); | 181 bool synchronous_only); |
| 182 ~AutocompleteInput(); |
188 | 183 |
189 // Converts |type| to a string representation. Used in logging. | 184 // Converts |type| to a string representation. Used in logging. |
190 static std::string TypeToString(Type type); | 185 static std::string TypeToString(Type type); |
191 | 186 |
192 // Parses |text| and returns the type of input this will be interpreted as. | 187 // Parses |text| and returns the type of input this will be interpreted as. |
193 // The components of the input are stored in the output parameter |parts|, if | 188 // The components of the input are stored in the output parameter |parts|, if |
194 // it is non-NULL. | 189 // it is non-NULL. |
195 static Type Parse(const std::wstring& text, | 190 static Type Parse(const std::wstring& text, |
196 const std::wstring& desired_tld, | 191 const std::wstring& desired_tld, |
197 url_parse::Parsed* parts, | 192 url_parse::Parsed* parts, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 OPEN_HISTORY_PAGE, // A synthetic result that opens the history page | 335 OPEN_HISTORY_PAGE, // A synthetic result that opens the history page |
341 // to search for the input. | 336 // to search for the input. |
342 NUM_TYPES, | 337 NUM_TYPES, |
343 }; | 338 }; |
344 | 339 |
345 AutocompleteMatch(); | 340 AutocompleteMatch(); |
346 AutocompleteMatch(AutocompleteProvider* provider, | 341 AutocompleteMatch(AutocompleteProvider* provider, |
347 int relevance, | 342 int relevance, |
348 bool deletable, | 343 bool deletable, |
349 Type type); | 344 Type type); |
| 345 ~AutocompleteMatch(); |
350 | 346 |
351 // Converts |type| to a string representation. Used in logging. | 347 // Converts |type| to a string representation. Used in logging. |
352 static std::string TypeToString(Type type); | 348 static std::string TypeToString(Type type); |
353 | 349 |
354 // Converts |type| to a resource identifier for the appropriate icon for this | 350 // Converts |type| to a resource identifier for the appropriate icon for this |
355 // type. | 351 // type. |
356 static int TypeToIcon(Type type); | 352 static int TypeToIcon(Type type); |
357 | 353 |
358 // Comparison function for determining when one match is better than another. | 354 // Comparison function for determining when one match is better than another. |
359 static bool MoreRelevant(const AutocompleteMatch& elem1, | 355 static bool MoreRelevant(const AutocompleteMatch& elem1, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // queries. Do not call this for a synchronous query. | 480 // queries. Do not call this for a synchronous query. |
485 // | 481 // |
486 // NOTE: There's no parameter to tell the listener _which_ provider is | 482 // NOTE: There's no parameter to tell the listener _which_ provider is |
487 // calling it. Because the AutocompleteController (the typical listener) | 483 // calling it. Because the AutocompleteController (the typical listener) |
488 // doesn't cache the providers' individual matches locally, it has to get | 484 // doesn't cache the providers' individual matches locally, it has to get |
489 // them all again when this is called anyway, so such a parameter wouldn't | 485 // them all again when this is called anyway, so such a parameter wouldn't |
490 // actually be useful. | 486 // actually be useful. |
491 virtual void OnProviderUpdate(bool updated_matches) = 0; | 487 virtual void OnProviderUpdate(bool updated_matches) = 0; |
492 | 488 |
493 protected: | 489 protected: |
494 virtual ~ACProviderListener() {} | 490 virtual ~ACProviderListener(); |
495 }; | 491 }; |
496 | 492 |
497 AutocompleteProvider(ACProviderListener* listener, | 493 AutocompleteProvider(ACProviderListener* listener, |
498 Profile* profile, | 494 Profile* profile, |
499 const char* name) | 495 const char* name); |
500 : profile_(profile), | |
501 listener_(listener), | |
502 done_(true), | |
503 name_(name) { | |
504 } | |
505 | 496 |
506 // Invoked when the profile changes. | 497 // Invoked when the profile changes. |
507 // NOTE: Do not access any previous Profile* at this point as it may have | 498 // NOTE: Do not access any previous Profile* at this point as it may have |
508 // already been deleted. | 499 // already been deleted. |
509 void SetProfile(Profile* profile); | 500 void SetProfile(Profile* profile); |
510 | 501 |
511 // Called to start an autocomplete query. The provider is responsible for | 502 // Called to start an autocomplete query. The provider is responsible for |
512 // tracking its matches for this query and whether it is done processing the | 503 // tracking its matches for this query and whether it is done processing the |
513 // query. When new matches are available or the provider finishes, it | 504 // query. When new matches are available or the provider finishes, it |
514 // calls the controller's OnProviderUpdate() method. The controller can then | 505 // calls the controller's OnProviderUpdate() method. The controller can then |
515 // get the new matches using the provider's accessors. | 506 // get the new matches using the provider's accessors. |
516 // Exception: Matches available immediately after starting the query (that | 507 // Exception: Matches available immediately after starting the query (that |
517 // is, synchronously) do not cause any notifications to be sent. The | 508 // is, synchronously) do not cause any notifications to be sent. The |
518 // controller is expected to check for these without prompting (since | 509 // controller is expected to check for these without prompting (since |
519 // otherwise, starting each provider running would result in a flurry of | 510 // otherwise, starting each provider running would result in a flurry of |
520 // notifications). | 511 // notifications). |
521 // | 512 // |
522 // Once Stop() has been called, no more notifications should be sent. | 513 // Once Stop() has been called, no more notifications should be sent. |
523 // | 514 // |
524 // |minimal_changes| is an optimization that lets the provider do less work | 515 // |minimal_changes| is an optimization that lets the provider do less work |
525 // when the |input|'s text hasn't changed. See the body of | 516 // when the |input|'s text hasn't changed. See the body of |
526 // AutocompletePopupModel::StartAutocomplete(). | 517 // AutocompletePopupModel::StartAutocomplete(). |
527 virtual void Start(const AutocompleteInput& input, | 518 virtual void Start(const AutocompleteInput& input, |
528 bool minimal_changes) = 0; | 519 bool minimal_changes) = 0; |
529 | 520 |
530 // Called when a provider must not make any more callbacks for the current | 521 // Called when a provider must not make any more callbacks for the current |
531 // query. This will be called regardless of whether the provider is already | 522 // query. This will be called regardless of whether the provider is already |
532 // done. | 523 // done. |
533 virtual void Stop() { | 524 virtual void Stop(); |
534 done_ = true; | |
535 } | |
536 | 525 |
537 // Returns the set of matches for the current query. | 526 // Returns the set of matches for the current query. |
538 const ACMatches& matches() const { return matches_; } | 527 const ACMatches& matches() const { return matches_; } |
539 | 528 |
540 // Returns whether the provider is done processing the query. | 529 // Returns whether the provider is done processing the query. |
541 bool done() const { return done_; } | 530 bool done() const { return done_; } |
542 | 531 |
543 // Returns the name of this provider. | 532 // Returns the name of this provider. |
544 const char* name() const { return name_; } | 533 const char* name() const { return name_; } |
545 | 534 |
546 // Called to delete a match and the backing data that produced it. This | 535 // Called to delete a match and the backing data that produced it. This |
547 // match should not appear again in this or future queries. This can only be | 536 // match should not appear again in this or future queries. This can only be |
548 // called for matches the provider marks as deletable. This should only be | 537 // called for matches the provider marks as deletable. This should only be |
549 // called when no query is running. | 538 // called when no query is running. |
550 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. | 539 // NOTE: Remember to call OnProviderUpdate() if matches_ is updated. |
551 virtual void DeleteMatch(const AutocompleteMatch& match) {} | 540 virtual void DeleteMatch(const AutocompleteMatch& match); |
552 | 541 |
553 // A suggested upper bound for how many matches a provider should return. | 542 // A suggested upper bound for how many matches a provider should return. |
554 // TODO(pkasting): http://b/1111299 , http://b/933133 This should go away once | 543 // TODO(pkasting): http://b/1111299 , http://b/933133 This should go away once |
555 // we have good relevance heuristics; the controller should handle all | 544 // we have good relevance heuristics; the controller should handle all |
556 // culling. | 545 // culling. |
557 static const size_t kMaxMatches; | 546 static const size_t kMaxMatches; |
558 | 547 |
559 protected: | 548 protected: |
560 friend class base::RefCountedThreadSafe<AutocompleteProvider>; | 549 friend class base::RefCountedThreadSafe<AutocompleteProvider>; |
561 | 550 |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 AutocompleteInput::Type input_type; | 879 AutocompleteInput::Type input_type; |
891 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). | 880 // Selected index (if selected) or -1 (AutocompletePopupModel::kNoMatch). |
892 size_t selected_index; | 881 size_t selected_index; |
893 // Inline autocompleted length (if displayed). | 882 // Inline autocompleted length (if displayed). |
894 size_t inline_autocompleted_length; | 883 size_t inline_autocompleted_length; |
895 // Result set. | 884 // Result set. |
896 const AutocompleteResult& result; | 885 const AutocompleteResult& result; |
897 }; | 886 }; |
898 | 887 |
899 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ | 888 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_H_ |
OLD | NEW |