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" |
11 #include "athena/home/app_list_view_delegate.h" | 11 #include "athena/home/app_list_view_delegate.h" |
12 #include "athena/home/athena_start_page_view.h" | 12 #include "athena/home/athena_start_page_view.h" |
13 #include "athena/home/minimized_home.h" | 13 #include "athena/home/minimized_home.h" |
14 #include "athena/home/public/app_model_builder.h" | 14 #include "athena/home/public/app_model_builder.h" |
15 #include "athena/input/public/accelerator_manager.h" | 15 #include "athena/input/public/accelerator_manager.h" |
16 #include "athena/screen/public/screen_manager.h" | 16 #include "athena/screen/public/screen_manager.h" |
17 #include "athena/wm/public/window_manager.h" | 17 #include "athena/wm/public/window_manager.h" |
18 #include "athena/wm/public/window_manager_observer.h" | 18 #include "athena/wm/public/window_manager_observer.h" |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
| 20 #include "base/memory/weak_ptr.h" |
20 #include "ui/app_list/search_provider.h" | 21 #include "ui/app_list/search_provider.h" |
21 #include "ui/app_list/views/app_list_main_view.h" | 22 #include "ui/app_list/views/app_list_main_view.h" |
22 #include "ui/app_list/views/contents_view.h" | 23 #include "ui/app_list/views/contents_view.h" |
23 #include "ui/aura/layout_manager.h" | 24 #include "ui/aura/layout_manager.h" |
24 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
| 26 #include "ui/compositor/closure_animation_observer.h" |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
26 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
27 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
28 #include "ui/views/widget/widget_delegate.h" | 31 #include "ui/views/widget/widget_delegate.h" |
29 #include "ui/wm/core/shadow_types.h" | 32 #include "ui/wm/core/shadow_types.h" |
30 #include "ui/wm/core/visibility_controller.h" | 33 #include "ui/wm/core/visibility_controller.h" |
31 #include "ui/wm/core/window_animations.h" | 34 #include "ui/wm/core/window_animations.h" |
32 #include "ui/wm/public/activation_change_observer.h" | 35 #include "ui/wm/public/activation_change_observer.h" |
33 #include "ui/wm/public/activation_client.h" | 36 #include "ui/wm/public/activation_client.h" |
34 | 37 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 | 84 |
82 virtual ~HomeCardLayoutManager() {} | 85 virtual ~HomeCardLayoutManager() {} |
83 | 86 |
84 void Layout() { | 87 void Layout() { |
85 aura::Window* home_card = delegate_->GetNativeWindow(); | 88 aura::Window* home_card = delegate_->GetNativeWindow(); |
86 // |home_card| could be detached from the root window (e.g. when it is being | 89 // |home_card| could be detached from the root window (e.g. when it is being |
87 // destroyed). | 90 // destroyed). |
88 if (!home_card || !home_card->GetRootWindow()) | 91 if (!home_card || !home_card->GetRootWindow()) |
89 return; | 92 return; |
90 | 93 |
91 SetChildBoundsDirect(home_card, GetBoundsForState( | 94 { |
92 home_card->GetRootWindow()->bounds(), delegate_->GetState())); | 95 ui::ScopedLayerAnimationSettings settings( |
| 96 home_card->layer()->GetAnimator()); |
| 97 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); |
| 98 SetChildBoundsDirect(home_card, GetBoundsForState( |
| 99 home_card->GetRootWindow()->bounds(), delegate_->GetState())); |
| 100 } |
93 } | 101 } |
94 | 102 |
95 private: | 103 private: |
96 // aura::LayoutManager: | 104 // aura::LayoutManager: |
97 virtual void OnWindowResized() OVERRIDE { Layout(); } | 105 virtual void OnWindowResized() OVERRIDE { Layout(); } |
98 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } | 106 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { Layout(); } |
99 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} | 107 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
100 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { | 108 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE { |
101 Layout(); | 109 Layout(); |
102 } | 110 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 268 |
261 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager); | 269 DISALLOW_COPY_AND_ASSIGN(HomeCardGestureManager); |
262 }; | 270 }; |
263 | 271 |
264 // The container view of home card contents of each state. | 272 // The container view of home card contents of each state. |
265 class HomeCardView : public views::WidgetDelegateView { | 273 class HomeCardView : public views::WidgetDelegateView { |
266 public: | 274 public: |
267 HomeCardView(app_list::AppListViewDelegate* view_delegate, | 275 HomeCardView(app_list::AppListViewDelegate* view_delegate, |
268 aura::Window* container, | 276 aura::Window* container, |
269 HomeCardGestureManager::Delegate* gesture_delegate) | 277 HomeCardGestureManager::Delegate* gesture_delegate) |
270 : gesture_delegate_(gesture_delegate) { | 278 : gesture_delegate_(gesture_delegate), |
| 279 weak_factory_(this) { |
271 bottom_view_ = new AthenaStartPageView(view_delegate); | 280 bottom_view_ = new AthenaStartPageView(view_delegate); |
272 AddChildView(bottom_view_); | 281 AddChildView(bottom_view_); |
273 bottom_view_->SetPaintToLayer(true); | 282 bottom_view_->SetPaintToLayer(true); |
274 bottom_view_->layer()->SetFillsBoundsOpaquely(false); | 283 bottom_view_->layer()->SetFillsBoundsOpaquely(false); |
275 | 284 |
276 main_view_ = new app_list::AppListMainView( | 285 main_view_ = new app_list::AppListMainView( |
277 view_delegate, 0 /* initial_apps_page */, container); | 286 view_delegate, 0 /* initial_apps_page */, container); |
278 AddChildView(main_view_); | 287 AddChildView(main_view_); |
279 main_view_->set_background( | 288 main_view_->set_background( |
280 views::Background::CreateSolidBackground(SK_ColorWHITE)); | 289 views::Background::CreateSolidBackground(SK_ColorWHITE)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 app_list::ContentsView* contents_view = main_view_->contents_view(); | 325 app_list::ContentsView* contents_view = main_view_->contents_view(); |
317 contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage( | 326 contents_view->SetActivePage(contents_view->GetPageIndexForNamedPage( |
318 app_list::ContentsView::NAMED_PAGE_START)); | 327 app_list::ContentsView::NAMED_PAGE_START)); |
319 } | 328 } |
320 wm::SetShadowType(GetWidget()->GetNativeView(), | 329 wm::SetShadowType(GetWidget()->GetNativeView(), |
321 state == HomeCard::VISIBLE_MINIMIZED ? | 330 state == HomeCard::VISIBLE_MINIMIZED ? |
322 wm::SHADOW_TYPE_NONE : | 331 wm::SHADOW_TYPE_NONE : |
323 wm::SHADOW_TYPE_RECTANGULAR); | 332 wm::SHADOW_TYPE_RECTANGULAR); |
324 } | 333 } |
325 | 334 |
| 335 void SetStateWithAnimation(HomeCard::State from_state, |
| 336 HomeCard::State to_state) { |
| 337 if ((from_state == HomeCard::VISIBLE_MINIMIZED && |
| 338 to_state == HomeCard::VISIBLE_BOTTOM) || |
| 339 (from_state == HomeCard::VISIBLE_BOTTOM && |
| 340 to_state == HomeCard::VISIBLE_MINIMIZED)) { |
| 341 minimized_view_->SetVisible(true); |
| 342 bottom_view_->SetVisible(true); |
| 343 { |
| 344 ui::ScopedLayerAnimationSettings settings( |
| 345 minimized_view_->layer()->GetAnimator()); |
| 346 settings.SetTweenType(gfx::Tween::EASE_IN_OUT); |
| 347 settings.AddObserver(new ui::ClosureAnimationObserver( |
| 348 base::Bind(&HomeCardView::SetState, |
| 349 weak_factory_.GetWeakPtr(), |
| 350 to_state))); |
| 351 minimized_view_->layer()->SetOpacity( |
| 352 (to_state == HomeCard::VISIBLE_MINIMIZED) ? 1.0f : 0.0f); |
| 353 } |
| 354 } else { |
| 355 // TODO(mukai): Take care of other transition. |
| 356 SetState(to_state); |
| 357 } |
| 358 } |
| 359 |
326 void ClearGesture() { | 360 void ClearGesture() { |
327 gesture_manager_.reset(); | 361 gesture_manager_.reset(); |
328 } | 362 } |
329 | 363 |
330 // views::View: | 364 // views::View: |
331 virtual void Layout() OVERRIDE { | 365 virtual void Layout() OVERRIDE { |
332 for (int i = 0; i < child_count(); ++i) { | 366 for (int i = 0; i < child_count(); ++i) { |
333 views::View* child = child_at(i); | 367 views::View* child = child_at(i); |
334 if (child->visible()) { | 368 if (child->visible()) { |
335 if (child == minimized_view_) { | 369 if (child == minimized_view_) { |
(...skipping 13 matching lines...) Expand all Loading... |
349 gesture_manager_.reset(new HomeCardGestureManager( | 383 gesture_manager_.reset(new HomeCardGestureManager( |
350 gesture_delegate_, | 384 gesture_delegate_, |
351 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds())); | 385 GetWidget()->GetNativeWindow()->GetRootWindow()->bounds())); |
352 } | 386 } |
353 | 387 |
354 if (gesture_manager_) | 388 if (gesture_manager_) |
355 gesture_manager_->ProcessGestureEvent(event); | 389 gesture_manager_->ProcessGestureEvent(event); |
356 } | 390 } |
357 | 391 |
358 private: | 392 private: |
| 393 // views::WidgetDelegate: |
359 virtual views::View* GetContentsView() OVERRIDE { | 394 virtual views::View* GetContentsView() OVERRIDE { |
360 return this; | 395 return this; |
361 } | 396 } |
362 | 397 |
363 app_list::AppListMainView* main_view_; | 398 app_list::AppListMainView* main_view_; |
364 views::View* bottom_view_; | 399 views::View* bottom_view_; |
365 views::View* minimized_view_; | 400 views::View* minimized_view_; |
366 scoped_ptr<HomeCardGestureManager> gesture_manager_; | 401 scoped_ptr<HomeCardGestureManager> gesture_manager_; |
367 HomeCardGestureManager::Delegate* gesture_delegate_; | 402 HomeCardGestureManager::Delegate* gesture_delegate_; |
| 403 base::WeakPtrFactory<HomeCardView> weak_factory_; |
368 | 404 |
369 DISALLOW_COPY_AND_ASSIGN(HomeCardView); | 405 DISALLOW_COPY_AND_ASSIGN(HomeCardView); |
370 }; | 406 }; |
371 | 407 |
372 class HomeCardImpl : public HomeCard, | 408 class HomeCardImpl : public HomeCard, |
373 public AcceleratorHandler, | 409 public AcceleratorHandler, |
374 public HomeCardLayoutManager::Delegate, | 410 public HomeCardLayoutManager::Delegate, |
375 public HomeCardGestureManager::Delegate, | 411 public HomeCardGestureManager::Delegate, |
376 public WindowManagerObserver, | 412 public WindowManagerObserver, |
377 public aura::client::ActivationChangeObserver { | 413 public aura::client::ActivationChangeObserver { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 AcceleratorManager::Get()->RegisterAccelerators( | 535 AcceleratorManager::Get()->RegisterAccelerators( |
500 accelerator_data, arraysize(accelerator_data), this); | 536 accelerator_data, arraysize(accelerator_data), this); |
501 } | 537 } |
502 | 538 |
503 void HomeCardImpl::SetState(HomeCard::State state) { | 539 void HomeCardImpl::SetState(HomeCard::State state) { |
504 if (state_ == state) | 540 if (state_ == state) |
505 return; | 541 return; |
506 | 542 |
507 // Update |state_| before changing the visibility of the widgets, so that | 543 // Update |state_| before changing the visibility of the widgets, so that |
508 // LayoutManager callbacks get the correct state. | 544 // LayoutManager callbacks get the correct state. |
| 545 HomeCard::State old_state = state_; |
509 state_ = state; | 546 state_ = state; |
510 original_state_ = state; | 547 original_state_ = state; |
511 if (state_ == HIDDEN) { | 548 if (state_ == HIDDEN) { |
512 home_card_widget_->Hide(); | 549 home_card_widget_->Hide(); |
513 } else { | 550 } else { |
514 if (state_ == VISIBLE_CENTERED) | 551 if (state_ == VISIBLE_CENTERED) |
515 home_card_widget_->Show(); | 552 home_card_widget_->Show(); |
516 else | 553 else |
517 home_card_widget_->ShowInactive(); | 554 home_card_widget_->ShowInactive(); |
518 home_card_view_->SetState(state); | 555 home_card_view_->SetStateWithAnimation(old_state, state); |
519 layout_manager_->Layout(); | 556 layout_manager_->Layout(); |
520 } | 557 } |
521 } | 558 } |
522 | 559 |
523 HomeCard::State HomeCardImpl::GetState() { | 560 HomeCard::State HomeCardImpl::GetState() { |
524 return state_; | 561 return state_; |
525 } | 562 } |
526 | 563 |
527 void HomeCardImpl::RegisterSearchProvider( | 564 void HomeCardImpl::RegisterSearchProvider( |
528 app_list::SearchProvider* search_provider) { | 565 app_list::SearchProvider* search_provider) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 | 598 |
562 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; | 599 return home_card_widget_ ? home_card_widget_->GetNativeWindow() : NULL; |
563 } | 600 } |
564 | 601 |
565 void HomeCardImpl::OnGestureEnded(State final_state) { | 602 void HomeCardImpl::OnGestureEnded(State final_state) { |
566 home_card_view_->ClearGesture(); | 603 home_card_view_->ClearGesture(); |
567 if (state_ != final_state && | 604 if (state_ != final_state && |
568 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { | 605 (state_ == VISIBLE_MINIMIZED || final_state == VISIBLE_MINIMIZED)) { |
569 WindowManager::GetInstance()->ToggleOverview(); | 606 WindowManager::GetInstance()->ToggleOverview(); |
570 } else { | 607 } else { |
| 608 HomeCard::State old_state = state_; |
571 state_ = final_state; | 609 state_ = final_state; |
572 home_card_view_->SetState(final_state); | 610 home_card_view_->SetStateWithAnimation(old_state, final_state); |
573 layout_manager_->Layout(); | 611 layout_manager_->Layout(); |
574 } | 612 } |
575 } | 613 } |
576 | 614 |
577 void HomeCardImpl::OnGestureProgressed( | 615 void HomeCardImpl::OnGestureProgressed( |
578 State from_state, State to_state, float progress) { | 616 State from_state, State to_state, float progress) { |
579 home_card_view_->SetStateProgress(from_state, to_state, progress); | 617 home_card_view_->SetStateProgress(from_state, to_state, progress); |
580 | 618 |
581 gfx::Rect screen_bounds = | 619 gfx::Rect screen_bounds = |
582 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); | 620 home_card_widget_->GetNativeWindow()->GetRootWindow()->bounds(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 instance = NULL; | 659 instance = NULL; |
622 } | 660 } |
623 | 661 |
624 // static | 662 // static |
625 HomeCard* HomeCard::Get() { | 663 HomeCard* HomeCard::Get() { |
626 DCHECK(instance); | 664 DCHECK(instance); |
627 return instance; | 665 return instance; |
628 } | 666 } |
629 | 667 |
630 } // namespace athena | 668 } // namespace athena |
OLD | NEW |