| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/wm/dock/docked_window_resizer.h" | 5 #include "ash/common/wm/dock/docked_window_resizer.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/shelf.h" | |
| 10 #include "ash/common/shelf/shelf_types.h" | 9 #include "ash/common/shelf/shelf_types.h" |
| 11 #include "ash/common/shelf/shelf_widget.h" | 10 #include "ash/common/shelf/shelf_widget.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/common/wm/dock/docked_window_layout_manager.h" | 13 #include "ash/common/wm/dock/docked_window_layout_manager.h" |
| 14 #include "ash/common/wm/panels/panel_layout_manager.h" | 14 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 15 #include "ash/common/wm/window_state.h" | 15 #include "ash/common/wm/window_state.h" |
| 16 #include "ash/common/wm/wm_event.h" | 16 #include "ash/common/wm/wm_event.h" |
| 17 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| 18 #include "ash/display/window_tree_host_manager.h" | 18 #include "ash/display/window_tree_host_manager.h" |
| 19 #include "ash/root_window_controller.h" | 19 #include "ash/root_window_controller.h" |
| 20 #include "ash/screen_util.h" | 20 #include "ash/screen_util.h" |
| 21 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 std::unique_ptr<aura::Window> window( | 354 std::unique_ptr<aura::Window> window( |
| 355 CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 355 CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 356 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 356 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 357 | 357 |
| 358 // The window should be docked at the right edge. | 358 // The window should be docked at the right edge. |
| 359 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), | 359 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), |
| 360 window->GetBoundsInScreen().right()); | 360 window->GetBoundsInScreen().right()); |
| 361 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 361 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 362 | 362 |
| 363 // set launcher shelf to be aligned on the right | 363 // set launcher shelf to be aligned on the right |
| 364 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 364 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
| 365 // The window should have moved and get attached to the left dock. | 365 // The window should have moved and get attached to the left dock. |
| 366 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), | 366 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), |
| 367 window->GetBoundsInScreen().x()); | 367 window->GetBoundsInScreen().x()); |
| 368 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 368 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 369 | 369 |
| 370 // set launcher shelf to be aligned on the left | 370 // set launcher shelf to be aligned on the left |
| 371 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT); | 371 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 372 // The window should have moved and get attached to the right edge. | 372 // The window should have moved and get attached to the right edge. |
| 373 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), | 373 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), |
| 374 window->GetBoundsInScreen().right()); | 374 window->GetBoundsInScreen().right()); |
| 375 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 375 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 376 | 376 |
| 377 // set launcher shelf to be aligned at the bottom | 377 // set launcher shelf to be aligned at the bottom |
| 378 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 378 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
| 379 // The window should stay in the right edge. | 379 // The window should stay in the right edge. |
| 380 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), | 380 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(), |
| 381 window->GetBoundsInScreen().right()); | 381 window->GetBoundsInScreen().right()); |
| 382 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 382 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 // Dock on the right side, try to undock, then drag more to really undock | 385 // Dock on the right side, try to undock, then drag more to really undock |
| 386 TEST_P(DockedWindowResizerTest, AttachTryDetach) { | 386 TEST_P(DockedWindowResizerTest, AttachTryDetach) { |
| 387 if (!SupportsHostWindowResize()) | 387 if (!SupportsHostWindowResize()) |
| 388 return; | 388 return; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 .work_area(); | 588 .work_area(); |
| 589 DockedWindowLayoutManager* manager = | 589 DockedWindowLayoutManager* manager = |
| 590 DockedWindowLayoutManager::Get(WmWindowAura::Get(w1.get())); | 590 DockedWindowLayoutManager::Get(WmWindowAura::Get(w1.get())); |
| 591 | 591 |
| 592 // Docked window should be centered vertically in the work area. | 592 // Docked window should be centered vertically in the work area. |
| 593 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); | 593 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); |
| 594 // Docked background should extend to the bottom of work area. | 594 // Docked background should extend to the bottom of work area. |
| 595 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); | 595 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); |
| 596 | 596 |
| 597 // Turn on shelf auto-hide. | 597 // Turn on shelf auto-hide. |
| 598 Shelf::ForPrimaryDisplay()->SetAutoHideBehavior( | 598 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 599 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
| 600 work_area = display::Screen::GetScreen() | 599 work_area = display::Screen::GetScreen() |
| 601 ->GetDisplayNearestWindow(w1.get()) | 600 ->GetDisplayNearestWindow(w1.get()) |
| 602 .work_area(); | 601 .work_area(); |
| 603 // Docked window should be centered vertically in the work area. | 602 // Docked window should be centered vertically in the work area. |
| 604 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); | 603 EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y()); |
| 605 // Docked background should extend to the bottom of work area. | 604 // Docked background should extend to the bottom of work area. |
| 606 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); | 605 EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom()); |
| 607 } | 606 } |
| 608 | 607 |
| 609 // Dock one window, try to dock another window on the opposite side (should not | 608 // Dock one window, try to dock another window on the opposite side (should not |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 // Detach and drag down to shelf. | 1364 // Detach and drag down to shelf. |
| 1366 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); | 1365 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); |
| 1367 DragMove(-40, 0); | 1366 DragMove(-40, 0); |
| 1368 // Alignment is set to "NONE" when drag starts. | 1367 // Alignment is set to "NONE" when drag starts. |
| 1369 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 1368 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 1370 // Release the mouse and the window should be no longer attached to the edge. | 1369 // Release the mouse and the window should be no longer attached to the edge. |
| 1371 DragEnd(); | 1370 DragEnd(); |
| 1372 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 1371 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 1373 | 1372 |
| 1374 // Drag down almost to shelf. A panel will snap, a regular window won't. | 1373 // Drag down almost to shelf. A panel will snap, a regular window won't. |
| 1375 ShelfWidget* shelf = Shelf::ForPrimaryDisplay()->shelf_widget(); | 1374 ShelfWidget* shelf = GetPrimaryShelf()->GetShelfWidgetForTesting(); |
| 1376 const int shelf_y = shelf->GetWindowBoundsInScreen().y(); | 1375 const int shelf_y = shelf->GetWindowBoundsInScreen().y(); |
| 1377 const int kDistanceFromShelf = 10; | 1376 const int kDistanceFromShelf = 10; |
| 1378 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); | 1377 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); |
| 1379 DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom()); | 1378 DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom()); |
| 1380 DragEnd(); | 1379 DragEnd(); |
| 1381 if (test_panels()) { | 1380 if (test_panels()) { |
| 1382 // The panel should be touching the shelf and attached. | 1381 // The panel should be touching the shelf and attached. |
| 1383 EXPECT_EQ(shelf_y, w1->bounds().bottom()); | 1382 EXPECT_EQ(shelf_y, w1->bounds().bottom()); |
| 1384 EXPECT_TRUE(wm::GetWindowState(w1.get())->panel_attached()); | 1383 EXPECT_TRUE(wm::GetWindowState(w1.get())->panel_attached()); |
| 1385 } else { | 1384 } else { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 EXPECT_TRUE(window_state->IsMaximized()); | 1570 EXPECT_TRUE(window_state->IsMaximized()); |
| 1572 } | 1571 } |
| 1573 | 1572 |
| 1574 // Tests run twice - on both panels and normal windows | 1573 // Tests run twice - on both panels and normal windows |
| 1575 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1574 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1576 DockedWindowResizerTest, | 1575 DockedWindowResizerTest, |
| 1577 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 1576 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
| 1578 ui::wm::WINDOW_TYPE_PANEL)); | 1577 ui::wm::WINDOW_TYPE_PANEL)); |
| 1579 | 1578 |
| 1580 } // namespace ash | 1579 } // namespace ash |
| OLD | NEW |