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/wm/app_list_controller.h" | 5 #include "ash/wm/app_list_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_delegate.h" | 13 #include "ash/shell_delegate.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "ui/app_list/app_list_constants.h" | 16 #include "ui/app_list/app_list_constants.h" |
17 #include "ui/app_list/app_list_switches.h" | 17 #include "ui/app_list/app_list_switches.h" |
18 #include "ui/app_list/pagination_model.h" | 18 #include "ui/app_list/pagination_model.h" |
19 #include "ui/app_list/views/app_list_main_view.h" | |
19 #include "ui/app_list/views/app_list_view.h" | 20 #include "ui/app_list/views/app_list_view.h" |
21 #include "ui/app_list/views/apps_container_view.h" | |
tapted
2014/06/02 08:36:49
nit: these 3 includes, and app_list_main_view.h ab
Matt Giuca
2014/06/03 01:52:36
Done.
| |
22 #include "ui/app_list/views/apps_grid_view.h" | |
23 #include "ui/app_list/views/contents_view.h" | |
20 #include "ui/aura/client/focus_client.h" | 24 #include "ui/aura/client/focus_client.h" |
21 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
22 #include "ui/aura/window_event_dispatcher.h" | 26 #include "ui/aura/window_event_dispatcher.h" |
23 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/scoped_layer_animation_settings.h" | 28 #include "ui/compositor/scoped_layer_animation_settings.h" |
25 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
26 #include "ui/gfx/transform_util.h" | 30 #include "ui/gfx/transform_util.h" |
27 #include "ui/keyboard/keyboard_controller.h" | 31 #include "ui/keyboard/keyboard_controller.h" |
28 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
29 | 33 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) { | 150 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) { |
147 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin; | 151 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin; |
148 } | 152 } |
149 | 153 |
150 } // namespace | 154 } // namespace |
151 | 155 |
152 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
153 // AppListController, public: | 157 // AppListController, public: |
154 | 158 |
155 AppListController::AppListController() | 159 AppListController::AppListController() |
156 : pagination_model_(new app_list::PaginationModel), | 160 : is_visible_(false), |
157 is_visible_(false), | |
158 is_centered_(false), | 161 is_centered_(false), |
159 view_(NULL), | 162 view_(NULL), |
163 current_app_page_(-1), | |
160 should_snap_back_(false) { | 164 should_snap_back_(false) { |
161 Shell::GetInstance()->AddShellObserver(this); | 165 Shell::GetInstance()->AddShellObserver(this); |
162 pagination_model_->AddObserver(this); | |
163 } | 166 } |
164 | 167 |
165 AppListController::~AppListController() { | 168 AppListController::~AppListController() { |
166 // Ensures app list view goes before the controller since pagination model | 169 // Ensures app list view goes before the controller since pagination model |
167 // lives in the controller and app list view would access it on destruction. | 170 // lives in the controller and app list view would access it on destruction. |
168 if (view_ && view_->GetWidget()) | 171 if (view_) { |
169 view_->GetWidget()->CloseNow(); | 172 view_->GetAppsPaginationModel()->RemoveObserver(this); |
173 if (view_->GetWidget()) | |
174 view_->GetWidget()->CloseNow(); | |
175 } | |
170 | 176 |
171 Shell::GetInstance()->RemoveShellObserver(this); | 177 Shell::GetInstance()->RemoveShellObserver(this); |
172 pagination_model_->RemoveObserver(this); | |
173 } | 178 } |
174 | 179 |
175 void AppListController::SetVisible(bool visible, aura::Window* window) { | 180 void AppListController::SetVisible(bool visible, aura::Window* window) { |
176 if (visible == is_visible_) | 181 if (visible == is_visible_) |
177 return; | 182 return; |
178 | 183 |
179 is_visible_ = visible; | 184 is_visible_ = visible; |
180 | 185 |
181 // App list needs to know the new shelf layout in order to calculate its | 186 // App list needs to know the new shelf layout in order to calculate its |
182 // UI layout when AppListView visibility changes. | 187 // UI layout when AppListView visibility changes. |
(...skipping 18 matching lines...) Expand all Loading... | |
201 aura::Window* container = GetRootWindowController(root_window)-> | 206 aura::Window* container = GetRootWindowController(root_window)-> |
202 GetContainer(kShellWindowId_AppListContainer); | 207 GetContainer(kShellWindowId_AppListContainer); |
203 views::View* applist_button = | 208 views::View* applist_button = |
204 Shelf::ForWindow(container)->GetAppListButtonView(); | 209 Shelf::ForWindow(container)->GetAppListButtonView(); |
205 is_centered_ = view->ShouldCenterWindow(); | 210 is_centered_ = view->ShouldCenterWindow(); |
206 if (is_centered_) { | 211 if (is_centered_) { |
207 // Note: We can't center the app list until we have its dimensions, so we | 212 // Note: We can't center the app list until we have its dimensions, so we |
208 // init at (0, 0) and then reset its anchor point. | 213 // init at (0, 0) and then reset its anchor point. |
209 view->InitAsBubbleAtFixedLocation( | 214 view->InitAsBubbleAtFixedLocation( |
210 container, | 215 container, |
211 pagination_model_.get(), | |
212 gfx::Point(), | 216 gfx::Point(), |
213 views::BubbleBorder::FLOAT, | 217 views::BubbleBorder::FLOAT, |
214 true /* border_accepts_events */); | 218 true /* border_accepts_events */); |
215 // The experimental app list is centered over the display of the app list | 219 // The experimental app list is centered over the display of the app list |
216 // button that was pressed (if triggered via keyboard, this is the display | 220 // button that was pressed (if triggered via keyboard, this is the display |
217 // with the currently focused window). | 221 // with the currently focused window). |
218 view->SetAnchorPoint(GetCenterOfDisplayForView( | 222 view->SetAnchorPoint(GetCenterOfDisplayForView( |
219 applist_button, GetMinimumBoundsHeightForAppList(view))); | 223 applist_button, GetMinimumBoundsHeightForAppList(view))); |
220 } else { | 224 } else { |
221 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); | 225 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); |
222 // We need the location of the button within the local screen. | 226 // We need the location of the button within the local screen. |
223 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( | 227 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( |
224 root_window, | 228 root_window, |
225 applist_button_bounds); | 229 applist_button_bounds); |
226 view->InitAsBubbleAttachedToAnchor( | 230 view->InitAsBubbleAttachedToAnchor( |
227 container, | 231 container, |
228 pagination_model_.get(), | |
229 Shelf::ForWindow(container)->GetAppListButtonView(), | 232 Shelf::ForWindow(container)->GetAppListButtonView(), |
230 GetAnchorPositionOffsetToShelf(applist_button_bounds, | 233 GetAnchorPositionOffsetToShelf(applist_button_bounds, |
231 Shelf::ForWindow(container)->GetAppListButtonView()-> | 234 Shelf::ForWindow(container)->GetAppListButtonView()-> |
232 GetWidget()), | 235 GetWidget()), |
233 GetBubbleArrow(container), | 236 GetBubbleArrow(container), |
234 true /* border_accepts_events */); | 237 true /* border_accepts_events */); |
235 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 238 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
236 } | 239 } |
237 SetView(view); | 240 SetView(view); |
238 // By setting us as DnD recipient, the app list knows that we can | 241 // By setting us as DnD recipient, the app list knows that we can |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 widget->AddObserver(this); | 273 widget->AddObserver(this); |
271 keyboard::KeyboardController* keyboard_controller = | 274 keyboard::KeyboardController* keyboard_controller = |
272 keyboard::KeyboardController::GetInstance(); | 275 keyboard::KeyboardController::GetInstance(); |
273 if (keyboard_controller) | 276 if (keyboard_controller) |
274 keyboard_controller->AddObserver(this); | 277 keyboard_controller->AddObserver(this); |
275 Shell::GetInstance()->AddPreTargetHandler(this); | 278 Shell::GetInstance()->AddPreTargetHandler(this); |
276 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); | 279 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); |
277 widget->GetNativeView()->GetRootWindow()->AddObserver(this); | 280 widget->GetNativeView()->GetRootWindow()->AddObserver(this); |
278 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); | 281 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); |
279 | 282 |
283 app_list::PaginationModel* pagination_model = view_->GetAppsPaginationModel(); | |
284 pagination_model->AddObserver(this); | |
285 if (pagination_model->is_valid_page(current_app_page_)) | |
286 pagination_model->SelectPage(current_app_page_, false); | |
287 | |
280 view_->ShowWhenReady(); | 288 view_->ShowWhenReady(); |
281 } | 289 } |
282 | 290 |
283 void AppListController::ResetView() { | 291 void AppListController::ResetView() { |
284 if (!view_) | 292 if (!view_) |
285 return; | 293 return; |
286 | 294 |
287 views::Widget* widget = view_->GetWidget(); | 295 views::Widget* widget = view_->GetWidget(); |
288 widget->RemoveObserver(this); | 296 widget->RemoveObserver(this); |
289 GetLayer(widget)->GetAnimator()->RemoveObserver(this); | 297 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
290 keyboard::KeyboardController* keyboard_controller = | 298 keyboard::KeyboardController* keyboard_controller = |
291 keyboard::KeyboardController::GetInstance(); | 299 keyboard::KeyboardController::GetInstance(); |
292 if (keyboard_controller) | 300 if (keyboard_controller) |
293 keyboard_controller->RemoveObserver(this); | 301 keyboard_controller->RemoveObserver(this); |
294 Shell::GetInstance()->RemovePreTargetHandler(this); | 302 Shell::GetInstance()->RemovePreTargetHandler(this); |
295 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); | 303 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); |
296 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); | 304 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); |
297 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); | 305 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); |
306 | |
307 view_->GetAppsPaginationModel()->RemoveObserver(this); | |
308 | |
298 view_ = NULL; | 309 view_ = NULL; |
299 } | 310 } |
300 | 311 |
301 void AppListController::ScheduleAnimation() { | 312 void AppListController::ScheduleAnimation() { |
302 // Stop observing previous animation. | 313 // Stop observing previous animation. |
303 StopObservingImplicitAnimations(); | 314 StopObservingImplicitAnimations(); |
304 | 315 |
305 views::Widget* widget = view_->GetWidget(); | 316 views::Widget* widget = view_->GetWidget(); |
306 ui::Layer* layer = GetLayer(widget); | 317 ui::Layer* layer = GetLayer(widget); |
307 layer->GetAnimator()->StopAnimating(); | 318 layer->GetAnimator()->StopAnimating(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 } | 453 } |
443 | 454 |
444 //////////////////////////////////////////////////////////////////////////////// | 455 //////////////////////////////////////////////////////////////////////////////// |
445 // AppListController, PaginationModelObserver implementation: | 456 // AppListController, PaginationModelObserver implementation: |
446 | 457 |
447 void AppListController::TotalPagesChanged() { | 458 void AppListController::TotalPagesChanged() { |
448 } | 459 } |
449 | 460 |
450 void AppListController::SelectedPageChanged(int old_selected, | 461 void AppListController::SelectedPageChanged(int old_selected, |
451 int new_selected) { | 462 int new_selected) { |
463 current_app_page_ = new_selected; | |
452 } | 464 } |
453 | 465 |
454 void AppListController::TransitionStarted() { | 466 void AppListController::TransitionStarted() { |
455 } | 467 } |
456 | 468 |
457 void AppListController::TransitionChanged() { | 469 void AppListController::TransitionChanged() { |
458 // |view_| could be NULL when app list is closed with a running transition. | 470 // |view_| could be NULL when app list is closed with a running transition. |
459 if (!view_) | 471 if (!view_) |
460 return; | 472 return; |
461 | 473 |
474 app_list::PaginationModel* pagination_model = view_->GetAppsPaginationModel(); | |
475 | |
462 const app_list::PaginationModel::Transition& transition = | 476 const app_list::PaginationModel::Transition& transition = |
463 pagination_model_->transition(); | 477 pagination_model->transition(); |
464 if (pagination_model_->is_valid_page(transition.target_page)) | 478 if (pagination_model->is_valid_page(transition.target_page)) |
465 return; | 479 return; |
466 | 480 |
467 views::Widget* widget = view_->GetWidget(); | 481 views::Widget* widget = view_->GetWidget(); |
468 ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator(); | 482 ui::LayerAnimator* widget_animator = GetLayer(widget)->GetAnimator(); |
469 if (!pagination_model_->IsRevertingCurrentTransition()) { | 483 if (!pagination_model->IsRevertingCurrentTransition()) { |
470 // Update cached |view_bounds_| if it is the first over-scroll move and | 484 // Update cached |view_bounds_| if it is the first over-scroll move and |
471 // widget does not have running animations. | 485 // widget does not have running animations. |
472 if (!should_snap_back_ && !widget_animator->is_animating()) | 486 if (!should_snap_back_ && !widget_animator->is_animating()) |
473 view_bounds_ = widget->GetWindowBoundsInScreen(); | 487 view_bounds_ = widget->GetWindowBoundsInScreen(); |
474 | 488 |
475 const int current_page = pagination_model_->selected_page(); | 489 const int current_page = pagination_model->selected_page(); |
476 const int dir = transition.target_page > current_page ? -1 : 1; | 490 const int dir = transition.target_page > current_page ? -1 : 1; |
477 | 491 |
478 const double progress = 1.0 - pow(1.0 - transition.progress, 4); | 492 const double progress = 1.0 - pow(1.0 - transition.progress, 4); |
479 const int shift = kMaxOverScrollShift * progress * dir; | 493 const int shift = kMaxOverScrollShift * progress * dir; |
480 | 494 |
481 gfx::Rect shifted(view_bounds_); | 495 gfx::Rect shifted(view_bounds_); |
482 shifted.set_x(shifted.x() + shift); | 496 shifted.set_x(shifted.x() + shift); |
483 widget->SetBounds(shifted); | 497 widget->SetBounds(shifted); |
484 should_snap_back_ = true; | 498 should_snap_back_ = true; |
485 } else if (should_snap_back_) { | 499 } else if (should_snap_back_) { |
486 should_snap_back_ = false; | 500 should_snap_back_ = false; |
487 ui::ScopedLayerAnimationSettings animation(widget_animator); | 501 ui::ScopedLayerAnimationSettings animation(widget_animator); |
488 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 502 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
489 app_list::kOverscrollPageTransitionDurationMs)); | 503 app_list::kOverscrollPageTransitionDurationMs)); |
490 widget->SetBounds(view_bounds_); | 504 widget->SetBounds(view_bounds_); |
491 } | 505 } |
492 } | 506 } |
493 | 507 |
494 } // namespace ash | 508 } // namespace ash |
OLD | NEW |