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/app_list_view_delegate.h" | 7 #include "athena/home/app_list_view_delegate.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/app_list/pagination_model.h" | 11 #include "ui/app_list/pagination_model.h" |
10 #include "ui/app_list/views/app_list_view.h" | 12 #include "ui/app_list/views/app_list_view.h" |
11 #include "ui/aura/layout_manager.h" | 13 #include "ui/aura/layout_manager.h" |
12 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
13 #include "ui/wm/core/visibility_controller.h" | 15 #include "ui/wm/core/visibility_controller.h" |
14 #include "ui/wm/core/window_animations.h" | 16 #include "ui/wm/core/window_animations.h" |
15 | 17 |
16 namespace athena { | 18 namespace athena { |
17 namespace { | 19 namespace { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 0); | 63 0); |
62 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | 64 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); |
63 SetChildBoundsDirect(home_card, card_bounds); | 65 SetChildBoundsDirect(home_card, card_bounds); |
64 } | 66 } |
65 | 67 |
66 aura::Window* container_; | 68 aura::Window* container_; |
67 | 69 |
68 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 70 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
69 }; | 71 }; |
70 | 72 |
71 class HomeCardImpl : public HomeCard { | 73 class HomeCardImpl : public HomeCard, public AcceleratorHandler { |
72 public: | 74 public: |
73 HomeCardImpl(); | 75 HomeCardImpl(); |
74 virtual ~HomeCardImpl(); | 76 virtual ~HomeCardImpl(); |
75 | 77 |
76 void Init(); | 78 void Init(); |
77 | 79 |
78 private: | 80 private: |
| 81 enum Command { |
| 82 COMMAND_SHOW_HOME_CARD, |
| 83 }; |
| 84 void InstallAccelerators(); |
| 85 |
| 86 // AcceleratorHandler: |
| 87 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
| 88 virtual bool OnAcceleratorFired(int command_id, |
| 89 const ui::Accelerator& accelerator) OVERRIDE { |
| 90 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
| 91 home_card_widget_->Show(); |
| 92 return true; |
| 93 } |
| 94 |
79 views::Widget* home_card_widget_; | 95 views::Widget* home_card_widget_; |
80 | 96 |
81 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 97 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
82 }; | 98 }; |
83 | 99 |
84 HomeCardImpl::HomeCardImpl() | 100 HomeCardImpl::HomeCardImpl() |
85 : home_card_widget_(NULL) { | 101 : home_card_widget_(NULL) { |
86 DCHECK(!instance); | 102 DCHECK(!instance); |
87 instance = this; | 103 instance = this; |
88 } | 104 } |
89 | 105 |
90 HomeCardImpl::~HomeCardImpl() { | 106 HomeCardImpl::~HomeCardImpl() { |
91 DCHECK(instance); | 107 DCHECK(instance); |
92 home_card_widget_->CloseNow(); | 108 home_card_widget_->CloseNow(); |
93 instance = NULL; | 109 instance = NULL; |
94 } | 110 } |
95 | 111 |
96 void HomeCardImpl::Init() { | 112 void HomeCardImpl::Init() { |
| 113 InstallAccelerators(); |
| 114 |
97 aura::Window* container = | 115 aura::Window* container = |
98 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 116 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
99 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 117 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
100 wm::SetChildWindowVisibilityChangesAnimated(container); | 118 wm::SetChildWindowVisibilityChangesAnimated(container); |
101 | 119 |
102 app_list::AppListView* view = new app_list::AppListView( | 120 app_list::AppListView* view = new app_list::AppListView( |
103 new AppListViewDelegate); | 121 new AppListViewDelegate); |
104 view->InitAsBubbleAtFixedLocation( | 122 view->InitAsBubbleAtFixedLocation( |
105 container, | 123 container, |
106 0 /* initial_apps_page */, | 124 0 /* initial_apps_page */, |
107 gfx::Point(), | 125 gfx::Point(), |
108 views::BubbleBorder::FLOAT, | 126 views::BubbleBorder::FLOAT, |
109 true /* border_accepts_events */); | 127 true /* border_accepts_events */); |
110 home_card_widget_ = view->GetWidget(); | 128 home_card_widget_ = view->GetWidget(); |
111 view->ShowWhenReady(); | 129 view->ShowWhenReady(); |
112 } | 130 } |
113 | 131 |
| 132 void HomeCardImpl::InstallAccelerators() { |
| 133 const AcceleratorData accelerator_data[] = { |
| 134 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
| 135 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
| 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 |