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::GetInstance()->AddObserver(this); | |
kevers
2014/05/01 11:55:20
GetInstance may return NULL.
Matt Giuca
2014/05/02 00:36:20
Interesting, Shell::GetInstance() doesn't have a n
| |
235 Shell::GetInstance()->AddPreTargetHandler(this); | 248 Shell::GetInstance()->AddPreTargetHandler(this); |
236 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); | 249 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); |
237 widget->GetNativeView()->GetRootWindow()->AddObserver(this); | 250 widget->GetNativeView()->GetRootWindow()->AddObserver(this); |
238 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); | 251 aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this); |
239 | 252 |
240 view_->ShowWhenReady(); | 253 view_->ShowWhenReady(); |
241 } | 254 } |
242 | 255 |
243 void AppListController::ResetView() { | 256 void AppListController::ResetView() { |
244 if (!view_) | 257 if (!view_) |
245 return; | 258 return; |
246 | 259 |
247 views::Widget* widget = view_->GetWidget(); | 260 views::Widget* widget = view_->GetWidget(); |
248 widget->RemoveObserver(this); | 261 widget->RemoveObserver(this); |
249 GetLayer(widget)->GetAnimator()->RemoveObserver(this); | 262 GetLayer(widget)->GetAnimator()->RemoveObserver(this); |
263 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
kevers
2014/05/01 11:55:20
GetInstance may return NULL.
Matt Giuca
2014/05/02 00:36:20
Done.
| |
250 Shell::GetInstance()->RemovePreTargetHandler(this); | 264 Shell::GetInstance()->RemovePreTargetHandler(this); |
251 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); | 265 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); |
252 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); | 266 widget->GetNativeView()->GetRootWindow()->RemoveObserver(this); |
253 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); | 267 aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this); |
254 view_ = NULL; | 268 view_ = NULL; |
255 } | 269 } |
256 | 270 |
257 void AppListController::ScheduleAnimation() { | 271 void AppListController::ScheduleAnimation() { |
258 // Stop observing previous animation. | 272 // Stop observing previous animation. |
259 StopObservingImplicitAnimations(); | 273 StopObservingImplicitAnimations(); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 // AppListController, views::WidgetObserver implementation: | 383 // AppListController, views::WidgetObserver implementation: |
370 | 384 |
371 void AppListController::OnWidgetDestroying(views::Widget* widget) { | 385 void AppListController::OnWidgetDestroying(views::Widget* widget) { |
372 DCHECK(view_->GetWidget() == widget); | 386 DCHECK(view_->GetWidget() == widget); |
373 if (is_visible_) | 387 if (is_visible_) |
374 SetVisible(false, widget->GetNativeView()); | 388 SetVisible(false, widget->GetNativeView()); |
375 ResetView(); | 389 ResetView(); |
376 } | 390 } |
377 | 391 |
378 //////////////////////////////////////////////////////////////////////////////// | 392 //////////////////////////////////////////////////////////////////////////////// |
393 // AppListController, keyboard::KeyboardControllerObserver implementation: | |
394 | |
395 void AppListController::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | |
396 UpdateBounds(); | |
397 } | |
398 | |
399 //////////////////////////////////////////////////////////////////////////////// | |
379 // AppListController, ShellObserver implementation: | 400 // AppListController, ShellObserver implementation: |
380 void AppListController::OnShelfAlignmentChanged(aura::Window* root_window) { | 401 void AppListController::OnShelfAlignmentChanged(aura::Window* root_window) { |
381 if (view_) | 402 if (view_) |
382 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); | 403 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); |
383 } | 404 } |
384 | 405 |
385 //////////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////////// |
386 // AppListController, ShelfIconObserver implementation: | 407 // AppListController, ShelfIconObserver implementation: |
387 | 408 |
388 void AppListController::OnShelfIconPositionsChanged() { | 409 void AppListController::OnShelfIconPositionsChanged() { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 } else if (should_snap_back_) { | 454 } else if (should_snap_back_) { |
434 should_snap_back_ = false; | 455 should_snap_back_ = false; |
435 ui::ScopedLayerAnimationSettings animation(widget_animator); | 456 ui::ScopedLayerAnimationSettings animation(widget_animator); |
436 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 457 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
437 app_list::kOverscrollPageTransitionDurationMs)); | 458 app_list::kOverscrollPageTransitionDurationMs)); |
438 widget->SetBounds(view_bounds_); | 459 widget->SetBounds(view_bounds_); |
439 } | 460 } |
440 } | 461 } |
441 | 462 |
442 } // namespace ash | 463 } // namespace ash |
OLD | NEW |