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

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

Issue 478293004: Refactor the home card structure and introduce animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 3 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/athena_start_page_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 <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "athena/common/container_priorities.h" 10 #include "athena/common/container_priorities.h"
11 #include "athena/env/public/athena_env.h" 11 #include "athena/env/public/athena_env.h"
12 #include "athena/home/app_list_view_delegate.h" 12 #include "athena/home/app_list_view_delegate.h"
13 #include "athena/home/athena_start_page_view.h" 13 #include "athena/home/athena_start_page_view.h"
14 #include "athena/home/minimized_home.h" 14 #include "athena/home/minimized_home.h"
15 #include "athena/home/public/app_model_builder.h" 15 #include "athena/home/public/app_model_builder.h"
16 #include "athena/input/public/accelerator_manager.h" 16 #include "athena/input/public/accelerator_manager.h"
17 #include "athena/screen/public/screen_manager.h" 17 #include "athena/screen/public/screen_manager.h"
18 #include "athena/wm/public/window_manager.h" 18 #include "athena/wm/public/window_manager.h"
19 #include "athena/wm/public/window_manager_observer.h" 19 #include "athena/wm/public/window_manager_observer.h"
20 #include "base/bind.h"
21 #include "base/memory/weak_ptr.h"
22 #include "ui/app_list/search_provider.h" 20 #include "ui/app_list/search_provider.h"
23 #include "ui/app_list/views/app_list_main_view.h" 21 #include "ui/app_list/views/app_list_main_view.h"
24 #include "ui/app_list/views/contents_view.h" 22 #include "ui/app_list/views/contents_view.h"
25 #include "ui/aura/layout_manager.h" 23 #include "ui/aura/layout_manager.h"
26 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
27 #include "ui/compositor/closure_animation_observer.h" 25 #include "ui/compositor/layer.h"
26 #include "ui/compositor/layer_owner.h"
28 #include "ui/compositor/scoped_layer_animation_settings.h" 27 #include "ui/compositor/scoped_layer_animation_settings.h"
29 #include "ui/views/background.h" 28 #include "ui/views/layout/fill_layout.h"
30 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
32 #include "ui/views/widget/widget_delegate.h" 30 #include "ui/views/widget/widget_delegate.h"
33 #include "ui/wm/core/shadow_types.h" 31 #include "ui/wm/core/shadow_types.h"
34 #include "ui/wm/core/visibility_controller.h" 32 #include "ui/wm/core/visibility_controller.h"
35 #include "ui/wm/core/window_animations.h"
36 #include "ui/wm/public/activation_change_observer.h" 33 #include "ui/wm/public/activation_change_observer.h"
37 #include "ui/wm/public/activation_client.h" 34 #include "ui/wm/public/activation_client.h"
38 35
39 namespace athena { 36 namespace athena {
40 namespace { 37 namespace {
41 38
42 HomeCard* instance = NULL; 39 HomeCard* instance = NULL;
43 const int kHomeCardHeight = 100; 40 const int kHomeCardHeight = 100;
44 const int kHomeCardMinimizedHeight = 6; 41 const int kHomeCardMinimizedHeight = 6;
45 42
46 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, 43 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds,
47 HomeCard::State state) { 44 HomeCard::State state) {
48 switch (state) { 45 switch (state) {
49 case HomeCard::HIDDEN: 46 case HomeCard::HIDDEN:
50 break; 47 break;
51 48
52 case HomeCard::VISIBLE_CENTERED: 49 case HomeCard::VISIBLE_CENTERED:
53 return screen_bounds; 50 return screen_bounds;
54 51
52 // Do not change the home_card's size, only changes the top position
53 // instead, because size change causes unnecessary re-layouts.
55 case HomeCard::VISIBLE_BOTTOM: 54 case HomeCard::VISIBLE_BOTTOM:
56 return gfx::Rect(0, 55 return gfx::Rect(0,
57 screen_bounds.bottom() - kHomeCardHeight, 56 screen_bounds.bottom() - kHomeCardHeight,
58 screen_bounds.width(), 57 screen_bounds.width(),
59 kHomeCardHeight); 58 screen_bounds.height());
60 case HomeCard::VISIBLE_MINIMIZED: 59 case HomeCard::VISIBLE_MINIMIZED:
61 return gfx::Rect(0, 60 return gfx::Rect(0,
62 screen_bounds.bottom() - kHomeCardMinimizedHeight, 61 screen_bounds.bottom() - kHomeCardMinimizedHeight,
63 screen_bounds.width(), 62 screen_bounds.width(),
64 kHomeCardMinimizedHeight); 63 screen_bounds.height());
65 } 64 }
66 65
67 NOTREACHED(); 66 NOTREACHED();
68 return gfx::Rect(); 67 return gfx::Rect();
69 } 68 }
70 69
71 // Makes sure the homecard is center-aligned horizontally and bottom-aligned 70 // Makes sure the homecard is center-aligned horizontally and bottom-aligned
72 // vertically. 71 // vertically.
73 class HomeCardLayoutManager : public aura::LayoutManager { 72 class HomeCardLayoutManager : public aura::LayoutManager {
74 public: 73 public:
75 explicit HomeCardLayoutManager() 74 explicit HomeCardLayoutManager()
sadrul 2014/08/26 20:11:18 You don't need 'explicit' here.
Jun Mukai 2014/08/26 20:48:45 Done.
76 : home_card_(NULL) {} 75 : home_card_(NULL),
76 minimized_layer_(NULL) {}
77 77
78 virtual ~HomeCardLayoutManager() {} 78 virtual ~HomeCardLayoutManager() {}
79 79
80 void Layout() { 80 void Layout(bool animate) {
81 // |home_card| could be detached from the root window (e.g. when it is being 81 // |home_card| could be detached from the root window (e.g. when it is being
82 // destroyed). 82 // destroyed).
83 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow()) 83 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow())
84 return; 84 return;
85 85
86 { 86 scoped_ptr<ui::ScopedLayerAnimationSettings> settings;
87 ui::ScopedLayerAnimationSettings settings( 87 if (animate) {
88 home_card_->layer()->GetAnimator()); 88 settings.reset(new ui::ScopedLayerAnimationSettings(
89 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); 89 home_card_->layer()->GetAnimator()));
90 SetChildBoundsDirect(home_card_, GetBoundsForState( 90 settings->SetTweenType(gfx::Tween::EASE_IN_OUT);
91 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState()));
92 } 91 }
92 SetChildBoundsDirect(home_card_, GetBoundsForState(
93 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState()));
94 }
95
96 void SetMinimizedLayer(ui::Layer* minimized_layer) {
97 minimized_layer_ = minimized_layer;
98 UpdateMinimizedHomeBounds();
93 } 99 }
94 100
95 private: 101 private:
102 void UpdateMinimizedHomeBounds() {
103 gfx::Rect minimized_bounds = minimized_layer_->parent()->bounds();
104 minimized_bounds.set_y(
105 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
106 minimized_bounds.set_height(kHomeCardMinimizedHeight);
107 minimized_layer_->SetBounds(minimized_bounds);
108 }
109
96 // aura::LayoutManager: 110 // aura::LayoutManager:
97 virtual void OnWindowResized() OVERRIDE { Layout(); } 111 virtual void OnWindowResized() OVERRIDE {
112 Layout(false);
113 UpdateMinimizedHomeBounds();
114 }
98 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { 115 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
99 if (!home_card_) { 116 if (!home_card_) {
100 home_card_ = child; 117 home_card_ = child;
101 Layout(); 118 Layout(false);
102 } 119 }
103 } 120 }
104 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { 121 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
105 if (home_card_ == child) 122 if (home_card_ == child)
106 home_card_ = NULL; 123 home_card_ = NULL;
107 } 124 }
108 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 125 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
109 Layout(); 126 Layout(false);
110 } 127 }
111 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 128 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
112 bool visible) OVERRIDE { 129 bool visible) OVERRIDE {
113 Layout(); 130 Layout(false);
114 } 131 }
115 virtual void SetChildBounds(aura::Window* child, 132 virtual void SetChildBounds(aura::Window* child,
116 const gfx::Rect& requested_bounds) OVERRIDE { 133 const gfx::Rect& requested_bounds) OVERRIDE {
117 SetChildBoundsDirect(child, requested_bounds); 134 SetChildBoundsDirect(child, requested_bounds);
118 } 135 }
119 136
120 aura::Window* home_card_; 137 aura::Window* home_card_;
138 ui::Layer* minimized_layer_;
121 139
122 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 140 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
123 }; 141 };
124 142
125 class HomeCardGestureManager { 143 class HomeCardGestureManager {
126 public: 144 public:
127 class Delegate { 145 class Delegate {
128 public: 146 public:
129 // Called when the gesture has ended. The state of the home card will 147 // Called when the gesture has ended. The state of the home card will
130 // end up with |final_state|. 148 // end up with |final_state|.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 284
267 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager); 285 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager);
268 }; 286 };
269 287
270 // The container view of home card contents of each state. 288 // The container view of home card contents of each state.
271 class HomeCardView : public views::WidgetDelegateView { 289 class HomeCardView : public views::WidgetDelegateView {
272 public: 290 public:
273 HomeCardView(app_list::AppListViewDelegate* view_delegate, 291 HomeCardView(app_list::AppListViewDelegate* view_delegate,
274 aura::Window* container, 292 aura::Window* container,
275 HomeCardGestureManager::Delegate* gesture_delegate) 293 HomeCardGestureManager::Delegate* gesture_delegate)
276 : gesture_delegate_(gesture_delegate), 294 : gesture_delegate_(gesture_delegate) {
277 weak_factory_(this) { 295 SetLayoutManager(new views::FillLayout());
278 // Ideally AppListMainView should be used here and have AthenaStartPageView 296 // Ideally AppListMainView should be used here and have AthenaStartPageView
279 // as its child view, so that custom pages and apps grid are available in 297 // as its child view, so that custom pages and apps grid are available in
280 // the home card. 298 // the home card.
281 // TODO(mukai): make it so after the detailed UI has been fixed. 299 // TODO(mukai): make it so after the detailed UI has been fixed.
282 main_view_ = new AthenaStartPageView(view_delegate); 300 main_view_ = new AthenaStartPageView(view_delegate);
283 AddChildView(main_view_); 301 AddChildView(main_view_);
284
285 minimized_view_ = CreateMinimizedHome();
286 minimized_view_->SetPaintToLayer(true);
287 AddChildView(minimized_view_);
288 } 302 }
289 303
290 void SetStateProgress(HomeCard::State from_state, 304 void SetStateProgress(HomeCard::State from_state,
291 HomeCard::State to_state, 305 HomeCard::State to_state,
292 float progress) { 306 float progress) {
293 if (from_state == HomeCard::VISIBLE_BOTTOM && 307 if (from_state == HomeCard::VISIBLE_CENTERED)
294 to_state == HomeCard::VISIBLE_MINIMIZED) { 308 main_view_->SetLayoutState(1.0f - progress);
295 SetStateProgress(to_state, from_state, 1.0 - progress); 309 else if (to_state == HomeCard::VISIBLE_CENTERED)
296 return; 310 main_view_->SetLayoutState(progress);
297 } 311 else
298 312 SetState(to_state);
299 // View from minimized to bottom.
300 if (from_state == HomeCard::VISIBLE_MINIMIZED &&
301 to_state == HomeCard::VISIBLE_BOTTOM) {
302 main_view_->SetVisible(true);
303 minimized_view_->SetVisible(true);
304 minimized_view_->layer()->SetOpacity(1.0f - progress);
305 return;
306 }
307
308 SetState(to_state);
309 } 313 }
310 314
311 void SetState(HomeCard::State state) { 315 void SetState(HomeCard::State state) {
312 main_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM ||
313 state == HomeCard::VISIBLE_CENTERED);
314 minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
315 if (minimized_view_->visible())
316 minimized_view_->layer()->SetOpacity(1.0f);
317 if (state == HomeCard::VISIBLE_CENTERED) 316 if (state == HomeCard::VISIBLE_CENTERED)
318 main_view_->RequestFocusOnSearchBox(); 317 main_view_->RequestFocusOnSearchBox();
319 else 318 else
320 GetWidget()->GetFocusManager()->ClearFocus(); 319 GetWidget()->GetFocusManager()->ClearFocus();
321 wm::SetShadowType(GetWidget()->GetNativeView(), 320 wm::SetShadowType(GetWidget()->GetNativeView(),
322 state == HomeCard::VISIBLE_MINIMIZED ? 321 state == HomeCard::VISIBLE_MINIMIZED ?
323 wm::SHADOW_TYPE_NONE : 322 wm::SHADOW_TYPE_NONE :
324 wm::SHADOW_TYPE_RECTANGULAR); 323 wm::SHADOW_TYPE_RECTANGULAR);
324 main_view_->SetLayoutState(
325 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
325 } 326 }
326 327
327 void SetStateWithAnimation(HomeCard::State from_state, 328 void SetStateWithAnimation(HomeCard::State state) {
328 HomeCard::State to_state) { 329 if (state == HomeCard::VISIBLE_MINIMIZED)
329 if ((from_state == HomeCard::VISIBLE_MINIMIZED && 330 return;
330 to_state == HomeCard::VISIBLE_BOTTOM) || 331
331 (from_state == HomeCard::VISIBLE_BOTTOM && 332 main_view_->SetLayoutStateWithAnimation(
332 to_state == HomeCard::VISIBLE_MINIMIZED)) { 333 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
333 minimized_view_->SetVisible(true);
334 main_view_->SetVisible(true);
335 {
336 ui::ScopedLayerAnimationSettings settings(
337 minimized_view_->layer()->GetAnimator());
338 settings.SetTweenType(gfx::Tween::EASE_IN_OUT);
339 settings.AddObserver(new ui::ClosureAnimationObserver(
340 base::Bind(&HomeCardView::SetState,
341 weak_factory_.GetWeakPtr(),
342 to_state)));
343 minimized_view_->layer()->SetOpacity(
344 (to_state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f);
345 }
346 } else {
347 // TODO(mukai): Take care of other transition.
348 SetState(to_state);
349 }
350 } 334 }
351 335
352 void ClearGesture() { 336 void ClearGesture() {
353 gesture_manager_.reset(); 337 gesture_manager_.reset();
354 } 338 }
355 339
356 // views::View: 340 // views::View:
357 virtual void Layout() OVERRIDE {
358 for (int i = 0; i < child_count(); ++i) {
359 views::View* child = child_at(i);
360 if (child->visible()) {
361 if (child == minimized_view_) {
362 gfx::Rect minimized_bounds = bounds();
363 minimized_bounds.set_y(
364 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
365 minimized_bounds.set_height(kHomeCardMinimizedHeight);
366 child->SetBoundsRect(minimized_bounds);
367 } else {
368 child->SetBoundsRect(bounds());
369 }
370 }
371 }
372 }
373 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 341 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
374 if (!gesture_manager_ && 342 if (!gesture_manager_ &&
375 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 343 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
376 gesture_manager_.reset(new HomeCardGestureManager( 344 gesture_manager_.reset(new HomeCardGestureManager(
377 gesture_delegate_, 345 gesture_delegate_,
378 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds())); 346 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds()));
379 } 347 }
380 348
381 if (gesture_manager_) 349 if (gesture_manager_)
382 gesture_manager_->ProcessGestureEvent(event); 350 gesture_manager_->ProcessGestureEvent(event);
383 } 351 }
352 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
353 if (HomeCard::Get()->GetState() == HomeCard::VISIBLE_MINIMIZED &&
354 event.IsLeftMouseButton() && event.GetClickCount() == 1) {
355 athena::WindowManager::GetInstance()->ToggleOverview();
356 return true;
357 }
358 return false;
359 }
384 360
385 private: 361 private:
386 // views::WidgetDelegate: 362 // views::WidgetDelegate:
387 virtual views::View* GetContentsView() OVERRIDE { 363 virtual views::View* GetContentsView() OVERRIDE {
388 return this; 364 return this;
389 } 365 }
390 366
391 AthenaStartPageView* main_view_; 367 AthenaStartPageView* main_view_;
392 views::View* minimized_view_;
393 scoped_ptr<HomeCardGestureManager> gesture_manager_; 368 scoped_ptr<HomeCardGestureManager> gesture_manager_;
394 HomeCardGestureManager::Delegate* gesture_delegate_; 369 HomeCardGestureManager::Delegate* gesture_delegate_;
395 base::WeakPtrFactory<HomeCardView> weak_factory_;
396 370
397 DISALLOW_COPY_AND_ASSIGN(HomeCardView); 371 DISALLOW_COPY_AND_ASSIGN(HomeCardView);
398 }; 372 };
399 373
400 class HomeCardImpl : public HomeCard, 374 class HomeCardImpl : public HomeCard,
401 public AcceleratorHandler, 375 public AcceleratorHandler,
402 public HomeCardGestureManager::Delegate, 376 public HomeCardGestureManager::Delegate,
403 public WindowManagerObserver, 377 public WindowManagerObserver,
404 public aura::client::ActivationChangeObserver { 378 public aura::client::ActivationChangeObserver {
405 public: 379 public:
406 explicit HomeCardImpl(AppModelBuilder* model_builder); 380 explicit HomeCardImpl(AppModelBuilder* model_builder);
407 virtual ~HomeCardImpl(); 381 virtual ~HomeCardImpl();
408 382
409 void Init(); 383 void Init();
410 384
411 private: 385 private:
412 enum Command { 386 enum Command {
413 COMMAND_SHOW_HOME_CARD, 387 COMMAND_SHOW_HOME_CARD,
414 }; 388 };
415 void InstallAccelerators(); 389 void InstallAccelerators();
390 void UpdateMinimizedHomeBounds();
416 391
417 // Overridden from HomeCard: 392 // Overridden from HomeCard:
418 virtual void SetState(State state) OVERRIDE; 393 virtual void SetState(State state) OVERRIDE;
419 virtual State GetState() OVERRIDE; 394 virtual State GetState() OVERRIDE;
420 virtual void RegisterSearchProvider( 395 virtual void RegisterSearchProvider(
421 app_list::SearchProvider* search_provider) OVERRIDE; 396 app_list::SearchProvider* search_provider) OVERRIDE;
422 virtual void UpdateVirtualKeyboardBounds( 397 virtual void UpdateVirtualKeyboardBounds(
423 const gfx::Rect& bounds) OVERRIDE; 398 const gfx::Rect& bounds) OVERRIDE;
424 399
425 // AcceleratorHandler: 400 // AcceleratorHandler:
(...skipping 20 matching lines...) Expand all
446 421
447 // original_state_ is the state which the home card should go back to after 422 // original_state_ is the state which the home card should go back to after
448 // the virtual keyboard is hidden. 423 // the virtual keyboard is hidden.
449 HomeCard::State original_state_; 424 HomeCard::State original_state_;
450 425
451 views::Widget* home_card_widget_; 426 views::Widget* home_card_widget_;
452 HomeCardView* home_card_view_; 427 HomeCardView* home_card_view_;
453 scoped_ptr<AppListViewDelegate> view_delegate_; 428 scoped_ptr<AppListViewDelegate> view_delegate_;
454 HomeCardLayoutManager* layout_manager_; 429 HomeCardLayoutManager* layout_manager_;
455 aura::client::ActivationClient* activation_client_; // Not owned 430 aura::client::ActivationClient* activation_client_; // Not owned
431 scoped_ptr<ui::LayerOwner> minimized_home_;
456 432
457 // Right now HomeCard allows only one search provider. 433 // Right now HomeCard allows only one search provider.
458 // TODO(mukai): port app-list's SearchController and Mixer. 434 // TODO(mukai): port app-list's SearchController and Mixer.
459 scoped_ptr<app_list::SearchProvider> search_provider_; 435 scoped_ptr<app_list::SearchProvider> search_provider_;
460 436
461 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); 437 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
462 }; 438 };
463 439
464 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) 440 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
465 : model_builder_(model_builder), 441 : model_builder_(model_builder),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 480
505 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this); 481 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
506 home_card_widget_ = new views::Widget(); 482 home_card_widget_ = new views::Widget();
507 views::Widget::InitParams widget_params( 483 views::Widget::InitParams widget_params(
508 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 484 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
509 widget_params.parent = container; 485 widget_params.parent = container;
510 widget_params.delegate = home_card_view_; 486 widget_params.delegate = home_card_view_;
511 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 487 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
512 home_card_widget_->Init(widget_params); 488 home_card_widget_->Init(widget_params);
513 489
490 minimized_home_ = CreateMinimizedHome();
491 container->layer()->Add(minimized_home_->layer());
492 container->layer()->StackAtTop(minimized_home_->layer());
493 layout_manager_->SetMinimizedLayer(minimized_home_->layer());
494
514 SetState(VISIBLE_MINIMIZED); 495 SetState(VISIBLE_MINIMIZED);
515 home_card_view_->Layout(); 496 home_card_view_->Layout();
516 497
517 activation_client_ = 498 activation_client_ =
518 aura::client::GetActivationClient(container->GetRootWindow()); 499 aura::client::GetActivationClient(container->GetRootWindow());
519 if (activation_client_) 500 if (activation_client_)
520 activation_client_->AddObserver(this); 501 activation_client_->AddObserver(this);
521 502
522 int work_area_bottom_inset =
523 GetBoundsForState(home_card_widget_->GetNativeWindow()->bounds(),
524 HomeCard::VISIBLE_MINIMIZED).height();
525 AthenaEnv::Get()->SetDisplayWorkAreaInsets( 503 AthenaEnv::Get()->SetDisplayWorkAreaInsets(
526 gfx::Insets(0, 0, work_area_bottom_inset, 0)); 504 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0));
527 } 505 }
528 506
529 void HomeCardImpl::InstallAccelerators() { 507 void HomeCardImpl::InstallAccelerators() {
530 const AcceleratorData accelerator_data[] = { 508 const AcceleratorData accelerator_data[] = {
531 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, 509 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
532 COMMAND_SHOW_HOME_CARD, AF_NONE}, 510 COMMAND_SHOW_HOME_CARD, AF_NONE},
533 }; 511 };
534 AcceleratorManager::Get()->RegisterAccelerators( 512 AcceleratorManager::Get()->RegisterAccelerators(
535 accelerator_data, arraysize(accelerator_data), this); 513 accelerator_data, arraysize(accelerator_data), this);
536 } 514 }
537 515
538 void HomeCardImpl::SetState(HomeCard::State state) { 516 void HomeCardImpl::SetState(HomeCard::State state) {
539 if (state_ == state) 517 if (state_ == state)
540 return; 518 return;
541 519
542 // Update |state_| before changing the visibility of the widgets, so that 520 // Update |state_| before changing the visibility of the widgets, so that
543 // LayoutManager callbacks get the correct state. 521 // LayoutManager callbacks get the correct state.
544 HomeCard::State old_state = state_; 522 HomeCard::State old_state = state_;
545 state_ = state; 523 state_ = state;
546 original_state_ = state; 524 original_state_ = state;
525
526 if (old_state == VISIBLE_MINIMIZED ||
527 state_ == VISIBLE_MINIMIZED) {
528 minimized_home_->layer()->SetVisible(true);
529 {
530 ui::ScopedLayerAnimationSettings settings(
531 minimized_home_->layer()->GetAnimator());
532 minimized_home_->layer()->SetVisible(state_ == VISIBLE_MINIMIZED);
533 minimized_home_->layer()->SetOpacity(
534 state_ == VISIBLE_MINIMIZED ? 1.0f : 0.0f);
535 }
536 }
547 if (state_ == HIDDEN) { 537 if (state_ == HIDDEN) {
548 home_card_widget_->Hide(); 538 home_card_widget_->Hide();
549 } else { 539 } else {
550 if (state_ == VISIBLE_CENTERED) 540 if (state_ == VISIBLE_CENTERED)
551 home_card_widget_->Show(); 541 home_card_widget_->Show();
552 else 542 else
553 home_card_widget_->ShowInactive(); 543 home_card_widget_->ShowInactive();
554 home_card_view_->SetStateWithAnimation(old_state, state); 544 home_card_view_->SetStateWithAnimation(state);
555 layout_manager_->Layout(); 545 layout_manager_->Layout(true);
556 } 546 }
557 } 547 }
558 548
559 HomeCard::State HomeCardImpl::GetState() { 549 HomeCard::State HomeCardImpl::GetState() {
560 return state_; 550 return state_;
561 } 551 }
562 552
563 void HomeCardImpl::RegisterSearchProvider( 553 void HomeCardImpl::RegisterSearchProvider(
564 app_list::SearchProvider* search_provider) { 554 app_list::SearchProvider* search_provider) {
565 DCHECK(!search_provider_); 555 DCHECK(!search_provider_);
(...skipping 24 matching lines...) Expand all
590 SetState(VISIBLE_CENTERED); 580 SetState(VISIBLE_CENTERED);
591 return true; 581 return true;
592 } 582 }
593 583
594 void HomeCardImpl::OnGestureEnded(State final_state) { 584 void HomeCardImpl::OnGestureEnded(State final_state) {
595 home_card_view_->ClearGesture(); 585 home_card_view_->ClearGesture();
596 if (state_ != final_state && 586 if (state_ != final_state &&
597 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { 587 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
598 WindowManager::GetInstance()->ToggleOverview(); 588 WindowManager::GetInstance()->ToggleOverview();
599 } else { 589 } else {
600 HomeCard::State old_state = state_;
601 state_ = final_state; 590 state_ = final_state;
602 home_card_view_->SetStateWithAnimation(old_state, final_state); 591 home_card_view_->SetStateWithAnimation(state_);
603 layout_manager_->Layout(); 592 layout_manager_->Layout(true);
604 } 593 }
605 } 594 }
606 595
607 void HomeCardImpl::OnGestureProgressed( 596 void HomeCardImpl::OnGestureProgressed(
608 State from_state, State to_state, float progress) { 597 State from_state, State to_state, float progress) {
609 home_card_view_->SetStateProgress(from_state, to_state, progress); 598 if (from_state == VISIBLE_MINIMIZED || to_state == VISIBLE_MINIMIZED) {
610 599 minimized_home_->layer()->SetVisible(true);
600 float opacity =
601 (from_state == VISIBLE_MINIMIZED) ? 1.0f - progress : progress;
602 minimized_home_->layer()->SetOpacity(opacity);
603 }
611 gfx::Rect screen_bounds = 604 gfx::Rect screen_bounds =
612 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); 605 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
613 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween( 606 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween(
614 progress, 607 progress,
615 GetBoundsForState(screen_bounds, from_state), 608 GetBoundsForState(screen_bounds, from_state),
616 GetBoundsForState(screen_bounds, to_state))); 609 GetBoundsForState(screen_bounds, to_state)));
617 610
611 home_card_view_->SetStateProgress(from_state, to_state, progress);
612
618 // TODO(mukai): signals the update to the window manager so that it shows the 613 // TODO(mukai): signals the update to the window manager so that it shows the
619 // intermediate visual state of overview mode. 614 // intermediate visual state of overview mode.
620 } 615 }
621 616
622 void HomeCardImpl::OnOverviewModeEnter() { 617 void HomeCardImpl::OnOverviewModeEnter() {
623 SetState(VISIBLE_BOTTOM); 618 SetState(VISIBLE_BOTTOM);
624 } 619 }
625 620
626 void HomeCardImpl::OnOverviewModeExit() { 621 void HomeCardImpl::OnOverviewModeExit() {
627 SetState(VISIBLE_MINIMIZED); 622 SetState(VISIBLE_MINIMIZED);
(...skipping 23 matching lines...) Expand all
651 instance = NULL; 646 instance = NULL;
652 } 647 }
653 648
654 // static 649 // static
655 HomeCard* HomeCard::Get() { 650 HomeCard* HomeCard::Get() {
656 DCHECK(instance); 651 DCHECK(instance);
657 return instance; 652 return instance;
658 } 653 }
659 654
660 } // namespace athena 655 } // namespace athena
OLDNEW
« no previous file with comments | « athena/home/athena_start_page_view.cc ('k') | athena/home/minimized_home.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698