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/common/wm/workspace/workspace_window_resizer.h" | 5 #include "ash/common/wm/workspace/workspace_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/shelf/shelf.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
| 9 #include "ash/common/shelf/wm_shelf.h" |
9 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
10 #include "ash/common/wm/window_positioning_utils.h" | 11 #include "ash/common/wm/window_positioning_utils.h" |
11 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
12 #include "ash/common/wm/wm_event.h" | 13 #include "ash/common/wm/wm_event.h" |
13 #include "ash/common/wm/workspace/phantom_window_controller.h" | 14 #include "ash/common/wm/workspace/phantom_window_controller.h" |
14 #include "ash/display/display_manager.h" | 15 #include "ash/display/display_manager.h" |
15 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
17 #include "ash/test/ash_md_test_base.h" | 18 #include "ash/test/ash_md_test_base.h" |
18 #include "ash/test/display_manager_test_api.h" | 19 #include "ash/test/display_manager_test_api.h" |
(...skipping 12 matching lines...) Expand all Loading... |
31 #include "ui/events/gesture_detection/gesture_configuration.h" | 32 #include "ui/events/gesture_detection/gesture_configuration.h" |
32 #include "ui/events/test/event_generator.h" | 33 #include "ui/events/test/event_generator.h" |
33 #include "ui/gfx/geometry/insets.h" | 34 #include "ui/gfx/geometry/insets.h" |
34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
35 | 36 |
36 namespace ash { | 37 namespace ash { |
37 namespace { | 38 namespace { |
38 | 39 |
39 const int kRootHeight = 600; | 40 const int kRootHeight = 600; |
40 | 41 |
41 Shelf* GetShelf() { | |
42 return Shelf::ForPrimaryDisplay(); | |
43 } | |
44 | |
45 // A simple window delegate that returns the specified min size. | 42 // A simple window delegate that returns the specified min size. |
46 class TestWindowDelegate : public aura::test::TestWindowDelegate { | 43 class TestWindowDelegate : public aura::test::TestWindowDelegate { |
47 public: | 44 public: |
48 TestWindowDelegate() {} | 45 TestWindowDelegate() {} |
49 ~TestWindowDelegate() override {} | 46 ~TestWindowDelegate() override {} |
50 | 47 |
51 void set_min_size(const gfx::Size& size) { min_size_ = size; } | 48 void set_min_size(const gfx::Size& size) { min_size_ = size; } |
52 | 49 |
53 void set_max_size(const gfx::Size& size) { max_size_ = size; } | 50 void set_max_size(const gfx::Size& size) { max_size_ = size; } |
54 | 51 |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
989 gfx::Insets(0, 0, 50, 0)); | 986 gfx::Insets(0, 0, 50, 0)); |
990 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); | 987 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); |
991 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); | 988 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); |
992 EXPECT_EQ(base::IntToString(window_x + window_width) + ",100 " + | 989 EXPECT_EQ(base::IntToString(window_x + window_width) + ",100 " + |
993 base::IntToString(window_width) + "x380", | 990 base::IntToString(window_width) + "x380", |
994 window_->bounds().ToString()); | 991 window_->bounds().ToString()); |
995 } | 992 } |
996 | 993 |
997 // Verifies snapping to edges works. | 994 // Verifies snapping to edges works. |
998 TEST_P(WorkspaceWindowResizerTest, SnapToEdge) { | 995 TEST_P(WorkspaceWindowResizerTest, SnapToEdge) { |
999 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 996 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
1000 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); | 997 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); |
1001 // Click 50px to the right so that the mouse pointer does not leave the | 998 // Click 50px to the right so that the mouse pointer does not leave the |
1002 // workspace ensuring sticky behavior. | 999 // workspace ensuring sticky behavior. |
1003 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest( | 1000 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest( |
1004 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0), | 1001 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0), |
1005 HTCAPTION)); | 1002 HTCAPTION)); |
1006 ASSERT_TRUE(resizer.get()); | 1003 ASSERT_TRUE(resizer.get()); |
1007 int distance_to_left = window_->bounds().x(); | 1004 int distance_to_left = window_->bounds().x(); |
1008 int distance_to_right = | 1005 int distance_to_right = |
1009 800 - window_->bounds().width() - window_->bounds().x(); | 1006 800 - window_->bounds().width() - window_->bounds().x(); |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 // Move it 50 to the left, which should contract w1 and expand w2-3. | 1762 // Move it 50 to the left, which should contract w1 and expand w2-3. |
1766 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); | 1763 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); |
1767 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); | 1764 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); |
1768 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); | 1765 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); |
1769 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); | 1766 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); |
1770 } | 1767 } |
1771 | 1768 |
1772 // The following variants test that windows are resized correctly to the edges | 1769 // The following variants test that windows are resized correctly to the edges |
1773 // of the screen using touch, when touch point is off of the window border. | 1770 // of the screen using touch, when touch point is off of the window border. |
1774 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { | 1771 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { |
1775 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1772 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1776 | 1773 |
1777 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); | 1774 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); |
1778 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1775 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
1779 touch_resize_window_->bounds().ToString()); | 1776 touch_resize_window_->bounds().ToString()); |
1780 | 1777 |
1781 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1778 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1782 touch_resize_window_.get()); | 1779 touch_resize_window_.get()); |
1783 | 1780 |
1784 // Drag out of the right border a bit and check if the border is aligned with | 1781 // Drag out of the right border a bit and check if the border is aligned with |
1785 // the touch point. | 1782 // the touch point. |
(...skipping 10 matching lines...) Expand all Loading... |
1796 touch_resize_window_->bounds().ToString()); | 1793 touch_resize_window_->bounds().ToString()); |
1797 // Drag even more to snap to the edge. | 1794 // Drag even more to snap to the edge. |
1798 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2), | 1795 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2), |
1799 gfx::Point(775, kRootHeight / 2), | 1796 gfx::Point(775, kRootHeight / 2), |
1800 base::TimeDelta::FromMilliseconds(10), 5); | 1797 base::TimeDelta::FromMilliseconds(10), 5); |
1801 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(), | 1798 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(), |
1802 touch_resize_window_->bounds().ToString()); | 1799 touch_resize_window_->bounds().ToString()); |
1803 } | 1800 } |
1804 | 1801 |
1805 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { | 1802 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { |
1806 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1803 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1807 | 1804 |
1808 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); | 1805 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); |
1809 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1806 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
1810 touch_resize_window_->bounds().ToString()); | 1807 touch_resize_window_->bounds().ToString()); |
1811 | 1808 |
1812 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1809 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1813 touch_resize_window_.get()); | 1810 touch_resize_window_.get()); |
1814 | 1811 |
1815 // Drag out of the left border a bit and check if the border is aligned with | 1812 // Drag out of the left border a bit and check if the border is aligned with |
1816 // the touch point. | 1813 // the touch point. |
(...skipping 10 matching lines...) Expand all Loading... |
1827 touch_resize_window_->bounds().ToString()); | 1824 touch_resize_window_->bounds().ToString()); |
1828 // Drag even more to snap to the edge. | 1825 // Drag even more to snap to the edge. |
1829 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2), | 1826 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2), |
1830 gfx::Point(25, kRootHeight / 2), | 1827 gfx::Point(25, kRootHeight / 2), |
1831 base::TimeDelta::FromMilliseconds(10), 5); | 1828 base::TimeDelta::FromMilliseconds(10), 5); |
1832 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(), | 1829 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(), |
1833 touch_resize_window_->bounds().ToString()); | 1830 touch_resize_window_->bounds().ToString()); |
1834 } | 1831 } |
1835 | 1832 |
1836 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { | 1833 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { |
1837 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1834 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1838 | 1835 |
1839 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); | 1836 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); |
1840 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1837 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
1841 touch_resize_window_->bounds().ToString()); | 1838 touch_resize_window_->bounds().ToString()); |
1842 | 1839 |
1843 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1840 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1844 touch_resize_window_.get()); | 1841 touch_resize_window_.get()); |
1845 | 1842 |
1846 // Drag out of the top border a bit and check if the border is aligned with | 1843 // Drag out of the top border a bit and check if the border is aligned with |
1847 // the touch point. | 1844 // the touch point. |
1848 generator.GestureScrollSequence(gfx::Point(400, 85), gfx::Point(400, 75), | 1845 generator.GestureScrollSequence(gfx::Point(400, 85), gfx::Point(400, 75), |
1849 base::TimeDelta::FromMilliseconds(10), 5); | 1846 base::TimeDelta::FromMilliseconds(10), 5); |
1850 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(), | 1847 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(), |
1851 touch_resize_window_->bounds().ToString()); | 1848 touch_resize_window_->bounds().ToString()); |
1852 // Drag more, but stop before being snapped to the edge. | 1849 // Drag more, but stop before being snapped to the edge. |
1853 generator.GestureScrollSequence(gfx::Point(400, 75), gfx::Point(400, 40), | 1850 generator.GestureScrollSequence(gfx::Point(400, 75), gfx::Point(400, 40), |
1854 base::TimeDelta::FromMilliseconds(10), 5); | 1851 base::TimeDelta::FromMilliseconds(10), 5); |
1855 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(), | 1852 EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(), |
1856 touch_resize_window_->bounds().ToString()); | 1853 touch_resize_window_->bounds().ToString()); |
1857 // Drag even more to snap to the edge. | 1854 // Drag even more to snap to the edge. |
1858 generator.GestureScrollSequence(gfx::Point(400, 40), gfx::Point(400, 25), | 1855 generator.GestureScrollSequence(gfx::Point(400, 40), gfx::Point(400, 25), |
1859 base::TimeDelta::FromMilliseconds(10), 5); | 1856 base::TimeDelta::FromMilliseconds(10), 5); |
1860 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(), | 1857 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(), |
1861 touch_resize_window_->bounds().ToString()); | 1858 touch_resize_window_->bounds().ToString()); |
1862 } | 1859 } |
1863 | 1860 |
1864 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { | 1861 TEST_P(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { |
1865 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1862 GetPrimaryShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
1866 | 1863 |
1867 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); | 1864 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); |
1868 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1865 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
1869 touch_resize_window_->bounds().ToString()); | 1866 touch_resize_window_->bounds().ToString()); |
1870 | 1867 |
1871 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1868 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
1872 touch_resize_window_.get()); | 1869 touch_resize_window_.get()); |
1873 | 1870 |
1874 // Drag out of the bottom border a bit and check if the border is aligned with | 1871 // Drag out of the bottom border a bit and check if the border is aligned with |
1875 // the touch point. | 1872 // the touch point. |
(...skipping 10 matching lines...) Expand all Loading... |
1886 touch_resize_window_->bounds().ToString()); | 1883 touch_resize_window_->bounds().ToString()); |
1887 // Drag even more to snap to the edge. | 1884 // Drag even more to snap to the edge. |
1888 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), | 1885 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), |
1889 gfx::Point(400, kRootHeight - 25), | 1886 gfx::Point(400, kRootHeight - 25), |
1890 base::TimeDelta::FromMilliseconds(10), 5); | 1887 base::TimeDelta::FromMilliseconds(10), 5); |
1891 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), | 1888 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), |
1892 touch_resize_window_->bounds().ToString()); | 1889 touch_resize_window_->bounds().ToString()); |
1893 } | 1890 } |
1894 | 1891 |
1895 } // namespace ash | 1892 } // namespace ash |
OLD | NEW |