| 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/wm/dock/docked_window_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shelf/shelf_types.h" | 13 #include "ash/shelf/shelf_types.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
| 17 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 18 #include "ash/test/cursor_manager_test_api.h" | 18 #include "ash/test/cursor_manager_test_api.h" |
| 19 #include "ash/test/shell_test_api.h" | 19 #include "ash/test/shell_test_api.h" |
| 20 #include "ash/test/test_launcher_delegate.h" | 20 #include "ash/test/test_launcher_delegate.h" |
| 21 #include "ash/wm/coordinate_conversion.h" | 21 #include "ash/wm/coordinate_conversion.h" |
| 22 #include "ash/wm/dock/docked_window_layout_manager.h" | 22 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 23 #include "ash/wm/drag_window_resizer.h" | 23 #include "ash/wm/drag_window_resizer.h" |
| 24 #include "ash/wm/panels/panel_layout_manager.h" | 24 #include "ash/wm/panels/panel_layout_manager.h" |
| 25 #include "ash/wm/window_settings.h" | 25 #include "ash/wm/window_state.h" |
| 26 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
| 27 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
| 30 #include "ui/aura/test/test_window_delegate.h" | 30 #include "ui/aura/test/test_window_delegate.h" |
| 31 #include "ui/base/hit_test.h" | 31 #include "ui/base/hit_test.h" |
| 32 #include "ui/base/ui_base_types.h" | 32 #include "ui/base/ui_base_types.h" |
| 33 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
| 34 | 34 |
| 35 namespace ash { | 35 namespace ash { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 else if (edge == DOCKED_EDGE_RIGHT) | 193 else if (edge == DOCKED_EDGE_RIGHT) |
| 194 dx += work_area.right() - 1 - initial_location_in_screen.x(); | 194 dx += work_area.right() - 1 - initial_location_in_screen.x(); |
| 195 DragMove(dx, dy); | 195 DragMove(dx, dy); |
| 196 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 196 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 197 // Release the mouse and the panel should be attached to the dock. | 197 // Release the mouse and the panel should be attached to the dock. |
| 198 DragEnd(); | 198 DragEnd(); |
| 199 | 199 |
| 200 // x-coordinate can get adjusted by snapping or sticking. | 200 // x-coordinate can get adjusted by snapping or sticking. |
| 201 // y-coordinate could be changed by possible automatic layout if docked. | 201 // y-coordinate could be changed by possible automatic layout if docked. |
| 202 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && | 202 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && |
| 203 GetRestoreBoundsInScreen(window) == NULL) { | 203 !wm::GetWindowState(window)->HasRestoreBounds()) { |
| 204 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 204 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool test_panels() const { | 208 bool test_panels() const { |
| 209 return window_type_ == aura::client::WINDOW_TYPE_PANEL; | 209 return window_type_ == aura::client::WINDOW_TYPE_PANEL; |
| 210 } | 210 } |
| 211 | 211 |
| 212 private: | 212 private: |
| 213 scoped_ptr<WindowResizer> resizer_; | 213 scoped_ptr<WindowResizer> resizer_; |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 694 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 695 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 695 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 696 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 696 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 697 // Desktop work area should now shrink. | 697 // Desktop work area should now shrink. |
| 698 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 698 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 699 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 699 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 700 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 700 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 701 | 701 |
| 702 // Maximize the second window - Maximized area should be shrunk. | 702 // Maximize the second window - Maximized area should be shrunk. |
| 703 const gfx::Rect restored_bounds = w2->bounds(); | 703 const gfx::Rect restored_bounds = w2->bounds(); |
| 704 wm::MaximizeWindow(w2.get()); | 704 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); |
| 705 w2_state->Maximize(); |
| 705 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 706 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 706 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 707 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 707 w2->bounds().width()); | 708 w2->bounds().width()); |
| 708 | 709 |
| 709 // Detach the first window (this should require very little drag). | 710 // Detach the first window (this should require very little drag). |
| 710 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); | 711 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); |
| 711 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 712 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 712 DragMove(-35, 10); | 713 DragMove(-35, 10); |
| 713 // Alignment is set to "NONE" when drag starts. | 714 // Alignment is set to "NONE" when drag starts. |
| 714 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); | 715 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 738 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); | 739 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); |
| 739 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 740 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 740 // Second window should still be in the desktop. | 741 // Second window should still be in the desktop. |
| 741 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 742 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 742 // Maximized window should be shrunk. | 743 // Maximized window should be shrunk. |
| 743 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 744 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 744 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 745 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 745 w2->bounds().width()); | 746 w2->bounds().width()); |
| 746 | 747 |
| 747 // Unmaximize the second window. | 748 // Unmaximize the second window. |
| 748 wm::RestoreWindow(w2.get()); | 749 w2_state->Restore(); |
| 749 // Its bounds should get restored. | 750 // Its bounds should get restored. |
| 750 EXPECT_EQ(restored_bounds, w2->bounds()); | 751 EXPECT_EQ(restored_bounds, w2->bounds()); |
| 751 } | 752 } |
| 752 | 753 |
| 753 // Dock one window. Test the sticky behavior near screen or desktop edge. | 754 // Dock one window. Test the sticky behavior near screen or desktop edge. |
| 754 TEST_P(DockedWindowResizerTest, AttachOneTestSticky) | 755 TEST_P(DockedWindowResizerTest, AttachOneTestSticky) |
| 755 { | 756 { |
| 756 if (!SupportsHostWindowResize()) | 757 if (!SupportsHostWindowResize()) |
| 757 return; | 758 return; |
| 758 | 759 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 // Drag down almost to shelf. A panel will snap, a regular window won't. | 1023 // Drag down almost to shelf. A panel will snap, a regular window won't. |
| 1023 ShelfWidget* shelf = Launcher::ForPrimaryDisplay()->shelf_widget(); | 1024 ShelfWidget* shelf = Launcher::ForPrimaryDisplay()->shelf_widget(); |
| 1024 const int shelf_y = shelf->GetWindowBoundsInScreen().y(); | 1025 const int shelf_y = shelf->GetWindowBoundsInScreen().y(); |
| 1025 const int kDistanceFromShelf = 10; | 1026 const int kDistanceFromShelf = 10; |
| 1026 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); | 1027 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); |
| 1027 DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom()); | 1028 DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom()); |
| 1028 DragEnd(); | 1029 DragEnd(); |
| 1029 if (test_panels()) { | 1030 if (test_panels()) { |
| 1030 // The panel should be touching the shelf and attached. | 1031 // The panel should be touching the shelf and attached. |
| 1031 EXPECT_EQ(shelf_y, w1->bounds().bottom()); | 1032 EXPECT_EQ(shelf_y, w1->bounds().bottom()); |
| 1032 EXPECT_TRUE(wm::GetWindowSettings(w1.get())->panel_attached()); | 1033 EXPECT_TRUE(wm::GetWindowState(w1.get())->panel_attached()); |
| 1033 } else { | 1034 } else { |
| 1034 // The window should not be touching the shelf. | 1035 // The window should not be touching the shelf. |
| 1035 EXPECT_EQ(shelf_y - kDistanceFromShelf, w1->bounds().bottom()); | 1036 EXPECT_EQ(shelf_y - kDistanceFromShelf, w1->bounds().bottom()); |
| 1036 } | 1037 } |
| 1037 } | 1038 } |
| 1038 | 1039 |
| 1039 // Tests run twice - on both panels and normal windows | 1040 // Tests run twice - on both panels and normal windows |
| 1040 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1041 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1041 DockedWindowResizerTest, | 1042 DockedWindowResizerTest, |
| 1042 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 1043 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
| 1043 aura::client::WINDOW_TYPE_PANEL)); | 1044 aura::client::WINDOW_TYPE_PANEL)); |
| 1044 } // namespace internal | 1045 } // namespace internal |
| 1045 } // namespace ash | 1046 } // namespace ash |
| OLD | NEW |