| 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/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shelf/shelf_model.h" | 12 #include "ash/shelf/shelf_model.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" |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // Dock two windows, undock one. | 700 // Dock two windows, undock one. |
| 701 // Test the docked windows area size and default container resizing. | 701 // Test the docked windows area size and default container resizing. |
| 702 TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) { | 702 TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) { |
| 703 if (!SupportsHostWindowResize()) | 703 if (!SupportsHostWindowResize()) |
| 704 return; | 704 return; |
| 705 UpdateDisplay("600x600"); | 705 UpdateDisplay("600x600"); |
| 706 | 706 |
| 707 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 707 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 708 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); | 708 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); |
| 709 // Work area should cover the whole screen. | 709 // Work area should cover the whole screen. |
| 710 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 710 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(), |
| 711 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 711 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 712 | 712 |
| 713 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 713 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 714 // A window should be docked at the right edge. | 714 // A window should be docked at the right edge. |
| 715 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 715 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 716 w1->GetBoundsInScreen().right()); | 716 w1->GetBoundsInScreen().right()); |
| 717 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 717 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 718 DockedWindowLayoutManager* manager = | 718 DockedWindowLayoutManager* manager = |
| 719 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 719 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 720 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 720 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 721 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 721 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 772 } |
| 773 | 773 |
| 774 // Dock one of the windows. Maximize other testing desktop resizing. | 774 // Dock one of the windows. Maximize other testing desktop resizing. |
| 775 TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) { | 775 TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) { |
| 776 if (!SupportsHostWindowResize()) | 776 if (!SupportsHostWindowResize()) |
| 777 return; | 777 return; |
| 778 | 778 |
| 779 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 779 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 780 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); | 780 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); |
| 781 // Work area should cover the whole screen. | 781 // Work area should cover the whole screen. |
| 782 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 782 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(), |
| 783 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 783 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 784 | 784 |
| 785 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 785 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 786 // A window should be docked at the right edge. | 786 // A window should be docked at the right edge. |
| 787 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 787 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 788 w1->GetBoundsInScreen().right()); | 788 w1->GetBoundsInScreen().right()); |
| 789 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 789 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 790 DockedWindowLayoutManager* manager = | 790 DockedWindowLayoutManager* manager = |
| 791 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 791 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 792 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 792 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 793 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 793 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 807 // The second window should be floating on the desktop. | 807 // The second window should be floating on the desktop. |
| 808 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - | 808 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - |
| 809 (w2->bounds().width()/2 + 20), | 809 (w2->bounds().width()/2 + 20), |
| 810 w2->GetBoundsInScreen().right()); | 810 w2->GetBoundsInScreen().right()); |
| 811 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 811 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 812 // Dock width should be set to remaining single docked window. | 812 // Dock width should be set to remaining single docked window. |
| 813 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 813 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 814 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 814 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 815 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 815 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 816 // Desktop work area should now shrink. | 816 // Desktop work area should now shrink. |
| 817 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 817 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 818 docked_width(manager) - min_dock_gap(), | 818 docked_width(manager) - min_dock_gap(), |
| 819 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 819 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 820 | 820 |
| 821 // Maximize the second window - Maximized area should be shrunk. | 821 // Maximize the second window - Maximized area should be shrunk. |
| 822 const gfx::Rect restored_bounds = w2->bounds(); | 822 const gfx::Rect restored_bounds = w2->bounds(); |
| 823 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); | 823 wm::WindowState* w2_state = wm::GetWindowState(w2.get()); |
| 824 w2_state->Maximize(); | 824 w2_state->Maximize(); |
| 825 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 825 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 826 docked_width(manager) - min_dock_gap(), | 826 docked_width(manager) - min_dock_gap(), |
| 827 w2->bounds().width()); | 827 w2->bounds().width()); |
| 828 | 828 |
| 829 // Detach the first window (this should require very little drag). | 829 // Detach the first window (this should require very little drag). |
| 830 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); | 830 ASSERT_NO_FATAL_FAILURE(DragStart(w1.get())); |
| 831 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 831 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 832 DragMove(-35, 10); | 832 DragMove(-35, 10); |
| 833 // Alignment is set to "NONE" when drag starts. | 833 // Alignment is set to "NONE" when drag starts. |
| 834 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 834 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 835 // Release the mouse and the window should be no longer attached to the edge. | 835 // Release the mouse and the window should be no longer attached to the edge. |
| 836 DragEnd(); | 836 DragEnd(); |
| 837 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 837 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 838 // Dock should get shrunk and desktop should get expanded. | 838 // Dock should get shrunk and desktop should get expanded. |
| 839 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); | 839 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); |
| 840 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 840 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 841 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 841 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 842 EXPECT_EQ(0, docked_width(manager)); | 842 EXPECT_EQ(0, docked_width(manager)); |
| 843 // The second window should now get resized and take up the whole screen. | 843 // The second window should now get resized and take up the whole screen. |
| 844 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 844 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(), |
| 845 w2->bounds().width()); | 845 w2->bounds().width()); |
| 846 | 846 |
| 847 // Dock the first window to the left edge. | 847 // Dock the first window to the left edge. |
| 848 // Click at an offset from origin to prevent snapping. | 848 // Click at an offset from origin to prevent snapping. |
| 849 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w1.get(), 10, 0)); | 849 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w1.get(), 10, 0)); |
| 850 // Drag left to get pointer touching the screen edge. | 850 // Drag left to get pointer touching the screen edge. |
| 851 DragMove(-w1->bounds().x() - 10, 0); | 851 DragMove(-w1->bounds().x() - 10, 0); |
| 852 // Alignment set to "NONE" during the drag of the window when none are docked. | 852 // Alignment set to "NONE" during the drag of the window when none are docked. |
| 853 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); | 853 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager)); |
| 854 // Release the mouse and the window should be now attached to the edge. | 854 // Release the mouse and the window should be now attached to the edge. |
| 855 DragEnd(); | 855 DragEnd(); |
| 856 // Dock should get expanded and desktop should get shrunk. | 856 // Dock should get expanded and desktop should get shrunk. |
| 857 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 857 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 858 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager)); | 858 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager)); |
| 859 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 859 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 860 // Second window should still be in the desktop. | 860 // Second window should still be in the desktop. |
| 861 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 861 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 862 // Maximized window should be shrunk. | 862 // Maximized window should be shrunk. |
| 863 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 863 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 864 docked_width(manager) - min_dock_gap(), | 864 docked_width(manager) - min_dock_gap(), |
| 865 w2->bounds().width()); | 865 w2->bounds().width()); |
| 866 | 866 |
| 867 // Unmaximize the second window. | 867 // Unmaximize the second window. |
| 868 w2_state->Restore(); | 868 w2_state->Restore(); |
| 869 // Its bounds should get restored. | 869 // Its bounds should get restored. |
| 870 EXPECT_EQ(restored_bounds, w2->bounds()); | 870 EXPECT_EQ(restored_bounds, w2->bounds()); |
| 871 } | 871 } |
| 872 | 872 |
| 873 // Dock one window. Test the sticky behavior near screen or desktop edge. | 873 // Dock one window. Test the sticky behavior near screen or desktop edge. |
| 874 TEST_P(DockedWindowResizerTest, AttachOneTestSticky) { | 874 TEST_P(DockedWindowResizerTest, AttachOneTestSticky) { |
| 875 if (!SupportsHostWindowResize()) | 875 if (!SupportsHostWindowResize()) |
| 876 return; | 876 return; |
| 877 | 877 |
| 878 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 878 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 879 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); | 879 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); |
| 880 // Work area should cover the whole screen. | 880 // Work area should cover the whole screen. |
| 881 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 881 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(), |
| 882 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 882 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 883 | 883 |
| 884 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w1.get(), 20); | 884 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w1.get(), 20); |
| 885 // A window should be docked at the left edge. | 885 // A window should be docked at the left edge. |
| 886 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), | 886 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), |
| 887 w1->GetBoundsInScreen().x()); | 887 w1->GetBoundsInScreen().x()); |
| 888 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 888 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 889 DockedWindowLayoutManager* manager = | 889 DockedWindowLayoutManager* manager = |
| 890 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 890 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 891 // The first window should be docked. | 891 // The first window should be docked. |
| 892 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), | 892 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // Release the mouse and the window should be attached to the edge. | 954 // Release the mouse and the window should be attached to the edge. |
| 955 DragEnd(); | 955 DragEnd(); |
| 956 // Both windows are docked now. | 956 // Both windows are docked now. |
| 957 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 957 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 958 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 958 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 959 // Dock should get expanded and desktop should get shrunk. | 959 // Dock should get expanded and desktop should get shrunk. |
| 960 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager)); | 960 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager)); |
| 961 EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()), | 961 EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()), |
| 962 docked_width(manager)); | 962 docked_width(manager)); |
| 963 // Desktop work area should now shrink by dock width. | 963 // Desktop work area should now shrink by dock width. |
| 964 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 964 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 965 docked_width(manager) - min_dock_gap(), | 965 docked_width(manager) - min_dock_gap(), |
| 966 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 966 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 967 } | 967 } |
| 968 | 968 |
| 969 // Dock two windows, resize one. | 969 // Dock two windows, resize one. |
| 970 // Test the docked windows area size and remaining desktop resizing. | 970 // Test the docked windows area size and remaining desktop resizing. |
| 971 TEST_P(DockedWindowResizerTest, ResizeOneOfTwoWindows) { | 971 TEST_P(DockedWindowResizerTest, ResizeOneOfTwoWindows) { |
| 972 if (!SupportsHostWindowResize()) | 972 if (!SupportsHostWindowResize()) |
| 973 return; | 973 return; |
| 974 | 974 |
| 975 // Wider display to start since panels are limited to half the display width. | 975 // Wider display to start since panels are limited to half the display width. |
| 976 UpdateDisplay("1000x600"); | 976 UpdateDisplay("1000x600"); |
| 977 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 977 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 978 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); | 978 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); |
| 979 // Work area should cover the whole screen. | 979 // Work area should cover the whole screen. |
| 980 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 980 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(), |
| 981 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 981 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 982 | 982 |
| 983 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 983 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 984 // A window should be docked at the right edge. | 984 // A window should be docked at the right edge. |
| 985 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 985 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 986 w1->GetBoundsInScreen().right()); | 986 w1->GetBoundsInScreen().right()); |
| 987 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 987 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 988 DockedWindowLayoutManager* manager = | 988 DockedWindowLayoutManager* manager = |
| 989 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 989 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 990 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 990 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 991 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 991 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1014 // Dock should still have both windows in it. | 1014 // Dock should still have both windows in it. |
| 1015 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1015 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 1016 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 1016 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 1017 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1017 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1018 // w1 is now wider than before. The dock should expand and be as wide as w1. | 1018 // w1 is now wider than before. The dock should expand and be as wide as w1. |
| 1019 EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width()); | 1019 EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width()); |
| 1020 // Both windows should get resized since they both don't have min/max size. | 1020 // Both windows should get resized since they both don't have min/max size. |
| 1021 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 1021 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 1022 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1022 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 1023 // Desktop work area should shrink. | 1023 // Desktop work area should shrink. |
| 1024 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 1024 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 1025 docked_width(manager) - min_dock_gap(), | 1025 docked_width(manager) - min_dock_gap(), |
| 1026 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 1026 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 1027 | 1027 |
| 1028 // Resize the first window left by more than the dock maximum width. | 1028 // Resize the first window left by more than the dock maximum width. |
| 1029 // This should cause the window width to be restricted by maximum dock width. | 1029 // This should cause the window width to be restricted by maximum dock width. |
| 1030 previous_width = w1->bounds().width(); | 1030 previous_width = w1->bounds().width(); |
| 1031 const int kResizeSpan2 = 250; | 1031 const int kResizeSpan2 = 250; |
| 1032 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), | 1032 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), |
| 1033 0, 20, | 1033 0, 20, |
| 1034 HTLEFT)); | 1034 HTLEFT)); |
| 1035 DragMove(-kResizeSpan2, 0); | 1035 DragMove(-kResizeSpan2, 0); |
| 1036 // Alignment set to "RIGHT" during the drag because dock has a window in it. | 1036 // Alignment set to "RIGHT" during the drag because dock has a window in it. |
| 1037 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1037 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1038 // Release the mouse and the window should be attached to the edge. | 1038 // Release the mouse and the window should be attached to the edge. |
| 1039 DragEnd(); | 1039 DragEnd(); |
| 1040 // Dock should still have both windows in it. | 1040 // Dock should still have both windows in it. |
| 1041 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1041 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 1042 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 1042 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 1043 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1043 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1044 // w1 is now as wide as the maximum dock width and the dock should get | 1044 // w1 is now as wide as the maximum dock width and the dock should get |
| 1045 // resized to the maximum width. | 1045 // resized to the maximum width. |
| 1046 EXPECT_EQ(max_width(), w1->bounds().width()); | 1046 EXPECT_EQ(max_width(), w1->bounds().width()); |
| 1047 // Both windows should get resized since they both don't have min/max size. | 1047 // Both windows should get resized since they both don't have min/max size. |
| 1048 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 1048 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 1049 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1049 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 1050 // Desktop work area should shrink. | 1050 // Desktop work area should shrink. |
| 1051 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 1051 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 1052 docked_width(manager) - min_dock_gap(), | 1052 docked_width(manager) - min_dock_gap(), |
| 1053 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 1053 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 1054 | 1054 |
| 1055 // Resize the first window right to get it completely inside the docked area. | 1055 // Resize the first window right to get it completely inside the docked area. |
| 1056 previous_width = w1->bounds().width(); | 1056 previous_width = w1->bounds().width(); |
| 1057 const int kResizeSpan3 = 100; | 1057 const int kResizeSpan3 = 100; |
| 1058 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), | 1058 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), |
| 1059 0, 20, | 1059 0, 20, |
| 1060 HTLEFT)); | 1060 HTLEFT)); |
| 1061 DragMove(kResizeSpan3, 0); | 1061 DragMove(kResizeSpan3, 0); |
| 1062 // Alignment set to "RIGHT" during the drag because dock has a window in it. | 1062 // Alignment set to "RIGHT" during the drag because dock has a window in it. |
| 1063 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1063 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1064 // Release the mouse and the window should be docked. | 1064 // Release the mouse and the window should be docked. |
| 1065 DragEnd(); | 1065 DragEnd(); |
| 1066 // Dock should still have both windows in it. | 1066 // Dock should still have both windows in it. |
| 1067 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1067 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 1068 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 1068 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 1069 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1069 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1070 // w1 should be narrower than before by the length of the drag. | 1070 // w1 should be narrower than before by the length of the drag. |
| 1071 EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width()); | 1071 EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width()); |
| 1072 // Both windows should get resized since they both don't have min/max size. | 1072 // Both windows should get resized since they both don't have min/max size. |
| 1073 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 1073 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 1074 // The dock should be as wide as w1 or w2. | 1074 // The dock should be as wide as w1 or w2. |
| 1075 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1075 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 1076 // Desktop work area should shrink. | 1076 // Desktop work area should shrink. |
| 1077 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 1077 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() - |
| 1078 docked_width(manager) - min_dock_gap(), | 1078 docked_width(manager) - min_dock_gap(), |
| 1079 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 1079 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 1080 | 1080 |
| 1081 // Resize the first window left to be overhang again. | 1081 // Resize the first window left to be overhang again. |
| 1082 previous_width = w1->bounds().width(); | 1082 previous_width = w1->bounds().width(); |
| 1083 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), | 1083 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(), |
| 1084 0, 20, | 1084 0, 20, |
| 1085 HTLEFT)); | 1085 HTLEFT)); |
| 1086 DragMove(-kResizeSpan3, 0); | 1086 DragMove(-kResizeSpan3, 0); |
| 1087 DragEnd(); | 1087 DragEnd(); |
| 1088 EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width()); | 1088 EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width()); |
| 1089 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1089 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1100 // Release the mouse and the window should be no longer attached to the edge. | 1100 // Release the mouse and the window should be no longer attached to the edge. |
| 1101 DragEnd(); | 1101 DragEnd(); |
| 1102 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); | 1102 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); |
| 1103 // Dock should be as wide as w2 (and same as ideal width). | 1103 // Dock should be as wide as w2 (and same as ideal width). |
| 1104 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1104 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1105 EXPECT_EQ(ideal_width(), docked_width(manager)); | 1105 EXPECT_EQ(ideal_width(), docked_width(manager)); |
| 1106 EXPECT_EQ(w2->bounds().width(), docked_width(manager)); | 1106 EXPECT_EQ(w2->bounds().width(), docked_width(manager)); |
| 1107 // The second window should be still docked. | 1107 // The second window should be still docked. |
| 1108 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 1108 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 1109 // Desktop work area should be inset. | 1109 // Desktop work area should be inset. |
| 1110 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w1.get()).width() - | 1110 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width() - |
| 1111 docked_width(manager) - min_dock_gap(), | 1111 docked_width(manager) - min_dock_gap(), |
| 1112 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).width()); | 1112 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width()); |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 // Dock a window, resize it and test that undocking it preserves the width. | 1115 // Dock a window, resize it and test that undocking it preserves the width. |
| 1116 TEST_P(DockedWindowResizerTest, ResizingKeepsWidth) { | 1116 TEST_P(DockedWindowResizerTest, ResizingKeepsWidth) { |
| 1117 if (!SupportsHostWindowResize()) | 1117 if (!SupportsHostWindowResize()) |
| 1118 return; | 1118 return; |
| 1119 | 1119 |
| 1120 // Wider display to start since panels are limited to half the display width. | 1120 // Wider display to start since panels are limited to half the display width. |
| 1121 UpdateDisplay("1000x600"); | 1121 UpdateDisplay("1000x600"); |
| 1122 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 1122 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 } | 1298 } |
| 1299 | 1299 |
| 1300 // Tests that dragging a window down to shelf attaches a panel but does not | 1300 // Tests that dragging a window down to shelf attaches a panel but does not |
| 1301 // attach a regular window. | 1301 // attach a regular window. |
| 1302 TEST_P(DockedWindowResizerTest, DragToShelf) { | 1302 TEST_P(DockedWindowResizerTest, DragToShelf) { |
| 1303 if (!SupportsHostWindowResize()) | 1303 if (!SupportsHostWindowResize()) |
| 1304 return; | 1304 return; |
| 1305 | 1305 |
| 1306 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 1306 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 1307 // Work area should cover the whole screen. | 1307 // Work area should cover the whole screen. |
| 1308 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w1.get()).width(), | 1308 EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width(), |
| 1309 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).width()); | 1309 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width()); |
| 1310 | 1310 |
| 1311 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 1311 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 1312 // A window should be docked at the right edge. | 1312 // A window should be docked at the right edge. |
| 1313 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 1313 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 1314 w1->GetBoundsInScreen().right()); | 1314 w1->GetBoundsInScreen().right()); |
| 1315 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1315 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 1316 DockedWindowLayoutManager* manager = | 1316 DockedWindowLayoutManager* manager = |
| 1317 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 1317 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 1318 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1318 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1319 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1319 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 1444 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 1445 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1445 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1446 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1446 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 1447 EXPECT_TRUE(window_state->IsDocked()); | 1447 EXPECT_TRUE(window_state->IsDocked()); |
| 1448 EXPECT_FALSE(window_state->IsSnapped()); | 1448 EXPECT_FALSE(window_state->IsSnapped()); |
| 1449 | 1449 |
| 1450 // Side snap at right edge. | 1450 // Side snap at right edge. |
| 1451 internal::SnapSizer::SnapWindow(window_state, | 1451 internal::SnapSizer::SnapWindow(window_state, |
| 1452 internal::SnapSizer::RIGHT_EDGE); | 1452 internal::SnapSizer::RIGHT_EDGE); |
| 1453 // The window should be snapped at the right edge and the dock should close. | 1453 // The window should be snapped at the right edge and the dock should close. |
| 1454 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get())); | 1454 gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get())); |
| 1455 EXPECT_EQ(0, docked_width(manager)); | 1455 EXPECT_EQ(0, docked_width(manager)); |
| 1456 EXPECT_EQ(work_area.height(), w1->bounds().height()); | 1456 EXPECT_EQ(work_area.height(), w1->bounds().height()); |
| 1457 EXPECT_EQ(work_area.right(), w1->bounds().right()); | 1457 EXPECT_EQ(work_area.right(), w1->bounds().right()); |
| 1458 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); | 1458 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); |
| 1459 EXPECT_FALSE(window_state->IsDocked()); | 1459 EXPECT_FALSE(window_state->IsDocked()); |
| 1460 EXPECT_TRUE(window_state->IsSnapped()); | 1460 EXPECT_TRUE(window_state->IsSnapped()); |
| 1461 | 1461 |
| 1462 // Dock again. | 1462 // Dock again. |
| 1463 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 1463 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 1464 // A window should be docked at the right edge. | 1464 // A window should be docked at the right edge. |
| 1465 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 1465 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 1466 w1->GetBoundsInScreen().right()); | 1466 w1->GetBoundsInScreen().right()); |
| 1467 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 1467 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 1468 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); | 1468 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager)); |
| 1469 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); | 1469 EXPECT_EQ(w1->bounds().width(), docked_width(manager)); |
| 1470 EXPECT_TRUE(window_state->IsDocked()); | 1470 EXPECT_TRUE(window_state->IsDocked()); |
| 1471 EXPECT_FALSE(window_state->IsSnapped()); | 1471 EXPECT_FALSE(window_state->IsSnapped()); |
| 1472 | 1472 |
| 1473 // Side snap at left edge. | 1473 // Side snap at left edge. |
| 1474 internal::SnapSizer::SnapWindow(window_state, | 1474 internal::SnapSizer::SnapWindow(window_state, |
| 1475 internal::SnapSizer::LEFT_EDGE); | 1475 internal::SnapSizer::LEFT_EDGE); |
| 1476 // The window should be snapped at the right edge and the dock should close. | 1476 // The window should be snapped at the right edge and the dock should close. |
| 1477 EXPECT_EQ(work_area.ToString(), | 1477 EXPECT_EQ(work_area.ToString(), |
| 1478 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).ToString()); | 1478 ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).ToString()); |
| 1479 EXPECT_EQ(0, docked_width(manager)); | 1479 EXPECT_EQ(0, docked_width(manager)); |
| 1480 EXPECT_EQ(work_area.height(), w1->bounds().height()); | 1480 EXPECT_EQ(work_area.height(), w1->bounds().height()); |
| 1481 EXPECT_EQ(work_area.x(), w1->bounds().x()); | 1481 EXPECT_EQ(work_area.x(), w1->bounds().x()); |
| 1482 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); | 1482 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w1->parent()->id()); |
| 1483 EXPECT_FALSE(window_state->IsDocked()); | 1483 EXPECT_FALSE(window_state->IsDocked()); |
| 1484 EXPECT_TRUE(window_state->IsSnapped()); | 1484 EXPECT_TRUE(window_state->IsSnapped()); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 // Tests run twice - on both panels and normal windows | 1487 // Tests run twice - on both panels and normal windows |
| 1488 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1488 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1489 DockedWindowResizerTest, | 1489 DockedWindowResizerTest, |
| 1490 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 1490 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
| 1491 ui::wm::WINDOW_TYPE_PANEL)); | 1491 ui::wm::WINDOW_TYPE_PANEL)); |
| 1492 } // namespace internal | 1492 } // namespace internal |
| 1493 } // namespace ash | 1493 } // namespace ash |
| OLD | NEW |