| 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/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/shelf/shelf_types.h" | 8 #include "ash/common/shelf/shelf_types.h" |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/display/window_tree_host_manager.h" | 11 #include "ash/display/window_tree_host_manager.h" |
| 12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 13 #include "ash/screen_util.h" | 13 #include "ash/screen_util.h" |
| 14 #include "ash/shelf/app_list_button.h" |
| 14 #include "ash/shelf/shelf.h" | 15 #include "ash/shelf/shelf.h" |
| 15 #include "ash/shelf/shelf_layout_manager.h" | 16 #include "ash/shelf/shelf_layout_manager.h" |
| 16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 17 #include "ash/shell_delegate.h" | 18 #include "ash/shell_delegate.h" |
| 18 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 19 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 19 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 20 #include "ui/app_list/app_list_constants.h" | 21 #include "ui/app_list/app_list_constants.h" |
| 21 #include "ui/app_list/app_list_switches.h" | 22 #include "ui/app_list/app_list_switches.h" |
| 22 #include "ui/app_list/presenter/app_list_presenter.h" | 23 #include "ui/app_list/presenter/app_list_presenter.h" |
| 23 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" | 24 #include "ui/app_list/presenter/app_list_view_delegate_factory.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // UI layout when AppListView visibility changes. | 146 // UI layout when AppListView visibility changes. |
| 146 ash::Shell::GetPrimaryRootWindowController() | 147 ash::Shell::GetPrimaryRootWindowController() |
| 147 ->GetShelfLayoutManager() | 148 ->GetShelfLayoutManager() |
| 148 ->UpdateAutoHideState(); | 149 ->UpdateAutoHideState(); |
| 149 view_ = view; | 150 view_ = view; |
| 150 aura::Window* root_window = Shell::GetInstance() | 151 aura::Window* root_window = Shell::GetInstance() |
| 151 ->window_tree_host_manager() | 152 ->window_tree_host_manager() |
| 152 ->GetRootWindowForDisplayId(display_id); | 153 ->GetRootWindowForDisplayId(display_id); |
| 153 aura::Window* container = GetRootWindowController(root_window) | 154 aura::Window* container = GetRootWindowController(root_window) |
| 154 ->GetContainer(kShellWindowId_AppListContainer); | 155 ->GetContainer(kShellWindowId_AppListContainer); |
| 155 views::View* applist_button = | 156 AppListButton* applist_button = |
| 156 Shelf::ForWindow(container)->GetAppListButtonView(); | 157 Shelf::ForWindow(container)->GetAppListButton(); |
| 157 is_centered_ = view->ShouldCenterWindow(); | 158 is_centered_ = view->ShouldCenterWindow(); |
| 158 bool is_fullscreen = IsFullscreenAppListEnabled() && | 159 bool is_fullscreen = IsFullscreenAppListEnabled() && |
| 159 Shell::GetInstance() | 160 Shell::GetInstance() |
| 160 ->maximize_mode_controller() | 161 ->maximize_mode_controller() |
| 161 ->IsMaximizeModeWindowManagerEnabled(); | 162 ->IsMaximizeModeWindowManagerEnabled(); |
| 162 if (is_fullscreen) { | 163 if (is_fullscreen) { |
| 163 view->InitAsFramelessWindow( | 164 view->InitAsFramelessWindow( |
| 164 container, current_apps_page, | 165 container, current_apps_page, |
| 165 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); | 166 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); |
| 166 } else if (is_centered_) { | 167 } else if (is_centered_) { |
| 167 // Note: We can't center the app list until we have its dimensions, so we | 168 // Note: We can't center the app list until we have its dimensions, so we |
| 168 // init at (0, 0) and then reset its anchor point. | 169 // init at (0, 0) and then reset its anchor point. |
| 169 view->InitAsBubbleAtFixedLocation(container, current_apps_page, | 170 view->InitAsBubbleAtFixedLocation(container, current_apps_page, |
| 170 gfx::Point(), views::BubbleBorder::FLOAT, | 171 gfx::Point(), views::BubbleBorder::FLOAT, |
| 171 true /* border_accepts_events */); | 172 true /* border_accepts_events */); |
| 172 // The experimental app list is centered over the display of the app list | 173 // The experimental app list is centered over the display of the app list |
| 173 // button that was pressed (if triggered via keyboard, this is the display | 174 // button that was pressed (if triggered via keyboard, this is the display |
| 174 // with the currently focused window). | 175 // with the currently focused window). |
| 175 view->SetAnchorPoint(GetCenterOfDisplayForView( | 176 view->SetAnchorPoint(GetCenterOfDisplayForView( |
| 176 applist_button, GetMinimumBoundsHeightForAppList(view))); | 177 applist_button, GetMinimumBoundsHeightForAppList(view))); |
| 177 } else { | 178 } else { |
| 178 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); | 179 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); |
| 179 // We need the location of the button within the local screen. | 180 // We need the location of the button within the local screen. |
| 180 applist_button_bounds = | 181 applist_button_bounds = |
| 181 ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds); | 182 ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds); |
| 182 view->InitAsBubbleAttachedToAnchor( | 183 view->InitAsBubbleAttachedToAnchor( |
| 183 container, current_apps_page, | 184 container, current_apps_page, |
| 184 Shelf::ForWindow(container)->GetAppListButtonView(), | 185 Shelf::ForWindow(container)->GetAppListButton(), |
| 185 GetAnchorPositionOffsetToShelf( | 186 GetAnchorPositionOffsetToShelf( |
| 186 applist_button_bounds, | 187 applist_button_bounds, |
| 187 Shelf::ForWindow(container)->GetAppListButtonView()->GetWidget()), | 188 Shelf::ForWindow(container)->GetAppListButton()->GetWidget()), |
| 188 GetBubbleArrow(container), true /* border_accepts_events */); | 189 GetBubbleArrow(container), true /* border_accepts_events */); |
| 189 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 190 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 190 } | 191 } |
| 191 | 192 |
| 192 keyboard::KeyboardController* keyboard_controller = | 193 keyboard::KeyboardController* keyboard_controller = |
| 193 keyboard::KeyboardController::GetInstance(); | 194 keyboard::KeyboardController::GetInstance(); |
| 194 if (keyboard_controller) | 195 if (keyboard_controller) |
| 195 keyboard_controller->AddObserver(this); | 196 keyboard_controller->AddObserver(this); |
| 196 Shell::GetInstance()->AddPreTargetHandler(this); | 197 Shell::GetInstance()->AddPreTargetHandler(this); |
| 197 views::Widget* widget = view->GetWidget(); | 198 views::Widget* widget = view->GetWidget(); |
| 198 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); | 199 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this); |
| 199 | 200 |
| 200 // By setting us as DnD recipient, the app list knows that we can | 201 // By setting us as DnD recipient, the app list knows that we can |
| 201 // handle items. | 202 // handle items. |
| 202 view->SetDragAndDropHostOfCurrentAppList( | 203 view->SetDragAndDropHostOfCurrentAppList( |
| 203 Shelf::ForWindow(root_window)->GetDragAndDropHostForAppList()); | 204 Shelf::ForWindow(root_window)->GetDragAndDropHostForAppList()); |
| 204 } | 205 } |
| 205 | 206 |
| 206 void AppListPresenterDelegate::OnShown(int64_t display_id) { | 207 void AppListPresenterDelegate::OnShown(int64_t display_id) { |
| 207 is_visible_ = true; | 208 is_visible_ = true; |
| 208 // Update applist button status when app list visibility is changed. | 209 // Update applist button status when app list visibility is changed. |
| 209 aura::Window* root_window = Shell::GetInstance() | 210 aura::Window* root_window = Shell::GetInstance() |
| 210 ->window_tree_host_manager() | 211 ->window_tree_host_manager() |
| 211 ->GetRootWindowForDisplayId(display_id); | 212 ->GetRootWindowForDisplayId(display_id); |
| 212 Shelf::ForWindow(root_window)->GetAppListButtonView()->SchedulePaint(); | 213 Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown(); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void AppListPresenterDelegate::OnDismissed() { | 216 void AppListPresenterDelegate::OnDismissed() { |
| 216 DCHECK(is_visible_); | 217 DCHECK(is_visible_); |
| 217 DCHECK(view_); | 218 DCHECK(view_); |
| 218 | 219 |
| 219 is_visible_ = false; | 220 is_visible_ = false; |
| 220 | 221 |
| 221 // App list needs to know the new shelf layout in order to calculate its | 222 // App list needs to know the new shelf layout in order to calculate its |
| 222 // UI layout when AppListView visibility changes. | 223 // UI layout when AppListView visibility changes. |
| 223 Shell::GetPrimaryRootWindowController() | 224 Shell::GetPrimaryRootWindowController() |
| 224 ->GetShelfLayoutManager() | 225 ->GetShelfLayoutManager() |
| 225 ->UpdateAutoHideState(); | 226 ->UpdateAutoHideState(); |
| 226 | 227 |
| 227 // Update applist button status when app list visibility is changed. | 228 // Update applist button status when app list visibility is changed. |
| 228 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) | 229 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) |
| 229 ->GetAppListButtonView() | 230 ->GetAppListButton() |
| 230 ->SchedulePaint(); | 231 ->OnAppListDismissed(); |
| 231 } | 232 } |
| 232 | 233 |
| 233 void AppListPresenterDelegate::UpdateBounds() { | 234 void AppListPresenterDelegate::UpdateBounds() { |
| 234 if (!view_ || !is_visible_) | 235 if (!view_ || !is_visible_) |
| 235 return; | 236 return; |
| 236 | 237 |
| 237 view_->UpdateBounds(); | 238 view_->UpdateBounds(); |
| 238 | 239 |
| 239 if (is_centered_) { | 240 if (is_centered_) { |
| 240 view_->SetAnchorPoint(GetCenterOfDisplayForView( | 241 view_->SetAnchorPoint(GetCenterOfDisplayForView( |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 337 } |
| 337 | 338 |
| 338 //////////////////////////////////////////////////////////////////////////////// | 339 //////////////////////////////////////////////////////////////////////////////// |
| 339 // AppListPresenterDelegate, ShelfIconObserver implementation: | 340 // AppListPresenterDelegate, ShelfIconObserver implementation: |
| 340 | 341 |
| 341 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { | 342 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { |
| 342 UpdateBounds(); | 343 UpdateBounds(); |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace ash | 346 } // namespace ash |
| OLD | NEW |