| 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 // 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 containing the given |window|. |
| 39 // 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 |
| 40 // 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 |
| 41 // 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). |
| 42 gfx::Point GetCenterOfDisplayForView(views::View* view, int minimum_height) { | 42 gfx::Point GetCenterOfDisplayForWindow(WmWindow* window, int minimum_height) { |
| 43 WmWindow* window = WmLookup::Get()->GetWindowForWidget(view->GetWidget()); | 43 DCHECK(window); |
| 44 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window); | 44 gfx::Rect bounds = wm::GetDisplayBoundsWithShelf(window); |
| 45 bounds = window->GetRootWindow()->ConvertRectToScreen(bounds); | 45 bounds = window->GetRootWindow()->ConvertRectToScreen(bounds); |
| 46 | 46 |
| 47 // 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 |
| 48 // 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. |
| 49 // (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 |
| 50 // until after this function is called.) | 50 // until after this function is called.) |
| 51 keyboard::KeyboardController* keyboard_controller = | 51 keyboard::KeyboardController* keyboard_controller = |
| 52 keyboard::KeyboardController::GetInstance(); | 52 keyboard::KeyboardController::GetInstance(); |
| 53 if (keyboard_controller && keyboard_controller->keyboard_visible()) | 53 if (keyboard_controller && keyboard_controller->keyboard_visible()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 int current_apps_page) { | 102 int current_apps_page) { |
| 103 // App list needs to know the new shelf layout in order to calculate its | 103 // App list needs to know the new shelf layout in order to calculate its |
| 104 // UI layout when AppListView visibility changes. | 104 // UI layout when AppListView visibility changes. |
| 105 ash::Shell::GetPrimaryRootWindowController() | 105 ash::Shell::GetPrimaryRootWindowController() |
| 106 ->GetShelfLayoutManager() | 106 ->GetShelfLayoutManager() |
| 107 ->UpdateAutoHideState(); | 107 ->UpdateAutoHideState(); |
| 108 view_ = view; | 108 view_ = view; |
| 109 aura::Window* root_window = Shell::GetInstance() | 109 aura::Window* root_window = Shell::GetInstance() |
| 110 ->window_tree_host_manager() | 110 ->window_tree_host_manager() |
| 111 ->GetRootWindowForDisplayId(display_id); | 111 ->GetRootWindowForDisplayId(display_id); |
| 112 WmWindow* wm_root_window = WmWindowAura::Get(root_window); |
| 112 aura::Window* container = GetRootWindowController(root_window) | 113 aura::Window* container = GetRootWindowController(root_window) |
| 113 ->GetContainer(kShellWindowId_AppListContainer); | 114 ->GetContainer(kShellWindowId_AppListContainer); |
| 114 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(container)); | |
| 115 AppListButton* applist_button = shelf->shelf_widget()->GetAppListButton(); | |
| 116 bool is_fullscreen = IsFullscreenAppListEnabled() && | 115 bool is_fullscreen = IsFullscreenAppListEnabled() && |
| 117 WmShell::Get() | 116 WmShell::Get() |
| 118 ->maximize_mode_controller() | 117 ->maximize_mode_controller() |
| 119 ->IsMaximizeModeWindowManagerEnabled(); | 118 ->IsMaximizeModeWindowManagerEnabled(); |
| 120 if (is_fullscreen) { | 119 if (is_fullscreen) { |
| 121 view->InitAsFramelessWindow( | 120 view->InitAsFramelessWindow( |
| 122 container, current_apps_page, | 121 container, current_apps_page, |
| 123 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); | 122 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); |
| 124 } else { | 123 } else { |
| 125 view->InitAsBubble(container, current_apps_page); | 124 view->InitAsBubble(container, current_apps_page); |
| 126 // The app list is centered over the display of the app list button that was | 125 // The app list is centered over the display. |
| 127 // pressed (if triggered via keyboard, this is the display with the | 126 view->SetAnchorPoint(GetCenterOfDisplayForWindow( |
| 128 // currently focused window). | 127 wm_root_window, GetMinimumBoundsHeightForAppList(view))); |
| 129 view->SetAnchorPoint(GetCenterOfDisplayForView( | |
| 130 applist_button, GetMinimumBoundsHeightForAppList(view))); | |
| 131 } | 128 } |
| 132 | 129 |
| 133 keyboard::KeyboardController* keyboard_controller = | 130 keyboard::KeyboardController* keyboard_controller = |
| 134 keyboard::KeyboardController::GetInstance(); | 131 keyboard::KeyboardController::GetInstance(); |
| 135 if (keyboard_controller) | 132 if (keyboard_controller) |
| 136 keyboard_controller->AddObserver(this); | 133 keyboard_controller->AddObserver(this); |
| 137 Shell::GetInstance()->AddPreTargetHandler(this); | 134 Shell::GetInstance()->AddPreTargetHandler(this); |
| 138 WmWindow* window = WmShell::Get()->GetRootWindowForDisplayId(display_id); | 135 WmShelf* shelf = WmShelf::ForWindow(wm_root_window); |
| 139 window->GetRootWindowController()->GetShelf()->AddObserver(this); | 136 shelf->AddObserver(this); |
| 140 | 137 |
| 141 // By setting us as DnD recipient, the app list knows that we can | 138 // By setting us as DnD recipient, the app list knows that we can |
| 142 // handle items. | 139 // handle items. |
| 143 view->SetDragAndDropHostOfCurrentAppList( | 140 view->SetDragAndDropHostOfCurrentAppList( |
| 144 shelf->shelf_widget()->GetDragAndDropHostForAppList()); | 141 shelf->shelf_widget()->GetDragAndDropHostForAppList()); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void AppListPresenterDelegate::OnShown(int64_t display_id) { | 144 void AppListPresenterDelegate::OnShown(int64_t display_id) { |
| 148 is_visible_ = true; | 145 is_visible_ = true; |
| 149 // Update applist button status when app list visibility is changed. | 146 // Update applist button status when app list visibility is changed. |
| 150 WmWindow* root_window = WmShell::Get()->GetRootWindowForDisplayId(display_id); | 147 WmWindow* root_window = WmShell::Get()->GetRootWindowForDisplayId(display_id); |
| 151 WmShelf::ForWindow(root_window) | 148 AppListButton* app_list_button = |
| 152 ->shelf_widget() | 149 WmShelf::ForWindow(root_window)->shelf_widget()->GetAppListButton(); |
| 153 ->GetAppListButton() | 150 if (app_list_button) |
| 154 ->OnAppListShown(); | 151 app_list_button->OnAppListShown(); |
| 155 } | 152 } |
| 156 | 153 |
| 157 void AppListPresenterDelegate::OnDismissed() { | 154 void AppListPresenterDelegate::OnDismissed() { |
| 158 DCHECK(is_visible_); | 155 DCHECK(is_visible_); |
| 159 DCHECK(view_); | 156 DCHECK(view_); |
| 160 | 157 |
| 161 is_visible_ = false; | 158 is_visible_ = false; |
| 162 | 159 |
| 163 // Update applist button status when app list visibility is changed. | 160 // Update applist button status when app list visibility is changed. |
| 164 WmShelf* shelf = WmShelf::ForWindow( | 161 WmWindow* window = WmLookup::Get()->GetWindowForWidget(view_->GetWidget()); |
| 165 WmLookup::Get()->GetWindowForWidget(view_->GetWidget())); | 162 AppListButton* app_list_button = |
| 166 shelf->shelf_widget()->GetAppListButton()->OnAppListDismissed(); | 163 WmShelf::ForWindow(window)->shelf_widget()->GetAppListButton(); |
| 164 if (app_list_button) |
| 165 app_list_button->OnAppListDismissed(); |
| 167 } | 166 } |
| 168 | 167 |
| 169 void AppListPresenterDelegate::UpdateBounds() { | 168 void AppListPresenterDelegate::UpdateBounds() { |
| 170 if (!view_ || !is_visible_) | 169 if (!view_ || !is_visible_) |
| 171 return; | 170 return; |
| 172 | 171 |
| 173 view_->UpdateBounds(); | 172 view_->UpdateBounds(); |
| 174 view_->SetAnchorPoint(GetCenterOfDisplayForView( | 173 view_->SetAnchorPoint(GetCenterOfDisplayForWindow( |
| 175 view_, GetMinimumBoundsHeightForAppList(view_))); | 174 WmLookup::Get()->GetWindowForWidget(view_->GetWidget()), |
| 175 GetMinimumBoundsHeightForAppList(view_))); |
| 176 } | 176 } |
| 177 | 177 |
| 178 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( | 178 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( |
| 179 aura::Window* root_window) { | 179 aura::Window* root_window) { |
| 180 DCHECK(Shell::HasInstance()); | 180 DCHECK(Shell::HasInstance()); |
| 181 | 181 |
| 182 // App list needs to know the new shelf layout in order to calculate its | 182 // App list needs to know the new shelf layout in order to calculate its |
| 183 // UI layout when AppListView visibility changes. | 183 // UI layout when AppListView visibility changes. |
| 184 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(root_window)); | 184 WmShelf* shelf = WmShelf::ForWindow(WmWindowAura::Get(root_window)); |
| 185 shelf->UpdateAutoHideState(); | 185 shelf->UpdateAutoHideState(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 277 } |
| 278 | 278 |
| 279 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
| 280 // AppListPresenterDelegate, WmShelfObserver implementation: | 280 // AppListPresenterDelegate, WmShelfObserver implementation: |
| 281 | 281 |
| 282 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { | 282 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { |
| 283 UpdateBounds(); | 283 UpdateBounds(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace ash | 286 } // namespace ash |
| OLD | NEW |