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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 15 matching lines...) Expand all Loading... |
26 struct AutocompleteMatch; | 26 struct AutocompleteMatch; |
27 class InstantDelegate; | 27 class InstantDelegate; |
28 class InstantLoader; | 28 class InstantLoader; |
29 class InstantTest; | 29 class InstantTest; |
30 class PrefService; | 30 class PrefService; |
31 class Profile; | 31 class Profile; |
32 class TabContentsWrapper; | 32 class TabContentsWrapper; |
33 class TemplateURL; | 33 class TemplateURL; |
34 class TemplateURLService; | 34 class TemplateURLService; |
35 | 35 |
36 // InstantController maintains a TabContents that is intended to give a preview | 36 // InstantController maintains a WebContents that is intended to give a preview |
37 // of a URL. InstantController is owned by Browser. | 37 // of a URL. InstantController is owned by Browser. |
38 // | 38 // |
39 // At any time the TabContents maintained by InstantController may be destroyed | 39 // At any time the WebContents maintained by InstantController may be destroyed |
40 // by way of |DestroyPreviewContents|, which results in |HideInstant| being | 40 // by way of |DestroyPreviewContents|, which results in |HideInstant| being |
41 // invoked on the delegate. Similarly the preview may be committed at any time | 41 // invoked on the delegate. Similarly the preview may be committed at any time |
42 // by invoking |CommitCurrentPreview|, which results in |CommitInstant| | 42 // by invoking |CommitCurrentPreview|, which results in |CommitInstant| |
43 // being invoked on the delegate. Also see |PrepareForCommit| below. | 43 // being invoked on the delegate. Also see |PrepareForCommit| below. |
44 class InstantController : public InstantLoaderDelegate { | 44 class InstantController : public InstantLoaderDelegate { |
45 public: | 45 public: |
46 // Amount of time to wait before starting the instant animation. | 46 // Amount of time to wait before starting the instant animation. |
47 static const int kAutoCommitPauseTimeMS = 1000; | 47 static const int kAutoCommitPauseTimeMS = 1000; |
48 // Duration of the instant animation in which the colors change. | 48 // Duration of the instant animation in which the colors change. |
49 static const int kAutoCommitFadeInTimeMS = 300; | 49 static const int kAutoCommitFadeInTimeMS = 300; |
(...skipping 14 matching lines...) Expand all Loading... |
64 static void Enable(Profile* profile); | 64 static void Enable(Profile* profile); |
65 | 65 |
66 // Disables instant. | 66 // Disables instant. |
67 static void Disable(Profile* profile); | 67 static void Disable(Profile* profile); |
68 | 68 |
69 // Accepts the currently showing instant preview, if any, and returns true. | 69 // Accepts the currently showing instant preview, if any, and returns true. |
70 // Returns false if there is no instant preview showing. | 70 // Returns false if there is no instant preview showing. |
71 static bool CommitIfCurrent(InstantController* controller); | 71 static bool CommitIfCurrent(InstantController* controller); |
72 | 72 |
73 // Invoked as the user types in the omnibox with the url to navigate to. If | 73 // Invoked as the user types in the omnibox with the url to navigate to. If |
74 // the url is valid and a preview TabContents has not been created, it is | 74 // the url is valid and a preview WebContents has not been created, it is |
75 // created. If |verbatim| is true search results are shown for |user_text| | 75 // created. If |verbatim| is true search results are shown for |user_text| |
76 // rather than the best guess as to what the search thought the user meant. | 76 // rather than the best guess as to what the search thought the user meant. |
77 // |verbatim| only matters if the AutocompleteMatch is for a search engine | 77 // |verbatim| only matters if the AutocompleteMatch is for a search engine |
78 // that supports instant. Returns true if the attempt to update does not | 78 // that supports instant. Returns true if the attempt to update does not |
79 // result in the preview TabContents being destroyed. | 79 // result in the preview WebContents being destroyed. |
80 bool Update(TabContentsWrapper* tab_contents, | 80 bool Update(TabContentsWrapper* tab_contents, |
81 const AutocompleteMatch& match, | 81 const AutocompleteMatch& match, |
82 const string16& user_text, | 82 const string16& user_text, |
83 bool verbatim, | 83 bool verbatim, |
84 string16* suggested_text); | 84 string16* suggested_text); |
85 | 85 |
86 // Sets the bounds of the omnibox (in screen coordinates). The bounds are | 86 // Sets the bounds of the omnibox (in screen coordinates). The bounds are |
87 // remembered until the preview is committed or destroyed. This is only used | 87 // remembered until the preview is committed or destroyed. This is only used |
88 // when showing results for a search provider that supports instant. | 88 // when showing results for a search provider that supports instant. |
89 void SetOmniboxBounds(const gfx::Rect& bounds); | 89 void SetOmniboxBounds(const gfx::Rect& bounds); |
90 | 90 |
91 // Notifies the delegate to hide the preview and destroys the preview | 91 // Notifies the delegate to hide the preview and destroys the preview |
92 // TabContents. Does nothing if the preview TabContents has not been created. | 92 // WebContents. Does nothing if the preview WebContents has not been created. |
93 void DestroyPreviewContents(); | 93 void DestroyPreviewContents(); |
94 | 94 |
95 // Notifies the delegate to hide the preview but leaves it around in hopes it | 95 // Notifies the delegate to hide the preview but leaves it around in hopes it |
96 // can be subsequently used. The preview will not be used until Update() (with | 96 // can be subsequently used. The preview will not be used until Update() (with |
97 // valid parameters) is invoked. | 97 // valid parameters) is invoked. |
98 void Hide(); | 98 void Hide(); |
99 | 99 |
100 // Returns true if we're showing the last URL passed to |Update|. If this is | 100 // Returns true if we're showing the last URL passed to |Update|. If this is |
101 // false a commit does not result in committing the last url passed to update. | 101 // false a commit does not result in committing the last url passed to update. |
102 // A return value of false happens if we're in the process of determining if | 102 // A return value of false happens if we're in the process of determining if |
(...skipping 24 matching lines...) Expand all Loading... |
127 bool IsMouseDownFromActivate(); | 127 bool IsMouseDownFromActivate(); |
128 | 128 |
129 // The autocomplete edit that was initiating the current instant session has | 129 // The autocomplete edit that was initiating the current instant session has |
130 // lost focus. Commit or discard the preview accordingly. | 130 // lost focus. Commit or discard the preview accordingly. |
131 void OnAutocompleteLostFocus(gfx::NativeView view_gaining_focus); | 131 void OnAutocompleteLostFocus(gfx::NativeView view_gaining_focus); |
132 | 132 |
133 // The autocomplete edit has gained focus. Preload the instant URL of the | 133 // The autocomplete edit has gained focus. Preload the instant URL of the |
134 // default search engine, in anticipation of the user typing a query. | 134 // default search engine, in anticipation of the user typing a query. |
135 void OnAutocompleteGotFocus(TabContentsWrapper* tab_contents); | 135 void OnAutocompleteGotFocus(TabContentsWrapper* tab_contents); |
136 | 136 |
137 // Releases the preview TabContents passing ownership to the caller. This is | 137 // Releases the preview WebContents passing ownership to the caller. This is |
138 // intended to be called when the preview TabContents is committed. This does | 138 // intended to be called when the preview WebContents is committed. This does |
139 // not notify the delegate. |tab_contents| is the underlying tab onto which | 139 // not notify the delegate. |tab_contents| is the underlying tab onto which |
140 // the preview will be committed. It can be NULL when the underlying tab is | 140 // the preview will be committed. It can be NULL when the underlying tab is |
141 // irrelevant, for example when |type| is INSTANT_COMMIT_DESTROY. | 141 // irrelevant, for example when |type| is INSTANT_COMMIT_DESTROY. |
142 // WARNING: be sure and invoke CompleteRelease after adding the returned | 142 // WARNING: be sure and invoke CompleteRelease after adding the returned |
143 // TabContents to a tabstrip. | 143 // WebContents to a tabstrip. |
144 TabContentsWrapper* ReleasePreviewContents(InstantCommitType type, | 144 TabContentsWrapper* ReleasePreviewContents(InstantCommitType type, |
145 TabContentsWrapper* tab_contents); | 145 TabContentsWrapper* tab_contents); |
146 | 146 |
147 // Does cleanup after the preview contents has been added to the tabstrip. | 147 // Does cleanup after the preview contents has been added to the tabstrip. |
148 // Invoke this if you explicitly invoke ReleasePreviewContents. | 148 // Invoke this if you explicitly invoke ReleasePreviewContents. |
149 void CompleteRelease(TabContentsWrapper* tab); | 149 void CompleteRelease(TabContentsWrapper* tab); |
150 | 150 |
151 // TabContents the match is being shown for. | 151 // TabContentsWrapper the match is being shown for. |
152 TabContentsWrapper* tab_contents() const { return tab_contents_; } | 152 TabContentsWrapper* tab_contents() const { return tab_contents_; } |
153 | 153 |
154 // The preview TabContents; may be null. | 154 // The preview TabContentsWrapper; may be null. |
155 TabContentsWrapper* GetPreviewContents() const; | 155 TabContentsWrapper* GetPreviewContents() const; |
156 | 156 |
157 // Returns true if the preview TabContents is ready to be displayed. In some | 157 // Returns true if the preview TabContentsWrapper is ready to be displayed. In |
158 // situations this may return false yet GetPreviewContents() returns non-NULL. | 158 // some situations this may return false yet GetPreviewContents() returns |
| 159 // non-NULL. |
159 bool is_displayable() const { return is_displayable_; } | 160 bool is_displayable() const { return is_displayable_; } |
160 | 161 |
161 // Returns the transition type of the last AutocompleteMatch passed to Update. | 162 // Returns the transition type of the last AutocompleteMatch passed to Update. |
162 content::PageTransition last_transition_type() const { | 163 content::PageTransition last_transition_type() const { |
163 return last_transition_type_; | 164 return last_transition_type_; |
164 } | 165 } |
165 | 166 |
166 // InstantLoaderDelegate | 167 // InstantLoaderDelegate |
167 virtual void InstantStatusChanged(InstantLoader* loader) OVERRIDE; | 168 virtual void InstantStatusChanged(InstantLoader* loader) OVERRIDE; |
168 virtual void SetSuggestedTextFor(InstantLoader* loader, | 169 virtual void SetSuggestedTextFor(InstantLoader* loader, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 204 |
204 // Returns true if the specified id has been blacklisted from supporting | 205 // Returns true if the specified id has been blacklisted from supporting |
205 // instant. | 206 // instant. |
206 bool IsBlacklistedFromInstant(TemplateURLID id); | 207 bool IsBlacklistedFromInstant(TemplateURLID id); |
207 | 208 |
208 // Clears the set of search engines blacklisted. | 209 // Clears the set of search engines blacklisted. |
209 void ClearBlacklist(); | 210 void ClearBlacklist(); |
210 | 211 |
211 // Deletes |loader| after a delay. At the time we determine a site doesn't | 212 // Deletes |loader| after a delay. At the time we determine a site doesn't |
212 // want to participate in instant we can't destroy the loader (because | 213 // want to participate in instant we can't destroy the loader (because |
213 // destroying the loader destroys the TabContents and the TabContents is on | 214 // destroying the loader destroys the WebContents and the WebContents is on |
214 // the stack). Instead we place the loader in |loaders_to_destroy_| and | 215 // the stack). Instead we place the loader in |loaders_to_destroy_| and |
215 // schedule a task. | 216 // schedule a task. |
216 void ScheduleDestroy(InstantLoader* loader); | 217 void ScheduleDestroy(InstantLoader* loader); |
217 | 218 |
218 // Destroys all loaders scheduled for destruction in |ScheduleForDestroy|. | 219 // Destroys all loaders scheduled for destruction in |ScheduleForDestroy|. |
219 void DestroyLoaders(); | 220 void DestroyLoaders(); |
220 | 221 |
221 InstantDelegate* delegate_; | 222 InstantDelegate* delegate_; |
222 | 223 |
223 // The TemplateURLService for the Profile provided at construction time. We | 224 // The TemplateURLService for the Profile provided at construction time. We |
224 // don't own this pointer. | 225 // don't own this pointer. |
225 TemplateURLService* template_url_service_; | 226 TemplateURLService* template_url_service_; |
226 | 227 |
227 // The TabContents last passed to |Update|. | 228 // The TabContentsWrapper last passed to |Update|. |
228 TabContentsWrapper* tab_contents_; | 229 TabContentsWrapper* tab_contents_; |
229 | 230 |
230 // True if |loader_| is ready to be displayed. | 231 // True if |loader_| is ready to be displayed. |
231 bool is_displayable_; | 232 bool is_displayable_; |
232 | 233 |
233 // Set to true in Hide() and false in UpdateLoader(). Used when we persist | 234 // Set to true in Hide() and false in UpdateLoader(). Used when we persist |
234 // the |loader_|, but it isn't up to date. | 235 // the |loader_|, but it isn't up to date. |
235 bool is_out_of_date_; | 236 bool is_out_of_date_; |
236 | 237 |
237 scoped_ptr<InstantLoader> loader_; | 238 scoped_ptr<InstantLoader> loader_; |
(...skipping 22 matching lines...) Expand all Loading... |
260 // The URL of the most recent match passed to |Update|. | 261 // The URL of the most recent match passed to |Update|. |
261 GURL last_url_; | 262 GURL last_url_; |
262 | 263 |
263 // The most recent user_text passed to |Update|. | 264 // The most recent user_text passed to |Update|. |
264 string16 last_user_text_; | 265 string16 last_user_text_; |
265 | 266 |
266 DISALLOW_COPY_AND_ASSIGN(InstantController); | 267 DISALLOW_COPY_AND_ASSIGN(InstantController); |
267 }; | 268 }; |
268 | 269 |
269 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 270 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
OLD | NEW |