OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/app_list/app_list.h" | 5 #include "ash/app_list/app_list.h" |
6 | 6 |
7 #include "ash/app_list/app_list_view.h" | 7 #include "ash/app_list/app_list_view.h" |
8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ui/aura/event.h" | 11 #include "ui/aura/event.h" |
12 #include "ui/aura/root_window.h" | 12 #include "ui/aura/root_window.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" | 14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" |
15 #include "ui/gfx/screen.h" | 15 #include "ui/gfx/screen.h" |
| 16 #include "ui/gfx/transform_util.h" |
16 | 17 |
17 namespace ash { | 18 namespace ash { |
18 namespace internal { | 19 namespace internal { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
| 23 const float kDefaultContainerAnimationScaleFactor = 1.05f; |
| 24 |
22 // Gets preferred bounds of app list window. | 25 // Gets preferred bounds of app list window. |
23 gfx::Rect GetPreferredBounds() { | 26 gfx::Rect GetPreferredBounds() { |
24 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); | 27 gfx::Point cursor = gfx::Screen::GetCursorScreenPoint(); |
25 // Use full monitor rect so that the app list shade goes behind the launcher. | 28 // Use full monitor rect so that the app list shade goes behind the launcher. |
26 return gfx::Screen::GetMonitorAreaNearestPoint(cursor); | 29 return gfx::Screen::GetMonitorAreaNearestPoint(cursor); |
27 } | 30 } |
28 | 31 |
29 ui::Layer* GetLayer(views::Widget* widget) { | 32 ui::Layer* GetLayer(views::Widget* widget) { |
30 return widget->GetNativeView()->layer(); | 33 return widget->GetNativeView()->layer(); |
31 } | 34 } |
32 | 35 |
33 } // namespace | 36 } // namespace |
34 | 37 |
35 //////////////////////////////////////////////////////////////////////////////// | 38 //////////////////////////////////////////////////////////////////////////////// |
36 // AppList, public: | 39 // AppList, public: |
37 | 40 |
38 AppList::AppList() : is_visible_(false), widget_(NULL) { | 41 AppList::AppList() : is_visible_(false), view_(NULL) { |
39 } | 42 } |
40 | 43 |
41 AppList::~AppList() { | 44 AppList::~AppList() { |
42 ResetWidget(); | 45 ResetView(); |
43 } | 46 } |
44 | 47 |
45 void AppList::SetVisible(bool visible) { | 48 void AppList::SetVisible(bool visible) { |
46 if (visible == is_visible_) | 49 if (visible == is_visible_) |
47 return; | 50 return; |
48 | 51 |
49 is_visible_ = visible; | 52 is_visible_ = visible; |
50 | 53 |
51 if (widget_) { | 54 if (view_) { |
52 ScheduleAnimation(); | 55 ScheduleAnimation(); |
53 } else if (is_visible_) { | 56 } else if (is_visible_) { |
54 // AppListModel and AppListViewDelegate are owned by AppListView. They | 57 // AppListModel and AppListViewDelegate are owned by AppListView. They |
55 // will be released with AppListView on close. | 58 // will be released with AppListView on close. |
56 AppListView* app_list_view = new AppListView( | 59 SetView(new AppListView( |
57 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), | 60 Shell::GetInstance()->delegate()->CreateAppListViewDelegate(), |
58 GetPreferredBounds()); | 61 GetPreferredBounds())); |
59 SetWidget(app_list_view->GetWidget()); | |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 bool AppList::IsVisible() { | 65 bool AppList::IsVisible() { |
64 return widget_ && widget_->IsVisible(); | 66 return view_ && view_->GetWidget()->IsVisible(); |
65 } | 67 } |
66 | 68 |
67 //////////////////////////////////////////////////////////////////////////////// | 69 //////////////////////////////////////////////////////////////////////////////// |
68 // AppList, private: | 70 // AppList, private: |
69 | 71 |
70 void AppList::SetWidget(views::Widget* widget) { | 72 void AppList::SetView(AppListView* view) { |
71 DCHECK(widget_ == NULL); | 73 DCHECK(view_ == NULL); |
72 | 74 |
73 if (is_visible_) { | 75 if (is_visible_) { |
74 widget_ = widget; | 76 view_ = view; |
75 widget_->AddObserver(this); | 77 views::Widget* widget = view_->GetWidget(); |
| 78 widget->AddObserver(this); |
76 Shell::GetInstance()->AddRootWindowEventFilter(this); | 79 Shell::GetInstance()->AddRootWindowEventFilter(this); |
77 widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this); | 80 widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this); |
78 | 81 |
79 widget_->SetOpacity(0); | 82 widget->SetOpacity(0); |
80 ScheduleAnimation(); | 83 ScheduleAnimation(); |
81 | 84 |
82 widget_->Show(); | 85 view_->GetWidget()->Show(); |
83 widget_->Activate(); | |
84 } else { | 86 } else { |
85 widget->Close(); | 87 view->GetWidget()->Close(); |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
89 void AppList::ResetWidget() { | 91 void AppList::ResetView() { |
90 if (!widget_) | 92 if (!view_) |
91 return; | 93 return; |
92 | 94 |
93 widget_->RemoveObserver(this); | 95 views::Widget* widget = view_->GetWidget(); |
94 GetLayer(widget_)->GetAnimator()->RemoveObserver(this); | 96 widget->RemoveObserver(this); |
| 97 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
95 Shell::GetInstance()->RemoveRootWindowEventFilter(this); | 98 Shell::GetInstance()->RemoveRootWindowEventFilter(this); |
96 widget_->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this); | 99 widget->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this); |
97 widget_ = NULL; | 100 view_ = NULL; |
98 } | 101 } |
99 | 102 |
100 void AppList::ScheduleAnimation() { | 103 void AppList::ScheduleAnimation() { |
101 aura::Window* default_container = Shell::GetInstance()->GetContainer( | 104 aura::Window* default_container = Shell::GetInstance()->GetContainer( |
102 internal::kShellWindowId_DefaultContainer); | 105 internal::kShellWindowId_DefaultContainer); |
103 // |default_container| could be NULL during Shell shutdown. | 106 // |default_container| could be NULL during Shell shutdown. |
104 if (!default_container) | 107 if (!default_container) |
105 return; | 108 return; |
106 | 109 |
107 ui::Layer* layer = GetLayer(widget_); | 110 ui::Layer* layer = GetLayer(view_->GetWidget()); |
108 | 111 |
109 // Stop observing previous animation. | 112 // Stop observing previous animation. |
110 StopObservingImplicitAnimations(); | 113 StopObservingImplicitAnimations(); |
111 | 114 |
112 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); | 115 ui::ScopedLayerAnimationSettings app_list_animation(layer->GetAnimator()); |
113 app_list_animation.AddObserver(this); | 116 app_list_animation.AddObserver(this); |
114 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 117 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
115 | 118 |
| 119 if (is_visible_) |
| 120 view_->AnimateShow(); |
| 121 else |
| 122 view_->AnimateHide(); |
| 123 |
116 ui::Layer* default_container_layer = default_container->layer(); | 124 ui::Layer* default_container_layer = default_container->layer(); |
117 ui::ScopedLayerAnimationSettings default_container_animation( | 125 ui::ScopedLayerAnimationSettings default_container_animation( |
118 default_container_layer->GetAnimator()); | 126 default_container_layer->GetAnimator()); |
119 app_list_animation.AddObserver(this); | 127 app_list_animation.AddObserver(this); |
120 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); | 128 default_container_layer->SetOpacity(is_visible_ ? 0.0 : 1.0); |
| 129 default_container_layer->SetTransform(is_visible_ ? |
| 130 ui::GetScaleTransform( |
| 131 gfx::Point(default_container_layer->bounds().width() / 2, |
| 132 default_container_layer->bounds().height() / 2), |
| 133 kDefaultContainerAnimationScaleFactor) : |
| 134 ui::Transform()); |
121 } | 135 } |
122 | 136 |
123 //////////////////////////////////////////////////////////////////////////////// | 137 //////////////////////////////////////////////////////////////////////////////// |
124 // AppList, aura::EventFilter implementation: | 138 // AppList, aura::EventFilter implementation: |
125 | 139 |
126 bool AppList::PreHandleKeyEvent(aura::Window* target, | 140 bool AppList::PreHandleKeyEvent(aura::Window* target, |
127 aura::KeyEvent* event) { | 141 aura::KeyEvent* event) { |
128 return false; | 142 return false; |
129 } | 143 } |
130 | 144 |
131 bool AppList::PreHandleMouseEvent(aura::Window* target, | 145 bool AppList::PreHandleMouseEvent(aura::Window* target, |
132 aura::MouseEvent* event) { | 146 aura::MouseEvent* event) { |
133 if (widget_ && is_visible_ && event->type() == ui::ET_MOUSE_PRESSED) { | 147 if (view_ && is_visible_ && event->type() == ui::ET_MOUSE_PRESSED) { |
134 aura::MouseEvent translated(*event, target, widget_->GetNativeView()); | 148 views::Widget* widget = view_->GetWidget(); |
135 if (!widget_->GetNativeView()->ContainsPoint(translated.location())) | 149 aura::MouseEvent translated(*event, target, widget->GetNativeView()); |
| 150 if (!widget->GetNativeView()->ContainsPoint(translated.location())) |
136 SetVisible(false); | 151 SetVisible(false); |
137 } | 152 } |
138 return false; | 153 return false; |
139 } | 154 } |
140 | 155 |
141 ui::TouchStatus AppList::PreHandleTouchEvent(aura::Window* target, | 156 ui::TouchStatus AppList::PreHandleTouchEvent(aura::Window* target, |
142 aura::TouchEvent* event) { | 157 aura::TouchEvent* event) { |
143 return ui::TOUCH_STATUS_UNKNOWN; | 158 return ui::TOUCH_STATUS_UNKNOWN; |
144 } | 159 } |
145 | 160 |
146 ui::GestureStatus AppList::PreHandleGestureEvent( | 161 ui::GestureStatus AppList::PreHandleGestureEvent( |
147 aura::Window* target, | 162 aura::Window* target, |
148 aura::GestureEvent* event) { | 163 aura::GestureEvent* event) { |
149 return ui::GESTURE_STATUS_UNKNOWN; | 164 return ui::GESTURE_STATUS_UNKNOWN; |
150 } | 165 } |
151 | 166 |
152 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
153 // AppList, ura::RootWindowObserver implementation: | 168 // AppList, ura::RootWindowObserver implementation: |
154 void AppList::OnRootWindowResized(const gfx::Size& new_size) { | 169 void AppList::OnRootWindowResized(const gfx::Size& new_size) { |
155 if (widget_ && is_visible_) | 170 if (view_&& is_visible_) |
156 widget_->SetBounds(gfx::Rect(new_size)); | 171 view_->GetWidget()->SetBounds(gfx::Rect(new_size)); |
157 } | 172 } |
158 | 173 |
159 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
160 // AppList, ui::ImplicitAnimationObserver implementation: | 175 // AppList, ui::ImplicitAnimationObserver implementation: |
161 | 176 |
162 void AppList::OnImplicitAnimationsCompleted() { | 177 void AppList::OnImplicitAnimationsCompleted() { |
163 if (!is_visible_ ) | 178 if (is_visible_ ) |
164 widget_->Close(); | 179 view_->GetWidget()->Activate(); |
| 180 else |
| 181 view_->GetWidget()->Close(); |
165 } | 182 } |
166 | 183 |
167 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
168 // AppList, views::Widget::Observer implementation: | 185 // AppList, views::Widget::Observer implementation: |
169 | 186 |
170 void AppList::OnWidgetClosing(views::Widget* widget) { | 187 void AppList::OnWidgetClosing(views::Widget* widget) { |
171 DCHECK(widget_ == widget); | 188 DCHECK(view_->GetWidget() == widget); |
172 if (is_visible_) | 189 if (is_visible_) |
173 SetVisible(false); | 190 SetVisible(false); |
174 ResetWidget(); | 191 ResetView(); |
175 } | 192 } |
176 | 193 |
177 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { | 194 void AppList::OnWidgetActivationChanged(views::Widget* widget, bool active) { |
178 DCHECK(widget_ == widget); | 195 DCHECK(view_->GetWidget() == widget); |
179 if (widget_ && is_visible_ && !active) | 196 if (view_ && is_visible_ && !active) |
180 SetVisible(false); | 197 SetVisible(false); |
181 } | 198 } |
182 | 199 |
183 } // namespace internal | 200 } // namespace internal |
184 } // namespace ash | 201 } // namespace ash |
OLD | NEW |