OLD | NEW |
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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 65 } |
66 | 66 |
67 NOTREACHED(); | 67 NOTREACHED(); |
68 return gfx::Rect(); | 68 return gfx::Rect(); |
69 } | 69 } |
70 | 70 |
71 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | 71 // Makes sure the homecard is center-aligned horizontally and bottom-aligned |
72 // vertically. | 72 // vertically. |
73 class HomeCardLayoutManager : public aura::LayoutManager { | 73 class HomeCardLayoutManager : public aura::LayoutManager { |
74 public: | 74 public: |
75 class Delegate { | 75 explicit HomeCardLayoutManager() |
76 public: | 76 : home_card_(NULL) {} |
77 virtual ~Delegate() {} | |
78 | |
79 virtual HomeCard::State GetState() = 0; | |
80 virtual aura::Window* GetNativeWindow() = 0; | |
81 }; | |
82 | |
83 explicit HomeCardLayoutManager(Delegate* delegate) | |
84 : delegate_(delegate) {} | |
85 | 77 |
86 virtual ~HomeCardLayoutManager() {} | 78 virtual ~HomeCardLayoutManager() {} |
87 | 79 |
88 void Layout() { | 80 void Layout() { |
89 aura::Window* home_card = delegate_->GetNativeWindow(); | |
90 // |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 |
91 // destroyed). | 82 // destroyed). |
92 if (!home_card || !home_card->GetRootWindow()) | 83 if (!home_card_ || !home_card_->IsVisible() || !home_card_->GetRootWindow()) |
93 return; | 84 return; |
94 | 85 |
95 { | 86 { |
96 ui::ScopedLayerAnimationSettings settings( | 87 ui::ScopedLayerAnimationSettings settings( |
97 home_card->layer()->GetAnimator()); | 88 home_card_->layer()->GetAnimator()); |
98 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); | 89 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); |
99 SetChildBoundsDirect(home_card, GetBoundsForState( | 90 SetChildBoundsDirect(home_card_, GetBoundsForState( |
100 home_card->GetRootWindow()->bounds(), delegate_->GetState())); | 91 home_card_->GetRootWindow()->bounds(), HomeCard::Get()->GetState())); |
101 } | 92 } |
102 } | 93 } |
103 | 94 |
104 private: | 95 private: |
105 // aura::LayoutManager: | 96 // aura::LayoutManager: |
106 virtual void OnWindowResized() OVERRIDE { Layout(); } | 97 virtual void OnWindowResized() OVERRIDE { Layout(); } |
107 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } | 98 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
108 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 99 if (!home_card_) { |
| 100 home_card_ = child; |
| 101 Layout(); |
| 102 } |
| 103 } |
| 104 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE { |
| 105 if (home_card_ == child) |
| 106 home_card_ = NULL; |
| 107 } |
109 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | 108 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
110 Layout(); | 109 Layout(); |
111 } | 110 } |
112 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 111 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
113 bool visible) OVERRIDE { | 112 bool visible) OVERRIDE { |
114 Layout(); | 113 Layout(); |
115 } | 114 } |
116 virtual void SetChildBounds(aura::Window* child, | 115 virtual void SetChildBounds(aura::Window* child, |
117 const gfx::Rect& requested_bounds) OVERRIDE { | 116 const gfx::Rect& requested_bounds) OVERRIDE { |
118 SetChildBoundsDirect(child, requested_bounds); | 117 SetChildBoundsDirect(child, requested_bounds); |
119 } | 118 } |
120 | 119 |
121 Delegate* delegate_; | 120 aura::Window* home_card_; |
122 | 121 |
123 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 122 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
124 }; | 123 }; |
125 | 124 |
126 class HomeCardGestureManager { | 125 class HomeCardGestureManager { |
127 public: | 126 public: |
128 class Delegate { | 127 class Delegate { |
129 public: | 128 public: |
130 // Called when the gesture has ended. The state of the home card will | 129 // Called when the gesture has ended. The state of the home card will |
131 // end up with |final_state|. | 130 // end up with |final_state|. |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 views::View* minimized_view_; | 392 views::View* minimized_view_; |
394 scoped_ptr<HomeCardGestureManager> gesture_manager_; | 393 scoped_ptr<HomeCardGestureManager> gesture_manager_; |
395 HomeCardGestureManager::Delegate* gesture_delegate_; | 394 HomeCardGestureManager::Delegate* gesture_delegate_; |
396 base::WeakPtrFactory<HomeCardView> weak_factory_; | 395 base::WeakPtrFactory<HomeCardView> weak_factory_; |
397 | 396 |
398 DISALLOW_COPY_AND_ASSIGN(HomeCardView); | 397 DISALLOW_COPY_AND_ASSIGN(HomeCardView); |
399 }; | 398 }; |
400 | 399 |
401 class HomeCardImpl : public HomeCard, | 400 class HomeCardImpl : public HomeCard, |
402 public AcceleratorHandler, | 401 public AcceleratorHandler, |
403 public HomeCardLayoutManager::Delegate, | |
404 public HomeCardGestureManager::Delegate, | 402 public HomeCardGestureManager::Delegate, |
405 public WindowManagerObserver, | 403 public WindowManagerObserver, |
406 public aura::client::ActivationChangeObserver { | 404 public aura::client::ActivationChangeObserver { |
407 public: | 405 public: |
408 explicit HomeCardImpl(AppModelBuilder* model_builder); | 406 explicit HomeCardImpl(AppModelBuilder* model_builder); |
409 virtual ~HomeCardImpl(); | 407 virtual ~HomeCardImpl(); |
410 | 408 |
411 void Init(); | 409 void Init(); |
412 | 410 |
413 private: | 411 private: |
414 enum Command { | 412 enum Command { |
415 COMMAND_SHOW_HOME_CARD, | 413 COMMAND_SHOW_HOME_CARD, |
416 }; | 414 }; |
417 void InstallAccelerators(); | 415 void InstallAccelerators(); |
418 | 416 |
419 // Overridden from HomeCard: | 417 // Overridden from HomeCard: |
420 virtual void SetState(State state) OVERRIDE; | 418 virtual void SetState(State state) OVERRIDE; |
421 virtual State GetState() OVERRIDE; | 419 virtual State GetState() OVERRIDE; |
422 virtual void RegisterSearchProvider( | 420 virtual void RegisterSearchProvider( |
423 app_list::SearchProvider* search_provider) OVERRIDE; | 421 app_list::SearchProvider* search_provider) OVERRIDE; |
424 virtual void UpdateVirtualKeyboardBounds( | 422 virtual void UpdateVirtualKeyboardBounds( |
425 const gfx::Rect& bounds) OVERRIDE; | 423 const gfx::Rect& bounds) OVERRIDE; |
426 | 424 |
427 // AcceleratorHandler: | 425 // AcceleratorHandler: |
428 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 426 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
429 virtual bool OnAcceleratorFired(int command_id, | 427 virtual bool OnAcceleratorFired(int command_id, |
430 const ui::Accelerator& accelerator) OVERRIDE; | 428 const ui::Accelerator& accelerator) OVERRIDE; |
431 | 429 |
432 // HomeCardLayoutManager::Delegate: | |
433 virtual aura::Window* GetNativeWindow() OVERRIDE; | |
434 | |
435 // HomeCardGestureManager::Delegate: | 430 // HomeCardGestureManager::Delegate: |
436 virtual void OnGestureEnded(State final_state) OVERRIDE; | 431 virtual void OnGestureEnded(State final_state) OVERRIDE; |
437 virtual void OnGestureProgressed( | 432 virtual void OnGestureProgressed( |
438 State from_state, State to_state, float progress) OVERRIDE; | 433 State from_state, State to_state, float progress) OVERRIDE; |
439 | 434 |
440 // WindowManagerObserver: | 435 // WindowManagerObserver: |
441 virtual void OnOverviewModeEnter() OVERRIDE; | 436 virtual void OnOverviewModeEnter() OVERRIDE; |
442 virtual void OnOverviewModeExit() OVERRIDE; | 437 virtual void OnOverviewModeExit() OVERRIDE; |
443 | 438 |
444 // aura::client::ActivationChangeObserver: | 439 // aura::client::ActivationChangeObserver: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 view_delegate_.reset(); | 486 view_delegate_.reset(); |
492 search_provider_.reset(); | 487 search_provider_.reset(); |
493 instance = NULL; | 488 instance = NULL; |
494 } | 489 } |
495 | 490 |
496 void HomeCardImpl::Init() { | 491 void HomeCardImpl::Init() { |
497 InstallAccelerators(); | 492 InstallAccelerators(); |
498 ScreenManager::ContainerParams params("HomeCardContainer", CP_HOME_CARD); | 493 ScreenManager::ContainerParams params("HomeCardContainer", CP_HOME_CARD); |
499 params.can_activate_children = true; | 494 params.can_activate_children = true; |
500 aura::Window* container = ScreenManager::Get()->CreateContainer(params); | 495 aura::Window* container = ScreenManager::Get()->CreateContainer(params); |
501 layout_manager_ = new HomeCardLayoutManager(this); | 496 layout_manager_ = new HomeCardLayoutManager(); |
502 | 497 |
503 container->SetLayoutManager(layout_manager_); | 498 container->SetLayoutManager(layout_manager_); |
504 wm::SetChildWindowVisibilityChangesAnimated(container); | 499 wm::SetChildWindowVisibilityChangesAnimated(container); |
505 | 500 |
506 view_delegate_.reset(new AppListViewDelegate(model_builder_.get())); | 501 view_delegate_.reset(new AppListViewDelegate(model_builder_.get())); |
507 if (search_provider_) | 502 if (search_provider_) |
508 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 503 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
509 | 504 |
510 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this); | 505 home_card_view_ = new HomeCardView(view_delegate_.get(), container, this); |
511 home_card_widget_ = new views::Widget(); | 506 home_card_widget_ = new views::Widget(); |
512 views::Widget::InitParams widget_params( | 507 views::Widget::InitParams widget_params( |
513 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 508 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
514 widget_params.parent = container; | 509 widget_params.parent = container; |
515 widget_params.delegate = home_card_view_; | 510 widget_params.delegate = home_card_view_; |
516 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 511 widget_params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
517 home_card_widget_->Init(widget_params); | 512 home_card_widget_->Init(widget_params); |
518 | 513 |
519 SetState(VISIBLE_MINIMIZED); | 514 SetState(VISIBLE_MINIMIZED); |
520 home_card_view_->Layout(); | 515 home_card_view_->Layout(); |
521 | 516 |
522 activation_client_ = | 517 activation_client_ = |
523 aura::client::GetActivationClient(container->GetRootWindow()); | 518 aura::client::GetActivationClient(container->GetRootWindow()); |
524 if (activation_client_) | 519 if (activation_client_) |
525 activation_client_->AddObserver(this); | 520 activation_client_->AddObserver(this); |
526 | 521 |
527 int work_area_bottom_inset = | 522 int work_area_bottom_inset = |
528 GetBoundsForState(GetNativeWindow()->bounds(), | 523 GetBoundsForState(home_card_widget_->GetNativeWindow()->bounds(), |
529 HomeCard::VISIBLE_MINIMIZED).height(); | 524 HomeCard::VISIBLE_MINIMIZED).height(); |
530 AthenaEnv::Get()->SetDisplayWorkAreaInsets( | 525 AthenaEnv::Get()->SetDisplayWorkAreaInsets( |
531 gfx::Insets(0, 0, work_area_bottom_inset, 0)); | 526 gfx::Insets(0, 0, work_area_bottom_inset, 0)); |
532 } | 527 } |
533 | 528 |
534 void HomeCardImpl::InstallAccelerators() { | 529 void HomeCardImpl::InstallAccelerators() { |
535 const AcceleratorData accelerator_data[] = { | 530 const AcceleratorData accelerator_data[] = { |
536 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 531 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
537 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 532 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
538 }; | 533 }; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 const ui::Accelerator& accelerator) { | 584 const ui::Accelerator& accelerator) { |
590 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 585 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
591 | 586 |
592 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM) | 587 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM) |
593 SetState(VISIBLE_MINIMIZED); | 588 SetState(VISIBLE_MINIMIZED); |
594 else if (state_ == VISIBLE_MINIMIZED) | 589 else if (state_ == VISIBLE_MINIMIZED) |
595 SetState(VISIBLE_CENTERED); | 590 SetState(VISIBLE_CENTERED); |
596 return true; | 591 return true; |
597 } | 592 } |
598 | 593 |
599 aura::Window* HomeCardImpl::GetNativeWindow() { | |
600 if (state_ == HIDDEN) | |
601 return NULL; | |
602 | |
603 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; | |
604 } | |
605 | |
606 void HomeCardImpl::OnGestureEnded(State final_state) { | 594 void HomeCardImpl::OnGestureEnded(State final_state) { |
607 home_card_view_->ClearGesture(); | 595 home_card_view_->ClearGesture(); |
608 if (state_ != final_state && | 596 if (state_ != final_state && |
609 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { | 597 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { |
610 WindowManager::GetInstance()->ToggleOverview(); | 598 WindowManager::GetInstance()->ToggleOverview(); |
611 } else { | 599 } else { |
612 HomeCard::State old_state = state_; | 600 HomeCard::State old_state = state_; |
613 state_ = final_state; | 601 state_ = final_state; |
614 home_card_view_->SetStateWithAnimation(old_state, final_state); | 602 home_card_view_->SetStateWithAnimation(old_state, final_state); |
615 layout_manager_->Layout(); | 603 layout_manager_->Layout(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 instance = NULL; | 651 instance = NULL; |
664 } | 652 } |
665 | 653 |
666 // static | 654 // static |
667 HomeCard* HomeCard::Get() { | 655 HomeCard* HomeCard::Get() { |
668 DCHECK(instance); | 656 DCHECK(instance); |
669 return instance; | 657 return instance; |
670 } | 658 } |
671 | 659 |
672 } // namespace athena | 660 } // namespace athena |
OLD | NEW |