OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "chrome/browser/instant/instant_commit_type.h" | 18 #include "chrome/browser/instant/instant_commit_type.h" |
19 #include "chrome/browser/instant/instant_model.h" | 19 #include "chrome/browser/instant/instant_model.h" |
| 20 #include "chrome/browser/ui/omnibox/omnibox_types.h" |
20 #include "chrome/common/instant_types.h" | 21 #include "chrome/common/instant_types.h" |
21 #include "chrome/common/search_types.h" | 22 #include "chrome/common/search_types.h" |
22 #include "content/public/common/page_transition_types.h" | 23 #include "content/public/common/page_transition_types.h" |
23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
24 #include "ui/gfx/native_widget_types.h" | 25 #include "ui/gfx/native_widget_types.h" |
25 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
26 | 27 |
27 struct AutocompleteMatch; | 28 struct AutocompleteMatch; |
28 class AutocompleteProvider; | 29 class AutocompleteProvider; |
29 class InstantLoader; | 30 class InstantLoader; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // The preview WebContents. May be NULL. InstantController retains ownership. | 78 // The preview WebContents. May be NULL. InstantController retains ownership. |
78 content::WebContents* GetPreviewContents() const; | 79 content::WebContents* GetPreviewContents() const; |
79 | 80 |
80 // Returns true if the Instant preview is showing a search results preview. | 81 // Returns true if the Instant preview is showing a search results preview. |
81 bool IsPreviewingSearchResults() const; | 82 bool IsPreviewingSearchResults() const; |
82 | 83 |
83 // If the preview is showing search results, commits the preview, calling | 84 // If the preview is showing search results, commits the preview, calling |
84 // CommitInstant() on the browser, and returns true. Else, returns false. | 85 // CommitInstant() on the browser, and returns true. Else, returns false. |
85 bool CommitIfPossible(InstantCommitType type); | 86 bool CommitIfPossible(InstantCommitType type); |
86 | 87 |
87 // The omnibox has lost focus. Commit or discard the preview accordingly. | 88 // Called to indicate that the omnibox focus state changed with the given |
88 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); | 89 // |reason|. If |focus_state| is FOCUS_NONE, |view_gaining_focus| is set to |
89 | 90 // the view gaining focus. |
90 // The omnibox has gained focus. Preload the default search engine, in | 91 void OmniboxFocusChanged(OmniboxFocusState focus_state, |
91 // anticipation of the user typing a query. | 92 OmniboxFocusChangeReason reason, |
92 void OmniboxGotFocus(); | 93 gfx::NativeView view_gaining_focus); |
93 | 94 |
94 // The search mode in the active tab has changed. Pass the message down to | 95 // The search mode in the active tab has changed. Pass the message down to |
95 // the loader which will notify the renderer. Create |instant_tab_| if the | 96 // the loader which will notify the renderer. Create |instant_tab_| if the |
96 // |new_mode| reflects an Instant search results page. | 97 // |new_mode| reflects an Instant search results page. |
97 void SearchModeChanged(const chrome::search::Mode& old_mode, | 98 void SearchModeChanged(const chrome::search::Mode& old_mode, |
98 const chrome::search::Mode& new_mode); | 99 const chrome::search::Mode& new_mode); |
99 | 100 |
100 // The user switched tabs. Hide the preview. Create |instant_tab_| if the | 101 // The user switched tabs. Hide the preview. Create |instant_tab_| if the |
101 // newly active tab is an Instant search results page. | 102 // newly active tab is an Instant search results page. |
102 void ActiveTabChanged(); | 103 void ActiveTabChanged(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 void InstantLoaderRenderViewGone(); | 147 void InstantLoaderRenderViewGone(); |
147 | 148 |
148 // Invoked by InstantLoader when the instant page is about to navigate. | 149 // Invoked by InstantLoader when the instant page is about to navigate. |
149 void InstantLoaderAboutToNavigateMainFrame(const GURL& url); | 150 void InstantLoaderAboutToNavigateMainFrame(const GURL& url); |
150 | 151 |
151 private: | 152 private: |
152 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); | 153 FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); |
153 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); | 154 FRIEND_TEST_ALL_PREFIXES(InstantTest, NonInstantSearchProvider); |
154 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); | 155 FRIEND_TEST_ALL_PREFIXES(InstantTest, InstantLoaderRefresh); |
155 | 156 |
| 157 // Helper for OmniboxFocusChanged. Commit or discard the preview. |
| 158 void OmniboxLostFocus(gfx::NativeView view_gaining_focus); |
| 159 |
156 // Creates a new loader if necessary, using the instant_url property of the | 160 // Creates a new loader if necessary, using the instant_url property of the |
157 // |template_url| (for example, if the Instant URL has changed since the last | 161 // |template_url| (for example, if the Instant URL has changed since the last |
158 // time the loader was created). Returns false if the |template_url| doesn't | 162 // time the loader was created). Returns false if the |template_url| doesn't |
159 // have a valid Instant URL; true otherwise. | 163 // have a valid Instant URL; true otherwise. |
160 bool ResetLoader(const TemplateURL* template_url, | 164 bool ResetLoader(const TemplateURL* template_url, |
161 const content::WebContents* active_tab); | 165 const content::WebContents* active_tab); |
162 | 166 |
163 // Ensures that the |loader_| uses the default Instant URL, recreating it if | 167 // Ensures that the |loader_| uses the default Instant URL, recreating it if |
164 // necessary, and returns true. Returns false if the Instant URL could not be | 168 // necessary, and returns true. Returns false if the Instant URL could not be |
165 // determined or the active tab is NULL (browser is shutting down). | 169 // determined or the active tab is NULL (browser is shutting down). |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 // the user has typed. | 240 // the user has typed. |
237 InstantSuggestion last_suggestion_; | 241 InstantSuggestion last_suggestion_; |
238 | 242 |
239 // See comments on the getter above. | 243 // See comments on the getter above. |
240 content::PageTransition last_transition_type_; | 244 content::PageTransition last_transition_type_; |
241 | 245 |
242 // True if the last match passed to Update() was a search (versus a URL). | 246 // True if the last match passed to Update() was a search (versus a URL). |
243 // Used to ensure that the preview page is committable. | 247 // Used to ensure that the preview page is committable. |
244 bool last_match_was_search_; | 248 bool last_match_was_search_; |
245 | 249 |
246 // True if the omnibox is focused, false otherwise. | 250 // Omnibox focus state. |
247 bool is_omnibox_focused_; | 251 OmniboxFocusState omnibox_focus_state_; |
248 | 252 |
249 // The search model mode for the active tab. | 253 // The search model mode for the active tab. |
250 chrome::search::Mode search_mode_; | 254 chrome::search::Mode search_mode_; |
251 | 255 |
252 // Current omnibox bounds. | 256 // Current omnibox bounds. |
253 gfx::Rect omnibox_bounds_; | 257 gfx::Rect omnibox_bounds_; |
254 | 258 |
255 // Last bounds passed to the page. | 259 // Last bounds passed to the page. |
256 gfx::Rect last_omnibox_bounds_; | 260 gfx::Rect last_omnibox_bounds_; |
257 | 261 |
(...skipping 24 matching lines...) Expand all Loading... |
282 | 286 |
283 // Whether to allow the preview to show search suggestions. In general, the | 287 // Whether to allow the preview to show search suggestions. In general, the |
284 // preview is allowed to show search suggestions whenever |search_mode_| is | 288 // preview is allowed to show search suggestions whenever |search_mode_| is |
285 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. | 289 // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. |
286 bool allow_preview_to_show_search_suggestions_; | 290 bool allow_preview_to_show_search_suggestions_; |
287 | 291 |
288 DISALLOW_COPY_AND_ASSIGN(InstantController); | 292 DISALLOW_COPY_AND_ASSIGN(InstantController); |
289 }; | 293 }; |
290 | 294 |
291 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ | 295 #endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ |
OLD | NEW |