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/wm/shelf_layout_manager.h" | 5 #include "ash/wm/shelf_layout_manager.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/focus_cycler.h" | 10 #include "ash/focus_cycler.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 SetState(shelf, ShelfLayoutManager::HIDDEN); | 211 SetState(shelf, ShelfLayoutManager::HIDDEN); |
212 // Run the animation to completion. | 212 // Run the animation to completion. |
213 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 213 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
214 StepWidgetLayerAnimatorToEnd(shelf->status()); | 214 StepWidgetLayerAnimatorToEnd(shelf->status()); |
215 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 215 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
216 EXPECT_EQ(0, | 216 EXPECT_EQ(0, |
217 display.bounds().bottom() - display.work_area().bottom()); | 217 display.bounds().bottom() - display.work_area().bottom()); |
218 | 218 |
219 // Make sure the bounds of the two widgets changed. | 219 // Make sure the bounds of the two widgets changed. |
220 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 220 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
221 gfx::Screen::GetPrimaryDisplay().bounds().bottom()); | 221 Shell::GetAshScreen()->GetPrimaryDisplay().bounds().bottom()); |
222 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 222 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
223 gfx::Screen::GetPrimaryDisplay().bounds().bottom()); | 223 Shell::GetAshScreen()->GetPrimaryDisplay().bounds().bottom()); |
224 | 224 |
225 // And show it again. | 225 // And show it again. |
226 SetState(shelf, ShelfLayoutManager::VISIBLE); | 226 SetState(shelf, ShelfLayoutManager::VISIBLE); |
227 // Run the animation to completion. | 227 // Run the animation to completion. |
228 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 228 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
229 StepWidgetLayerAnimatorToEnd(shelf->status()); | 229 StepWidgetLayerAnimatorToEnd(shelf->status()); |
230 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 230 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
231 EXPECT_EQ(shelf_height, | 231 EXPECT_EQ(shelf_height, |
232 display.bounds().bottom() - display.work_area().bottom()); | 232 display.bounds().bottom() - display.work_area().bottom()); |
233 | 233 |
234 // Make sure the bounds of the two widgets changed. | 234 // Make sure the bounds of the two widgets changed. |
235 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); | 235 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); |
236 int bottom = gfx::Screen::GetPrimaryDisplay().bounds().bottom() - | 236 int bottom = |
| 237 Shell::GetAshScreen()->GetPrimaryDisplay().bounds().bottom() - |
237 shelf_height; | 238 shelf_height; |
238 EXPECT_EQ(launcher_bounds.y(), | 239 EXPECT_EQ(launcher_bounds.y(), |
239 bottom + (shelf->GetIdealBounds().height() - | 240 bottom + (shelf->GetIdealBounds().height() - |
240 launcher_bounds.height()) / 2); | 241 launcher_bounds.height()) / 2); |
241 status_bounds = shelf->status()->GetNativeView()->bounds(); | 242 status_bounds = shelf->status()->GetNativeView()->bounds(); |
242 EXPECT_EQ(status_bounds.y(), | 243 EXPECT_EQ(status_bounds.y(), |
243 bottom + shelf_height - status_bounds.height()); | 244 bottom + shelf_height - status_bounds.height()); |
244 } | 245 } |
245 | 246 |
246 // Makes sure LayoutShelf invoked while animating cleans things up. | 247 // Makes sure LayoutShelf invoked while animating cleans things up. |
247 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { | 248 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { |
248 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 249 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
249 // Force an initial layout. | 250 // Force an initial layout. |
250 shelf->LayoutShelf(); | 251 shelf->LayoutShelf(); |
251 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 252 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
252 | 253 |
253 const aura::DisplayManager* manager = | 254 const aura::DisplayManager* manager = |
254 aura::Env::GetInstance()->display_manager(); | 255 aura::Env::GetInstance()->display_manager(); |
255 const gfx::Display& display = | 256 const gfx::Display& display = |
256 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 257 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
257 | 258 |
258 // Hide the shelf. | 259 // Hide the shelf. |
259 SetState(shelf, ShelfLayoutManager::HIDDEN); | 260 SetState(shelf, ShelfLayoutManager::HIDDEN); |
260 shelf->LayoutShelf(); | 261 shelf->LayoutShelf(); |
261 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 262 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
262 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); | 263 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); |
263 | 264 |
264 // Make sure the bounds of the two widgets changed. | 265 // Make sure the bounds of the two widgets changed. |
265 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 266 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
266 gfx::Screen::GetPrimaryDisplay().bounds().bottom()); | 267 Shell::GetAshScreen()->GetPrimaryDisplay().bounds().bottom()); |
267 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 268 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
268 gfx::Screen::GetPrimaryDisplay().bounds().bottom()); | 269 Shell::GetAshScreen()->GetPrimaryDisplay().bounds().bottom()); |
269 } | 270 } |
270 | 271 |
271 // Makes sure the launcher is initially sized correctly. | 272 // Makes sure the launcher is initially sized correctly. |
272 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { | 273 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { |
273 Launcher* launcher = Shell::GetInstance()->launcher(); | 274 Launcher* launcher = Shell::GetInstance()->launcher(); |
274 ASSERT_TRUE(launcher); | 275 ASSERT_TRUE(launcher); |
275 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 276 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); |
276 ASSERT_TRUE(shelf_layout_manager); | 277 ASSERT_TRUE(shelf_layout_manager); |
277 ASSERT_TRUE(shelf_layout_manager->status()); | 278 ASSERT_TRUE(shelf_layout_manager->status()); |
278 int status_width = | 279 int status_width = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 widget->Show(); | 322 widget->Show(); |
322 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); | 323 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); |
323 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 324 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
324 | 325 |
325 // LayoutShelf() forces the animation to completion, at which point the | 326 // LayoutShelf() forces the animation to completion, at which point the |
326 // launcher should go off the screen. | 327 // launcher should go off the screen. |
327 shelf->LayoutShelf(); | 328 shelf->LayoutShelf(); |
328 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 329 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
329 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 330 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); |
330 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 331 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
331 gfx::Screen::GetDisplayNearestWindow(root).work_area().bottom()); | 332 Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 333 root).work_area().bottom()); |
332 | 334 |
333 // Move the mouse to the bottom of the screen. | 335 // Move the mouse to the bottom of the screen. |
334 generator.MoveMouseTo(0, root->bounds().bottom() - 1); | 336 generator.MoveMouseTo(0, root->bounds().bottom() - 1); |
335 | 337 |
336 // Shelf should be shown again (but it shouldn't have changed the work area). | 338 // Shelf should be shown again (but it shouldn't have changed the work area). |
337 SetState(shelf, ShelfLayoutManager::AUTO_HIDE); | 339 SetState(shelf, ShelfLayoutManager::AUTO_HIDE); |
338 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 340 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
339 shelf->LayoutShelf(); | 341 shelf->LayoutShelf(); |
340 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), | 342 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(), |
341 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 343 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); |
342 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 344 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
343 gfx::Screen::GetDisplayNearestWindow(root).work_area().bottom()); | 345 Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 346 root).work_area().bottom()); |
344 | 347 |
345 // Move mouse back up. | 348 // Move mouse back up. |
346 generator.MoveMouseTo(0, 0); | 349 generator.MoveMouseTo(0, 0); |
347 SetState(shelf, ShelfLayoutManager::AUTO_HIDE); | 350 SetState(shelf, ShelfLayoutManager::AUTO_HIDE); |
348 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 351 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
349 shelf->LayoutShelf(); | 352 shelf->LayoutShelf(); |
350 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, | 353 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize, |
351 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); | 354 shelf->launcher_widget()->GetWindowBoundsInScreen().y()); |
352 | 355 |
353 // Drag mouse to bottom of screen. | 356 // Drag mouse to bottom of screen. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 431 |
429 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 432 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
430 views::Widget* widget = new views::Widget; | 433 views::Widget* widget = new views::Widget; |
431 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 434 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
432 params.bounds = gfx::Rect(0, 0, 200, 200); | 435 params.bounds = gfx::Rect(0, 0, 200, 200); |
433 // Widget is now owned by the parent window. | 436 // Widget is now owned by the parent window. |
434 widget->Init(params); | 437 widget->Init(params); |
435 widget->Show(); | 438 widget->Show(); |
436 aura::Window* window = widget->GetNativeWindow(); | 439 aura::Window* window = widget->GetNativeWindow(); |
437 gfx::Rect display_bounds( | 440 gfx::Rect display_bounds( |
438 gfx::Screen::GetDisplayNearestWindow(window).bounds()); | 441 Shell::GetAshScreen()->GetDisplayNearestWindow(window).bounds()); |
439 | 442 |
440 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 443 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
441 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); | 444 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); |
442 EXPECT_EQ(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize, | 445 EXPECT_EQ(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize, |
443 shelf->GetMaximizedWindowBounds(window).bottom()); | 446 shelf->GetMaximizedWindowBounds(window).bottom()); |
444 | 447 |
445 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 448 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
446 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 449 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
447 EXPECT_GT(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize, | 450 EXPECT_GT(display_bounds.bottom() - ShelfLayoutManager::kAutoHideSize, |
448 shelf->GetMaximizedWindowBounds(window).bottom()); | 451 shelf->GetMaximizedWindowBounds(window).bottom()); |
449 | 452 |
450 widget->Maximize(); | 453 widget->Maximize(); |
451 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 454 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
452 EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(), | 455 EXPECT_EQ(Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 456 window).work_area().bottom(), |
453 widget->GetWorkAreaBoundsInScreen().bottom()); | 457 widget->GetWorkAreaBoundsInScreen().bottom()); |
454 | 458 |
455 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 459 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
456 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); | 460 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); |
457 EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(), | 461 EXPECT_EQ(Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 462 window).work_area().bottom(), |
458 widget->GetWorkAreaBoundsInScreen().bottom()); | 463 widget->GetWorkAreaBoundsInScreen().bottom()); |
459 | 464 |
460 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 465 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
461 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 466 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
462 EXPECT_EQ(gfx::Screen::GetDisplayNearestWindow(window).work_area().bottom(), | 467 EXPECT_EQ(Shell::GetAshScreen()->GetDisplayNearestWindow( |
| 468 window).work_area().bottom(), |
463 widget->GetWorkAreaBoundsInScreen().bottom()); | 469 widget->GetWorkAreaBoundsInScreen().bottom()); |
464 } | 470 } |
465 | 471 |
466 // Verifies the shelf is visible when status/launcher is focused. | 472 // Verifies the shelf is visible when status/launcher is focused. |
467 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrLauncherFocused) { | 473 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrLauncherFocused) { |
468 // Since ShelfLayoutManager queries for mouse location, move the mouse so | 474 // Since ShelfLayoutManager queries for mouse location, move the mouse so |
469 // it isn't over the shelf. | 475 // it isn't over the shelf. |
470 aura::test::EventGenerator generator( | 476 aura::test::EventGenerator generator( |
471 Shell::GetPrimaryRootWindow(), gfx::Point()); | 477 Shell::GetPrimaryRootWindow(), gfx::Point()); |
472 generator.MoveMouseTo(0, 0); | 478 generator.MoveMouseTo(0, 0); |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 EXPECT_TRUE(status_area->IsMessageBubbleShown()); | 955 EXPECT_TRUE(status_area->IsMessageBubbleShown()); |
950 } else { | 956 } else { |
951 EXPECT_FALSE(shelf->IsVisible()); | 957 EXPECT_FALSE(shelf->IsVisible()); |
952 EXPECT_FALSE(status_area->IsMessageBubbleShown()); | 958 EXPECT_FALSE(status_area->IsMessageBubbleShown()); |
953 } | 959 } |
954 } | 960 } |
955 } | 961 } |
956 | 962 |
957 } // namespace internal | 963 } // namespace internal |
958 } // namespace ash | 964 } // namespace ash |
OLD | NEW |