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/home/minimized_home.h" | |
8 #include "athena/home/public/app_model_builder.h" | 9 #include "athena/home/public/app_model_builder.h" |
9 #include "athena/input/public/accelerator_manager.h" | 10 #include "athena/input/public/accelerator_manager.h" |
10 #include "athena/screen/public/screen_manager.h" | 11 #include "athena/screen/public/screen_manager.h" |
12 #include "athena/wm/public/window_manager.h" | |
13 #include "base/bind.h" | |
11 #include "ui/app_list/search_provider.h" | 14 #include "ui/app_list/search_provider.h" |
12 #include "ui/app_list/views/app_list_view.h" | 15 #include "ui/app_list/views/app_list_view.h" |
13 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
14 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/views/layout/box_layout.h" | |
15 #include "ui/wm/core/visibility_controller.h" | 19 #include "ui/wm/core/visibility_controller.h" |
16 #include "ui/wm/core/window_animations.h" | 20 #include "ui/wm/core/window_animations.h" |
17 | 21 |
18 namespace athena { | 22 namespace athena { |
19 namespace { | 23 namespace { |
20 | 24 |
21 HomeCard* instance = NULL; | 25 HomeCard* instance = NULL; |
22 | 26 |
27 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | |
28 // vertically. | |
23 class HomeCardLayoutManager : public aura::LayoutManager { | 29 class HomeCardLayoutManager : public aura::LayoutManager { |
24 public: | 30 public: |
25 explicit HomeCardLayoutManager(aura::Window* container) | 31 class Delegate { |
26 : container_(container) {} | 32 public: |
33 virtual ~Delegate() {} | |
34 | |
35 virtual int GetHomeCardHeight() const = 0; | |
36 | |
37 virtual int GetHorizontalMargin() const = 0; | |
oshima
2014/07/16 16:24:31
How about returning preferred size?
sadrul
2014/07/16 16:58:26
I considered doing that, but that would require th
oshima
2014/07/16 19:10:38
OK, i wont block CL, but asking home card horizont
| |
38 | |
39 // TODO(mukai): Remove this when bubble is no longer used for | |
40 // VISIBLE_CENTERED or VISIBLE_BOTTOM states. | |
41 virtual bool HasShadow() const = 0; | |
42 }; | |
43 | |
44 HomeCardLayoutManager(Delegate* delegate, aura::Window* container) | |
45 : delegate_(delegate), container_(container) {} | |
27 virtual ~HomeCardLayoutManager() {} | 46 virtual ~HomeCardLayoutManager() {} |
28 | 47 |
29 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { | 48 void UpdateVirtualKeyboardBounds(const gfx::Rect& bounds) { |
30 virtual_keyboard_bounds_ = bounds; | 49 virtual_keyboard_bounds_ = bounds; |
31 Layout(); | 50 Layout(); |
32 } | 51 } |
33 | 52 |
34 private: | 53 private: |
35 // aura::LayoutManager: | 54 // aura::LayoutManager: |
36 virtual void OnWindowResized() OVERRIDE { Layout(); } | 55 virtual void OnWindowResized() OVERRIDE { Layout(); } |
37 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } | 56 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } |
38 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 57 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
39 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | 58 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
40 Layout(); | 59 Layout(); |
41 } | 60 } |
42 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 61 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
43 bool visible) OVERRIDE { | 62 bool visible) OVERRIDE { |
44 Layout(); | 63 Layout(); |
45 } | 64 } |
46 virtual void SetChildBounds(aura::Window* child, | 65 virtual void SetChildBounds(aura::Window* child, |
47 const gfx::Rect& requested_bounds) OVERRIDE { | 66 const gfx::Rect& requested_bounds) OVERRIDE { |
48 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 67 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
49 } | 68 } |
50 | 69 |
51 void Layout() { | 70 void Layout() { |
52 const int kHomeCardHeight = 150; | 71 int height = delegate_->GetHomeCardHeight(); |
53 const int kHomeCardHorizontalMargin = 50; | 72 int horiz_margin = delegate_->GetHorizontalMargin(); |
54 // Currently the home card is provided as a bubble and the bounds has to be | |
55 // increased to cancel the shadow. | |
56 // TODO(mukai): stops using the bubble and remove this. | |
57 const int kHomeCardShadowWidth = 30; | |
58 if (container_->children().size() < 1) | 73 if (container_->children().size() < 1) |
59 return; | 74 return; |
75 | |
76 // There should only be a single visible window. Find it. | |
60 aura::Window* home_card = container_->children()[0]; | 77 aura::Window* home_card = container_->children()[0]; |
61 if (!home_card->IsVisible()) | 78 for (size_t i = 1; !home_card->IsVisible() && i < |
79 container_->children().size(); ++i) { | |
80 home_card = container_->children()[i]; | |
81 } | |
oshima
2014/07/16 16:24:31
can we just pass the window of the home card inste
sadrul
2014/07/16 16:58:26
Done (introduced HomeCard::GetNativeWindow()).
| |
82 if (!home_card) | |
62 return; | 83 return; |
63 | 84 |
64 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | 85 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
65 if (!virtual_keyboard_bounds_.IsEmpty()) | 86 if (!virtual_keyboard_bounds_.IsEmpty()) |
66 screen_bounds.set_height(virtual_keyboard_bounds_.y()); | 87 screen_bounds.set_height(virtual_keyboard_bounds_.y()); |
67 gfx::Rect card_bounds = screen_bounds; | 88 gfx::Rect card_bounds = screen_bounds; |
68 card_bounds.Inset(kHomeCardHorizontalMargin, | 89 card_bounds.Inset(horiz_margin, screen_bounds.height() - height, |
69 screen_bounds.height() - kHomeCardHeight, | 90 horiz_margin, 0); |
70 kHomeCardHorizontalMargin, | 91 |
71 0); | 92 if (delegate_->HasShadow()) { |
72 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | 93 // Currently the home card is provided as a bubble and the bounds has to |
94 // be increased to cancel the shadow. | |
95 // TODO(mukai): stops using the bubble and remove this. | |
oshima
2014/07/16 16:24:31
Can't we just disable bubble's shadow using AppLis
sadrul
2014/07/16 16:58:26
I tried that, but it looks like we still need this
Jun Mukai
2014/07/16 18:31:56
That is right, unfortunately it's hard to disable
| |
96 const int kHomeCardShadowWidth = 30; | |
97 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | |
98 } | |
73 SetChildBoundsDirect(home_card, card_bounds); | 99 SetChildBoundsDirect(home_card, card_bounds); |
74 } | 100 } |
75 | 101 |
102 Delegate* delegate_; | |
76 aura::Window* container_; | 103 aura::Window* container_; |
77 gfx::Rect virtual_keyboard_bounds_; | 104 gfx::Rect virtual_keyboard_bounds_; |
78 | 105 |
79 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 106 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
80 }; | 107 }; |
81 | 108 |
82 class HomeCardImpl : public HomeCard, public AcceleratorHandler { | 109 class HomeCardImpl : public HomeCard, |
110 public AcceleratorHandler, | |
111 public HomeCardLayoutManager::Delegate, | |
112 public MinimizedHomeDragDelegate { | |
83 public: | 113 public: |
84 explicit HomeCardImpl(AppModelBuilder* model_builder); | 114 explicit HomeCardImpl(AppModelBuilder* model_builder); |
85 virtual ~HomeCardImpl(); | 115 virtual ~HomeCardImpl(); |
86 | 116 |
87 void Init(); | 117 void Init(); |
88 | 118 |
89 private: | 119 private: |
90 enum Command { | 120 enum Command { |
91 COMMAND_SHOW_HOME_CARD, | 121 COMMAND_SHOW_HOME_CARD, |
92 }; | 122 }; |
(...skipping 11 matching lines...) Expand all Loading... | |
104 virtual bool OnAcceleratorFired(int command_id, | 134 virtual bool OnAcceleratorFired(int command_id, |
105 const ui::Accelerator& accelerator) OVERRIDE { | 135 const ui::Accelerator& accelerator) OVERRIDE { |
106 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 136 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
107 if (state_ == HIDDEN) | 137 if (state_ == HIDDEN) |
108 SetState(VISIBLE_CENTERED); | 138 SetState(VISIBLE_CENTERED); |
109 else | 139 else |
110 SetState(HIDDEN); | 140 SetState(HIDDEN); |
111 return true; | 141 return true; |
112 } | 142 } |
113 | 143 |
144 // HomeCardLayoutManager::Delegate: | |
145 virtual int GetHomeCardHeight() const OVERRIDE { | |
146 const int kHomeCardHeight = 150; | |
147 const int kHomeCardMinimizedHeight = 8; | |
148 CHECK_NE(HIDDEN, state_); | |
149 return state_ == VISIBLE_MINIMIZED ? kHomeCardMinimizedHeight : | |
150 kHomeCardHeight; | |
151 } | |
152 | |
153 virtual int GetHorizontalMargin() const OVERRIDE { | |
154 CHECK_NE(HIDDEN, state_); | |
155 const int kHomeCardHorizontalMargin = 50; | |
156 return state_ == VISIBLE_MINIMIZED ? 0 : kHomeCardHorizontalMargin; | |
157 } | |
158 | |
159 virtual bool HasShadow() const OVERRIDE { | |
160 CHECK_NE(HIDDEN, state_); | |
161 return state_ != VISIBLE_MINIMIZED; | |
162 } | |
163 | |
164 // MinimizedHomeDragDelegate: | |
165 virtual void OnDragUpCompleted() OVERRIDE { | |
166 SetState(VISIBLE_BOTTOM); | |
167 WindowManager::GetInstance()->ToggleOverview(); | |
168 } | |
169 | |
114 scoped_ptr<AppModelBuilder> model_builder_; | 170 scoped_ptr<AppModelBuilder> model_builder_; |
115 | 171 |
116 HomeCard::State state_; | 172 HomeCard::State state_; |
117 | 173 |
118 views::Widget* home_card_widget_; | 174 views::Widget* home_card_widget_; |
175 views::Widget* minimized_widget_; | |
119 AppListViewDelegate* view_delegate_; | 176 AppListViewDelegate* view_delegate_; |
120 HomeCardLayoutManager* layout_manager_; | 177 HomeCardLayoutManager* layout_manager_; |
121 | 178 |
122 // Right now HomeCard allows only one search provider. | 179 // Right now HomeCard allows only one search provider. |
123 // TODO(mukai): port app-list's SearchController and Mixer. | 180 // TODO(mukai): port app-list's SearchController and Mixer. |
124 scoped_ptr<app_list::SearchProvider> search_provider_; | 181 scoped_ptr<app_list::SearchProvider> search_provider_; |
125 | 182 |
126 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 183 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
127 }; | 184 }; |
128 | 185 |
129 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) | 186 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
130 : model_builder_(model_builder), | 187 : model_builder_(model_builder), |
131 state_(HIDDEN), | 188 state_(VISIBLE_MINIMIZED), |
132 home_card_widget_(NULL), | 189 home_card_widget_(NULL), |
190 minimized_widget_(NULL), | |
133 layout_manager_(NULL) { | 191 layout_manager_(NULL) { |
134 DCHECK(!instance); | 192 DCHECK(!instance); |
135 instance = this; | 193 instance = this; |
136 } | 194 } |
137 | 195 |
138 HomeCardImpl::~HomeCardImpl() { | 196 HomeCardImpl::~HomeCardImpl() { |
139 DCHECK(instance); | 197 DCHECK(instance); |
140 home_card_widget_->CloseNow(); | 198 home_card_widget_->CloseNow(); |
199 minimized_widget_->CloseNow(); | |
141 view_delegate_ = NULL; | 200 view_delegate_ = NULL; |
142 instance = NULL; | 201 instance = NULL; |
143 } | 202 } |
144 | 203 |
145 void HomeCardImpl::SetState(HomeCard::State state) { | 204 void HomeCardImpl::SetState(HomeCard::State state) { |
146 if (state == HIDDEN) | 205 // Update |state_| before changing the visibility of the widgets, so that |
206 // LayoutManager callbacks get the correct state. | |
207 state_ = state; | |
208 if (state == VISIBLE_MINIMIZED) { | |
oshima
2014/07/16 16:24:31
would you mind using switch instead?
sadrul
2014/07/16 16:58:26
Done.
| |
147 home_card_widget_->Hide(); | 209 home_card_widget_->Hide(); |
148 else | 210 minimized_widget_->Show(); |
211 } else if (state == HIDDEN) { | |
212 home_card_widget_->Hide(); | |
213 minimized_widget_->Hide(); | |
214 } else { | |
149 home_card_widget_->Show(); | 215 home_card_widget_->Show(); |
150 state_ = state; | 216 minimized_widget_->Hide(); |
217 } | |
151 } | 218 } |
152 | 219 |
153 void HomeCardImpl::RegisterSearchProvider( | 220 void HomeCardImpl::RegisterSearchProvider( |
154 app_list::SearchProvider* search_provider) { | 221 app_list::SearchProvider* search_provider) { |
155 DCHECK(!search_provider_); | 222 DCHECK(!search_provider_); |
156 search_provider_.reset(search_provider); | 223 search_provider_.reset(search_provider); |
157 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 224 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
158 } | 225 } |
159 | 226 |
160 void HomeCardImpl::UpdateVirtualKeyboardBounds( | 227 void HomeCardImpl::UpdateVirtualKeyboardBounds( |
161 const gfx::Rect& bounds) { | 228 const gfx::Rect& bounds) { |
229 if (state_ == VISIBLE_MINIMIZED) { | |
230 if (bounds.IsEmpty()) | |
231 minimized_widget_->Show(); | |
232 else | |
233 minimized_widget_->Hide(); | |
234 } | |
162 layout_manager_->UpdateVirtualKeyboardBounds(bounds); | 235 layout_manager_->UpdateVirtualKeyboardBounds(bounds); |
163 } | 236 } |
164 | 237 |
165 void HomeCardImpl::Init() { | 238 void HomeCardImpl::Init() { |
166 InstallAccelerators(); | 239 InstallAccelerators(); |
167 | 240 |
168 aura::Window* container = | 241 aura::Window* container = |
169 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 242 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
170 layout_manager_ = new HomeCardLayoutManager(container); | 243 layout_manager_ = new HomeCardLayoutManager(this, container); |
171 container->SetLayoutManager(layout_manager_); | 244 container->SetLayoutManager(layout_manager_); |
172 wm::SetChildWindowVisibilityChangesAnimated(container); | 245 wm::SetChildWindowVisibilityChangesAnimated(container); |
173 | 246 |
174 view_delegate_ = new AppListViewDelegate(model_builder_.get()); | 247 view_delegate_ = new AppListViewDelegate(model_builder_.get()); |
175 if (search_provider_) | 248 if (search_provider_) |
176 view_delegate_->RegisterSearchProvider(search_provider_.get()); | 249 view_delegate_->RegisterSearchProvider(search_provider_.get()); |
177 app_list::AppListView* view = new app_list::AppListView(view_delegate_); | 250 app_list::AppListView* view = new app_list::AppListView(view_delegate_); |
178 view->InitAsBubbleAtFixedLocation( | 251 view->InitAsBubbleAtFixedLocation( |
179 container, | 252 container, |
180 0 /* initial_apps_page */, | 253 0 /* initial_apps_page */, |
181 gfx::Point(), | 254 gfx::Point(), |
182 views::BubbleBorder::FLOAT, | 255 views::BubbleBorder::FLOAT, |
183 true /* border_accepts_events */); | 256 true /* border_accepts_events */); |
184 home_card_widget_ = view->GetWidget(); | 257 home_card_widget_ = view->GetWidget(); |
185 // TODO: the initial value might not be visible. | 258 // TODO: the initial value might not be visible. |
186 state_ = VISIBLE_CENTERED; | 259 state_ = VISIBLE_CENTERED; |
187 view->ShowWhenReady(); | 260 view->ShowWhenReady(); |
Jun Mukai
2014/07/16 05:53:58
Please remove line 258-260.
ShowWhenReady() seems
sadrul
2014/07/16 16:58:26
Done.
| |
261 | |
262 // Start off in the minimized state. | |
263 minimized_widget_ = CreateMinimizedHome(container, this); | |
264 SetState(VISIBLE_MINIMIZED); | |
188 } | 265 } |
189 | 266 |
190 void HomeCardImpl::InstallAccelerators() { | 267 void HomeCardImpl::InstallAccelerators() { |
191 const AcceleratorData accelerator_data[] = { | 268 const AcceleratorData accelerator_data[] = { |
192 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 269 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
193 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 270 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
194 }; | 271 }; |
195 AcceleratorManager::Get()->RegisterAccelerators( | 272 AcceleratorManager::Get()->RegisterAccelerators( |
196 accelerator_data, arraysize(accelerator_data), this); | 273 accelerator_data, arraysize(accelerator_data), this); |
197 } | 274 } |
(...skipping 14 matching lines...) Expand all Loading... | |
212 instance = NULL; | 289 instance = NULL; |
213 } | 290 } |
214 | 291 |
215 // static | 292 // static |
216 HomeCard* HomeCard::Get() { | 293 HomeCard* HomeCard::Get() { |
217 DCHECK(instance); | 294 DCHECK(instance); |
218 return instance; | 295 return instance; |
219 } | 296 } |
220 | 297 |
221 } // namespace athena | 298 } // namespace athena |
OLD | NEW |