1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_SEARCH_VIEW_CONTROLLER_H_
#define CHROME_BROWSER_UI_VIEWS_SEARCH_VIEW_CONTROLLER_H_
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/ui/search/search_model_observer.h"
#include "ui/compositor/layer_animation_observer.h"
class ContentsContainer;
class LocationBarContainer;
class TabContents;
class ToolbarView;
namespace chrome {
namespace search {
class SearchModel;
class ToolbarSearchAnimator;
}
}
namespace content {
class BrowserContext;
class WebContents;
}
namespace internal {
class OmniboxPopupContainer;
}
namespace views {
class ImageView;
class Label;
class View;
class WebView;
}
// SearchViewController maintains the search overlay (native new tab page).
// To avoid ordering dependencies this class listens directly to the
// SearchModel of the active tab. BrowserView is responsible for telling this
// class when the active tab changes.
class SearchViewController
: public chrome::search::SearchModelObserver,
public ui::ImplicitAnimationObserver {
friend class internal::OmniboxPopupContainer;
friend class SearchViewControllerTest;
public:
SearchViewController(
content::BrowserContext* browser_context,
ContentsContainer* contents_container,
chrome::search::ToolbarSearchAnimator* toolbar_search_animator,
ToolbarView* toolbar_view);
virtual ~SearchViewController();
// Provides a host parent view for the omnibox popup.
views::View* omnibox_popup_parent();
// Set by host to facilitate proper view/layer stacking.
void set_location_bar_container(
LocationBarContainer* location_bar_container) {
location_bar_container_ = location_bar_container;
}
// Sets the active tab.
void SetTabContents(TabContents* tab_contents);
// Stacks the overlay at the top.
void StackAtTop();
// Invoked when the instant preview is ready to be shown.
void InstantReady();
// chrome::search::SearchModelObserver overrides:
virtual void ModeChanged(const chrome::search::Mode& old_mode,
const chrome::search::Mode& new_mode) OVERRIDE;
protected:
// ui::ImplicitAnimationObserver overrides:
virtual void OnImplicitAnimationsCompleted() OVERRIDE;
private:
enum State {
// Search/ntp is not visible.
STATE_NOT_VISIBLE,
// Layout for the new tab page.
STATE_NTP,
// Animating between STATE_NTP and STATE_SUGGESTIONS.
STATE_NTP_ANIMATING,
// Search layout. This is only used when the suggestions UI is visible.
STATE_SUGGESTIONS,
};
// Invokes SetState() based on the search model and omnibox.
void UpdateState();
// Updates the views and animations. May do any of the following: create the
// views, start an animation, or destroy the views. What happens is determined
// from the current state of the SearchModel.
void SetState(State state);
// Test support.
State state() const { return state_; }
// Starts the animation.
void StartAnimation();
// Create the various views and installs them as an overlay on
// |contents_container_|. |state| is used to determine visual style
// of the created views.
void CreateViews(State state);
// Returns the logo image view, or a name label if an image is not available.
views::View* GetLogoView() const;
// Destroys the various views.
void DestroyViews();
// Invoked when the visibility of the omnibox popup changes.
void PopupVisibilityChanged();
// Hide the overlay, when suggestions are showing and Instant is enabled.
void MaybeHideOverlay();
// Access active search model.
chrome::search::SearchModel* search_model();
// Access active web contents.
content::WebContents* web_contents();
// The profile. Weak.
content::BrowserContext* browser_context_;
// Where the overlay is placed. Weak.
ContentsContainer* contents_container_;
// Weak.
chrome::search::ToolbarSearchAnimator* toolbar_search_animator_;
// The browser's toolbar view. Weak.
ToolbarView* toolbar_view_;
// Weak.
LocationBarContainer* location_bar_container_;
State state_;
// The active TabContents. Weak. May be NULL.
TabContents* tab_contents_;
// The following views are created to render the NTP. Visually they look
// something like:
//
// |---SearchContainerView------------------------------|
// ||-----NTPView & OmniboxPopupViewParent-------------||
// || ||
// || |--Logo or Name------------------------| ||
// || | | ||
// || | | ||
// || |--------------------------------------| ||
// || ||
// || * ||
// || ||
// || |--ContentView-------------------------| ||
// || | | ||
// || | | ||
// || |--------------------------------------| ||
// || ||
// ||--------------------------------------------------||
// |----------------------------------------------------|
//
// * - the LocationBarContainer gets positioned here, but it is not a child
// of any of these views.
//
// NTPView and OmniboxPopupViewParent are siblings. When on the NTP the
// OmniboxPopupViewParent is obscured by the NTPView. When on a search page
// the NTPView is hidden.
// The outermost view. Set as the overlay within |contents_container_| passed
// in from owning |BrowserView|.
views::View* search_container_;
// A container view for the NTP component views.
views::View* ntp_container_;
// The default provider's logo, may be NULL. When NULL,
// |default_provider_name_| is used.
// Lifetime is managed by this controller, not the parent |ntp_container_|.
scoped_ptr<views::ImageView> default_provider_logo_;
// The default provider's name. Used as a fallback if the logo is NULL.
// Lifetime is managed by this controller, not the parent |ntp_container_|.
scoped_ptr<views::Label> default_provider_name_;
// An alias to |contents_container_->active()|, but reparented within
// |ntp_view_| when in the NTP state.
views::WebView* content_view_;
// Container provided to clients to host the omnibox popup view.
internal::OmniboxPopupContainer* omnibox_popup_parent_;
DISALLOW_COPY_AND_ASSIGN(SearchViewController);
};
#endif // CHROME_BROWSER_UI_VIEWS_SEARCH_VIEW_CONTROLLER_H_
|