| 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.h" | |
| 11 #include "ash/common/shelf/shelf_layout_manager.h" | 10 #include "ash/common/shelf/shelf_layout_manager.h" |
| 12 #include "ash/common/shelf/shelf_types.h" | 11 #include "ash/common/shelf/shelf_types.h" |
| 13 #include "ash/common/shelf/wm_shelf.h" | 12 #include "ash/common/shelf/wm_shelf.h" |
| 14 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 14 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 16 #include "ash/common/wm/wm_screen_util.h" | 15 #include "ash/common/wm/wm_screen_util.h" |
| 17 #include "ash/common/wm_lookup.h" | 16 #include "ash/common/wm_lookup.h" |
| 18 #include "ash/common/wm_root_window_controller.h" | 17 #include "ash/common/wm_root_window_controller.h" |
| 19 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 20 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 namespace { | 36 namespace { |
| 38 | 37 |
| 39 // The minimal anchor position offset to make sure that the bubble is still on | 38 // The minimal anchor position offset to make sure that the bubble is still on |
| 40 // the screen with 8 pixels spacing on the left / right. This constant is a | 39 // the screen with 8 pixels spacing on the left / right. This constant is a |
| 41 // result of minimal bubble arrow sizes and offsets. | 40 // result of minimal bubble arrow sizes and offsets. |
| 42 const int kMinimalAnchorPositionOffset = 57; | 41 const int kMinimalAnchorPositionOffset = 57; |
| 43 | 42 |
| 44 // Gets arrow location based on shelf alignment. | 43 // Gets arrow location based on shelf alignment. |
| 45 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { | 44 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { |
| 46 DCHECK(Shell::HasInstance()); | 45 DCHECK(Shell::HasInstance()); |
| 47 WmShelf* shelf = Shelf::ForWindow(WmWindowAura::Get(window))->wm_shelf(); | 46 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(window)); |
| 48 switch (shelf->alignment()) { | 47 switch (shelf->alignment()) { |
| 49 case SHELF_ALIGNMENT_BOTTOM: | 48 case SHELF_ALIGNMENT_BOTTOM: |
| 50 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 49 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 51 return views::BubbleBorder::BOTTOM_CENTER; | 50 return views::BubbleBorder::BOTTOM_CENTER; |
| 52 case SHELF_ALIGNMENT_LEFT: | 51 case SHELF_ALIGNMENT_LEFT: |
| 53 return views::BubbleBorder::LEFT_CENTER; | 52 return views::BubbleBorder::LEFT_CENTER; |
| 54 case SHELF_ALIGNMENT_RIGHT: | 53 case SHELF_ALIGNMENT_RIGHT: |
| 55 return views::BubbleBorder::RIGHT_CENTER; | 54 return views::BubbleBorder::RIGHT_CENTER; |
| 56 } | 55 } |
| 57 NOTREACHED(); | 56 NOTREACHED(); |
| 58 return views::BubbleBorder::BOTTOM_CENTER; | 57 return views::BubbleBorder::BOTTOM_CENTER; |
| 59 } | 58 } |
| 60 | 59 |
| 61 // Using |button_bounds|, determine the anchor offset so that the bubble gets | 60 // Using |button_bounds|, determine the anchor offset so that the bubble gets |
| 62 // shown above the shelf (used for the alternate shelf theme). | 61 // shown above the shelf (used for the alternate shelf theme). |
| 63 gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds, | 62 gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds, |
| 64 views::Widget* widget) { | 63 views::Widget* widget) { |
| 65 DCHECK(Shell::HasInstance()); | 64 DCHECK(Shell::HasInstance()); |
| 66 ShelfAlignment shelf_alignment = | 65 ShelfAlignment shelf_alignment = |
| 67 Shelf::ForWindow(WmLookup::Get()->GetWindowForWidget(widget)) | 66 WmShelf::ForWindow(WmLookup::Get()->GetWindowForWidget(widget)) |
| 68 ->wm_shelf() | |
| 69 ->alignment(); | 67 ->alignment(); |
| 70 gfx::Point anchor(button_bounds.CenterPoint()); | 68 gfx::Point anchor(button_bounds.CenterPoint()); |
| 71 switch (shelf_alignment) { | 69 switch (shelf_alignment) { |
| 72 case SHELF_ALIGNMENT_BOTTOM: | 70 case SHELF_ALIGNMENT_BOTTOM: |
| 73 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 71 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 74 if (base::i18n::IsRTL()) { | 72 if (base::i18n::IsRTL()) { |
| 75 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); | 73 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); |
| 76 return gfx::Vector2d( | 74 return gfx::Vector2d( |
| 77 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), | 75 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), |
| 78 0), | 76 0), |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // UI layout when AppListView visibility changes. | 159 // UI layout when AppListView visibility changes. |
| 162 ash::Shell::GetPrimaryRootWindowController() | 160 ash::Shell::GetPrimaryRootWindowController() |
| 163 ->GetShelfLayoutManager() | 161 ->GetShelfLayoutManager() |
| 164 ->UpdateAutoHideState(); | 162 ->UpdateAutoHideState(); |
| 165 view_ = view; | 163 view_ = view; |
| 166 aura::Window* root_window = Shell::GetInstance() | 164 aura::Window* root_window = Shell::GetInstance() |
| 167 ->window_tree_host_manager() | 165 ->window_tree_host_manager() |
| 168 ->GetRootWindowForDisplayId(display_id); | 166 ->GetRootWindowForDisplayId(display_id); |
| 169 aura::Window* container = GetRootWindowController(root_window) | 167 aura::Window* container = GetRootWindowController(root_window) |
| 170 ->GetContainer(kShellWindowId_AppListContainer); | 168 ->GetContainer(kShellWindowId_AppListContainer); |
| 171 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(container)); | 169 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(container)); |
| 172 AppListButton* applist_button = shelf->GetAppListButton(); | 170 AppListButton* applist_button = shelf->shelf_widget()->GetAppListButton(); |
| 173 is_centered_ = view->ShouldCenterWindow(); | 171 is_centered_ = view->ShouldCenterWindow(); |
| 174 bool is_fullscreen = IsFullscreenAppListEnabled() && | 172 bool is_fullscreen = IsFullscreenAppListEnabled() && |
| 175 WmShell::Get() | 173 WmShell::Get() |
| 176 ->maximize_mode_controller() | 174 ->maximize_mode_controller() |
| 177 ->IsMaximizeModeWindowManagerEnabled(); | 175 ->IsMaximizeModeWindowManagerEnabled(); |
| 178 if (is_fullscreen) { | 176 if (is_fullscreen) { |
| 179 view->InitAsFramelessWindow( | 177 view->InitAsFramelessWindow( |
| 180 container, current_apps_page, | 178 container, current_apps_page, |
| 181 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); | 179 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); |
| 182 } else if (is_centered_) { | 180 } else if (is_centered_) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 207 keyboard::KeyboardController::GetInstance(); | 205 keyboard::KeyboardController::GetInstance(); |
| 208 if (keyboard_controller) | 206 if (keyboard_controller) |
| 209 keyboard_controller->AddObserver(this); | 207 keyboard_controller->AddObserver(this); |
| 210 Shell::GetInstance()->AddPreTargetHandler(this); | 208 Shell::GetInstance()->AddPreTargetHandler(this); |
| 211 WmWindow* window = WmShell::Get()->GetRootWindowForDisplayId(display_id); | 209 WmWindow* window = WmShell::Get()->GetRootWindowForDisplayId(display_id); |
| 212 window->GetRootWindowController()->GetShelf()->AddObserver(this); | 210 window->GetRootWindowController()->GetShelf()->AddObserver(this); |
| 213 | 211 |
| 214 // By setting us as DnD recipient, the app list knows that we can | 212 // By setting us as DnD recipient, the app list knows that we can |
| 215 // handle items. | 213 // handle items. |
| 216 view->SetDragAndDropHostOfCurrentAppList( | 214 view->SetDragAndDropHostOfCurrentAppList( |
| 217 shelf->GetDragAndDropHostForAppList()); | 215 shelf->shelf_widget()->GetDragAndDropHostForAppList()); |
| 218 } | 216 } |
| 219 | 217 |
| 220 void AppListPresenterDelegate::OnShown(int64_t display_id) { | 218 void AppListPresenterDelegate::OnShown(int64_t display_id) { |
| 221 is_visible_ = true; | 219 is_visible_ = true; |
| 222 // Update applist button status when app list visibility is changed. | 220 // Update applist button status when app list visibility is changed. |
| 223 WmWindow* root_window = WmShell::Get()->GetRootWindowForDisplayId(display_id); | 221 WmWindow* root_window = WmShell::Get()->GetRootWindowForDisplayId(display_id); |
| 224 Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown(); | 222 WmShelf::ForWindow(root_window) |
| 223 ->shelf_widget() |
| 224 ->GetAppListButton() |
| 225 ->OnAppListShown(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void AppListPresenterDelegate::OnDismissed() { | 228 void AppListPresenterDelegate::OnDismissed() { |
| 228 DCHECK(is_visible_); | 229 DCHECK(is_visible_); |
| 229 DCHECK(view_); | 230 DCHECK(view_); |
| 230 | 231 |
| 231 is_visible_ = false; | 232 is_visible_ = false; |
| 232 | 233 |
| 233 // App list needs to know the new shelf layout in order to calculate its | 234 // App list needs to know the new shelf layout in order to calculate its |
| 234 // UI layout when AppListView visibility changes. | 235 // UI layout when AppListView visibility changes. |
| 235 Shelf* shelf = | 236 WmShelf* shelf = WmShelf::ForWindow( |
| 236 Shelf::ForWindow(WmLookup::Get()->GetWindowForWidget(view_->GetWidget())); | 237 WmLookup::Get()->GetWindowForWidget(view_->GetWidget())); |
| 237 shelf->shelf_layout_manager()->UpdateAutoHideState(); | 238 shelf->UpdateAutoHideState(); |
| 238 | 239 |
| 239 // Update applist button status when app list visibility is changed. | 240 // Update applist button status when app list visibility is changed. |
| 240 shelf->GetAppListButton()->OnAppListDismissed(); | 241 shelf->shelf_widget()->GetAppListButton()->OnAppListDismissed(); |
| 241 } | 242 } |
| 242 | 243 |
| 243 void AppListPresenterDelegate::UpdateBounds() { | 244 void AppListPresenterDelegate::UpdateBounds() { |
| 244 if (!view_ || !is_visible_) | 245 if (!view_ || !is_visible_) |
| 245 return; | 246 return; |
| 246 | 247 |
| 247 view_->UpdateBounds(); | 248 view_->UpdateBounds(); |
| 248 | 249 |
| 249 if (is_centered_) { | 250 if (is_centered_) { |
| 250 view_->SetAnchorPoint(GetCenterOfDisplayForView( | 251 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
| 251 view_, GetMinimumBoundsHeightForAppList(view_))); | 252 view_, GetMinimumBoundsHeightForAppList(view_))); |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( | 256 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( |
| 256 aura::Window* root_window) { | 257 aura::Window* root_window) { |
| 257 DCHECK(Shell::HasInstance()); | 258 DCHECK(Shell::HasInstance()); |
| 258 | 259 |
| 259 // App list needs to know the new shelf layout in order to calculate its | 260 // App list needs to know the new shelf layout in order to calculate its |
| 260 // UI layout when AppListView visibility changes. | 261 // UI layout when AppListView visibility changes. |
| 261 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(root_window)); | 262 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(root_window)); |
| 262 shelf->shelf_layout_manager()->UpdateAutoHideState(); | 263 shelf->UpdateAutoHideState(); |
| 263 | 264 |
| 264 switch (shelf->wm_shelf()->alignment()) { | 265 switch (shelf->alignment()) { |
| 265 case SHELF_ALIGNMENT_BOTTOM: | 266 case SHELF_ALIGNMENT_BOTTOM: |
| 266 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 267 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 267 return gfx::Vector2d(0, kAnimationOffset); | 268 return gfx::Vector2d(0, kAnimationOffset); |
| 268 case SHELF_ALIGNMENT_LEFT: | 269 case SHELF_ALIGNMENT_LEFT: |
| 269 return gfx::Vector2d(-kAnimationOffset, 0); | 270 return gfx::Vector2d(-kAnimationOffset, 0); |
| 270 case SHELF_ALIGNMENT_RIGHT: | 271 case SHELF_ALIGNMENT_RIGHT: |
| 271 return gfx::Vector2d(kAnimationOffset, 0); | 272 return gfx::Vector2d(kAnimationOffset, 0); |
| 272 } | 273 } |
| 273 NOTREACHED(); | 274 NOTREACHED(); |
| 274 return gfx::Vector2d(); | 275 return gfx::Vector2d(); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 358 } |
| 358 | 359 |
| 359 //////////////////////////////////////////////////////////////////////////////// | 360 //////////////////////////////////////////////////////////////////////////////// |
| 360 // AppListPresenterDelegate, WmShelfObserver implementation: | 361 // AppListPresenterDelegate, WmShelfObserver implementation: |
| 361 | 362 |
| 362 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { | 363 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { |
| 363 UpdateBounds(); | 364 UpdateBounds(); |
| 364 } | 365 } |
| 365 | 366 |
| 366 } // namespace ash | 367 } // namespace ash |
| OLD | NEW |