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