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/home_card_delegate_view.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" | |
11 #include "ui/aura/layout_manager.h" | 9 #include "ui/aura/layout_manager.h" |
12 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/views/widget/widget.h" |
13 #include "ui/wm/core/visibility_controller.h" | 12 #include "ui/wm/core/visibility_controller.h" |
14 #include "ui/wm/core/window_animations.h" | 13 #include "ui/wm/core/window_animations.h" |
15 | 14 |
16 namespace athena { | 15 namespace athena { |
17 namespace { | 16 namespace { |
18 | 17 |
19 HomeCard* instance = NULL; | 18 HomeCard* instance = NULL; |
20 | 19 |
21 class HomeCardLayoutManager : public aura::LayoutManager { | 20 class HomeCardLayoutManager : public aura::LayoutManager { |
22 public: | 21 public: |
(...skipping 12 matching lines...) Expand all Loading... |
35 virtual void OnChildWindowVisibilityChanged(aura::Window* child, | 34 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
36 bool visible) OVERRIDE { | 35 bool visible) OVERRIDE { |
37 Layout(); | 36 Layout(); |
38 } | 37 } |
39 virtual void SetChildBounds(aura::Window* child, | 38 virtual void SetChildBounds(aura::Window* child, |
40 const gfx::Rect& requested_bounds) OVERRIDE { | 39 const gfx::Rect& requested_bounds) OVERRIDE { |
41 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); | 40 SetChildBoundsDirect(child, gfx::Rect(requested_bounds.size())); |
42 } | 41 } |
43 | 42 |
44 void Layout() { | 43 void Layout() { |
45 const int kHomeCardHeight = 150; | 44 const int kHomeCardHeight = 50; |
46 const int kHomeCardHorizontalMargin = 50; | 45 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; | |
51 if (container_->children().size() < 1) | 46 if (container_->children().size() < 1) |
52 return; | 47 return; |
53 aura::Window* home_card = container_->children()[0]; | 48 aura::Window* home_card = container_->children()[0]; |
54 if (!home_card->IsVisible()) | 49 if (!home_card->IsVisible()) |
55 return; | 50 return; |
56 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); | 51 gfx::Rect screen_bounds = home_card->GetRootWindow()->bounds(); |
57 gfx::Rect card_bounds = screen_bounds; | 52 gfx::Rect card_bounds = screen_bounds; |
58 card_bounds.Inset(kHomeCardHorizontalMargin, | 53 card_bounds.Inset(kHomeCardHorizontalMargin, |
59 screen_bounds.height() - kHomeCardHeight, | 54 screen_bounds.height() - kHomeCardHeight, |
60 kHomeCardHorizontalMargin, | 55 kHomeCardHorizontalMargin, |
61 0); | 56 0); |
62 card_bounds.Inset(-kHomeCardShadowWidth, -kHomeCardShadowWidth); | |
63 SetChildBoundsDirect(home_card, card_bounds); | 57 SetChildBoundsDirect(home_card, card_bounds); |
64 } | 58 } |
65 | 59 |
66 aura::Window* container_; | 60 aura::Window* container_; |
67 | 61 |
68 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); | 62 DISALLOW_COPY_AND_ASSIGN(HomeCardLayoutManager); |
69 }; | 63 }; |
70 | 64 |
71 class HomeCardImpl : public HomeCard { | 65 class HomeCardImpl : public HomeCard { |
72 public: | 66 public: |
73 HomeCardImpl(); | 67 HomeCardImpl(); |
74 virtual ~HomeCardImpl(); | 68 virtual ~HomeCardImpl(); |
75 | 69 |
76 void Init(); | 70 void Init(); |
77 | 71 |
78 private: | 72 private: |
79 views::Widget* home_card_widget_; | 73 views::Widget* home_card_widget_; |
80 | 74 |
81 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 75 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
82 }; | 76 }; |
83 | 77 |
84 HomeCardImpl::HomeCardImpl() | 78 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { |
85 : home_card_widget_(NULL) { | |
86 DCHECK(!instance); | 79 DCHECK(!instance); |
87 instance = this; | 80 instance = this; |
88 } | 81 } |
89 | 82 |
90 HomeCardImpl::~HomeCardImpl() { | 83 HomeCardImpl::~HomeCardImpl() { |
91 DCHECK(instance); | 84 DCHECK(instance); |
92 home_card_widget_->CloseNow(); | 85 home_card_widget_->CloseNow(); |
93 instance = NULL; | 86 instance = NULL; |
94 } | 87 } |
95 | 88 |
96 void HomeCardImpl::Init() { | 89 void HomeCardImpl::Init() { |
97 aura::Window* container = | 90 aura::Window* container = |
98 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 91 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
99 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 92 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
100 wm::SetChildWindowVisibilityChangesAnimated(container); | 93 wm::SetChildWindowVisibilityChangesAnimated(container); |
101 | 94 |
102 app_list::AppListView* view = new app_list::AppListView( | 95 views::Widget::InitParams params( |
103 new AppListViewDelegate); | 96 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
104 view->InitAsBubbleAtFixedLocation( | 97 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
105 container, | 98 params.delegate = new HomeCardDelegateView(); |
106 0 /* initial_apps_page */, | 99 params.parent = container; |
107 gfx::Point(), | 100 |
108 views::BubbleBorder::FLOAT, | 101 home_card_widget_ = new views::Widget; |
109 true /* border_accepts_events */); | 102 home_card_widget_->Init(params); |
110 home_card_widget_ = view->GetWidget(); | 103 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); |
111 view->ShowWhenReady(); | 104 |
| 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 } | 112 } |
113 | 113 |
114 } // namespace | 114 } // namespace |
115 | 115 |
116 // static | 116 // static |
117 HomeCard* HomeCard::Create() { | 117 HomeCard* HomeCard::Create() { |
118 (new HomeCardImpl())->Init(); | 118 (new HomeCardImpl())->Init(); |
119 DCHECK(instance); | 119 DCHECK(instance); |
120 return instance; | 120 return instance; |
121 } | 121 } |
122 | 122 |
123 // static | 123 // static |
124 void HomeCard::Shutdown() { | 124 void HomeCard::Shutdown() { |
125 DCHECK(instance); | 125 DCHECK(instance); |
126 delete instance; | 126 delete instance; |
127 instance = NULL; | 127 instance = NULL; |
128 } | 128 } |
129 | 129 |
130 } // namespace athena | 130 } // namespace athena |
OLD | NEW |