Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: athena/home/home_card_impl.cc

Issue 397343003: Introduce centered view and bottom view for home card. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « athena/home/bottom_home_view.cc ('k') | athena/home/minimized_home.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "athena/home/public/home_card.h" 5 #include "athena/home/public/home_card.h"
6 6
7 #include <limits>
8
7 #include "athena/home/app_list_view_delegate.h" 9 #include "athena/home/app_list_view_delegate.h"
10 #include "athena/home/bottom_home_view.h"
8 #include "athena/home/minimized_home.h" 11 #include "athena/home/minimized_home.h"
9 #include "athena/home/public/app_model_builder.h" 12 #include "athena/home/public/app_model_builder.h"
10 #include "athena/input/public/accelerator_manager.h" 13 #include "athena/input/public/accelerator_manager.h"
11 #include "athena/screen/public/screen_manager.h" 14 #include "athena/screen/public/screen_manager.h"
12 #include "athena/wm/public/window_manager.h" 15 #include "athena/wm/public/window_manager.h"
13 #include "athena/wm/public/window_manager_observer.h" 16 #include "athena/wm/public/window_manager_observer.h"
14 #include "base/bind.h" 17 #include "base/bind.h"
15 #include "ui/app_list/search_provider.h" 18 #include "ui/app_list/search_provider.h"
16 #include "ui/app_list/views/app_list_view.h" 19 #include "ui/app_list/views/app_list_main_view.h"
20 #include "ui/app_list/views/contents_view.h"
17 #include "ui/aura/layout_manager.h" 21 #include "ui/aura/layout_manager.h"
18 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/views/background.h"
19 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/widget/widget.h"
26 #include "ui/views/widget/widget_delegate.h"
20 #include "ui/wm/core/visibility_controller.h" 27 #include "ui/wm/core/visibility_controller.h"
21 #include "ui/wm/core/window_animations.h" 28 #include "ui/wm/core/window_animations.h"
22 29
23 namespace athena { 30 namespace athena {
24 namespace { 31 namespace {
25 32
26 HomeCard* instance = NULL; 33 HomeCard* instance = NULL;
27 34
28 // Makes sure the homecard is center-aligned horizontally and bottom-aligned 35 // Makes sure the homecard is center-aligned horizontally and bottom-aligned
29 // vertically. 36 // vertically.
30 class HomeCardLayoutManager : public aura::LayoutManager { 37 class HomeCardLayoutManager : public aura::LayoutManager {
31 public: 38 public:
32 class Delegate { 39 class Delegate {
33 public: 40 public:
34 virtual ~Delegate() {} 41 virtual ~Delegate() {}
35 42
36 virtual int GetHomeCardHeight() const = 0; 43 virtual int GetHomeCardHeight() const = 0;
37 44
38 virtual int GetHorizontalMargin() const = 0; 45 virtual int GetHorizontalMargin() const = 0;
39 46
40 // TODO(mukai): Remove this when bubble is no longer used for
41 // VISIBLE_CENTERED or VISIBLE_BOTTOM states.
42 virtual bool HasShadow() const = 0;
43
44 virtual aura::Window* GetNativeWindow() = 0; 47 virtual aura::Window* GetNativeWindow() = 0;
45 }; 48 };
46 49
47 explicit HomeCardLayoutManager(Delegate* delegate) 50 explicit HomeCardLayoutManager(Delegate* delegate)
48 : delegate_(delegate) {} 51 : delegate_(delegate) {}
52
49 virtual ~HomeCardLayoutManager() {} 53 virtual ~HomeCardLayoutManager() {}
50 54
51 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { 55 void Layout() {
52 virtual_keyboard_bounds_ = bounds; 56 aura::Window* home_card = delegate_->GetNativeWindow();
53 Layout(); 57 // |home_card| could be detached from the root window (e.g. when it is being
58 // destroyed).
59 if (!home_card || !home_card->GetRootWindow())
60 return;
61
62 int height = delegate_->GetHomeCardHeight();
63 int horiz_margin = delegate_->GetHorizontalMargin();
64 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
65 height = std::min(height, screen_bounds.height());
66 gfx::Rect card_bounds = screen_bounds;
67 card_bounds.Inset(horiz_margin, screen_bounds.height() - height,
68 horiz_margin, 0);
69
70 SetChildBoundsDirect(home_card, card_bounds);
54 } 71 }
55 72
56 private: 73 private:
57 // aura::LayoutManager: 74 // aura::LayoutManager:
58 virtual void OnWindowResized() OVERRIDE { Layout(); } 75 virtual void OnWindowResized() OVERRIDE { Layout(); }
59 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } 76 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); }
60 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 77 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
61 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 78 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
62 Layout(); 79 Layout();
63 } 80 }
64 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 81 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
65 bool visible) OVERRIDE { 82 bool visible) OVERRIDE {
66 Layout(); 83 Layout();
67 } 84 }
68 virtual void SetChildBounds(aura::Window* child, 85 virtual void SetChildBounds(aura::Window* child,
69 const gfx::Rect& requested_bounds) OVERRIDE { 86 const gfx::Rect& requested_bounds) OVERRIDE {
70 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); 87 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size()));
71 } 88 }
72 89
73 void Layout() {
74 int height = delegate_->GetHomeCardHeight();
75 int horiz_margin = delegate_->GetHorizontalMargin();
76 aura::Window* home_card = delegate_->GetNativeWindow();
77 // |home_card| could be detached from the root window (e.g. when it is being
78 // destroyed).
79 if (!home_card || !home_card->GetRootWindow())
80 return;
81
82 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds();
83 if (!virtual_keyboard_bounds_.IsEmpty())
84 screen_bounds.set_height(virtual_keyboard_bounds_.y());
85 gfx::Rect card_bounds = screen_bounds;
86 card_bounds.Inset(horiz_margin, screen_bounds.height() - height,
87 horiz_margin, 0);
88
89 if (delegate_->HasShadow()) {
90 // Currently the home card is provided as a bubble and the bounds has to
91 // be increased to cancel the shadow.
92 // TODO(mukai): stops using the bubble and remove this.
93 const int kHomeCardShadowWidth = 30;
94 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth);
95 }
96 SetChildBoundsDirect(home_card, card_bounds);
97 }
98
99 Delegate* delegate_; 90 Delegate* delegate_;
100 gfx::Rect virtual_keyboard_bounds_;
101 91
102 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 92 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
103 }; 93 };
104 94
95 // The container view of home card contents of each state.
96 class HomeCardView : public views::WidgetDelegateView {
97 public:
98 HomeCardView(app_list::AppListViewDelegate* view_delegate,
99 aura::Window* container,
100 MinimizedHomeDragDelegate* minimized_delegate) {
101 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE));
102
103 bottom_view_ = new BottomHomeView(view_delegate);
104 AddChildView(bottom_view_);
105
106 main_view_ = new app_list::AppListMainView(
107 view_delegate, 0 /* initial_apps_page */, container);
108 AddChildView(main_view_);
109
110 minimized_view_ = CreateMinimizedHome(minimized_delegate);
111 AddChildView(minimized_view_);
112 }
113
114 void SetState(HomeCard::State state) {
115 bottom_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM);
116 main_view_->SetVisible(state == HomeCard::VISIBLE_CENTERED);
117 minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
118 if (state == HomeCard::VISIBLE_CENTERED) {
119 app_list::ContentsView* contents_view = main_view_->contents_view();
120 contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage(
121 app_list::ContentsView::NAMED_PAGE_START));
122 }
123 }
124
125 // views::View:
126 virtual void Layout() OVERRIDE {
127 for (int i = 0; i < child_count(); ++i) {
128 views::View* child = child_at(i);
129 if (child->visible()) {
130 child->SetBoundsRect(bounds());
131 return;
132 }
133 }
134
135 // One of the child views has to be visible.
136 NOTREACHED();
137 }
138
139 private:
140 // views::WidgetDelegate:
141 virtual views::View* GetContentsView() OVERRIDE {
142 return this;
143 }
144
145 app_list::AppListMainView* main_view_;
146 BottomHomeView* bottom_view_;
147 views::View* minimized_view_;
148
149 DISALLOW_COPY_AND_ASSIGN(HomeCardView);
150 };
151
105 class HomeCardImpl : public HomeCard, 152 class HomeCardImpl : public HomeCard,
106 public AcceleratorHandler, 153 public AcceleratorHandler,
107 public HomeCardLayoutManager::Delegate, 154 public HomeCardLayoutManager::Delegate,
108 public MinimizedHomeDragDelegate, 155 public MinimizedHomeDragDelegate,
109 public WindowManagerObserver { 156 public WindowManagerObserver {
110 public: 157 public:
111 explicit HomeCardImpl(AppModelBuilder* model_builder); 158 explicit HomeCardImpl(AppModelBuilder* model_builder);
112 virtual ~HomeCardImpl(); 159 virtual ~HomeCardImpl();
113 160
114 void Init(); 161 void Init();
(...skipping 20 matching lines...) Expand all
135 SetState(VISIBLE_CENTERED); 182 SetState(VISIBLE_CENTERED);
136 else 183 else
137 SetState(HIDDEN); 184 SetState(HIDDEN);
138 return true; 185 return true;
139 } 186 }
140 187
141 // HomeCardLayoutManager::Delegate: 188 // HomeCardLayoutManager::Delegate:
142 virtual int GetHomeCardHeight() const OVERRIDE { 189 virtual int GetHomeCardHeight() const OVERRIDE {
143 const int kHomeCardHeight = 150; 190 const int kHomeCardHeight = 150;
144 const int kHomeCardMinimizedHeight = 8; 191 const int kHomeCardMinimizedHeight = 8;
145 CHECK_NE(HIDDEN, state_); 192
146 return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight : 193 switch (state_) {
147 kHomeCardHeight; 194 case VISIBLE_CENTERED:
195 // Span the screen fully.
196 return std::numeric_limits<int>::max();
197 case VISIBLE_BOTTOM:
198 return kHomeCardHeight;
199 case VISIBLE_MINIMIZED:
200 return kHomeCardMinimizedHeight;
201 case HIDDEN:
202 NOTREACHED();
203 return -1;
204 }
148 } 205 }
149 206
150 virtual int GetHorizontalMargin() const OVERRIDE { 207 virtual int GetHorizontalMargin() const OVERRIDE {
151 CHECK_NE(HIDDEN, state_); 208 CHECK_NE(HIDDEN, state_);
152 const int kHomeCardHorizontalMargin = 50; 209 const int kHomeCardHorizontalMargin = 50;
153 return state_ == VISIBLE_MINIMIZED ? 0 : kHomeCardHorizontalMargin; 210 return state_ == VISIBLE_BOTTOM ? kHomeCardHorizontalMargin : 0;
154 }
155
156 virtual bool HasShadow() const OVERRIDE {
157 CHECK_NE(HIDDEN, state_);
158 return state_ != VISIBLE_MINIMIZED;
159 } 211 }
160 212
161 virtual aura::Window* GetNativeWindow() OVERRIDE { 213 virtual aura::Window* GetNativeWindow() OVERRIDE {
162 switch (state_) { 214 if (state_ == HIDDEN)
163 case HIDDEN: 215 return NULL;
164 return NULL; 216
165 case VISIBLE_MINIMIZED: 217 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
166 return minimized_widget_ ? minimized_widget_->GetNativeWindow() : NULL;
167 case VISIBLE_CENTERED:
168 case VISIBLE_BOTTOM:
169 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
170 }
171 return NULL;
172 } 218 }
173 219
174 // MinimizedHomeDragDelegate: 220 // MinimizedHomeDragDelegate:
175 virtual void OnDragUpCompleted() OVERRIDE { 221 virtual void OnDragUpCompleted() OVERRIDE {
176 WindowManager::GetInstance()->ToggleOverview(); 222 WindowManager::GetInstance()->ToggleOverview();
177 } 223 }
178 224
179 // WindowManagerObserver: 225 // WindowManagerObserver:
180 virtual void OnOverviewModeEnter() OVERRIDE { 226 virtual void OnOverviewModeEnter() OVERRIDE {
181 SetState(VISIBLE_BOTTOM); 227 SetState(VISIBLE_BOTTOM);
182 } 228 }
183 229
184 virtual void OnOverviewModeExit() OVERRIDE { 230 virtual void OnOverviewModeExit() OVERRIDE {
185 SetState(VISIBLE_MINIMIZED); 231 SetState(VISIBLE_MINIMIZED);
186 } 232 }
187 233
188 scoped_ptr<AppModelBuilder> model_builder_; 234 scoped_ptr<AppModelBuilder> model_builder_;
189 235
190 HomeCard::State state_; 236 HomeCard::State state_;
191 237
238 // original_state_ is the state which the home card should go back to after
239 // the virtual keyboard is hidden.
240 HomeCard::State original_state_;
241
192 views::Widget* home_card_widget_; 242 views::Widget* home_card_widget_;
193 views::Widget* minimized_widget_; 243 HomeCardView* home_card_view_;
194 AppListViewDelegate* view_delegate_; 244 scoped_ptr<AppListViewDelegate> view_delegate_;
195 HomeCardLayoutManager* layout_manager_; 245 HomeCardLayoutManager* layout_manager_;
196 246
197 // Right now HomeCard allows only one search provider. 247 // Right now HomeCard allows only one search provider.
198 // TODO(mukai): port app-list's SearchController and Mixer. 248 // TODO(mukai): port app-list's SearchController and Mixer.
199 scoped_ptr<app_list::SearchProvider> search_provider_; 249 scoped_ptr<app_list::SearchProvider> search_provider_;
200 250
201 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); 251 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
202 }; 252 };
203 253
204 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) 254 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
205 : model_builder_(model_builder), 255 : model_builder_(model_builder),
206 state_(VISIBLE_MINIMIZED), 256 state_(VISIBLE_MINIMIZED),
257 original_state_(VISIBLE_MINIMIZED),
207 home_card_widget_(NULL), 258 home_card_widget_(NULL),
208 minimized_widget_(NULL), 259 home_card_view_(NULL),
209 layout_manager_(NULL) { 260 layout_manager_(NULL) {
210 DCHECK(!instance); 261 DCHECK(!instance);
211 instance = this; 262 instance = this;
212 WindowManager::GetInstance()->AddObserver(this); 263 WindowManager::GetInstance()->AddObserver(this);
213 } 264 }
214 265
215 HomeCardImpl::~HomeCardImpl() { 266 HomeCardImpl::~HomeCardImpl() {
216 DCHECK(instance); 267 DCHECK(instance);
217 WindowManager::GetInstance()->RemoveObserver(this); 268 WindowManager::GetInstance()->RemoveObserver(this);
218 home_card_widget_->CloseNow(); 269 home_card_widget_->CloseNow();
219 minimized_widget_->CloseNow();
220 view_delegate_ = NULL;
221 instance = NULL; 270 instance = NULL;
222 } 271 }
223 272
224 void HomeCardImpl::SetState(HomeCard::State state) { 273 void HomeCardImpl::SetState(HomeCard::State state) {
225 // Update |state_| before changing the visibility of the widgets, so that 274 // Update |state_| before changing the visibility of the widgets, so that
226 // LayoutManager callbacks get the correct state. 275 // LayoutManager callbacks get the correct state.
227 state_ = state; 276 state_ = state;
228 switch (state_) { 277 original_state_ = state;
229 case VISIBLE_MINIMIZED: 278 if (state_ == HIDDEN) {
230 home_card_widget_->Hide(); 279 home_card_widget_->Hide();
231 minimized_widget_->Show(); 280 } else {
232 break; 281 home_card_widget_->Show();
233 case HIDDEN: 282 home_card_view_->SetState(state);
234 home_card_widget_->Hide(); 283 layout_manager_->Layout();
235 minimized_widget_->Hide();
236 break;
237 case VISIBLE_BOTTOM:
238 case VISIBLE_CENTERED:
239 home_card_widget_->Show();
240 minimized_widget_->Hide();
241 break;
242 } 284 }
243 } 285 }
244 286
245 void HomeCardImpl::RegisterSearchProvider( 287 void HomeCardImpl::RegisterSearchProvider(
246 app_list::SearchProvider* search_provider) { 288 app_list::SearchProvider* search_provider) {
247 DCHECK(!search_provider_); 289 DCHECK(!search_provider_);
248 search_provider_.reset(search_provider); 290 search_provider_.reset(search_provider);
249 view_delegate_->RegisterSearchProvider(search_provider_.get()); 291 view_delegate_->RegisterSearchProvider(search_provider_.get());
250 } 292 }
251 293
252 void HomeCardImpl::UpdateVirtualKeyboardBounds( 294 void HomeCardImpl::UpdateVirtualKeyboardBounds(
253 const gfx::Rect& bounds) { 295 const gfx::Rect& bounds) {
254 if (state_ == VISIBLE_MINIMIZED) { 296 if (state_ == VISIBLE_MINIMIZED && !bounds.IsEmpty()) {
255 if (bounds.IsEmpty()) 297 SetState(HIDDEN);
256 minimized_widget_->Show(); 298 original_state_ = VISIBLE_MINIMIZED;
257 else 299 } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) {
258 minimized_widget_->Hide(); 300 SetState(VISIBLE_CENTERED);
301 original_state_ = VISIBLE_BOTTOM;
302 } else if (state_ != original_state_ && bounds.IsEmpty()) {
303 SetState(original_state_);
259 } 304 }
260 layout_manager_->UpdateVirtualKeyboardBounds(bounds);
261 } 305 }
262 306
263 void HomeCardImpl::Init() { 307 void HomeCardImpl::Init() {
264 InstallAccelerators(); 308 InstallAccelerators();
265 ScreenManager::ContainerParams params("HomeCardContainer"); 309 ScreenManager::ContainerParams params("HomeCardContainer");
266 params.can_activate_children = true; 310 params.can_activate_children = true;
267 aura::Window* container = ScreenManager::Get()->CreateContainer(params); 311 aura::Window* container = ScreenManager::Get()->CreateContainer(params);
268 layout_manager_ = new HomeCardLayoutManager(this); 312 layout_manager_ = new HomeCardLayoutManager(this);
269 313
270 container->SetLayoutManager(layout_manager_); 314 container->SetLayoutManager(layout_manager_);
271 wm::SetChildWindowVisibilityChangesAnimated(container); 315 wm::SetChildWindowVisibilityChangesAnimated(container);
272 316
273 view_delegate_ = new AppListViewDelegate(model_builder_.get()); 317 view_delegate_.reset(new AppListViewDelegate(model_builder_.get()));
274 if (search_provider_) 318 if (search_provider_)
275 view_delegate_->RegisterSearchProvider(search_provider_.get()); 319 view_delegate_->RegisterSearchProvider(search_provider_.get());
276 app_list::AppListView* view = new app_list::AppListView(view_delegate_);
277 view->InitAsBubbleAtFixedLocation(
278 container,
279 0 /* initial_apps_page */,
280 gfx::Point(),
281 views::BubbleBorder::FLOAT,
282 true /* border_accepts_events */);
283 home_card_widget_ = view->GetWidget();
284 320
285 // Start off in the minimized state. 321 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
286 minimized_widget_ = CreateMinimizedHome(container, this); 322 home_card_widget_ = new views::Widget();
323 views::Widget::InitParams widget_params(
324 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
325 widget_params.parent = container;
326 widget_params.delegate = home_card_view_;
327 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
328 home_card_widget_->Init(widget_params);
329
287 SetState(VISIBLE_MINIMIZED); 330 SetState(VISIBLE_MINIMIZED);
331 home_card_view_->Layout();
288 } 332 }
289 333
290 void HomeCardImpl::InstallAccelerators() { 334 void HomeCardImpl::InstallAccelerators() {
291 const AcceleratorData accelerator_data[] = { 335 const AcceleratorData accelerator_data[] = {
292 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, 336 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
293 COMMAND_SHOW_HOME_CARD, AF_NONE}, 337 COMMAND_SHOW_HOME_CARD, AF_NONE},
294 }; 338 };
295 AcceleratorManager::Get()->RegisterAccelerators( 339 AcceleratorManager::Get()->RegisterAccelerators(
296 accelerator_data, arraysize(accelerator_data), this); 340 accelerator_data, arraysize(accelerator_data), this);
297 } 341 }
(...skipping 14 matching lines...) Expand all
312 instance = NULL; 356 instance = NULL;
313 } 357 }
314 358
315 // static 359 // static
316 HomeCard* HomeCard::Get() { 360 HomeCard* HomeCard::Get() {
317 DCHECK(instance); 361 DCHECK(instance);
318 return instance; 362 return instance;
319 } 363 }
320 364
321 } // namespace athena 365 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/bottom_home_view.cc ('k') | athena/home/minimized_home.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698