Chromium Code Reviews| 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/app_list_view_delegate.h" |
| 8 #include "athena/screen/public/screen_manager.h" | 8 #include "athena/screen/public/screen_manager.h" |
| 9 #include "ui/app_list/pagination_model.h" | |
| 10 #include "ui/app_list/views/app_list_view.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" | |
| 12 #include "ui/wm/core/visibility_controller.h" | 13 #include "ui/wm/core/visibility_controller.h" |
| 13 #include "ui/wm/core/window_animations.h" | 14 #include "ui/wm/core/window_animations.h" |
| 14 | 15 |
| 15 namespace athena { | 16 namespace athena { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 HomeCard* instance = NULL; | 19 HomeCard* instance = NULL; |
| 19 | 20 |
| 20 class HomeCardLayoutManager : public aura::LayoutManager { | 21 class HomeCardLayoutManager : public aura::LayoutManager { |
| 21 public: | 22 public: |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 34 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 35 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 35 bool visible) OVERRIDE { | 36 bool visible) OVERRIDE { |
| 36 Layout(); | 37 Layout(); |
| 37 } | 38 } |
| 38 virtual void SetChildBounds(aura::Window* child, | 39 virtual void SetChildBounds(aura::Window* child, |
| 39 const gfx::Rect& requested_bounds) OVERRIDE { | 40 const gfx::Rect& requested_bounds) OVERRIDE { |
| 40 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 41 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void Layout() { | 44 void Layout() { |
| 44 const int kHomeCardHeight = 50; | 45 const int kHomeCardHeight = 150; |
| 45 const int kHomeCardHorizontalMargin = 50; | 46 const int kHomeCardHorizontalMargin = 50; |
| 47 // Currently the home card is provided as a bubble and the bounds has to be | |
| 48 // increased to cancel the shadow. | |
| 49 // TODO(mukai): stops using the bubble and remove this. | |
| 50 const int kHomeCardShadowWidth = 30; | |
| 46 if (container_->children().size() < 1) | 51 if (container_->children().size() < 1) |
| 47 return; | 52 return; |
| 48 aura::Window* home_card = container_->children()[0]; | 53 aura::Window* home_card = container_->children()[0]; |
| 49 if (!home_card->IsVisible()) | 54 if (!home_card->IsVisible()) |
| 50 return; | 55 return; |
| 51 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | 56 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
| 52 gfx::Rect card_bounds = screen_bounds; | 57 gfx::Rect card_bounds = screen_bounds; |
| 53 card_bounds.Inset(kHomeCardHorizontalMargin, | 58 card_bounds.Inset(kHomeCardHorizontalMargin, |
| 54 screen_bounds.height() - kHomeCardHeight, | 59 screen_bounds.height() - kHomeCardHeight, |
| 55 kHomeCardHorizontalMargin, | 60 kHomeCardHorizontalMargin, |
| 56 0); | 61 0); |
| 62 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | |
| 57 SetChildBoundsDirect(home_card, card_bounds); | 63 SetChildBoundsDirect(home_card, card_bounds); |
| 58 } | 64 } |
| 59 | 65 |
| 60 aura::Window* container_; | 66 aura::Window* container_; |
| 61 | 67 |
| 62 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 68 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
| 63 }; | 69 }; |
| 64 | 70 |
| 65 class HomeCardImpl : public HomeCard { | 71 class HomeCardImpl : public HomeCard { |
| 66 public: | 72 public: |
| 67 HomeCardImpl(); | 73 HomeCardImpl(); |
| 68 virtual ~HomeCardImpl(); | 74 virtual ~HomeCardImpl(); |
| 69 | 75 |
| 70 void Init(); | 76 void Init(); |
| 71 | 77 |
| 72 private: | 78 private: |
| 73 views::Widget* home_card_widget_; | 79 views::Widget* home_card_widget_; |
| 80 scoped_ptr<app_list::PaginationModel> pagination_model_; | |
| 74 | 81 |
| 75 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 82 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
| 76 }; | 83 }; |
| 77 | 84 |
| 78 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { | 85 HomeCardImpl::HomeCardImpl() |
| 86 : home_card_widget_(NULL), | |
| 87 pagination_model_(new app_list::PaginationModel) { | |
| 79 DCHECK(!instance); | 88 DCHECK(!instance); |
| 80 instance = this; | 89 instance = this; |
| 81 } | 90 } |
| 82 | 91 |
| 83 HomeCardImpl::~HomeCardImpl() { | 92 HomeCardImpl::~HomeCardImpl() { |
| 84 DCHECK(instance); | 93 DCHECK(instance); |
| 85 home_card_widget_->CloseNow(); | 94 home_card_widget_->CloseNow(); |
| 86 instance = NULL; | 95 instance = NULL; |
| 87 } | 96 } |
| 88 | 97 |
| 89 void HomeCardImpl::Init() { | 98 void HomeCardImpl::Init() { |
| 90 aura::Window* container = | 99 aura::Window* container = |
| 91 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 100 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
| 92 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 101 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
| 93 wm::SetChildWindowVisibilityChangesAnimated(container); | 102 wm::SetChildWindowVisibilityChangesAnimated(container); |
| 94 | 103 |
| 95 views::Widget::InitParams params( | 104 app_list::AppListView* view = new app_list::AppListView( |
| 96 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 105 new AppListViewDelegate); |
| 97 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 106 view->InitAsBubbleAtFixedLocation( |
| 98 params.delegate = new HomeCardDelegateView(); | 107 container, |
| 99 params.parent = container; | 108 pagination_model_.get(), |
|
xiyuan
2014/06/02 17:24:34
fyi, https://codereview.chromium.org/302803002/ is
Jun Mukai
2014/06/02 17:37:37
Good to know. Then it's better to wait for that la
| |
| 100 | 109 gfx::Point(), |
| 101 home_card_widget_ = new views::Widget; | 110 views::BubbleBorder::FLOAT, |
| 102 home_card_widget_->Init(params); | 111 true /* border_accepts_events */); |
| 103 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); | 112 home_card_widget_ = view->GetWidget(); |
| 104 | 113 view->ShowWhenReady(); |
| 105 aura::Window* home_card_window = home_card_widget_->GetNativeView(); | |
| 106 wm::SetWindowVisibilityAnimationType( | |
| 107 home_card_window, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 108 wm::SetWindowVisibilityAnimationTransition(home_card_window, | |
| 109 wm::ANIMATE_BOTH); | |
| 110 | |
| 111 home_card_widget_->Show(); | |
| 112 } | 114 } |
| 113 | 115 |
| 114 } // namespace | 116 } // namespace |
| 115 | 117 |
| 116 // static | 118 // static |
| 117 HomeCard* HomeCard::Create() { | 119 HomeCard* HomeCard::Create() { |
| 118 (new HomeCardImpl())->Init(); | 120 (new HomeCardImpl())->Init(); |
| 119 DCHECK(instance); | 121 DCHECK(instance); |
| 120 return instance; | 122 return instance; |
| 121 } | 123 } |
| 122 | 124 |
| 123 // static | 125 // static |
| 124 void HomeCard::Shutdown() { | 126 void HomeCard::Shutdown() { |
| 125 DCHECK(instance); | 127 DCHECK(instance); |
| 126 delete instance; | 128 delete instance; |
| 127 instance = NULL; | 129 instance = NULL; |
| 128 } | 130 } |
| 129 | 131 |
| 130 } // namespace athena | 132 } // namespace athena |
| OLD | NEW |