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 "athena/home/home_card_delegate_view.h" | 7 #include "athena/home/home_card_delegate_view.h" |
8 #include "athena/input/public/accelerator_manager.h" | |
9 #include "athena/input/public/input_manager.h" | |
8 #include "athena/screen/public/screen_manager.h" | 10 #include "athena/screen/public/screen_manager.h" |
9 #include "ui/aura/layout_manager.h" | 11 #include "ui/aura/layout_manager.h" |
10 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
11 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
12 #include "ui/wm/core/visibility_controller.h" | 14 #include "ui/wm/core/visibility_controller.h" |
13 #include "ui/wm/core/window_animations.h" | 15 #include "ui/wm/core/window_animations.h" |
14 | 16 |
15 namespace athena { | 17 namespace athena { |
16 namespace { | 18 namespace { |
17 | 19 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 kHomeCardHorizontalMargin, | 57 kHomeCardHorizontalMargin, |
56 0); | 58 0); |
57 SetChildBoundsDirect(home_card, card_bounds); | 59 SetChildBoundsDirect(home_card, card_bounds); |
58 } | 60 } |
59 | 61 |
60 aura::Window* container_; | 62 aura::Window* container_; |
61 | 63 |
62 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 64 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
63 }; | 65 }; |
64 | 66 |
65 class HomeCardImpl : public HomeCard { | 67 class HomeCardImpl : public HomeCard, public AcceleratorHandler { |
66 public: | 68 public: |
67 HomeCardImpl(); | 69 HomeCardImpl(); |
68 virtual ~HomeCardImpl(); | 70 virtual ~HomeCardImpl(); |
69 | 71 |
70 void Init(); | 72 void Init(); |
71 | 73 |
72 private: | 74 private: |
75 enum Command { | |
76 COMMAND_SHOW_HOME_CARD, | |
77 }; | |
78 void InstallAccelerators(); | |
79 | |
80 // AcceleratorHandler: | |
81 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | |
82 virtual bool OnAcceleratorFired(int command_id, | |
83 const ui::Accelerator& accelerator) OVERRIDE { | |
84 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | |
85 home_card_widget_->Show(); | |
86 return true; | |
87 } | |
88 | |
73 views::Widget* home_card_widget_; | 89 views::Widget* home_card_widget_; |
74 | 90 |
75 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 91 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
76 }; | 92 }; |
77 | 93 |
78 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { | 94 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { |
79 DCHECK(!instance); | 95 DCHECK(!instance); |
80 instance = this; | 96 instance = this; |
81 } | 97 } |
82 | 98 |
83 HomeCardImpl::~HomeCardImpl() { | 99 HomeCardImpl::~HomeCardImpl() { |
84 DCHECK(instance); | 100 DCHECK(instance); |
85 home_card_widget_->CloseNow(); | 101 home_card_widget_->CloseNow(); |
86 instance = NULL; | 102 instance = NULL; |
87 } | 103 } |
88 | 104 |
89 void HomeCardImpl::Init() { | 105 void HomeCardImpl::Init() { |
106 InstallAccelerators(); | |
107 | |
90 aura::Window* container = | 108 aura::Window* container = |
91 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 109 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
92 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 110 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
93 wm::SetChildWindowVisibilityChangesAnimated(container); | 111 wm::SetChildWindowVisibilityChangesAnimated(container); |
94 | 112 |
95 views::Widget::InitParams params( | 113 views::Widget::InitParams params( |
96 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 114 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
97 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 115 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
98 params.delegate = new HomeCardDelegateView(); | 116 params.delegate = new HomeCardDelegateView(); |
99 params.parent = container; | 117 params.parent = container; |
100 | 118 |
101 home_card_widget_ = new views::Widget; | 119 home_card_widget_ = new views::Widget; |
102 home_card_widget_->Init(params); | 120 home_card_widget_->Init(params); |
103 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); | 121 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); |
104 | 122 |
105 aura::Window* home_card_window = home_card_widget_->GetNativeView(); | 123 aura::Window* home_card_window = home_card_widget_->GetNativeView(); |
106 wm::SetWindowVisibilityAnimationType( | 124 wm::SetWindowVisibilityAnimationType( |
107 home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 125 home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
108 wm::SetWindowVisibilityAnimationTransition(home_card_window, | 126 wm::SetWindowVisibilityAnimationTransition(home_card_window, |
109 wm::ANIMATE_BOTH); | 127 wm::ANIMATE_BOTH); |
110 | 128 |
111 home_card_widget_->Show(); | 129 home_card_widget_->Show(); |
112 } | 130 } |
113 | 131 |
132 void HomeCardImpl::InstallAccelerators() { | |
133 const AcceleratorData accelerator_data[] = { | |
134 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, COMMAND_SHOW_HOME_CARD, | |
135 AF_NONE}, | |
Jun Mukai
2014/06/04 04:02:34
I am not sure if splitting the table into each of
oshima
2014/06/04 04:24:26
That's actually not true. ChromeOS+ash already has
| |
136 }; | |
137 InputManager::Get()->GetAcceleratorManager()->RegisterAccelerators( | |
138 accelerator_data, arraysize(accelerator_data), this); | |
139 } | |
140 | |
114 } // namespace | 141 } // namespace |
115 | 142 |
116 // static | 143 // static |
117 HomeCard* HomeCard::Create() { | 144 HomeCard* HomeCard::Create() { |
118 (new HomeCardImpl())->Init(); | 145 (new HomeCardImpl())->Init(); |
119 DCHECK(instance); | 146 DCHECK(instance); |
120 return instance; | 147 return instance; |
121 } | 148 } |
122 | 149 |
123 // static | 150 // static |
124 void HomeCard::Shutdown() { | 151 void HomeCard::Shutdown() { |
125 DCHECK(instance); | 152 DCHECK(instance); |
126 delete instance; | 153 delete instance; |
127 instance = NULL; | 154 instance = NULL; |
128 } | 155 } |
129 | 156 |
130 } // namespace athena | 157 } // namespace athena |
OLD | NEW |