Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 37 const int kAnimationOffset = 8; | 37 const int kAnimationOffset = 8; |
| 38 | 38 |
| 39 // The maximum shift in pixels when over-scroll happens. | 39 // The maximum shift in pixels when over-scroll happens. |
| 40 const int kMaxOverScrollShift = 48; | 40 const int kMaxOverScrollShift = 48; |
| 41 | 41 |
| 42 // The minimal anchor position offset to make sure that the bubble is still on | 42 // The minimal anchor position offset to make sure that the bubble is still on |
| 43 // the screen with 8 pixels spacing on the left / right. This constant is a | 43 // the screen with 8 pixels spacing on the left / right. This constant is a |
| 44 // result of minimal bubble arrow sizes and offsets. | 44 // result of minimal bubble arrow sizes and offsets. |
| 45 const int kMinimalAnchorPositionOffset = 57; | 45 const int kMinimalAnchorPositionOffset = 57; |
| 46 | 46 |
| 47 // The minimal margin (in pixels) around the app list when in centered mode. | |
| 48 const int kMinimalCenteredAppListMargin = 10; | |
| 49 | |
| 47 ui::Layer* GetLayer(views::Widget* widget) { | 50 ui::Layer* GetLayer(views::Widget* widget) { |
| 48 return widget->GetNativeView()->layer(); | 51 return widget->GetNativeView()->layer(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 // Gets arrow location based on shelf alignment. | 54 // Gets arrow location based on shelf alignment. |
| 52 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { | 55 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { |
| 53 DCHECK(Shell::HasInstance()); | 56 DCHECK(Shell::HasInstance()); |
| 54 return ShelfLayoutManager::ForShelf(window)-> | 57 return ShelfLayoutManager::ForShelf(window)-> |
| 55 SelectValueForShelfAlignment( | 58 SelectValueForShelfAlignment( |
| 56 views::BubbleBorder::BOTTOM_CENTER, | 59 views::BubbleBorder::BOTTOM_CENTER, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 case SHELF_ALIGNMENT_RIGHT: | 111 case SHELF_ALIGNMENT_RIGHT: |
| 109 return gfx::Vector2d( | 112 return gfx::Vector2d( |
| 110 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | 113 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); |
| 111 default: | 114 default: |
| 112 NOTREACHED(); | 115 NOTREACHED(); |
| 113 return gfx::Vector2d(); | 116 return gfx::Vector2d(); |
| 114 } | 117 } |
| 115 } | 118 } |
| 116 | 119 |
| 117 // Gets the point at the center of the display that a particular view is on. | 120 // Gets the point at the center of the display that a particular view is on. |
| 118 // This calculation excludes the virtual keyboard area. | 121 // This calculation excludes the virtual keyboard area. If the height of the |
| 119 gfx::Point GetCenterOfDisplayForView(const views::View* view) { | 122 // display area is less than |minimum_height|, its bottom will be extended to |
| 123 // that height (so that the app list never starts above the top of the screen). | |
| 124 gfx::Point GetCenterOfDisplayForView(const views::View* view, | |
| 125 int minimum_height) { | |
| 120 gfx::Rect bounds = Shell::GetScreen()->GetDisplayNearestWindow( | 126 gfx::Rect bounds = Shell::GetScreen()->GetDisplayNearestWindow( |
| 121 view->GetWidget()->GetNativeView()).bounds(); | 127 view->GetWidget()->GetNativeView()).bounds(); |
| 122 | 128 |
| 123 // If the virtual keyboard is active, subtract it from the display bounds, so | 129 // If the virtual keyboard is active, subtract it from the display bounds, so |
| 124 // that the app list is centered in the non-keyboard area of the display. | 130 // that the app list is centered in the non-keyboard area of the display. |
| 125 // (Note that work_area excludes the keyboard, but it doesn't get updated | 131 // (Note that work_area excludes the keyboard, but it doesn't get updated |
| 126 // until after this function is called.) | 132 // until after this function is called.) |
| 127 keyboard::KeyboardController* keyboard_controller = | 133 keyboard::KeyboardController* keyboard_controller = |
| 128 keyboard::KeyboardController::GetInstance(); | 134 keyboard::KeyboardController::GetInstance(); |
| 129 if (keyboard_controller && keyboard_controller->keyboard_visible()) | 135 if (keyboard_controller && keyboard_controller->keyboard_visible()) |
| 130 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); | 136 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); |
| 131 | 137 |
| 138 // Apply the |minimum_height|. | |
| 139 if (bounds.height() < minimum_height) | |
| 140 bounds.set_height(minimum_height); | |
| 141 | |
| 132 return bounds.CenterPoint(); | 142 return bounds.CenterPoint(); |
| 133 } | 143 } |
| 134 | 144 |
| 145 // Gets the minimum height of the rectangle to center the app list in. | |
| 146 int GetMinimumBoundsHeightForAppList(const app_list::AppListView* app_list) { | |
| 147 return app_list->bounds().height() + 2 * kMinimalCenteredAppListMargin; | |
| 148 } | |
| 149 | |
| 135 } // namespace | 150 } // namespace |
| 136 | 151 |
| 137 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
| 138 // AppListController, public: | 153 // AppListController, public: |
| 139 | 154 |
| 140 AppListController::AppListController() | 155 AppListController::AppListController() |
| 141 : pagination_model_(new app_list::PaginationModel), | 156 : pagination_model_(new app_list::PaginationModel), |
| 142 is_visible_(false), | 157 is_visible_(false), |
| 143 is_centered_(false), | 158 is_centered_(false), |
| 144 view_(NULL), | 159 view_(NULL), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 // will be released with AppListView on close. | 197 // will be released with AppListView on close. |
| 183 app_list::AppListView* view = new app_list::AppListView( | 198 app_list::AppListView* view = new app_list::AppListView( |
| 184 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); | 199 Shell::GetInstance()->delegate()->CreateAppListViewDelegate()); |
| 185 aura::Window* root_window = window->GetRootWindow(); | 200 aura::Window* root_window = window->GetRootWindow(); |
| 186 aura::Window* container = GetRootWindowController(root_window)-> | 201 aura::Window* container = GetRootWindowController(root_window)-> |
| 187 GetContainer(kShellWindowId_AppListContainer); | 202 GetContainer(kShellWindowId_AppListContainer); |
| 188 views::View* applist_button = | 203 views::View* applist_button = |
| 189 Shelf::ForWindow(container)->GetAppListButtonView(); | 204 Shelf::ForWindow(container)->GetAppListButtonView(); |
| 190 is_centered_ = view->ShouldCenterWindow(); | 205 is_centered_ = view->ShouldCenterWindow(); |
| 191 if (is_centered_) { | 206 if (is_centered_) { |
| 207 // 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 view->InitAsBubbleAtFixedLocation( | |
| 210 container, | |
| 211 pagination_model_.get(), | |
| 212 gfx::Point(), | |
| 213 views::BubbleBorder::FLOAT, | |
| 214 true /* border_accepts_events */); | |
| 192 // 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 |
| 193 // 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 |
| 194 // with the currently focused window). | 217 // with the currently focused window). |
| 195 view->InitAsBubbleAtFixedLocation( | 218 view->SetAnchorPoint(GetCenterOfDisplayForView( |
| 196 container, | 219 applist_button, GetMinimumBoundsHeightForAppList(view))); |
|
varkha
2014/05/13 03:25:31
Would it be clearer if s/applist_button/view?
Matt Giuca
2014/05/13 04:02:12
Yes, but it *has* to be the button, or we regress
varkha
2014/05/13 04:40:11
I see. I guess UpdateBounds never moves to another
| |
| 197 pagination_model_.get(), | |
| 198 GetCenterOfDisplayForView(applist_button), | |
| 199 views::BubbleBorder::FLOAT, | |
| 200 true /* border_accepts_events */); | |
| 201 } else { | 220 } else { |
| 202 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); | 221 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); |
| 203 // We need the location of the button within the local screen. | 222 // We need the location of the button within the local screen. |
| 204 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( | 223 applist_button_bounds = ScreenUtil::ConvertRectFromScreen( |
| 205 root_window, | 224 root_window, |
| 206 applist_button_bounds); | 225 applist_button_bounds); |
| 207 view->InitAsBubbleAttachedToAnchor( | 226 view->InitAsBubbleAttachedToAnchor( |
| 208 container, | 227 container, |
| 209 pagination_model_.get(), | 228 pagination_model_.get(), |
| 210 Shelf::ForWindow(container)->GetAppListButtonView(), | 229 Shelf::ForWindow(container)->GetAppListButtonView(), |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 SetVisible(false, window); | 352 SetVisible(false, window); |
| 334 } | 353 } |
| 335 | 354 |
| 336 void AppListController::UpdateBounds() { | 355 void AppListController::UpdateBounds() { |
| 337 if (!view_ || !is_visible_) | 356 if (!view_ || !is_visible_) |
| 338 return; | 357 return; |
| 339 | 358 |
| 340 view_->UpdateBounds(); | 359 view_->UpdateBounds(); |
| 341 | 360 |
| 342 if (is_centered_) | 361 if (is_centered_) |
| 343 view_->SetAnchorPoint(GetCenterOfDisplayForView(view_)); | 362 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
| 363 view_, GetMinimumBoundsHeightForAppList(view_))); | |
| 344 } | 364 } |
| 345 | 365 |
| 346 //////////////////////////////////////////////////////////////////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// |
| 347 // AppListController, aura::EventFilter implementation: | 367 // AppListController, aura::EventFilter implementation: |
| 348 | 368 |
| 349 void AppListController::OnMouseEvent(ui::MouseEvent* event) { | 369 void AppListController::OnMouseEvent(ui::MouseEvent* event) { |
| 350 if (event->type() == ui::ET_MOUSE_PRESSED) | 370 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 351 ProcessLocatedEvent(event); | 371 ProcessLocatedEvent(event); |
| 352 } | 372 } |
| 353 | 373 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } else if (should_snap_back_) { | 485 } else if (should_snap_back_) { |
| 466 should_snap_back_ = false; | 486 should_snap_back_ = false; |
| 467 ui::ScopedLayerAnimationSettings animation(widget_animator); | 487 ui::ScopedLayerAnimationSettings animation(widget_animator); |
| 468 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 488 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 469 app_list::kOverscrollPageTransitionDurationMs)); | 489 app_list::kOverscrollPageTransitionDurationMs)); |
| 470 widget->SetBounds(view_bounds_); | 490 widget->SetBounds(view_bounds_); |
| 471 } | 491 } |
| 472 } | 492 } |
| 473 | 493 |
| 474 } // namespace ash | 494 } // namespace ash |
| OLD | NEW |