| 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_view.h" | 19 #include "ui/app_list/views/app_list_view.h" |
| 20 #include "ui/aura/client/focus_client.h" | 20 #include "ui/aura/client/focus_client.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_event_dispatcher.h" | 22 #include "ui/aura/window_event_dispatcher.h" |
| 23 #include "ui/compositor/layer.h" | 23 #include "ui/compositor/layer.h" |
| 24 #include "ui/compositor/scoped_layer_animation_settings.h" | 24 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 25 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 26 #include "ui/gfx/transform_util.h" | 26 #include "ui/gfx/transform_util.h" |
| 27 #include "ui/keyboard/keyboard_controller.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 | 29 |
| 29 namespace ash { | 30 namespace ash { |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Duration for show/hide animation in milliseconds. | 33 // Duration for show/hide animation in milliseconds. |
| 33 const int kAnimationDurationMs = 200; | 34 const int kAnimationDurationMs = 200; |
| 34 | 35 |
| 35 // Offset in pixels to animation away/towards the shelf. | 36 // Offset in pixels to animation away/towards the shelf. |
| 36 const int kAnimationOffset = 8; | 37 const int kAnimationOffset = 8; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | 107 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); |
| 107 case SHELF_ALIGNMENT_RIGHT: | 108 case SHELF_ALIGNMENT_RIGHT: |
| 108 return gfx::Vector2d( | 109 return gfx::Vector2d( |
| 109 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | 110 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); |
| 110 default: | 111 default: |
| 111 NOTREACHED(); | 112 NOTREACHED(); |
| 112 return gfx::Vector2d(); | 113 return gfx::Vector2d(); |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 | 116 |
| 116 // Gets the point at the center of the screen. | 117 // Gets the point at the center of the screen, excluding the virtual keyboard. |
| 117 gfx::Point GetScreenCenter() { | 118 gfx::Point GetScreenCenter() { |
| 118 return Shell::GetScreen()->GetPrimaryDisplay().bounds().CenterPoint(); | 119 gfx::Rect bounds = Shell::GetScreen()->GetPrimaryDisplay().bounds(); |
| 120 |
| 121 // If the virtual keyboard is active, subtract it from the display bounds, so |
| 122 // that the app list is centered in the non-keyboard area of the display. |
| 123 // (Note that work_area excludes the keyboard, but it doesn't get updated |
| 124 // until after this function is called.) |
| 125 keyboard::KeyboardController* keyboard_controller = |
| 126 keyboard::KeyboardController::GetInstance(); |
| 127 if (keyboard_controller && keyboard_controller->keyboard_visible()) |
| 128 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); |
| 129 |
| 130 return bounds.CenterPoint(); |
| 119 } | 131 } |
| 120 | 132 |
| 121 } // namespace | 133 } // namespace |
| 122 | 134 |
| 123 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
| 124 // AppListController, public: | 136 // AppListController, public: |
| 125 | 137 |
| 126 AppListController::AppListController() | 138 AppListController::AppListController() |
| 127 : pagination_model_(new app_list::PaginationModel), | 139 : pagination_model_(new app_list::PaginationModel), |
| 128 is_visible_(false), | 140 is_visible_(false), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 237 view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 226 } | 238 } |
| 227 | 239 |
| 228 void AppListController::SetView(app_list::AppListView* view) { | 240 void AppListController::SetView(app_list::AppListView* view) { |
| 229 DCHECK(view_ == NULL); | 241 DCHECK(view_ == NULL); |
| 230 DCHECK(is_visible_); | 242 DCHECK(is_visible_); |
| 231 | 243 |
| 232 view_ = view; | 244 view_ = view; |
| 233 views::Widget* widget = view_->GetWidget(); | 245 views::Widget* widget = view_->GetWidget(); |
| 234 widget->AddObserver(this); | 246 widget->AddObserver(this); |
| 247 keyboard::KeyboardController* keyboard_controller = |
| 248 keyboard::KeyboardController::GetInstance(); |
| 249 if (keyboard_controller) |
| 250 keyboard_controller->AddObserver(this); |
| 235 Shell::GetInstance()->AddPreTargetHandler(this); | 251 Shell::GetInstance()->AddPreTargetHandler(this); |
| 236 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); | 252 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); |
| 237 widget->GetNativeView()->GetRootWindow()->AddObserver(this); | 253 widget->GetNativeView()->GetRootWindow()->AddObserver(this); |
| 238 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); | 254 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); |
| 239 | 255 |
| 240 view_->ShowWhenReady(); | 256 view_->ShowWhenReady(); |
| 241 } | 257 } |
| 242 | 258 |
| 243 void AppListController::ResetView() { | 259 void AppListController::ResetView() { |
| 244 if (!view_) | 260 if (!view_) |
| 245 return; | 261 return; |
| 246 | 262 |
| 247 views::Widget* widget = view_->GetWidget(); | 263 views::Widget* widget = view_->GetWidget(); |
| 248 widget->RemoveObserver(this); | 264 widget->RemoveObserver(this); |
| 249 GetLayer(widget)->GetAnimator()->RemoveObserver(this); | 265 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
| 266 keyboard::KeyboardController* keyboard_controller = |
| 267 keyboard::KeyboardController::GetInstance(); |
| 268 if (keyboard_controller) |
| 269 keyboard_controller->RemoveObserver(this); |
| 250 Shell::GetInstance()->RemovePreTargetHandler(this); | 270 Shell::GetInstance()->RemovePreTargetHandler(this); |
| 251 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); | 271 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); |
| 252 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); | 272 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); |
| 253 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); | 273 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); |
| 254 view_ = NULL; | 274 view_ = NULL; |
| 255 } | 275 } |
| 256 | 276 |
| 257 void AppListController::ScheduleAnimation() { | 277 void AppListController::ScheduleAnimation() { |
| 258 // Stop observing previous animation. | 278 // Stop observing previous animation. |
| 259 StopObservingImplicitAnimations(); | 279 StopObservingImplicitAnimations(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // AppListController, views::WidgetObserver implementation: | 389 // AppListController, views::WidgetObserver implementation: |
| 370 | 390 |
| 371 void AppListController::OnWidgetDestroying(views::Widget* widget) { | 391 void AppListController::OnWidgetDestroying(views::Widget* widget) { |
| 372 DCHECK(view_->GetWidget() == widget); | 392 DCHECK(view_->GetWidget() == widget); |
| 373 if (is_visible_) | 393 if (is_visible_) |
| 374 SetVisible(false, widget->GetNativeView()); | 394 SetVisible(false, widget->GetNativeView()); |
| 375 ResetView(); | 395 ResetView(); |
| 376 } | 396 } |
| 377 | 397 |
| 378 //////////////////////////////////////////////////////////////////////////////// | 398 //////////////////////////////////////////////////////////////////////////////// |
| 399 // AppListController, keyboard::KeyboardControllerObserver implementation: |
| 400 |
| 401 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 402 UpdateBounds(); |
| 403 } |
| 404 |
| 405 //////////////////////////////////////////////////////////////////////////////// |
| 379 // AppListController, ShellObserver implementation: | 406 // AppListController, ShellObserver implementation: |
| 380 void AppListController::OnShelfAlignmentChanged(aura::Window* root_window) { | 407 void AppListController::OnShelfAlignmentChanged(aura::Window* root_window) { |
| 381 if (view_) | 408 if (view_) |
| 382 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); | 409 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); |
| 383 } | 410 } |
| 384 | 411 |
| 385 //////////////////////////////////////////////////////////////////////////////// | 412 //////////////////////////////////////////////////////////////////////////////// |
| 386 // AppListController, ShelfIconObserver implementation: | 413 // AppListController, ShelfIconObserver implementation: |
| 387 | 414 |
| 388 void AppListController::OnShelfIconPositionsChanged() { | 415 void AppListController::OnShelfIconPositionsChanged() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 } else if (should_snap_back_) { | 460 } else if (should_snap_back_) { |
| 434 should_snap_back_ = false; | 461 should_snap_back_ = false; |
| 435 ui::ScopedLayerAnimationSettings animation(widget_animator); | 462 ui::ScopedLayerAnimationSettings animation(widget_animator); |
| 436 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 463 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 437 app_list::kOverscrollPageTransitionDurationMs)); | 464 app_list::kOverscrollPageTransitionDurationMs)); |
| 438 widget->SetBounds(view_bounds_); | 465 widget->SetBounds(view_bounds_); |
| 439 } | 466 } |
| 440 } | 467 } |
| 441 | 468 |
| 442 } // namespace ash | 469 } // namespace ash |
| OLD | NEW |