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/home_card_impl.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/home_card_constants.h" | 14 #include "athena/home/home_card_constants.h" |
15 #include "athena/home/home_card_gesture_manager.h" | |
16 #include "athena/home/minimized_home.h" | 15 #include "athena/home/minimized_home.h" |
17 #include "athena/home/public/app_model_builder.h" | 16 #include "athena/home/public/app_model_builder.h" |
18 #include "athena/input/public/accelerator_manager.h" | |
19 #include "athena/screen/public/screen_manager.h" | 17 #include "athena/screen/public/screen_manager.h" |
20 #include "athena/wm/public/window_manager.h" | 18 #include "athena/wm/public/window_manager.h" |
21 #include "athena/wm/public/window_manager_observer.h" | |
22 #include "ui/app_list/search_provider.h" | 19 #include "ui/app_list/search_provider.h" |
23 #include "ui/app_list/views/app_list_main_view.h" | 20 #include "ui/app_list/views/app_list_main_view.h" |
24 #include "ui/app_list/views/contents_view.h" | 21 #include "ui/app_list/views/contents_view.h" |
25 #include "ui/aura/layout_manager.h" | 22 #include "ui/aura/layout_manager.h" |
26 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
27 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
28 #include "ui/compositor/layer_owner.h" | |
29 #include "ui/compositor/scoped_layer_animation_settings.h" | 25 #include "ui/compositor/scoped_layer_animation_settings.h" |
30 #include "ui/views/layout/fill_layout.h" | 26 #include "ui/views/layout/fill_layout.h" |
31 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
32 #include "ui/views/widget/widget_delegate.h" | 28 #include "ui/views/widget/widget_delegate.h" |
33 #include "ui/wm/core/shadow_types.h" | 29 #include "ui/wm/core/shadow_types.h" |
34 #include "ui/wm/core/visibility_controller.h" | 30 #include "ui/wm/core/visibility_controller.h" |
35 #include "ui/wm/public/activation_change_observer.h" | |
36 #include "ui/wm/public/activation_client.h" | 31 #include "ui/wm/public/activation_client.h" |
37 | 32 |
38 namespace athena { | 33 namespace athena { |
39 namespace { | 34 namespace { |
40 | 35 |
41 HomeCard* instance = NULL; | 36 HomeCard* instance = NULL; |
42 | 37 |
43 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, | 38 gfx::Rect GetBoundsForState(const gfx::Rect& screen_bounds, |
44 HomeCard::State state) { | 39 HomeCard::State state) { |
45 switch (state) { | 40 switch (state) { |
(...skipping 14 matching lines...) Expand all Loading... |
60 return gfx::Rect(0, | 55 return gfx::Rect(0, |
61 screen_bounds.bottom() - kHomeCardMinimizedHeight, | 56 screen_bounds.bottom() - kHomeCardMinimizedHeight, |
62 screen_bounds.width(), | 57 screen_bounds.width(), |
63 screen_bounds.height()); | 58 screen_bounds.height()); |
64 } | 59 } |
65 | 60 |
66 NOTREACHED(); | 61 NOTREACHED(); |
67 return gfx::Rect(); | 62 return gfx::Rect(); |
68 } | 63 } |
69 | 64 |
| 65 } // namespace |
| 66 |
70 // Makes sure the homecard is center-aligned horizontally and bottom-aligned | 67 // Makes sure the homecard is center-aligned horizontally and bottom-aligned |
71 // vertically. | 68 // vertically. |
72 class HomeCardLayoutManager : public aura::LayoutManager { | 69 class HomeCardLayoutManager : public aura::LayoutManager { |
73 public: | 70 public: |
74 HomeCardLayoutManager() | 71 HomeCardLayoutManager() |
75 : home_card_(NULL), | 72 : home_card_(NULL), |
76 minimized_layer_(NULL) {} | 73 minimized_layer_(NULL) {} |
77 | 74 |
78 virtual ~HomeCardLayoutManager() {} | 75 virtual ~HomeCardLayoutManager() {} |
79 | 76 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 return this; | 216 return this; |
220 } | 217 } |
221 | 218 |
222 AthenaStartPageView* main_view_; | 219 AthenaStartPageView* main_view_; |
223 scoped_ptr<HomeCardGestureManager> gesture_manager_; | 220 scoped_ptr<HomeCardGestureManager> gesture_manager_; |
224 HomeCardGestureManager::Delegate* gesture_delegate_; | 221 HomeCardGestureManager::Delegate* gesture_delegate_; |
225 | 222 |
226 DISALLOW_COPY_AND_ASSIGN(HomeCardView); | 223 DISALLOW_COPY_AND_ASSIGN(HomeCardView); |
227 }; | 224 }; |
228 | 225 |
229 class HomeCardImpl : public HomeCard, | |
230 public AcceleratorHandler, | |
231 public HomeCardGestureManager::Delegate, | |
232 public WindowManagerObserver, | |
233 public aura::client::ActivationChangeObserver { | |
234 public: | |
235 explicit HomeCardImpl(AppModelBuilder* model_builder); | |
236 virtual ~HomeCardImpl(); | |
237 | |
238 void Init(); | |
239 | |
240 private: | |
241 enum Command { | |
242 COMMAND_SHOW_HOME_CARD, | |
243 }; | |
244 void InstallAccelerators(); | |
245 void UpdateMinimizedHomeBounds(); | |
246 | |
247 // Overridden from HomeCard: | |
248 virtual void SetState(State state) OVERRIDE; | |
249 virtual State GetState() OVERRIDE; | |
250 virtual void RegisterSearchProvider( | |
251 app_list::SearchProvider* search_provider) OVERRIDE; | |
252 virtual void UpdateVirtualKeyboardBounds( | |
253 const gfx::Rect& bounds) OVERRIDE; | |
254 | |
255 // AcceleratorHandler: | |
256 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | |
257 virtual bool OnAcceleratorFired(int command_id, | |
258 const ui::Accelerator& accelerator) OVERRIDE; | |
259 | |
260 // HomeCardGestureManager::Delegate: | |
261 virtual void OnGestureEnded(State final_state) OVERRIDE; | |
262 virtual void OnGestureProgressed( | |
263 State from_state, State to_state, float progress) OVERRIDE; | |
264 | |
265 // WindowManagerObserver: | |
266 virtual void OnOverviewModeEnter() OVERRIDE; | |
267 virtual void OnOverviewModeExit() OVERRIDE; | |
268 | |
269 // aura::client::ActivationChangeObserver: | |
270 virtual void OnWindowActivated(aura::Window* gained_active, | |
271 aura::Window* lost_active) OVERRIDE; | |
272 | |
273 scoped_ptr<AppModelBuilder> model_builder_; | |
274 | |
275 HomeCard::State state_; | |
276 | |
277 // original_state_ is the state which the home card should go back to after | |
278 // the virtual keyboard is hidden. | |
279 HomeCard::State original_state_; | |
280 | |
281 views::Widget* home_card_widget_; | |
282 HomeCardView* home_card_view_; | |
283 scoped_ptr<AppListViewDelegate> view_delegate_; | |
284 HomeCardLayoutManager* layout_manager_; | |
285 aura::client::ActivationClient* activation_client_; // Not owned | |
286 scoped_ptr<ui::LayerOwner> minimized_home_; | |
287 | |
288 // Right now HomeCard allows only one search provider. | |
289 // TODO(mukai): port app-list's SearchController and Mixer. | |
290 scoped_ptr<app_list::SearchProvider> search_provider_; | |
291 | |
292 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | |
293 }; | |
294 | |
295 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) | 226 HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder) |
296 : model_builder_(model_builder), | 227 : model_builder_(model_builder), |
297 state_(HIDDEN), | 228 state_(HIDDEN), |
298 original_state_(VISIBLE_MINIMIZED), | 229 original_state_(VISIBLE_MINIMIZED), |
299 home_card_widget_(NULL), | 230 home_card_widget_(NULL), |
300 home_card_view_(NULL), | 231 home_card_view_(NULL), |
301 layout_manager_(NULL), | 232 layout_manager_(NULL), |
302 activation_client_(NULL) { | 233 activation_client_(NULL) { |
303 DCHECK(!instance); | 234 DCHECK(!instance); |
304 instance = this; | 235 instance = this; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 | 283 |
353 activation_client_ = | 284 activation_client_ = |
354 aura::client::GetActivationClient(container->GetRootWindow()); | 285 aura::client::GetActivationClient(container->GetRootWindow()); |
355 if (activation_client_) | 286 if (activation_client_) |
356 activation_client_->AddObserver(this); | 287 activation_client_->AddObserver(this); |
357 | 288 |
358 AthenaEnv::Get()->SetDisplayWorkAreaInsets( | 289 AthenaEnv::Get()->SetDisplayWorkAreaInsets( |
359 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0)); | 290 gfx::Insets(0, 0, kHomeCardMinimizedHeight, 0)); |
360 } | 291 } |
361 | 292 |
| 293 aura::Window* HomeCardImpl::GetHomeCardWindowForTest() const { |
| 294 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; |
| 295 } |
| 296 |
362 void HomeCardImpl::InstallAccelerators() { | 297 void HomeCardImpl::InstallAccelerators() { |
363 const AcceleratorData accelerator_data[] = { | 298 const AcceleratorData accelerator_data[] = { |
364 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, | 299 {TRIGGER_ON_PRESS, ui::VKEY_L, ui::EF_CONTROL_DOWN, |
365 COMMAND_SHOW_HOME_CARD, AF_NONE}, | 300 COMMAND_SHOW_HOME_CARD, AF_NONE}, |
366 }; | 301 }; |
367 AcceleratorManager::Get()->RegisterAccelerators( | 302 AcceleratorManager::Get()->RegisterAccelerators( |
368 accelerator_data, arraysize(accelerator_data), this); | 303 accelerator_data, arraysize(accelerator_data), this); |
369 } | 304 } |
370 | 305 |
371 void HomeCardImpl::SetState(HomeCard::State state) { | 306 void HomeCardImpl::SetState(HomeCard::State state) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 SetState(HIDDEN); | 353 SetState(HIDDEN); |
419 original_state_ = VISIBLE_MINIMIZED; | 354 original_state_ = VISIBLE_MINIMIZED; |
420 } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) { | 355 } else if (state_ == VISIBLE_BOTTOM && !bounds.IsEmpty()) { |
421 SetState(VISIBLE_CENTERED); | 356 SetState(VISIBLE_CENTERED); |
422 original_state_ = VISIBLE_BOTTOM; | 357 original_state_ = VISIBLE_BOTTOM; |
423 } else if (state_ != original_state_ && bounds.IsEmpty()) { | 358 } else if (state_ != original_state_ && bounds.IsEmpty()) { |
424 SetState(original_state_); | 359 SetState(original_state_); |
425 } | 360 } |
426 } | 361 } |
427 | 362 |
| 363 bool HomeCardImpl::IsCommandEnabled(int command_id) const { |
| 364 return true; |
| 365 } |
| 366 |
428 bool HomeCardImpl::OnAcceleratorFired(int command_id, | 367 bool HomeCardImpl::OnAcceleratorFired(int command_id, |
429 const ui::Accelerator& accelerator) { | 368 const ui::Accelerator& accelerator) { |
430 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); | 369 DCHECK_EQ(COMMAND_SHOW_HOME_CARD, command_id); |
431 | 370 |
432 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM) | 371 if (state_ == VISIBLE_CENTERED && original_state_ != VISIBLE_BOTTOM) |
433 SetState(VISIBLE_MINIMIZED); | 372 SetState(VISIBLE_MINIMIZED); |
434 else if (state_ == VISIBLE_MINIMIZED) | 373 else if (state_ == VISIBLE_MINIMIZED) |
435 SetState(VISIBLE_CENTERED); | 374 SetState(VISIBLE_CENTERED); |
436 return true; | 375 return true; |
437 } | 376 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 } | 419 } |
481 | 420 |
482 void HomeCardImpl::OnWindowActivated(aura::Window* gained_active, | 421 void HomeCardImpl::OnWindowActivated(aura::Window* gained_active, |
483 aura::Window* lost_active) { | 422 aura::Window* lost_active) { |
484 if (state_ != HIDDEN && | 423 if (state_ != HIDDEN && |
485 gained_active != home_card_widget_->GetNativeWindow()) { | 424 gained_active != home_card_widget_->GetNativeWindow()) { |
486 SetState(VISIBLE_MINIMIZED); | 425 SetState(VISIBLE_MINIMIZED); |
487 } | 426 } |
488 } | 427 } |
489 | 428 |
490 } // namespace | |
491 | |
492 // static | 429 // static |
493 HomeCard* HomeCard::Create(AppModelBuilder* model_builder) { | 430 HomeCard* HomeCard::Create(AppModelBuilder* model_builder) { |
494 (new HomeCardImpl(model_builder))->Init(); | 431 (new HomeCardImpl(model_builder))->Init(); |
495 DCHECK(instance); | 432 DCHECK(instance); |
496 return instance; | 433 return instance; |
497 } | 434 } |
498 | 435 |
499 // static | 436 // static |
500 void HomeCard::Shutdown() { | 437 void HomeCard::Shutdown() { |
501 DCHECK(instance); | 438 DCHECK(instance); |
502 delete instance; | 439 delete instance; |
503 instance = NULL; | 440 instance = NULL; |
504 } | 441 } |
505 | 442 |
506 // static | 443 // static |
507 HomeCard* HomeCard::Get() { | 444 HomeCard* HomeCard::Get() { |
508 DCHECK(instance); | 445 DCHECK(instance); |
509 return instance; | 446 return instance; |
510 } | 447 } |
511 | 448 |
512 } // namespace athena | 449 } // namespace athena |
OLD | NEW |