Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(720)

Side by Side Diff: ash/app_list/app_list_presenter_delegate.cc

Issue 2237903003: mash: Migrate Shelf aura::Window uses to WmWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move shelf notify functions to WmShell. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ash/aura/wm_shelf_aura.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/ash_switches.h" 8 #include "ash/common/ash_switches.h"
8 #include "ash/common/shelf/app_list_button.h" 9 #include "ash/common/shelf/app_list_button.h"
9 #include "ash/common/shelf/shelf_types.h" 10 #include "ash/common/shelf/shelf_types.h"
10 #include "ash/common/shell_window_ids.h" 11 #include "ash/common/shell_window_ids.h"
11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 12 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
12 #include "ash/common/wm/wm_screen_util.h" 13 #include "ash/common/wm/wm_screen_util.h"
13 #include "ash/common/wm_lookup.h" 14 #include "ash/common/wm_lookup.h"
14 #include "ash/common/wm_shell.h" 15 #include "ash/common/wm_shell.h"
15 #include "ash/common/wm_window.h" 16 #include "ash/common/wm_window.h"
16 #include "ash/display/window_tree_host_manager.h" 17 #include "ash/display/window_tree_host_manager.h"
(...skipping 17 matching lines...) Expand all
34 namespace { 35 namespace {
35 36
36 // The minimal anchor position offset to make sure that the bubble is still on 37 // The minimal anchor position offset to make sure that the bubble is still on
37 // the screen with 8 pixels spacing on the left / right. This constant is a 38 // the screen with 8 pixels spacing on the left / right. This constant is a
38 // result of minimal bubble arrow sizes and offsets. 39 // result of minimal bubble arrow sizes and offsets.
39 const int kMinimalAnchorPositionOffset = 57; 40 const int kMinimalAnchorPositionOffset = 57;
40 41
41 // Gets arrow location based on shelf alignment. 42 // Gets arrow location based on shelf alignment.
42 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) { 43 views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) {
43 DCHECK(Shell::HasInstance()); 44 DCHECK(Shell::HasInstance());
44 switch (Shelf::ForWindow(window)->alignment()) { 45 switch (Shelf::ForWindow(WmWindowAura::Get(window))->alignment()) {
45 case SHELF_ALIGNMENT_BOTTOM: 46 case SHELF_ALIGNMENT_BOTTOM:
46 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 47 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
47 return views::BubbleBorder::BOTTOM_CENTER; 48 return views::BubbleBorder::BOTTOM_CENTER;
48 case SHELF_ALIGNMENT_LEFT: 49 case SHELF_ALIGNMENT_LEFT:
49 return views::BubbleBorder::LEFT_CENTER; 50 return views::BubbleBorder::LEFT_CENTER;
50 case SHELF_ALIGNMENT_RIGHT: 51 case SHELF_ALIGNMENT_RIGHT:
51 return views::BubbleBorder::RIGHT_CENTER; 52 return views::BubbleBorder::RIGHT_CENTER;
52 } 53 }
53 NOTREACHED(); 54 NOTREACHED();
54 return views::BubbleBorder::BOTTOM_CENTER; 55 return views::BubbleBorder::BOTTOM_CENTER;
55 } 56 }
56 57
57 // Using |button_bounds|, determine the anchor offset so that the bubble gets 58 // Using |button_bounds|, determine the anchor offset so that the bubble gets
58 // shown above the shelf (used for the alternate shelf theme). 59 // shown above the shelf (used for the alternate shelf theme).
59 gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds, 60 gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds,
60 views::Widget* widget) { 61 views::Widget* widget) {
61 DCHECK(Shell::HasInstance()); 62 DCHECK(Shell::HasInstance());
62 ShelfAlignment shelf_alignment = 63 ShelfAlignment shelf_alignment =
63 Shelf::ForWindow(widget->GetNativeView()->GetRootWindow())->alignment(); 64 Shelf::ForWindow(WmLookup::Get()->GetWindowForWidget(widget))
65 ->alignment();
64 gfx::Point anchor(button_bounds.CenterPoint()); 66 gfx::Point anchor(button_bounds.CenterPoint());
65 switch (shelf_alignment) { 67 switch (shelf_alignment) {
66 case SHELF_ALIGNMENT_BOTTOM: 68 case SHELF_ALIGNMENT_BOTTOM:
67 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 69 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
68 if (base::i18n::IsRTL()) { 70 if (base::i18n::IsRTL()) {
69 int screen_width = widget->GetWorkAreaBoundsInScreen().width(); 71 int screen_width = widget->GetWorkAreaBoundsInScreen().width();
70 return gfx::Vector2d( 72 return gfx::Vector2d(
71 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(), 73 std::min(screen_width - kMinimalAnchorPositionOffset - anchor.x(),
72 0), 74 0),
73 0); 75 0);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 : presenter_(presenter), view_delegate_factory_(view_delegate_factory) { 133 : presenter_(presenter), view_delegate_factory_(view_delegate_factory) {
132 WmShell::Get()->AddShellObserver(this); 134 WmShell::Get()->AddShellObserver(this);
133 } 135 }
134 136
135 AppListPresenterDelegate::~AppListPresenterDelegate() { 137 AppListPresenterDelegate::~AppListPresenterDelegate() {
136 DCHECK(view_); 138 DCHECK(view_);
137 keyboard::KeyboardController* keyboard_controller = 139 keyboard::KeyboardController* keyboard_controller =
138 keyboard::KeyboardController::GetInstance(); 140 keyboard::KeyboardController::GetInstance();
139 if (keyboard_controller) 141 if (keyboard_controller)
140 keyboard_controller->RemoveObserver(this); 142 keyboard_controller->RemoveObserver(this);
141 views::Widget* widget = view_->GetWidget();
142 Shell::GetInstance()->RemovePreTargetHandler(this); 143 Shell::GetInstance()->RemovePreTargetHandler(this);
143 Shelf::ForWindow(widget->GetNativeWindow())->RemoveIconObserver(this); 144 WmWindow* window = WmLookup::Get()->GetWindowForWidget(view_->GetWidget());
145 Shelf::ForWindow(window)->RemoveIconObserver(this);
144 WmShell::Get()->RemoveShellObserver(this); 146 WmShell::Get()->RemoveShellObserver(this);
145 } 147 }
146 148
147 app_list::AppListViewDelegate* AppListPresenterDelegate::GetViewDelegate() { 149 app_list::AppListViewDelegate* AppListPresenterDelegate::GetViewDelegate() {
148 return view_delegate_factory_->GetDelegate(); 150 return view_delegate_factory_->GetDelegate();
149 } 151 }
150 152
151 void AppListPresenterDelegate::Init(app_list::AppListView* view, 153 void AppListPresenterDelegate::Init(app_list::AppListView* view,
152 int64_t display_id, 154 int64_t display_id,
153 int current_apps_page) { 155 int current_apps_page) {
154 // App list needs to know the new shelf layout in order to calculate its 156 // App list needs to know the new shelf layout in order to calculate its
155 // UI layout when AppListView visibility changes. 157 // UI layout when AppListView visibility changes.
156 ash::Shell::GetPrimaryRootWindowController() 158 ash::Shell::GetPrimaryRootWindowController()
157 ->GetShelfLayoutManager() 159 ->GetShelfLayoutManager()
158 ->UpdateAutoHideState(); 160 ->UpdateAutoHideState();
159 view_ = view; 161 view_ = view;
160 aura::Window* root_window = Shell::GetInstance() 162 aura::Window* root_window = Shell::GetInstance()
161 ->window_tree_host_manager() 163 ->window_tree_host_manager()
162 ->GetRootWindowForDisplayId(display_id); 164 ->GetRootWindowForDisplayId(display_id);
163 aura::Window* container = GetRootWindowController(root_window) 165 aura::Window* container = GetRootWindowController(root_window)
164 ->GetContainer(kShellWindowId_AppListContainer); 166 ->GetContainer(kShellWindowId_AppListContainer);
165 AppListButton* applist_button = 167 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(container));
166 Shelf::ForWindow(container)->GetAppListButton(); 168 AppListButton* applist_button = shelf->GetAppListButton();
167 is_centered_ = view->ShouldCenterWindow(); 169 is_centered_ = view->ShouldCenterWindow();
168 bool is_fullscreen = IsFullscreenAppListEnabled() && 170 bool is_fullscreen = IsFullscreenAppListEnabled() &&
169 WmShell::Get() 171 WmShell::Get()
170 ->maximize_mode_controller() 172 ->maximize_mode_controller()
171 ->IsMaximizeModeWindowManagerEnabled(); 173 ->IsMaximizeModeWindowManagerEnabled();
172 if (is_fullscreen) { 174 if (is_fullscreen) {
173 view->InitAsFramelessWindow( 175 view->InitAsFramelessWindow(
174 container, current_apps_page, 176 container, current_apps_page,
175 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container)); 177 ScreenUtil::GetDisplayWorkAreaBoundsInParent(container));
176 } else if (is_centered_) { 178 } else if (is_centered_) {
177 // Note: We can't center the app list until we have its dimensions, so we 179 // Note: We can't center the app list until we have its dimensions, so we
178 // init at (0, 0) and then reset its anchor point. 180 // init at (0, 0) and then reset its anchor point.
179 view->InitAsBubbleAtFixedLocation(container, current_apps_page, 181 view->InitAsBubbleAtFixedLocation(container, current_apps_page,
180 gfx::Point(), views::BubbleBorder::FLOAT, 182 gfx::Point(), views::BubbleBorder::FLOAT,
181 true /* border_accepts_events */); 183 true /* border_accepts_events */);
182 // The experimental app list is centered over the display of the app list 184 // The experimental app list is centered over the display of the app list
183 // button that was pressed (if triggered via keyboard, this is the display 185 // button that was pressed (if triggered via keyboard, this is the display
184 // with the currently focused window). 186 // with the currently focused window).
185 view->SetAnchorPoint(GetCenterOfDisplayForView( 187 view->SetAnchorPoint(GetCenterOfDisplayForView(
186 applist_button, GetMinimumBoundsHeightForAppList(view))); 188 applist_button, GetMinimumBoundsHeightForAppList(view)));
187 } else { 189 } else {
188 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen(); 190 gfx::Rect applist_button_bounds = applist_button->GetBoundsInScreen();
189 // We need the location of the button within the local screen. 191 // We need the location of the button within the local screen.
190 applist_button_bounds = 192 applist_button_bounds =
191 ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds); 193 ScreenUtil::ConvertRectFromScreen(root_window, applist_button_bounds);
192 view->InitAsBubbleAttachedToAnchor( 194 view->InitAsBubbleAttachedToAnchor(
193 container, current_apps_page, 195 container, current_apps_page, applist_button,
194 Shelf::ForWindow(container)->GetAppListButton(), 196 GetAnchorPositionOffsetToShelf(applist_button_bounds,
195 GetAnchorPositionOffsetToShelf( 197 applist_button->GetWidget()),
196 applist_button_bounds,
197 Shelf::ForWindow(container)->GetAppListButton()->GetWidget()),
198 GetBubbleArrow(container), true /* border_accepts_events */); 198 GetBubbleArrow(container), true /* border_accepts_events */);
199 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); 199 view->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
200 } 200 }
201 201
202 keyboard::KeyboardController* keyboard_controller = 202 keyboard::KeyboardController* keyboard_controller =
203 keyboard::KeyboardController::GetInstance(); 203 keyboard::KeyboardController::GetInstance();
204 if (keyboard_controller) 204 if (keyboard_controller)
205 keyboard_controller->AddObserver(this); 205 keyboard_controller->AddObserver(this);
206 Shell::GetInstance()->AddPreTargetHandler(this); 206 Shell::GetInstance()->AddPreTargetHandler(this);
207 views::Widget* widget = view->GetWidget(); 207 shelf->AddIconObserver(this);
208 Shelf::ForWindow(widget->GetNativeWindow())->AddIconObserver(this);
209 208
210 // By setting us as DnD recipient, the app list knows that we can 209 // By setting us as DnD recipient, the app list knows that we can
211 // handle items. 210 // handle items.
212 view->SetDragAndDropHostOfCurrentAppList( 211 view->SetDragAndDropHostOfCurrentAppList(
213 Shelf::ForWindow(root_window)->GetDragAndDropHostForAppList()); 212 shelf->GetDragAndDropHostForAppList());
214 } 213 }
215 214
216 void AppListPresenterDelegate::OnShown(int64_t display_id) { 215 void AppListPresenterDelegate::OnShown(int64_t display_id) {
217 is_visible_ = true; 216 is_visible_ = true;
218 // Update applist button status when app list visibility is changed. 217 // Update applist button status when app list visibility is changed.
219 aura::Window* root_window = Shell::GetInstance() 218 WmWindow* root_window = WmShell::Get()->GetRootWindowForDisplayId(display_id);
220 ->window_tree_host_manager()
221 ->GetRootWindowForDisplayId(display_id);
222 Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown(); 219 Shelf::ForWindow(root_window)->GetAppListButton()->OnAppListShown();
223 } 220 }
224 221
225 void AppListPresenterDelegate::OnDismissed() { 222 void AppListPresenterDelegate::OnDismissed() {
226 DCHECK(is_visible_); 223 DCHECK(is_visible_);
227 DCHECK(view_); 224 DCHECK(view_);
228 225
229 is_visible_ = false; 226 is_visible_ = false;
230 227
231 // App list needs to know the new shelf layout in order to calculate its 228 // App list needs to know the new shelf layout in order to calculate its
232 // UI layout when AppListView visibility changes. 229 // UI layout when AppListView visibility changes.
233 Shell::GetPrimaryRootWindowController() 230 Shelf* shelf =
234 ->GetShelfLayoutManager() 231 Shelf::ForWindow(WmLookup::Get()->GetWindowForWidget(view_->GetWidget()));
235 ->UpdateAutoHideState(); 232 shelf->shelf_layout_manager()->UpdateAutoHideState();
236 233
237 // Update applist button status when app list visibility is changed. 234 // Update applist button status when app list visibility is changed.
238 Shelf::ForWindow(view_->GetWidget()->GetNativeView()) 235 shelf->GetAppListButton()->OnAppListDismissed();
239 ->GetAppListButton()
240 ->OnAppListDismissed();
241 } 236 }
242 237
243 void AppListPresenterDelegate::UpdateBounds() { 238 void AppListPresenterDelegate::UpdateBounds() {
244 if (!view_ || !is_visible_) 239 if (!view_ || !is_visible_)
245 return; 240 return;
246 241
247 view_->UpdateBounds(); 242 view_->UpdateBounds();
248 243
249 if (is_centered_) { 244 if (is_centered_) {
250 view_->SetAnchorPoint(GetCenterOfDisplayForView( 245 view_->SetAnchorPoint(GetCenterOfDisplayForView(
251 view_, GetMinimumBoundsHeightForAppList(view_))); 246 view_, GetMinimumBoundsHeightForAppList(view_)));
252 } 247 }
253 } 248 }
254 249
255 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset( 250 gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset(
256 aura::Window* root_window) { 251 aura::Window* root_window) {
257 DCHECK(Shell::HasInstance()); 252 DCHECK(Shell::HasInstance());
258 253
259 // App list needs to know the new shelf layout in order to calculate its 254 // App list needs to know the new shelf layout in order to calculate its
260 // UI layout when AppListView visibility changes. 255 // UI layout when AppListView visibility changes.
261 Shell::GetPrimaryRootWindowController() 256 Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(root_window));
262 ->GetShelfLayoutManager() 257 shelf->shelf_layout_manager()->UpdateAutoHideState();
263 ->UpdateAutoHideState();
264 258
265 switch (Shelf::ForWindow(root_window)->alignment()) { 259 switch (shelf->alignment()) {
266 case SHELF_ALIGNMENT_BOTTOM: 260 case SHELF_ALIGNMENT_BOTTOM:
267 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 261 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
268 return gfx::Vector2d(0, kAnimationOffset); 262 return gfx::Vector2d(0, kAnimationOffset);
269 case SHELF_ALIGNMENT_LEFT: 263 case SHELF_ALIGNMENT_LEFT:
270 return gfx::Vector2d(-kAnimationOffset, 0); 264 return gfx::Vector2d(-kAnimationOffset, 0);
271 case SHELF_ALIGNMENT_RIGHT: 265 case SHELF_ALIGNMENT_RIGHT:
272 return gfx::Vector2d(kAnimationOffset, 0); 266 return gfx::Vector2d(kAnimationOffset, 0);
273 } 267 }
274 NOTREACHED(); 268 NOTREACHED();
275 return gfx::Vector2d(); 269 return gfx::Vector2d();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 352 }
359 353
360 //////////////////////////////////////////////////////////////////////////////// 354 ////////////////////////////////////////////////////////////////////////////////
361 // AppListPresenterDelegate, ShelfIconObserver implementation: 355 // AppListPresenterDelegate, ShelfIconObserver implementation:
362 356
363 void AppListPresenterDelegate::OnShelfIconPositionsChanged() { 357 void AppListPresenterDelegate::OnShelfIconPositionsChanged() {
364 UpdateBounds(); 358 UpdateBounds();
365 } 359 }
366 360
367 } // namespace ash 361 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/aura/wm_shelf_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698