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/app_list/app_list_presenter_delegate.h" | 5 #include "ash/app_list/app_list_presenter_delegate.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/shelf/app_list_button.h" | 9 #include "ash/common/shelf/app_list_button.h" |
| 10 #include "ash/common/shelf/shelf_layout_manager.h" | 10 #include "ash/common/shelf/shelf_layout_manager.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" | 28 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" |
| 29 #include "ui/app_list/views/app_list_view.h" | 29 #include "ui/app_list/views/app_list_view.h" |
| 30 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
| 31 #include "ui/events/event.h" | 31 #include "ui/events/event.h" |
| 32 #include "ui/keyboard/keyboard_controller.h" | 32 #include "ui/keyboard/keyboard_controller.h" |
| 33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // The minimal anchor position offset to make sure that the bubble is still on | |
| 39 // the screen with 8 pixels spacing on the left / right. This constant is a | |
| 40 // result of minimal bubble arrow sizes and offsets. | |
| 41 const int kMinimalAnchorPositionOffset = 57; | |
| 42 | |
| 43 // Gets arrow location based on shelf alignment. | |
| 44 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { | |
| 45 DCHECK(Shell::HasInstance()); | |
| 46 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(window)); | |
| 47 switch (shelf->alignment()) { | |
| 48 case SHELF_ALIGNMENT_BOTTOM: | |
| 49 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | |
| 50 return views::BubbleBorder::BOTTOM_CENTER; | |
| 51 case SHELF_ALIGNMENT_LEFT: | |
| 52 return views::BubbleBorder::LEFT_CENTER; | |
| 53 case SHELF_ALIGNMENT_RIGHT: | |
| 54 return views::BubbleBorder::RIGHT_CENTER; | |
| 55 } | |
| 56 NOTREACHED(); | |
| 57 return views::BubbleBorder::BOTTOM_CENTER; | |
| 58 } | |
| 59 | |
| 60 // Using |button_bounds|, determine the anchor offset so that the bubble gets | |
| 61 // shown above the shelf (used for the alternate shelf theme). | |
| 62 gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds, | |
| 63 views::Widget* widget) { | |
| 64 DCHECK(Shell::HasInstance()); | |
| 65 ShelfAlignment shelf_alignment = | |
| 66 WmShelf::ForWindow(WmLookup::Get()->GetWindowForWidget(widget)) | |
| 67 ->alignment(); | |
| 68 gfx::Point anchor(button_bounds.CenterPoint()); | |
| 69 switch (shelf_alignment) { | |
| 70 case SHELF_ALIGNMENT_BOTTOM: | |
| 71 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | |
| 72 if (base::i18n::IsRTL()) { | |
| 73 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); | |
| 74 return gfx::Vector2d( | |
| 75 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), | |
| 76 0), | |
| 77 0); | |
| 78 } | |
| 79 return gfx::Vector2d( | |
| 80 std::max(kMinimalAnchorPositionOffset - anchor.x(), 0), 0); | |
| 81 case SHELF_ALIGNMENT_LEFT: | |
| 82 return gfx::Vector2d( | |
| 83 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | |
| 84 case SHELF_ALIGNMENT_RIGHT: | |
| 85 return gfx::Vector2d( | |
| 86 0, std::max(kMinimalAnchorPositionOffset - anchor.y(), 0)); | |
| 87 } | |
| 88 NOTREACHED(); | |
| 89 return gfx::Vector2d(); | |
| 90 } | |
| 91 | |
| 92 // Gets the point at the center of the display that a particular view is on. | 38 // Gets the point at the center of the display that a particular view is on. |
| 93 // This calculation excludes the virtual keyboard area. If the height of the | 39 // This calculation excludes the virtual keyboard area. If the height of the |
| 94 // display area is less than |minimum_height|, its bottom will be extended to | 40 // display area is less than |minimum_height|, its bottom will be extended to |
| 95 // that height (so that the app list never starts above the top of the screen). | 41 // that height (so that the app list never starts above the top of the screen). |
| 96 gfx::Point GetCenterOfDisplayForView(views::View* view, int minimum_height) { | 42 gfx::Point GetCenterOfDisplayForView(views::View* view, int minimum_height) { |
| 97 WmWindow* window = WmLookup::Get()->GetWindowForWidget(view->GetWidget()); | 43 WmWindow* window = WmLookup::Get()->GetWindowForWidget(view->GetWidget()); |
| 98 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window); | 44 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window); |
| 99 bounds = window->GetRootWindow()->ConvertRectToScreen(bounds); | 45 bounds = window->GetRootWindow()->ConvertRectToScreen(bounds); |
| 100 | 46 |
| 101 // If the virtual keyboard is active, subtract it from the display bounds, so | 47 // If the virtual keyboard is active, subtract it from the display bounds, so |
| 102 // that the app list is centered in the non-keyboard area of the display. | 48 // that the app list is centered in the non-keyboard area of the display. |
| 103 // (Note that work_area excludes the keyboard, but it doesn't get updated | 49 // (Note that work_area excludes the keyboard, but it doesn't get updated |
| 104 // until after this function is called.) | 50 // until after this function is called.) |
| 105 keyboard::KeyboardController* keyboard_controller = | 51 keyboard::KeyboardController* keyboard_controller = |
| 106 keyboard::KeyboardController::GetInstance(); | 52 keyboard::KeyboardController::GetInstance(); |
| 107 if (keyboard_controller && keyboard_controller->keyboard_visible()) | 53 if (keyboard_controller && keyboard_controller->keyboard_visible()) |
| 108 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); | 54 bounds.Subtract(keyboard_controller->current_keyboard_bounds()); |
| 109 | 55 |
| 110 // Apply the |minimum_height|. | 56 // Apply the |minimum_height|. |
| 111 if (bounds.height() < minimum_height) | 57 if (bounds.height() < minimum_height) |
| 112 bounds.set_height(minimum_height); | 58 bounds.set_height(minimum_height); |
| 113 | 59 |
| 114 return bounds.CenterPoint(); | 60 return bounds.CenterPoint(); |
| 115 } | 61 } |
| 116 | 62 |
| 117 bool IsFullscreenAppListEnabled() { | 63 bool IsFullscreenAppListEnabled() { |
| 118 #if defined(OS_CHROMEOS) | 64 #if defined(OS_CHROMEOS) |
| 119 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 65 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 120 switches::kAshEnableFullscreenAppList) && | 66 switches::kAshEnableFullscreenAppList); |
| 121 app_list::switches::IsExperimentalAppListEnabled(); | |
| 122 #else | 67 #else |
| 123 return false; | 68 return false; |
| 124 #endif | 69 #endif |
| 125 } | 70 } |
| 126 | 71 |
| 127 } // namespace | 72 } // namespace |
| 128 | 73 |
| 129 //////////////////////////////////////////////////////////////////////////////// | 74 //////////////////////////////////////////////////////////////////////////////// |
| 130 // AppListPresenterDelegate, public: | 75 // AppListPresenterDelegate, public: |
| 131 | 76 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 161 ->GetShelfLayoutManager() | 106 ->GetShelfLayoutManager() |
| 162 ->UpdateAutoHideState(); | 107 ->UpdateAutoHideState(); |
| 163 view_ = view; | 108 view_ = view; |
| 164 aura::Window* root_window = Shell::GetInstance() | 109 aura::Window* root_window = Shell::GetInstance() |
| 165 ->window_tree_host_manager() | 110 ->window_tree_host_manager() |
| 166 ->GetRootWindowForDisplayId(display_id); | 111 ->GetRootWindowForDisplayId(display_id); |
| 167 aura::Window* container = GetRootWindowController(root_window) | 112 aura::Window* container = GetRootWindowController(root_window) |
| 168 ->GetContainer(kShellWindowId_AppListContainer); | 113 ->GetContainer(kShellWindowId_AppListContainer); |
| 169 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(container)); | 114 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(container)); |
| 170 AppListButton* applist_button = shelf->shelf_widget()->GetAppListButton(); | 115 AppListButton* applist_button = shelf->shelf_widget()->GetAppListButton(); |
| 171 is_centered_ = view->ShouldCenterWindow(); | |
| 172 bool is_fullscreen = IsFullscreenAppListEnabled() && | 116 bool is_fullscreen = IsFullscreenAppListEnabled() && |
| 173 WmShell::Get() | 117 WmShell::Get() |
| 174 ->maximize_mode_controller() | 118 ->maximize_mode_controller() |
| 175 ->IsMaximizeModeWindowManagerEnabled(); | 119 ->IsMaximizeModeWindowManagerEnabled(); |
| 176 if (is_fullscreen) { | 120 if (is_fullscreen) { |
| 177 view->InitAsFramelessWindow( | 121 view->InitAsFramelessWindow( |
| 178 container, current_apps_page, | 122 container, current_apps_page, |
| 179 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); | 123 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); |
| 180 } else if (is_centered_) { | 124 } else { |
| 181 // Note: We can't center the app list until we have its dimensions, so we | 125 // Note: We can't center the app list until we have its dimensions, so we |
| 182 // init at (0, 0) and then reset its anchor point. | 126 // init at (0, 0) and then reset its anchor point. |
| 183 view->InitAsBubbleAtFixedLocation(container, current_apps_page, | 127 view->InitAsBubbleAtFixedLocation(container, current_apps_page, |
| 184 gfx::Point(), views::BubbleBorder::FLOAT, | 128 gfx::Point(), views::BubbleBorder::FLOAT, |
| 185 true /* border_accepts_events */); | 129 true /* border_accepts_events */); |
| 186 // The experimental app list is centered over the display of the app list | 130 // The experimental app list is centered over the display of the app list |
|
calamity
2016/09/21 07:54:10
nit: Gotcha.
Matt Giuca
2016/09/22 06:49:44
Ah, I didn't grep ash.
| |
| 187 // button that was pressed (if triggered via keyboard, this is the display | 131 // button that was pressed (if triggered via keyboard, this is the display |
| 188 // with the currently focused window). | 132 // with the currently focused window). |
| 189 view->SetAnchorPoint(GetCenterOfDisplayForView( | 133 view->SetAnchorPoint(GetCenterOfDisplayForView( |
| 190 applist_button, GetMinimumBoundsHeightForAppList(view))); | 134 applist_button, GetMinimumBoundsHeightForAppList(view))); |
| 191 } else { | |
| 192 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); | |
| 193 // We need the location of the button within the local screen. | |
| 194 applist_button_bounds = | |
| 195 ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds); | |
| 196 view->InitAsBubbleAttachedToAnchor( | |
| 197 container, current_apps_page, applist_button, | |
| 198 GetAnchorPositionOffsetToShelf(applist_button_bounds, | |
| 199 applist_button->GetWidget()), | |
| 200 GetBubbleArrow(container), true /* border_accepts_events */); | |
| 201 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | |
| 202 } | 135 } |
| 203 | 136 |
| 204 keyboard::KeyboardController* keyboard_controller = | 137 keyboard::KeyboardController* keyboard_controller = |
| 205 keyboard::KeyboardController::GetInstance(); | 138 keyboard::KeyboardController::GetInstance(); |
| 206 if (keyboard_controller) | 139 if (keyboard_controller) |
| 207 keyboard_controller->AddObserver(this); | 140 keyboard_controller->AddObserver(this); |
| 208 Shell::GetInstance()->AddPreTargetHandler(this); | 141 Shell::GetInstance()->AddPreTargetHandler(this); |
| 209 WmWindow* window = WmShell::Get()->GetRootWindowForDisplayId(display_id); | 142 WmWindow* window = WmShell::Get()->GetRootWindowForDisplayId(display_id); |
| 210 window->GetRootWindowController()->GetShelf()->AddObserver(this); | 143 window->GetRootWindowController()->GetShelf()->AddObserver(this); |
| 211 | 144 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 239 | 172 |
| 240 // Update applist button status when app list visibility is changed. | 173 // Update applist button status when app list visibility is changed. |
| 241 shelf->shelf_widget()->GetAppListButton()->OnAppListDismissed(); | 174 shelf->shelf_widget()->GetAppListButton()->OnAppListDismissed(); |
| 242 } | 175 } |
| 243 | 176 |
| 244 void AppListPresenterDelegate::UpdateBounds() { | 177 void AppListPresenterDelegate::UpdateBounds() { |
| 245 if (!view_ || !is_visible_) | 178 if (!view_ || !is_visible_) |
| 246 return; | 179 return; |
| 247 | 180 |
| 248 view_->UpdateBounds(); | 181 view_->UpdateBounds(); |
| 249 | 182 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
| 250 if (is_centered_) { | 183 view_, GetMinimumBoundsHeightForAppList(view_))); |
| 251 view_->SetAnchorPoint(GetCenterOfDisplayForView( | |
| 252 view_, GetMinimumBoundsHeightForAppList(view_))); | |
| 253 } | |
| 254 } | 184 } |
| 255 | 185 |
| 256 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( | 186 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( |
| 257 aura::Window* root_window) { | 187 aura::Window* root_window) { |
| 258 DCHECK(Shell::HasInstance()); | 188 DCHECK(Shell::HasInstance()); |
| 259 | 189 |
| 260 // App list needs to know the new shelf layout in order to calculate its | 190 // App list needs to know the new shelf layout in order to calculate its |
| 261 // UI layout when AppListView visibility changes. | 191 // UI layout when AppListView visibility changes. |
| 262 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(root_window)); | 192 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(root_window)); |
| 263 shelf->UpdateAutoHideState(); | 193 shelf->UpdateAutoHideState(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 256 |
| 327 void AppListPresenterDelegate::OnKeyboardBoundsChanging( | 257 void AppListPresenterDelegate::OnKeyboardBoundsChanging( |
| 328 const gfx::Rect& new_bounds) { | 258 const gfx::Rect& new_bounds) { |
| 329 UpdateBounds(); | 259 UpdateBounds(); |
| 330 } | 260 } |
| 331 | 261 |
| 332 void AppListPresenterDelegate::OnKeyboardClosed() {} | 262 void AppListPresenterDelegate::OnKeyboardClosed() {} |
| 333 | 263 |
| 334 //////////////////////////////////////////////////////////////////////////////// | 264 //////////////////////////////////////////////////////////////////////////////// |
| 335 // AppListPresenterDelegate, ShellObserver implementation: | 265 // AppListPresenterDelegate, ShellObserver implementation: |
| 336 void AppListPresenterDelegate::OnShelfAlignmentChanged(WmWindow* root_window) { | |
| 337 if (view_) | |
| 338 view_->SetBubbleArrow(GetBubbleArrow(view_->GetWidget()->GetNativeView())); | |
| 339 } | |
| 340 | |
| 341 void AppListPresenterDelegate::OnOverviewModeStarting() { | 266 void AppListPresenterDelegate::OnOverviewModeStarting() { |
| 342 if (is_visible_) | 267 if (is_visible_) |
| 343 presenter_->Dismiss(); | 268 presenter_->Dismiss(); |
| 344 } | 269 } |
| 345 | 270 |
| 346 void AppListPresenterDelegate::OnMaximizeModeStarted() { | 271 void AppListPresenterDelegate::OnMaximizeModeStarted() { |
| 347 // The "fullscreen" app-list is initialized as in a different type of window, | 272 // The "fullscreen" app-list is initialized as in a different type of window, |
| 348 // therefore we can't switch between the fullscreen status and the normal | 273 // therefore we can't switch between the fullscreen status and the normal |
| 349 // app-list bubble. App-list should be dismissed for the transition between | 274 // app-list bubble. App-list should be dismissed for the transition between |
| 350 // maximize mode (touch-view mode) and non-maximize mode, otherwise the app | 275 // maximize mode (touch-view mode) and non-maximize mode, otherwise the app |
| 351 // list tries to behave as a bubble which leads to a crash. crbug.com/510062 | 276 // list tries to behave as a bubble which leads to a crash. crbug.com/510062 |
| 352 if (IsFullscreenAppListEnabled() && is_visible_) | 277 if (IsFullscreenAppListEnabled() && is_visible_) |
| 353 presenter_->Dismiss(); | 278 presenter_->Dismiss(); |
| 354 } | 279 } |
| 355 | 280 |
| 356 void AppListPresenterDelegate::OnMaximizeModeEnded() { | 281 void AppListPresenterDelegate::OnMaximizeModeEnded() { |
| 357 // See the comments of OnMaximizeModeStarted(). | 282 // See the comments of OnMaximizeModeStarted(). |
| 358 if (IsFullscreenAppListEnabled() && is_visible_) | 283 if (IsFullscreenAppListEnabled() && is_visible_) |
| 359 presenter_->Dismiss(); | 284 presenter_->Dismiss(); |
| 360 } | 285 } |
| 361 | 286 |
| 362 //////////////////////////////////////////////////////////////////////////////// | 287 //////////////////////////////////////////////////////////////////////////////// |
| 363 // AppListPresenterDelegate, WmShelfObserver implementation: | 288 // AppListPresenterDelegate, WmShelfObserver implementation: |
| 364 | 289 |
| 365 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { | 290 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { |
| 366 UpdateBounds(); | 291 UpdateBounds(); |
| 367 } | 292 } |
| 368 | 293 |
| 369 } // namespace ash | 294 } // namespace ash |
| OLD | NEW |