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

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: rease Created 6 years, 4 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
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 class Delegate { 74 class Delegate {
76 public: 75 public:
77 virtual ~Delegate() {} 76 virtual ~Delegate() {}
78 77
79 virtual HomeCard::State GetState() = 0; 78 virtual HomeCard::State GetState() = 0;
80 virtual aura::Window* GetNativeWindow() = 0; 79 virtual aura::Window* GetNativeWindow() = 0;
81 }; 80 };
82 81
83 explicit HomeCardLayoutManager(Delegate* delegate) 82 explicit HomeCardLayoutManager(Delegate* delegate)
84 : delegate_(delegate) {} 83 : delegate_(delegate),
84 minimized_layer_(NULL) {}
85 85
86 virtual ~HomeCardLayoutManager() {} 86 virtual ~HomeCardLayoutManager() {}
87 87
88 void Layout() { 88 void Layout(bool animate) {
89 aura::Window* home_card = delegate_->GetNativeWindow(); 89 aura::Window* home_card = delegate_->GetNativeWindow();
90 // |home_card| could be detached from the root window (e.g. when it is being 90 // |home_card| could be detached from the root window (e.g. when it is being
91 // destroyed). 91 // destroyed).
92 if (!home_card || !home_card->GetRootWindow()) 92 if (!home_card || !home_card->GetRootWindow())
93 return; 93 return;
94 94
95 { 95 scoped_ptr<ui::ScopedLayerAnimationSettings> settings;
96 ui::ScopedLayerAnimationSettings settings( 96 if (animate) {
97 home_card->layer()->GetAnimator()); 97 settings.reset(new ui::ScopedLayerAnimationSettings(
98 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); 98 home_card->layer()->GetAnimator()));
99 SetChildBoundsDirect(home_card, GetBoundsForState( 99 settings->SetTweenType(gfx::Tween::EASE_IN_OUT);
100 home_card->GetRootWindow()->bounds(), delegate_->GetState()));
101 } 100 }
101 SetChildBoundsDirect(home_card, GetBoundsForState(
102 home_card->GetRootWindow()->bounds(), delegate_->GetState()));
103 }
104
105 void SetMinimizedLayer(ui::Layer* minimized_layer) {
106 minimized_layer_ = minimized_layer;
107 UpdateMinimizedHomeBounds();
102 } 108 }
103 109
104 private: 110 private:
111 void UpdateMinimizedHomeBounds() {
112 gfx::Rect minimized_bounds = minimized_layer_->parent()->bounds();
113 minimized_bounds.set_y(
114 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
115 minimized_bounds.set_height(kHomeCardMinimizedHeight);
116 minimized_layer_->SetBounds(minimized_bounds);
117 }
118
105 // aura::LayoutManager: 119 // aura::LayoutManager:
106 virtual void OnWindowResized() OVERRIDE { Layout(); } 120 virtual void OnWindowResized() OVERRIDE {
107 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } 121 Layout(false);
122 UpdateMinimizedHomeBounds();
123 }
124 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
125 Layout(false);
126 }
108 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} 127 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
109 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { 128 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
110 Layout(); 129 Layout(false);
111 } 130 }
112 virtual void OnChildWindowVisibilityChanged(aura::Window* child, 131 virtual void OnChildWindowVisibilityChanged(aura::Window* child,
113 bool visible) OVERRIDE { 132 bool visible) OVERRIDE {
114 Layout(); 133 Layout(false);
115 } 134 }
116 virtual void SetChildBounds(aura::Window* child, 135 virtual void SetChildBounds(aura::Window* child,
117 const gfx::Rect& requested_bounds) OVERRIDE { 136 const gfx::Rect& requested_bounds) OVERRIDE {
118 SetChildBoundsDirect(child, requested_bounds); 137 SetChildBoundsDirect(child, requested_bounds);
119 } 138 }
120 139
121 Delegate* delegate_; 140 Delegate* delegate_;
141 ui::Layer* minimized_layer_;
122 142
123 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); 143 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager);
124 }; 144 };
125 145
126 class HomeCardGestureManager { 146 class HomeCardGestureManager {
127 public: 147 public:
128 class Delegate { 148 class Delegate {
129 public: 149 public:
130 // Called when the gesture has ended. The state of the home card will 150 // Called when the gesture has ended. The state of the home card will
131 // end up with |final_state|. 151 // end up with |final_state|.
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 287
268 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager); 288 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager);
269 }; 289 };
270 290
271 // The container view of home card contents of each state. 291 // The container view of home card contents of each state.
272 class HomeCardView : public views::WidgetDelegateView { 292 class HomeCardView : public views::WidgetDelegateView {
273 public: 293 public:
274 HomeCardView(app_list::AppListViewDelegate* view_delegate, 294 HomeCardView(app_list::AppListViewDelegate* view_delegate,
275 aura::Window* container, 295 aura::Window* container,
276 HomeCardGestureManager::Delegate* gesture_delegate) 296 HomeCardGestureManager::Delegate* gesture_delegate)
277 : gesture_delegate_(gesture_delegate), 297 : gesture_delegate_(gesture_delegate) {
278 weak_factory_(this) { 298 SetLayoutManager(new views::FillLayout());
279 // Ideally AppListMainView should be used here and have AthenaStartPageView 299 // Ideally AppListMainView should be used here and have AthenaStartPageView
280 // as its child view, so that custom pages and apps grid are available in 300 // as its child view, so that custom pages and apps grid are available in
281 // the home card. 301 // the home card.
282 // TODO(mukai): make it so after the detailed UI has been fixed. 302 // TODO(mukai): make it so after the detailed UI has been fixed.
283 main_view_ = new AthenaStartPageView(view_delegate); 303 main_view_ = new AthenaStartPageView(view_delegate);
284 AddChildView(main_view_); 304 AddChildView(main_view_);
285
286 minimized_view_ = CreateMinimizedHome();
287 minimized_view_->SetPaintToLayer(true);
288 AddChildView(minimized_view_);
289 } 305 }
290 306
291 void SetStateProgress(HomeCard::State from_state, 307 void SetStateProgress(HomeCard::State from_state,
292 HomeCard::State to_state, 308 HomeCard::State to_state,
293 float progress) { 309 float progress) {
294 if (from_state == HomeCard::VISIBLE_BOTTOM && 310 if (from_state == HomeCard::VISIBLE_CENTERED)
295 to_state == HomeCard::VISIBLE_MINIMIZED) { 311 main_view_->SetLayoutState(1.0f - progress);
296 SetStateProgress(to_state, from_state, 1.0 - progress); 312 else if (to_state == HomeCard::VISIBLE_CENTERED)
297 return; 313 main_view_->SetLayoutState(progress);
298 } 314 else
299 315 SetState(to_state);
300 // View from minimized to bottom.
301 if (from_state == HomeCard::VISIBLE_MINIMIZED &&
302 to_state == HomeCard::VISIBLE_BOTTOM) {
303 main_view_->SetVisible(true);
304 minimized_view_->SetVisible(true);
305 minimized_view_->layer()->SetOpacity(1.0f - progress);
306 return;
307 }
308
309 SetState(to_state);
310 } 316 }
311 317
312 void SetState(HomeCard::State state) { 318 void SetState(HomeCard::State state) {
313 main_view_->SetVisible(state == HomeCard::VISIBLE_BOTTOM ||
314 state == HomeCard::VISIBLE_CENTERED);
315 minimized_view_->SetVisible(state == HomeCard::VISIBLE_MINIMIZED);
316 if (minimized_view_->visible())
317 minimized_view_->layer()->SetOpacity(1.0f);
318 if (state == HomeCard::VISIBLE_CENTERED) 319 if (state == HomeCard::VISIBLE_CENTERED)
319 main_view_->RequestFocusOnSearchBox(); 320 main_view_->RequestFocusOnSearchBox();
320 else 321 else
321 GetWidget()->GetFocusManager()->ClearFocus(); 322 GetWidget()->GetFocusManager()->ClearFocus();
322 wm::SetShadowType(GetWidget()->GetNativeView(), 323 wm::SetShadowType(GetWidget()->GetNativeView(),
323 state == HomeCard::VISIBLE_MINIMIZED ? 324 state == HomeCard::VISIBLE_MINIMIZED ?
324 wm::SHADOW_TYPE_NONE : 325 wm::SHADOW_TYPE_NONE :
325 wm::SHADOW_TYPE_RECTANGULAR); 326 wm::SHADOW_TYPE_RECTANGULAR);
327 main_view_->SetLayoutState(
328 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
326 } 329 }
327 330
328 void SetStateWithAnimation(HomeCard::State from_state, 331 void SetStateWithAnimation(HomeCard::State state) {
329 HomeCard::State to_state) { 332 if (state == HomeCard::VISIBLE_MINIMIZED)
330 if ((from_state == HomeCard::VISIBLE_MINIMIZED && 333 return;
331 to_state == HomeCard::VISIBLE_BOTTOM) || 334
332 (from_state == HomeCard::VISIBLE_BOTTOM && 335 main_view_->SetLayoutStateWithAnimation(
333 to_state == HomeCard::VISIBLE_MINIMIZED)) { 336 (state == HomeCard::VISIBLE_CENTERED) ? 1.0f : 0.0f);
334 minimized_view_->SetVisible(true);
335 main_view_->SetVisible(true);
336 {
337 ui::ScopedLayerAnimationSettings settings(
338 minimized_view_->layer()->GetAnimator());
339 settings.SetTweenType(gfx::Tween::EASE_IN_OUT);
340 settings.AddObserver(new ui::ClosureAnimationObserver(
341 base::Bind(&HomeCardView::SetState,
342 weak_factory_.GetWeakPtr(),
343 to_state)));
344 minimized_view_->layer()->SetOpacity(
345 (to_state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f);
346 }
347 } else {
348 // TODO(mukai): Take care of other transition.
349 SetState(to_state);
350 }
351 } 337 }
352 338
353 void ClearGesture() { 339 void ClearGesture() {
354 gesture_manager_.reset(); 340 gesture_manager_.reset();
355 } 341 }
356 342
357 // views::View: 343 // views::View:
358 virtual void Layout() OVERRIDE {
359 for (int i = 0; i < child_count(); ++i) {
360 views::View* child = child_at(i);
361 if (child->visible()) {
362 if (child == minimized_view_) {
363 gfx::Rect minimized_bounds = bounds();
364 minimized_bounds.set_y(
365 minimized_bounds.bottom() - kHomeCardMinimizedHeight);
366 minimized_bounds.set_height(kHomeCardMinimizedHeight);
367 child->SetBoundsRect(minimized_bounds);
368 } else {
369 child->SetBoundsRect(bounds());
370 }
371 }
372 }
373 }
374 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE { 344 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
375 if (!gesture_manager_ && 345 if (!gesture_manager_ &&
376 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 346 event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
377 gesture_manager_.reset(new HomeCardGestureManager( 347 gesture_manager_.reset(new HomeCardGestureManager(
378 gesture_delegate_, 348 gesture_delegate_,
379 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds())); 349 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds()));
380 } 350 }
381 351
382 if (gesture_manager_) 352 if (gesture_manager_)
383 gesture_manager_->ProcessGestureEvent(event); 353 gesture_manager_->ProcessGestureEvent(event);
384 } 354 }
355 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
356 if (HomeCard::Get()->GetState() == HomeCard::VISIBLE_MINIMIZED &&
357 event.IsLeftMouseButton() && event.GetClickCount() == 1) {
358 athena::WindowManager::GetInstance()->ToggleOverview();
359 return true;
360 }
361 return false;
362 }
385 363
386 private: 364 private:
387 // views::WidgetDelegate: 365 // views::WidgetDelegate:
388 virtual views::View* GetContentsView() OVERRIDE { 366 virtual views::View* GetContentsView() OVERRIDE {
389 return this; 367 return this;
390 } 368 }
391 369
392 AthenaStartPageView* main_view_; 370 AthenaStartPageView* main_view_;
393 views::View* minimized_view_;
394 scoped_ptr<HomeCardGestureManager> gesture_manager_; 371 scoped_ptr<HomeCardGestureManager> gesture_manager_;
395 HomeCardGestureManager::Delegate* gesture_delegate_; 372 HomeCardGestureManager::Delegate* gesture_delegate_;
396 base::WeakPtrFactory<HomeCardView> weak_factory_;
397 373
398 DISALLOW_COPY_AND_ASSIGN(HomeCardView); 374 DISALLOW_COPY_AND_ASSIGN(HomeCardView);
399 }; 375 };
400 376
401 class HomeCardImpl : public HomeCard, 377 class HomeCardImpl : public HomeCard,
402 public AcceleratorHandler, 378 public AcceleratorHandler,
403 public HomeCardLayoutManager::Delegate, 379 public HomeCardLayoutManager::Delegate,
404 public HomeCardGestureManager::Delegate, 380 public HomeCardGestureManager::Delegate,
405 public WindowManagerObserver, 381 public WindowManagerObserver,
406 public aura::client::ActivationChangeObserver { 382 public aura::client::ActivationChangeObserver {
407 public: 383 public:
408 explicit HomeCardImpl(AppModelBuilder* model_builder); 384 explicit HomeCardImpl(AppModelBuilder* model_builder);
409 virtual ~HomeCardImpl(); 385 virtual ~HomeCardImpl();
410 386
411 void Init(); 387 void Init();
412 388
413 private: 389 private:
414 enum Command { 390 enum Command {
415 COMMAND_SHOW_HOME_CARD, 391 COMMAND_SHOW_HOME_CARD,
416 }; 392 };
417 void InstallAccelerators(); 393 void InstallAccelerators();
394 void UpdateMinimizedHomeBounds();
418 395
419 // Overridden from HomeCard: 396 // Overridden from HomeCard:
420 virtual void SetState(State state) OVERRIDE; 397 virtual void SetState(State state) OVERRIDE;
421 virtual State GetState() OVERRIDE; 398 virtual State GetState() OVERRIDE;
422 virtual void RegisterSearchProvider( 399 virtual void RegisterSearchProvider(
423 app_list::SearchProvider* search_provider) OVERRIDE; 400 app_list::SearchProvider* search_provider) OVERRIDE;
424 virtual void UpdateVirtualKeyboardBounds( 401 virtual void UpdateVirtualKeyboardBounds(
425 const gfx::Rect& bounds) OVERRIDE; 402 const gfx::Rect& bounds) OVERRIDE;
426 403
427 // AcceleratorHandler: 404 // AcceleratorHandler:
(...skipping 23 matching lines...) Expand all
451 428
452 // original_state_ is the state which the home card should go back to after 429 // original_state_ is the state which the home card should go back to after
453 // the virtual keyboard is hidden. 430 // the virtual keyboard is hidden.
454 HomeCard::State original_state_; 431 HomeCard::State original_state_;
455 432
456 views::Widget* home_card_widget_; 433 views::Widget* home_card_widget_;
457 HomeCardView* home_card_view_; 434 HomeCardView* home_card_view_;
458 scoped_ptr<AppListViewDelegate> view_delegate_; 435 scoped_ptr<AppListViewDelegate> view_delegate_;
459 HomeCardLayoutManager* layout_manager_; 436 HomeCardLayoutManager* layout_manager_;
460 aura::client::ActivationClient* activation_client_; // Not owned 437 aura::client::ActivationClient* activation_client_; // Not owned
438 scoped_ptr<ui::LayerOwner> minimized_home_;
461 439
462 // Right now HomeCard allows only one search provider. 440 // Right now HomeCard allows only one search provider.
463 // TODO(mukai): port app-list's SearchController and Mixer. 441 // TODO(mukai): port app-list's SearchController and Mixer.
464 scoped_ptr<app_list::SearchProvider> search_provider_; 442 scoped_ptr<app_list::SearchProvider> search_provider_;
465 443
466 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); 444 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
467 }; 445 };
468 446
469 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) 447 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
470 : model_builder_(model_builder), 448 : model_builder_(model_builder),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 487
510 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this); 488 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this);
511 home_card_widget_ = new views::Widget(); 489 home_card_widget_ = new views::Widget();
512 views::Widget::InitParams widget_params( 490 views::Widget::InitParams widget_params(
513 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 491 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
514 widget_params.parent = container; 492 widget_params.parent = container;
515 widget_params.delegate = home_card_view_; 493 widget_params.delegate = home_card_view_;
516 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 494 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
517 home_card_widget_->Init(widget_params); 495 home_card_widget_->Init(widget_params);
518 496
497 minimized_home_ = CreateMinimizedHome();
498 container->layer()->Add(minimized_home_->layer());
499 container->layer()->StackAtTop(minimized_home_->layer());
500 layout_manager_->SetMinimizedLayer(minimized_home_->layer());
501
519 SetState(VISIBLE_MINIMIZED); 502 SetState(VISIBLE_MINIMIZED);
520 home_card_view_->Layout(); 503 home_card_view_->Layout();
521 504
522 activation_client_ = 505 activation_client_ =
523 aura::client::GetActivationClient(container->GetRootWindow()); 506 aura::client::GetActivationClient(container->GetRootWindow());
524 if (activation_client_) 507 if (activation_client_)
525 activation_client_->AddObserver(this); 508 activation_client_->AddObserver(this);
526 509
527 int work_area_bottom_inset =
528 GetBoundsForState(GetNativeWindow()->bounds(),
529 HomeCard::VISIBLE_MINIMIZED).height();
530 AthenaEnv::Get()->SetDisplayWorkAreaInsets( 510 AthenaEnv::Get()->SetDisplayWorkAreaInsets(
531 gfx::Insets(0, 0, work_area_bottom_inset, 0)); 511 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0));
532 } 512 }
533 513
534 void HomeCardImpl::InstallAccelerators() { 514 void HomeCardImpl::InstallAccelerators() {
535 const AcceleratorData accelerator_data[] = { 515 const AcceleratorData accelerator_data[] = {
536 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, 516 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN,
537 COMMAND_SHOW_HOME_CARD, AF_NONE}, 517 COMMAND_SHOW_HOME_CARD, AF_NONE},
538 }; 518 };
539 AcceleratorManager::Get()->RegisterAccelerators( 519 AcceleratorManager::Get()->RegisterAccelerators(
540 accelerator_data, arraysize(accelerator_data), this); 520 accelerator_data, arraysize(accelerator_data), this);
541 } 521 }
542 522
543 void HomeCardImpl::SetState(HomeCard::State state) { 523 void HomeCardImpl::SetState(HomeCard::State state) {
544 if (state_ == state) 524 if (state_ == state)
545 return; 525 return;
546 526
547 // Update |state_| before changing the visibility of the widgets, so that 527 // Update |state_| before changing the visibility of the widgets, so that
548 // LayoutManager callbacks get the correct state. 528 // LayoutManager callbacks get the correct state.
549 HomeCard::State old_state = state_; 529 HomeCard::State old_state = state_;
550 state_ = state; 530 state_ = state;
551 original_state_ = state; 531 original_state_ = state;
532
533 if (old_state == VISIBLE_MINIMIZED ||
534 state_ == VISIBLE_MINIMIZED) {
535 minimized_home_->layer()->SetVisible(true);
536 {
537 ui::ScopedLayerAnimationSettings settings(
538 minimized_home_->layer()->GetAnimator());
539 minimized_home_->layer()->SetVisible(state_ == VISIBLE_MINIMIZED);
540 minimized_home_->layer()->SetOpacity(
541 state_ == VISIBLE_MINIMIZED ? 1.0f : 0.0f);
542 }
543 }
552 if (state_ == HIDDEN) { 544 if (state_ == HIDDEN) {
553 home_card_widget_->Hide(); 545 home_card_widget_->Hide();
554 } else { 546 } else {
555 if (state_ == VISIBLE_CENTERED) 547 if (state_ == VISIBLE_CENTERED)
556 home_card_widget_->Show(); 548 home_card_widget_->Show();
557 else 549 else
558 home_card_widget_->ShowInactive(); 550 home_card_widget_->ShowInactive();
559 home_card_view_->SetStateWithAnimation(old_state, state); 551 home_card_view_->SetStateWithAnimation(state);
560 layout_manager_->Layout(); 552 layout_manager_->Layout(true);
561 } 553 }
562 } 554 }
563 555
564 HomeCard::State HomeCardImpl::GetState() { 556 HomeCard::State HomeCardImpl::GetState() {
565 return state_; 557 return state_;
566 } 558 }
567 559
568 void HomeCardImpl::RegisterSearchProvider( 560 void HomeCardImpl::RegisterSearchProvider(
569 app_list::SearchProvider* search_provider) { 561 app_list::SearchProvider* search_provider) {
570 DCHECK(!search_provider_); 562 DCHECK(!search_provider_);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 594
603 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; 595 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL;
604 } 596 }
605 597
606 void HomeCardImpl::OnGestureEnded(State final_state) { 598 void HomeCardImpl::OnGestureEnded(State final_state) {
607 home_card_view_->ClearGesture(); 599 home_card_view_->ClearGesture();
608 if (state_ != final_state && 600 if (state_ != final_state &&
609 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { 601 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) {
610 WindowManager::GetInstance()->ToggleOverview(); 602 WindowManager::GetInstance()->ToggleOverview();
611 } else { 603 } else {
612 HomeCard::State old_state = state_;
613 state_ = final_state; 604 state_ = final_state;
614 home_card_view_->SetStateWithAnimation(old_state, final_state); 605 home_card_view_->SetStateWithAnimation(state_);
615 layout_manager_->Layout(); 606 layout_manager_->Layout(true);
616 } 607 }
617 } 608 }
618 609
619 void HomeCardImpl::OnGestureProgressed( 610 void HomeCardImpl::OnGestureProgressed(
620 State from_state, State to_state, float progress) { 611 State from_state, State to_state, float progress) {
621 home_card_view_->SetStateProgress(from_state, to_state, progress); 612 if (from_state == VISIBLE_MINIMIZED || to_state == VISIBLE_MINIMIZED) {
622 613 minimized_home_->layer()->SetVisible(true);
614 float opacity =
615 (from_state == VISIBLE_MINIMIZED) ? 1.0f - progress : progress;
616 minimized_home_->layer()->SetOpacity(opacity);
617 }
623 gfx::Rect screen_bounds = 618 gfx::Rect screen_bounds =
624 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); 619 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds();
625 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween( 620 home_card_widget_->SetBounds(gfx::Tween::RectValueBetween(
626 progress, 621 progress,
627 GetBoundsForState(screen_bounds, from_state), 622 GetBoundsForState(screen_bounds, from_state),
628 GetBoundsForState(screen_bounds, to_state))); 623 GetBoundsForState(screen_bounds, to_state)));
629 624
625 home_card_view_->SetStateProgress(from_state, to_state, progress);
626
630 // TODO(mukai): signals the update to the window manager so that it shows the 627 // TODO(mukai): signals the update to the window manager so that it shows the
631 // intermediate visual state of overview mode. 628 // intermediate visual state of overview mode.
632 } 629 }
633 630
634 void HomeCardImpl::OnOverviewModeEnter() { 631 void HomeCardImpl::OnOverviewModeEnter() {
635 SetState(VISIBLE_BOTTOM); 632 SetState(VISIBLE_BOTTOM);
636 } 633 }
637 634
638 void HomeCardImpl::OnOverviewModeExit() { 635 void HomeCardImpl::OnOverviewModeExit() {
639 SetState(VISIBLE_MINIMIZED); 636 SetState(VISIBLE_MINIMIZED);
(...skipping 23 matching lines...) Expand all
663 instance = NULL; 660 instance = NULL;
664 } 661 }
665 662
666 // static 663 // static
667 HomeCard* HomeCard::Get() { 664 HomeCard* HomeCard::Get() {
668 DCHECK(instance); 665 DCHECK(instance);
669 return instance; 666 return instance;
670 } 667 }
671 668
672 } // namespace athena 669 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698