OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/app_list/shower/app_list_shower_impl.h" | 5 #include "ui/app_list/presenter/app_list_presenter_impl.h" |
6 | 6 |
7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
8 #include "ui/app_list/app_list_switches.h" | 8 #include "ui/app_list/app_list_switches.h" |
9 #include "ui/app_list/pagination_model.h" | 9 #include "ui/app_list/pagination_model.h" |
10 #include "ui/app_list/shower/app_list_shower_delegate_factory.h" | 10 #include "ui/app_list/presenter/app_list_presenter_delegate_factory.h" |
11 #include "ui/app_list/views/app_list_view.h" | 11 #include "ui/app_list/views/app_list_view.h" |
12 #include "ui/aura/client/focus_client.h" | 12 #include "ui/aura/client/focus_client.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/compositor/layer.h" | 14 #include "ui/compositor/layer.h" |
15 #include "ui/compositor/scoped_layer_animation_settings.h" | 15 #include "ui/compositor/scoped_layer_animation_settings.h" |
16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
17 | 17 |
18 namespace app_list { | 18 namespace app_list { |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Duration for show/hide animation in milliseconds. | 21 // Duration for show/hide animation in milliseconds. |
22 const int kAnimationDurationMs = 200; | 22 const int kAnimationDurationMs = 200; |
23 | 23 |
24 // The maximum shift in pixels when over-scroll happens. | 24 // The maximum shift in pixels when over-scroll happens. |
25 const int kMaxOverScrollShift = 48; | 25 const int kMaxOverScrollShift = 48; |
26 | 26 |
27 ui::Layer* GetLayer(views::Widget* widget) { | 27 ui::Layer* GetLayer(views::Widget* widget) { |
28 return widget->GetNativeView()->layer(); | 28 return widget->GetNativeView()->layer(); |
29 } | 29 } |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 AppListShowerImpl::AppListShowerImpl(AppListShowerDelegateFactory* factory) | 33 AppListPresenterImpl::AppListPresenterImpl( |
| 34 AppListPresenterDelegateFactory* factory) |
34 : factory_(factory) { | 35 : factory_(factory) { |
35 DCHECK(factory); | 36 DCHECK(factory); |
36 } | 37 } |
37 | 38 |
38 AppListShowerImpl::~AppListShowerImpl() { | 39 AppListPresenterImpl::~AppListPresenterImpl() { |
39 shower_delegate_.reset(); | 40 presenter_delegate_.reset(); |
40 // Ensures app list view goes before the controller since pagination model | 41 // Ensures app list view goes before the controller since pagination model |
41 // lives in the controller and app list view would access it on destruction. | 42 // lives in the controller and app list view would access it on destruction. |
42 if (view_) { | 43 if (view_) { |
43 view_->GetAppsPaginationModel()->RemoveObserver(this); | 44 view_->GetAppsPaginationModel()->RemoveObserver(this); |
44 if (view_->GetWidget()) | 45 if (view_->GetWidget()) |
45 view_->GetWidget()->CloseNow(); | 46 view_->GetWidget()->CloseNow(); |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 aura::Window* AppListShowerImpl::GetWindow() { | 50 aura::Window* AppListPresenterImpl::GetWindow() { |
50 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : nullptr; | 51 return is_visible_ && view_ ? view_->GetWidget()->GetNativeWindow() : nullptr; |
51 } | 52 } |
52 | 53 |
53 void AppListShowerImpl::Show(aura::Window* window) { | 54 void AppListPresenterImpl::Show(aura::Window* window) { |
54 if (is_visible_) | 55 if (is_visible_) |
55 return; | 56 return; |
56 | 57 |
57 DCHECK(window); | 58 DCHECK(window); |
58 is_visible_ = true; | 59 is_visible_ = true; |
59 aura::Window* root_window = window->GetRootWindow(); | 60 aura::Window* root_window = window->GetRootWindow(); |
60 if (view_) { | 61 if (view_) { |
61 ScheduleAnimation(); | 62 ScheduleAnimation(); |
62 } else { | 63 } else { |
63 shower_delegate_ = factory_->GetDelegate(this); | 64 presenter_delegate_ = factory_->GetDelegate(this); |
64 AppListViewDelegate* view_delegate = shower_delegate_->GetViewDelegate(); | 65 AppListViewDelegate* view_delegate = presenter_delegate_->GetViewDelegate(); |
65 DCHECK(view_delegate); | 66 DCHECK(view_delegate); |
66 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view | 67 // Note the AppListViewDelegate outlives the AppListView. For Ash, the view |
67 // is destroyed when dismissed. | 68 // is destroyed when dismissed. |
68 AppListView* view = new AppListView(view_delegate); | 69 AppListView* view = new AppListView(view_delegate); |
69 shower_delegate_->Init(view, root_window, current_apps_page_); | 70 presenter_delegate_->Init(view, root_window, current_apps_page_); |
70 SetView(view); | 71 SetView(view); |
71 } | 72 } |
72 shower_delegate_->OnShown(root_window); | 73 presenter_delegate_->OnShown(root_window); |
73 } | 74 } |
74 | 75 |
75 void AppListShowerImpl::Dismiss() { | 76 void AppListPresenterImpl::Dismiss() { |
76 if (!is_visible_) | 77 if (!is_visible_) |
77 return; | 78 return; |
78 | 79 |
79 // If the app list is currently visible, there should be an existing view. | 80 // If the app list is currently visible, there should be an existing view. |
80 DCHECK(view_); | 81 DCHECK(view_); |
81 | 82 |
82 is_visible_ = false; | 83 is_visible_ = false; |
83 | 84 |
84 // Our widget is currently active. When the animation completes we'll hide | 85 // Our widget is currently active. When the animation completes we'll hide |
85 // the widget, changing activation. If a menu is shown before the animation | 86 // the widget, changing activation. If a menu is shown before the animation |
86 // completes then the activation change triggers the menu to close. By | 87 // completes then the activation change triggers the menu to close. By |
87 // deactivating now we ensure there is no activation change when the | 88 // deactivating now we ensure there is no activation change when the |
88 // animation completes and any menus stay open. | 89 // animation completes and any menus stay open. |
89 view_->GetWidget()->Deactivate(); | 90 view_->GetWidget()->Deactivate(); |
90 | 91 |
91 shower_delegate_->OnDismissed(); | 92 presenter_delegate_->OnDismissed(); |
92 ScheduleAnimation(); | 93 ScheduleAnimation(); |
93 } | 94 } |
94 | 95 |
95 bool AppListShowerImpl::IsVisible() const { | 96 bool AppListPresenterImpl::IsVisible() const { |
96 return view_ && view_->GetWidget()->IsVisible(); | 97 return view_ && view_->GetWidget()->IsVisible(); |
97 } | 98 } |
98 | 99 |
99 bool AppListShowerImpl::GetTargetVisibility() const { | 100 bool AppListPresenterImpl::GetTargetVisibility() const { |
100 return is_visible_; | 101 return is_visible_; |
101 } | 102 } |
102 | 103 |
103 //////////////////////////////////////////////////////////////////////////////// | 104 //////////////////////////////////////////////////////////////////////////////// |
104 // AppListShowerImpl, private: | 105 // AppListPresenterImpl, private: |
105 | 106 |
106 void AppListShowerImpl::SetView(AppListView* view) { | 107 void AppListPresenterImpl::SetView(AppListView* view) { |
107 DCHECK(view_ == nullptr); | 108 DCHECK(view_ == nullptr); |
108 DCHECK(is_visible_); | 109 DCHECK(is_visible_); |
109 | 110 |
110 view_ = view; | 111 view_ = view; |
111 views::Widget* widget = view_->GetWidget(); | 112 views::Widget* widget = view_->GetWidget(); |
112 widget->AddObserver(this); | 113 widget->AddObserver(this); |
113 widget->GetNativeView()->GetRootWindow()->AddObserver(this); | 114 widget->GetNativeView()->GetRootWindow()->AddObserver(this); |
114 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); | 115 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); |
115 view_->GetAppsPaginationModel()->AddObserver(this); | 116 view_->GetAppsPaginationModel()->AddObserver(this); |
116 view_->ShowWhenReady(); | 117 view_->ShowWhenReady(); |
117 } | 118 } |
118 | 119 |
119 void AppListShowerImpl::ResetView() { | 120 void AppListPresenterImpl::ResetView() { |
120 if (!view_) | 121 if (!view_) |
121 return; | 122 return; |
122 | 123 |
123 views::Widget* widget = view_->GetWidget(); | 124 views::Widget* widget = view_->GetWidget(); |
124 widget->RemoveObserver(this); | 125 widget->RemoveObserver(this); |
125 GetLayer(widget)->GetAnimator()->RemoveObserver(this); | 126 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
126 shower_delegate_.reset(); | 127 presenter_delegate_.reset(); |
127 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); | 128 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); |
128 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); | 129 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); |
129 | 130 |
130 view_->GetAppsPaginationModel()->RemoveObserver(this); | 131 view_->GetAppsPaginationModel()->RemoveObserver(this); |
131 | 132 |
132 view_ = nullptr; | 133 view_ = nullptr; |
133 } | 134 } |
134 | 135 |
135 void AppListShowerImpl::ScheduleAnimation() { | 136 void AppListPresenterImpl::ScheduleAnimation() { |
136 // Stop observing previous animation. | 137 // Stop observing previous animation. |
137 StopObservingImplicitAnimations(); | 138 StopObservingImplicitAnimations(); |
138 | 139 |
139 views::Widget* widget = view_->GetWidget(); | 140 views::Widget* widget = view_->GetWidget(); |
140 ui::Layer* layer = GetLayer(widget); | 141 ui::Layer* layer = GetLayer(widget); |
141 layer->GetAnimator()->StopAnimating(); | 142 layer->GetAnimator()->StopAnimating(); |
142 | 143 |
143 gfx::Rect target_bounds; | 144 gfx::Rect target_bounds; |
144 gfx::Vector2d offset = shower_delegate_->GetVisibilityAnimationOffset( | 145 gfx::Vector2d offset = presenter_delegate_->GetVisibilityAnimationOffset( |
145 widget->GetNativeView()->GetRootWindow()); | 146 widget->GetNativeView()->GetRootWindow()); |
146 if (is_visible_) { | 147 if (is_visible_) { |
147 target_bounds = widget->GetWindowBoundsInScreen(); | 148 target_bounds = widget->GetWindowBoundsInScreen(); |
148 gfx::Rect start_bounds = gfx::Rect(target_bounds); | 149 gfx::Rect start_bounds = gfx::Rect(target_bounds); |
149 start_bounds.Offset(offset); | 150 start_bounds.Offset(offset); |
150 widget->SetBounds(start_bounds); | 151 widget->SetBounds(start_bounds); |
151 } else { | 152 } else { |
152 target_bounds = widget->GetWindowBoundsInScreen(); | 153 target_bounds = widget->GetWindowBoundsInScreen(); |
153 target_bounds.Offset(offset); | 154 target_bounds.Offset(offset); |
154 } | 155 } |
155 | 156 |
156 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); | 157 ui::ScopedLayerAnimationSettings animation(layer->GetAnimator()); |
157 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 158 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
158 is_visible_ ? 0 : kAnimationDurationMs)); | 159 is_visible_ ? 0 : kAnimationDurationMs)); |
159 animation.AddObserver(this); | 160 animation.AddObserver(this); |
160 | 161 |
161 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); | 162 layer->SetOpacity(is_visible_ ? 1.0 : 0.0); |
162 widget->SetBounds(target_bounds); | 163 widget->SetBounds(target_bounds); |
163 } | 164 } |
164 | 165 |
165 //////////////////////////////////////////////////////////////////////////////// | 166 //////////////////////////////////////////////////////////////////////////////// |
166 // AppListShowerImpl, aura::client::FocusChangeObserver implementation: | 167 // AppListPresenterImpl, aura::client::FocusChangeObserver implementation: |
167 | 168 |
168 void AppListShowerImpl::OnWindowFocused(aura::Window* gained_focus, | 169 void AppListPresenterImpl::OnWindowFocused(aura::Window* gained_focus, |
169 aura::Window* lost_focus) { | 170 aura::Window* lost_focus) { |
170 if (view_ && is_visible_) { | 171 if (view_ && is_visible_) { |
171 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); | 172 aura::Window* applist_window = view_->GetWidget()->GetNativeView(); |
172 aura::Window* applist_container = applist_window->parent(); | 173 aura::Window* applist_container = applist_window->parent(); |
173 if (applist_container->Contains(lost_focus) && | 174 if (applist_container->Contains(lost_focus) && |
174 (!gained_focus || !applist_container->Contains(gained_focus)) && | 175 (!gained_focus || !applist_container->Contains(gained_focus)) && |
175 !switches::ShouldNotDismissOnBlur()) { | 176 !switches::ShouldNotDismissOnBlur()) { |
176 Dismiss(); | 177 Dismiss(); |
177 } | 178 } |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
181 //////////////////////////////////////////////////////////////////////////////// | 182 //////////////////////////////////////////////////////////////////////////////// |
182 // AppListShowerImpl, aura::WindowObserver implementation: | 183 // AppListPresenterImpl, aura::WindowObserver implementation: |
183 void AppListShowerImpl::OnWindowBoundsChanged(aura::Window* root, | 184 void AppListPresenterImpl::OnWindowBoundsChanged(aura::Window* root, |
184 const gfx::Rect& old_bounds, | 185 const gfx::Rect& old_bounds, |
185 const gfx::Rect& new_bounds) { | 186 const gfx::Rect& new_bounds) { |
186 if (shower_delegate_) | 187 if (presenter_delegate_) |
187 shower_delegate_->UpdateBounds(); | 188 presenter_delegate_->UpdateBounds(); |
188 } | 189 } |
189 | 190 |
190 //////////////////////////////////////////////////////////////////////////////// | 191 //////////////////////////////////////////////////////////////////////////////// |
191 // AppListShowerImpl, ui::ImplicitAnimationObserver implementation: | 192 // AppListPresenterImpl, ui::ImplicitAnimationObserver implementation: |
192 | 193 |
193 void AppListShowerImpl::OnImplicitAnimationsCompleted() { | 194 void AppListPresenterImpl::OnImplicitAnimationsCompleted() { |
194 if (is_visible_) | 195 if (is_visible_) |
195 view_->GetWidget()->Activate(); | 196 view_->GetWidget()->Activate(); |
196 else | 197 else |
197 view_->GetWidget()->Close(); | 198 view_->GetWidget()->Close(); |
198 } | 199 } |
199 | 200 |
200 //////////////////////////////////////////////////////////////////////////////// | 201 //////////////////////////////////////////////////////////////////////////////// |
201 // AppListShowerImpl, views::WidgetObserver implementation: | 202 // AppListPresenterImpl, views::WidgetObserver implementation: |
202 | 203 |
203 void AppListShowerImpl::OnWidgetDestroying(views::Widget* widget) { | 204 void AppListPresenterImpl::OnWidgetDestroying(views::Widget* widget) { |
204 DCHECK(view_->GetWidget() == widget); | 205 DCHECK(view_->GetWidget() == widget); |
205 if (is_visible_) | 206 if (is_visible_) |
206 Dismiss(); | 207 Dismiss(); |
207 ResetView(); | 208 ResetView(); |
208 } | 209 } |
209 | 210 |
210 //////////////////////////////////////////////////////////////////////////////// | 211 //////////////////////////////////////////////////////////////////////////////// |
211 // AppListShowerImpl, PaginationModelObserver implementation: | 212 // AppListPresenterImpl, PaginationModelObserver implementation: |
212 | 213 |
213 void AppListShowerImpl::TotalPagesChanged() {} | 214 void AppListPresenterImpl::TotalPagesChanged() {} |
214 | 215 |
215 void AppListShowerImpl::SelectedPageChanged(int old_selected, | 216 void AppListPresenterImpl::SelectedPageChanged(int old_selected, |
216 int new_selected) { | 217 int new_selected) { |
217 current_apps_page_ = new_selected; | 218 current_apps_page_ = new_selected; |
218 } | 219 } |
219 | 220 |
220 void AppListShowerImpl::TransitionStarted() {} | 221 void AppListPresenterImpl::TransitionStarted() {} |
221 | 222 |
222 void AppListShowerImpl::TransitionChanged() { | 223 void AppListPresenterImpl::TransitionChanged() { |
223 // |view_| could be NULL when app list is closed with a running transition. | 224 // |view_| could be NULL when app list is closed with a running transition. |
224 if (!view_) | 225 if (!view_) |
225 return; | 226 return; |
226 | 227 |
227 PaginationModel* pagination_model = view_->GetAppsPaginationModel(); | 228 PaginationModel* pagination_model = view_->GetAppsPaginationModel(); |
228 | 229 |
229 const PaginationModel::Transition& transition = | 230 const PaginationModel::Transition& transition = |
230 pagination_model->transition(); | 231 pagination_model->transition(); |
231 if (pagination_model->is_valid_page(transition.target_page)) | 232 if (pagination_model->is_valid_page(transition.target_page)) |
232 return; | 233 return; |
(...skipping 22 matching lines...) Expand all Loading... |
255 } else if (should_snap_back_) { | 256 } else if (should_snap_back_) { |
256 should_snap_back_ = false; | 257 should_snap_back_ = false; |
257 ui::ScopedLayerAnimationSettings animation(widget_animator); | 258 ui::ScopedLayerAnimationSettings animation(widget_animator); |
258 animation.SetTransitionDuration( | 259 animation.SetTransitionDuration( |
259 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); | 260 base::TimeDelta::FromMilliseconds(kOverscrollPageTransitionDurationMs)); |
260 widget->SetBounds(view_bounds_); | 261 widget->SetBounds(view_bounds_); |
261 } | 262 } |
262 } | 263 } |
263 | 264 |
264 } // namespace app_list | 265 } // namespace app_list |
OLD | NEW |