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_; |
74 | 80 |
75 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); | 81 DISALLOW_COPY_AND_ASSIGN(HomeCardImpl); |
76 }; | 82 }; |
77 | 83 |
78 HomeCardImpl::HomeCardImpl() : home_card_widget_(NULL) { | 84 HomeCardImpl::HomeCardImpl() |
| 85 : home_card_widget_(NULL) { |
79 DCHECK(!instance); | 86 DCHECK(!instance); |
80 instance = this; | 87 instance = this; |
81 } | 88 } |
82 | 89 |
83 HomeCardImpl::~HomeCardImpl() { | 90 HomeCardImpl::~HomeCardImpl() { |
84 DCHECK(instance); | 91 DCHECK(instance); |
85 home_card_widget_->CloseNow(); | 92 home_card_widget_->CloseNow(); |
86 instance = NULL; | 93 instance = NULL; |
87 } | 94 } |
88 | 95 |
89 void HomeCardImpl::Init() { | 96 void HomeCardImpl::Init() { |
90 aura::Window* container = | 97 aura::Window* container = |
91 ScreenManager::Get()->CreateContainer("HomeCardContainer"); | 98 ScreenManager::Get()->CreateContainer("HomeCardContainer"); |
92 container->SetLayoutManager(new HomeCardLayoutManager(container)); | 99 container->SetLayoutManager(new HomeCardLayoutManager(container)); |
93 wm::SetChildWindowVisibilityChangesAnimated(container); | 100 wm::SetChildWindowVisibilityChangesAnimated(container); |
94 | 101 |
95 views::Widget::InitParams params( | 102 app_list::AppListView* view = new app_list::AppListView( |
96 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 103 new AppListViewDelegate); |
97 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 104 view->InitAsBubbleAtFixedLocation( |
98 params.delegate = new HomeCardDelegateView(); | 105 container, |
99 params.parent = container; | 106 0 /* initial_apps_page */, |
100 | 107 gfx::Point(), |
101 home_card_widget_ = new views::Widget; | 108 views::BubbleBorder::FLOAT, |
102 home_card_widget_->Init(params); | 109 true /* border_accepts_events */); |
103 home_card_widget_->GetNativeView()->SetName("HomeCardWidget"); | 110 home_card_widget_ = view->GetWidget(); |
104 | 111 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 } | 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 |