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 | |
|
Peter Kasting
2012/08/31 01:51:19
Nit: Might make sense to write the full descriptio
sreeram
2012/09/04 17:42:16
Done.
| |
| 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); | |
| 71 virtual ~InstantController(); | 72 virtual ~InstantController(); |
| 72 | 73 |
| 74 // Creates a new InstantController. Caller owns the returned object. The | |
| 75 // |profile| pointer is not cached, so the underlying object need not live | |
| 76 // beyond this call. ***NOTE***: May return NULL, which means that Instant is | |
| 77 // disabled in this profile. | |
|
Peter Kasting
2012/08/31 01:51:19
Is it legal to call this multiple times on the sam
sreeram
2012/09/04 17:42:16
Yes, it's legal to call it multiple times. I think
| |
| 78 static InstantController* CreateInstant(Profile* profile, | |
| 79 InstantControllerDelegate* delegate); | |
| 80 | |
| 81 // Returns true if Instant is enabled and supports the extended API. | |
| 82 static bool IsExtendedAPIEnabled(Profile* profile); | |
| 83 | |
| 84 // Returns true if Instant is enabled in a visible, preview-showing mode. | |
| 85 static bool IsInstantEnabled(Profile* profile); | |
| 86 | |
| 87 // Returns true if Instant will provide autocomplete suggestions. | |
| 88 static bool IsSuggestEnabled(Profile* profile); | |
| 89 | |
| 73 // Registers Instant related preferences. | 90 // Registers Instant related preferences. |
| 74 static void RegisterUserPrefs(PrefService* prefs); | 91 static void RegisterUserPrefs(PrefService* prefs); |
| 75 | 92 |
| 76 // Returns true if Instant is enabled for the given |profile|. | |
| 77 static bool IsEnabled(Profile* profile); | |
| 78 | |
| 79 // Invoked as the user types into the omnibox. |user_text| is what the user | 93 // 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 | 94 // 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 | 95 // 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, | 96 // |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 | 97 // 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). | 98 // update is accepted (i.e., if |match| is a search rather than a URL). |
| 85 bool Update(const AutocompleteMatch& match, | 99 bool Update(const AutocompleteMatch& match, |
| 86 const string16& user_text, | 100 const string16& user_text, |
| 87 const string16& full_text, | 101 const string16& full_text, |
| 88 bool verbatim); | 102 bool verbatim); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 162 |
| 149 #if defined(UNIT_TEST) | 163 #if defined(UNIT_TEST) |
| 150 // Accessors used only in tests. | 164 // Accessors used only in tests. |
| 151 bool is_showing() const { return is_showing_; } | 165 bool is_showing() const { return is_showing_; } |
| 152 InstantLoader* loader() const { return loader_.get(); } | 166 InstantLoader* loader() const { return loader_.get(); } |
| 153 #endif | 167 #endif |
| 154 | 168 |
| 155 private: | 169 private: |
| 156 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 170 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
| 157 | 171 |
| 172 InstantController(InstantControllerDelegate* delegate, Mode mode); | |
| 173 | |
| 158 // Creates a new loader if necessary (for example, if the |instant_url| has | 174 // Creates a new loader if necessary (for example, if the |instant_url| has |
| 159 // changed since the last time we created the loader). | 175 // changed since the last time we created the loader). |
| 160 void ResetLoader(const std::string& instant_url, | 176 void ResetLoader(const std::string& instant_url, |
| 161 const TabContents* active_tab); | 177 const TabContents* active_tab); |
| 162 | 178 |
| 163 // Ensures that the |loader_| uses the default Instant URL, recreating it if | 179 // 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 | 180 // necessary. Will not do anything if the Instant URL could not be determined |
| 165 // or the active tab is NULL (browser is shutting down). | 181 // or the active tab is NULL (browser is shutting down). |
| 166 void CreateDefaultLoader(); | 182 void CreateDefaultLoader(); |
| 167 | 183 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 // Search terms extraction (for autocomplete history matches) doesn't work | 267 // Search terms extraction (for autocomplete history matches) doesn't work |
| 252 // on Instant URLs. So, whenever the user commits an Instant search, we add | 268 // 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 | 269 // an equivalent non-Instant search URL to history, so that the search shows |
| 254 // up in autocomplete history matches. | 270 // up in autocomplete history matches. |
| 255 GURL url_for_history_; | 271 GURL url_for_history_; |
| 256 | 272 |
| 257 DISALLOW_COPY_AND_ASSIGN(InstantController); | 273 DISALLOW_COPY_AND_ASSIGN(InstantController); |
| 258 }; | 274 }; |
| 259 | 275 |
| 260 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 276 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
| OLD | NEW |