Chromium Code Reviews| 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/common/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/common/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
|
msw
2016/06/01 00:53:24
nit: remove
James Cook
2016/06/01 15:53:07
Done.
| |
| 9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
|
msw
2016/06/01 00:53:24
nit: remove
James Cook
2016/06/01 15:53:07
Done. Thanks for catching all these unused include
| |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "ash/test/display_manager_test_api.h" | 14 #include "ash/test/display_manager_test_api.h" |
| 15 #include "ash/wm/aura/wm_window_aura.h" | 15 #include "ash/wm/aura/wm_window_aura.h" |
| 16 #include "ash/wm/common/window_positioning_utils.h" | 16 #include "ash/wm/common/window_positioning_utils.h" |
| 17 #include "ash/wm/common/window_state.h" | 17 #include "ash/wm/common/window_state.h" |
| 18 #include "ash/wm/common/wm_event.h" | 18 #include "ash/wm/common/wm_event.h" |
| 19 #include "ash/wm/common/workspace/phantom_window_controller.h" | 19 #include "ash/wm/common/workspace/phantom_window_controller.h" |
| 20 #include "ash/wm/window_state_aura.h" | 20 #include "ash/wm/window_state_aura.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 32 #include "ui/events/gesture_detection/gesture_configuration.h" | 32 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 33 #include "ui/events/test/event_generator.h" | 33 #include "ui/events/test/event_generator.h" |
| 34 #include "ui/gfx/geometry/insets.h" | 34 #include "ui/gfx/geometry/insets.h" |
| 35 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 36 | 36 |
| 37 namespace ash { | 37 namespace ash { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const int kRootHeight = 600; | 40 const int kRootHeight = 600; |
| 41 | 41 |
| 42 Shelf* GetShelf() { | |
| 43 return Shelf::ForPrimaryDisplay(); | |
| 44 } | |
| 45 | |
| 42 // A simple window delegate that returns the specified min size. | 46 // A simple window delegate that returns the specified min size. |
| 43 class TestWindowDelegate : public aura::test::TestWindowDelegate { | 47 class TestWindowDelegate : public aura::test::TestWindowDelegate { |
| 44 public: | 48 public: |
| 45 TestWindowDelegate() { | 49 TestWindowDelegate() { |
| 46 } | 50 } |
| 47 ~TestWindowDelegate() override {} | 51 ~TestWindowDelegate() override {} |
| 48 | 52 |
| 49 void set_min_size(const gfx::Size& size) { | 53 void set_min_size(const gfx::Size& size) { |
| 50 min_size_ = size; | 54 min_size_ = size; |
| 51 } | 55 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 gfx::Point location = resizer.GetInitialLocation(); | 179 gfx::Point location = resizer.GetInitialLocation(); |
| 176 location.set_x(location.x() + delta_x); | 180 location.set_x(location.x() + delta_x); |
| 177 location.set_y(location.y() + delta_y); | 181 location.set_y(location.y() + delta_y); |
| 178 return location; | 182 return location; |
| 179 } | 183 } |
| 180 | 184 |
| 181 std::vector<aura::Window*> empty_windows() const { | 185 std::vector<aura::Window*> empty_windows() const { |
| 182 return std::vector<aura::Window*>(); | 186 return std::vector<aura::Window*>(); |
| 183 } | 187 } |
| 184 | 188 |
| 185 ShelfLayoutManager* shelf_layout_manager() { | 189 ShelfLayoutManager* shelf_layout_manager() { |
|
msw
2016/06/01 00:53:24
nit: remove
James Cook
2016/06/01 15:53:07
Done.
| |
| 186 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 190 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
| 187 } | 191 } |
| 188 | 192 |
| 189 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) { | 193 void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) { |
| 190 touch_resize_delegate_.set_window_component(window_component); | 194 touch_resize_delegate_.set_window_component(window_component); |
| 191 touch_resize_window_.reset( | 195 touch_resize_window_.reset( |
| 192 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0, | 196 CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0, |
| 193 bounds)); | 197 bounds)); |
| 194 } | 198 } |
| 195 | 199 |
| (...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); | 1000 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); |
| 997 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); | 1001 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); |
| 998 EXPECT_EQ(base::IntToString(window_x + window_width) + | 1002 EXPECT_EQ(base::IntToString(window_x + window_width) + |
| 999 ",100 " + | 1003 ",100 " + |
| 1000 base::IntToString(window_width) + | 1004 base::IntToString(window_width) + |
| 1001 "x380", window_->bounds().ToString()); | 1005 "x380", window_->bounds().ToString()); |
| 1002 } | 1006 } |
| 1003 | 1007 |
| 1004 // Verifies snapping to edges works. | 1008 // Verifies snapping to edges works. |
| 1005 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { | 1009 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { |
| 1006 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> | 1010 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1007 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | |
| 1008 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); | 1011 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); |
| 1009 // Click 50px to the right so that the mouse pointer does not leave the | 1012 // Click 50px to the right so that the mouse pointer does not leave the |
| 1010 // workspace ensuring sticky behavior. | 1013 // workspace ensuring sticky behavior. |
| 1011 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest( | 1014 std::unique_ptr<WindowResizer> resizer(CreateResizerForTest( |
| 1012 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0), | 1015 window_.get(), window_->bounds().origin() + gfx::Vector2d(50, 0), |
| 1013 HTCAPTION)); | 1016 HTCAPTION)); |
| 1014 ASSERT_TRUE(resizer.get()); | 1017 ASSERT_TRUE(resizer.get()); |
| 1015 // Move to an x-coordinate of 15, which should not snap. | 1018 // Move to an x-coordinate of 15, which should not snap. |
| 1016 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); | 1019 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); |
| 1017 // An x-coordinate of 7 should snap. | 1020 // An x-coordinate of 7 should snap. |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1752 // Move it 50 to the left, which should contract w1 and expand w2-3. | 1755 // Move it 50 to the left, which should contract w1 and expand w2-3. |
| 1753 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); | 1756 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); |
| 1754 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); | 1757 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); |
| 1755 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); | 1758 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); |
| 1756 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); | 1759 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); |
| 1757 } | 1760 } |
| 1758 | 1761 |
| 1759 // The following variants test that windows are resized correctly to the edges | 1762 // The following variants test that windows are resized correctly to the edges |
| 1760 // of the screen using touch, when touch point is off of the window border. | 1763 // of the screen using touch, when touch point is off of the window border. |
| 1761 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { | 1764 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { |
| 1762 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1765 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1763 | 1766 |
| 1764 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); | 1767 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); |
| 1765 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1768 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1766 touch_resize_window_->bounds().ToString()); | 1769 touch_resize_window_->bounds().ToString()); |
| 1767 | 1770 |
| 1768 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1771 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1769 touch_resize_window_.get()); | 1772 touch_resize_window_.get()); |
| 1770 | 1773 |
| 1771 // Drag out of the right border a bit and check if the border is aligned with | 1774 // Drag out of the right border a bit and check if the border is aligned with |
| 1772 // the touch point. | 1775 // the touch point. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1786 // Drag even more to snap to the edge. | 1789 // Drag even more to snap to the edge. |
| 1787 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2), | 1790 generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2), |
| 1788 gfx::Point(775, kRootHeight / 2), | 1791 gfx::Point(775, kRootHeight / 2), |
| 1789 base::TimeDelta::FromMilliseconds(10), | 1792 base::TimeDelta::FromMilliseconds(10), |
| 1790 5); | 1793 5); |
| 1791 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(), | 1794 EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(), |
| 1792 touch_resize_window_->bounds().ToString()); | 1795 touch_resize_window_->bounds().ToString()); |
| 1793 } | 1796 } |
| 1794 | 1797 |
| 1795 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { | 1798 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { |
| 1796 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1799 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1797 | 1800 |
| 1798 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); | 1801 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); |
| 1799 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1802 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1800 touch_resize_window_->bounds().ToString()); | 1803 touch_resize_window_->bounds().ToString()); |
| 1801 | 1804 |
| 1802 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1805 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1803 touch_resize_window_.get()); | 1806 touch_resize_window_.get()); |
| 1804 | 1807 |
| 1805 // Drag out of the left border a bit and check if the border is aligned with | 1808 // Drag out of the left border a bit and check if the border is aligned with |
| 1806 // the touch point. | 1809 // the touch point. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1820 // Drag even more to snap to the edge. | 1823 // Drag even more to snap to the edge. |
| 1821 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2), | 1824 generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2), |
| 1822 gfx::Point(25, kRootHeight / 2), | 1825 gfx::Point(25, kRootHeight / 2), |
| 1823 base::TimeDelta::FromMilliseconds(10), | 1826 base::TimeDelta::FromMilliseconds(10), |
| 1824 5); | 1827 5); |
| 1825 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(), | 1828 EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(), |
| 1826 touch_resize_window_->bounds().ToString()); | 1829 touch_resize_window_->bounds().ToString()); |
| 1827 } | 1830 } |
| 1828 | 1831 |
| 1829 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { | 1832 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { |
| 1830 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1833 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1831 | 1834 |
| 1832 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); | 1835 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); |
| 1833 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1836 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1834 touch_resize_window_->bounds().ToString()); | 1837 touch_resize_window_->bounds().ToString()); |
| 1835 | 1838 |
| 1836 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1839 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1837 touch_resize_window_.get()); | 1840 touch_resize_window_.get()); |
| 1838 | 1841 |
| 1839 // Drag out of the top border a bit and check if the border is aligned with | 1842 // Drag out of the top border a bit and check if the border is aligned with |
| 1840 // the touch point. | 1843 // the touch point. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1854 // Drag even more to snap to the edge. | 1857 // Drag even more to snap to the edge. |
| 1855 generator.GestureScrollSequence(gfx::Point(400, 40), | 1858 generator.GestureScrollSequence(gfx::Point(400, 40), |
| 1856 gfx::Point(400, 25), | 1859 gfx::Point(400, 25), |
| 1857 base::TimeDelta::FromMilliseconds(10), | 1860 base::TimeDelta::FromMilliseconds(10), |
| 1858 5); | 1861 5); |
| 1859 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(), | 1862 EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(), |
| 1860 touch_resize_window_->bounds().ToString()); | 1863 touch_resize_window_->bounds().ToString()); |
| 1861 } | 1864 } |
| 1862 | 1865 |
| 1863 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { | 1866 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { |
| 1864 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1867 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1865 | 1868 |
| 1866 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); | 1869 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); |
| 1867 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1870 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1868 touch_resize_window_->bounds().ToString()); | 1871 touch_resize_window_->bounds().ToString()); |
| 1869 | 1872 |
| 1870 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1873 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1871 touch_resize_window_.get()); | 1874 touch_resize_window_.get()); |
| 1872 | 1875 |
| 1873 // Drag out of the bottom border a bit and check if the border is aligned with | 1876 // Drag out of the bottom border a bit and check if the border is aligned with |
| 1874 // the touch point. | 1877 // the touch point. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1888 // Drag even more to snap to the edge. | 1891 // Drag even more to snap to the edge. |
| 1889 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), | 1892 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), |
| 1890 gfx::Point(400, kRootHeight - 25), | 1893 gfx::Point(400, kRootHeight - 25), |
| 1891 base::TimeDelta::FromMilliseconds(10), | 1894 base::TimeDelta::FromMilliseconds(10), |
| 1892 5); | 1895 5); |
| 1893 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), | 1896 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), |
| 1894 touch_resize_window_->bounds().ToString()); | 1897 touch_resize_window_->bounds().ToString()); |
| 1895 } | 1898 } |
| 1896 | 1899 |
| 1897 } // namespace ash | 1900 } // namespace ash |
| OLD | NEW |