Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 6 #define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 // invoked on the delegate. | 43 // invoked on the delegate. |
| 44 class InstantController : public InstantLoaderDelegate { | 44 class InstantController : public InstantLoaderDelegate { |
| 45 public: | 45 public: |
| 46 // Amount of time to wait before starting the animation for suggested text. | 46 // Amount of time to wait before starting the animation for suggested text. |
| 47 static const int kInlineAutocompletePauseTimeMS = 1000; | 47 static const int kInlineAutocompletePauseTimeMS = 1000; |
| 48 | 48 |
| 49 // Duration of the suggested text animation in which the colors change. | 49 // Duration of the suggested text animation in which the colors change. |
| 50 static const int kInlineAutocompleteFadeInTimeMS = 300; | 50 static const int kInlineAutocompleteFadeInTimeMS = 300; |
| 51 | 51 |
| 52 // InstantController may operate in one of these modes: | 52 // InstantController may operate in one of these modes: |
| 53 // EXTENDED: Similar to INSTANT, but with extended functionality, such as | |
| 54 // rendering suggestions within the preview and previews of URLs. | |
| 53 // INSTANT: The default search engine is preloaded when the omnibox gets | 55 // INSTANT: The default search engine is preloaded when the omnibox gets |
| 54 // focus. Queries are issued as the user types. Predicted queries are | 56 // focus. Queries are issued as the user types. Predicted queries are |
| 55 // inline autocompleted into the omnibox. Result previews are shown. | 57 // inline autocompleted into the omnibox. Result previews are shown. |
| 56 // SUGGEST: Same as INSTANT, without visible previews. | 58 // SUGGEST: Same as INSTANT, without visible previews. |
| 57 // HIDDEN: Same as SUGGEST, without the inline autocompletion. | 59 // HIDDEN: Same as SUGGEST, without the inline autocompletion. |
| 58 // SILENT: Same as HIDDEN, without issuing queries as the user types. The | 60 // SILENT: Same as HIDDEN, without issuing queries as the user types. The |
| 59 // query is sent only after the user presses <Enter>. | 61 // query is sent only after the user presses <Enter>. |
| 60 // EXTENDED: Similar to INSTANT, but with extended functionality, such as | 62 // DISABLED: Instant is disabled. |
| 61 // rendering suggestions within the preview and previews of URLs. | |
| 62 enum Mode { | 63 enum Mode { |
| 64 EXTENDED, | |
| 63 INSTANT, | 65 INSTANT, |
| 64 SUGGEST, | 66 SUGGEST, |
| 65 HIDDEN, | 67 HIDDEN, |
| 66 SILENT, | 68 SILENT, |
| 67 EXTENDED, | 69 DISABLED, |
| 68 }; | 70 }; |
| 69 | 71 |
| 70 InstantController(InstantControllerDelegate* delegate, Mode mode); | 72 // Returns true if Instant is enabled and supports the extended API. |
| 71 virtual ~InstantController(); | 73 static bool IsExtendedAPIEnabled(Profile* profile); |
| 74 | |
| 75 // Returns true if Instant is enabled in a visible, preview-showing mode. | |
| 76 static bool IsInstantEnabled(Profile* profile); | |
| 77 | |
| 78 // Returns true if Instant will provide autocomplete suggestions. | |
| 79 static bool IsSuggestEnabled(Profile* profile); | |
| 72 | 80 |
| 73 // Registers Instant related preferences. | 81 // Registers Instant related preferences. |
| 74 static void RegisterUserPrefs(PrefService* prefs); | 82 static void RegisterUserPrefs(PrefService* prefs); |
| 75 | 83 |
| 76 // Returns true if Instant is enabled for the given |profile|. | 84 // Factory-style constructor. The |profile| pointer is not cached, so the |
| 77 static bool IsEnabled(Profile* profile); | 85 // underlying object need not live beyond this call. May return NULL, which |
| 86 // means that Instant is disabled in this profile. | |
| 87 static InstantController* GetInstance(Profile* profile, | |
|
sky
2012/08/30 22:33:13
Naming this Get is misleading since it always crea
sreeram
2012/08/30 23:23:51
Done.
| |
| 88 InstantControllerDelegate* delegate); | |
| 89 virtual ~InstantController(); | |
|
sky
2012/08/30 22:33:13
constructor/destructor before any methods (includi
sreeram
2012/08/30 23:23:51
Done.
| |
| 78 | 90 |
| 79 // Invoked as the user types into the omnibox. |user_text| is what the user | 91 // Invoked as the user types into the omnibox. |user_text| is what the user |
| 80 // has typed. |full_text| is what the omnibox is showing. These may differ if | 92 // has typed. |full_text| is what the omnibox is showing. These may differ if |
| 81 // the user typed only some text, and the rest was inline autocompleted. If | 93 // the user typed only some text, and the rest was inline autocompleted. If |
| 82 // |verbatim| is true, search results are shown for the exact omnibox text, | 94 // |verbatim| is true, search results are shown for the exact omnibox text, |
| 83 // rather than the best guess as to what the user means. Returns true if the | 95 // rather than the best guess as to what the user means. Returns true if the |
| 84 // update is accepted (i.e., if |match| is a search rather than a URL). | 96 // update is accepted (i.e., if |match| is a search rather than a URL). |
| 85 bool Update(const AutocompleteMatch& match, | 97 bool Update(const AutocompleteMatch& match, |
| 86 const string16& user_text, | 98 const string16& user_text, |
| 87 const string16& full_text, | 99 const string16& full_text, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 160 |
| 149 #if defined(UNIT_TEST) | 161 #if defined(UNIT_TEST) |
| 150 // Accessors used only in tests. | 162 // Accessors used only in tests. |
| 151 bool is_showing() const { return is_showing_; } | 163 bool is_showing() const { return is_showing_; } |
| 152 InstantLoader* loader() const { return loader_.get(); } | 164 InstantLoader* loader() const { return loader_.get(); } |
| 153 #endif | 165 #endif |
| 154 | 166 |
| 155 private: | 167 private: |
| 156 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 168 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
| 157 | 169 |
| 170 InstantController(InstantControllerDelegate* delegate, Mode mode); | |
| 171 | |
| 158 // Creates a new loader if necessary (for example, if the |instant_url| has | 172 // Creates a new loader if necessary (for example, if the |instant_url| has |
| 159 // changed since the last time we created the loader). | 173 // changed since the last time we created the loader). |
| 160 void ResetLoader(const std::string& instant_url, | 174 void ResetLoader(const std::string& instant_url, |
| 161 const TabContents* active_tab); | 175 const TabContents* active_tab); |
| 162 | 176 |
| 163 // Ensures that the |loader_| uses the default Instant URL, recreating it if | 177 // Ensures that the |loader_| uses the default Instant URL, recreating it if |
| 164 // necessary. Will not do anything if the Instant URL could not be determined | 178 // necessary. Will not do anything if the Instant URL could not be determined |
| 165 // or the active tab is NULL (browser is shutting down). | 179 // or the active tab is NULL (browser is shutting down). |
| 166 void CreateDefaultLoader(); | 180 void CreateDefaultLoader(); |
| 167 | 181 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // Search terms extraction (for autocomplete history matches) doesn't work | 265 // Search terms extraction (for autocomplete history matches) doesn't work |
| 252 // on Instant URLs. So, whenever the user commits an Instant search, we add | 266 // on Instant URLs. So, whenever the user commits an Instant search, we add |
| 253 // an equivalent non-Instant search URL to history, so that the search shows | 267 // an equivalent non-Instant search URL to history, so that the search shows |
| 254 // up in autocomplete history matches. | 268 // up in autocomplete history matches. |
| 255 GURL url_for_history_; | 269 GURL url_for_history_; |
| 256 | 270 |
| 257 DISALLOW_COPY_AND_ASSIGN(InstantController); | 271 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 258 }; | 272 }; |
| 259 | 273 |
| 260 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 274 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |