| 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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/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" |
| 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" |
| 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/wm/window_state.h" | 14 #include "ash/wm/window_state.h" |
| 15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "ash/wm/wm_event.h" | 16 #include "ash/wm/wm_event.h" |
| 17 #include "ash/wm/workspace/phantom_window_controller.h" | 17 #include "ash/wm/workspace/phantom_window_controller.h" |
| 18 #include "ash/wm/workspace_controller.h" | 18 #include "ash/wm/workspace_controller.h" |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "ui/aura/client/aura_constants.h" | 22 #include "ui/aura/client/aura_constants.h" |
| 23 #include "ui/aura/test/event_generator.h" | |
| 24 #include "ui/aura/test/test_window_delegate.h" | 23 #include "ui/aura/test/test_window_delegate.h" |
| 25 #include "ui/aura/window_event_dispatcher.h" | 24 #include "ui/aura/window_event_dispatcher.h" |
| 26 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
| 27 #include "ui/events/gestures/gesture_configuration.h" | 26 #include "ui/events/gestures/gesture_configuration.h" |
| 27 #include "ui/events/test/event_generator.h" |
| 28 #include "ui/gfx/insets.h" | 28 #include "ui/gfx/insets.h" |
| 29 #include "ui/gfx/screen.h" | 29 #include "ui/gfx/screen.h" |
| 30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 31 | 31 |
| 32 namespace ash { | 32 namespace ash { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 const int kRootHeight = 600; | 35 const int kRootHeight = 600; |
| 36 | 36 |
| 37 // A simple window delegate that returns the specified min size. | 37 // A simple window delegate that returns the specified min size. |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); | 507 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 // Tests that touch-dragging a window does not lock the mouse cursor | 510 // Tests that touch-dragging a window does not lock the mouse cursor |
| 511 // and therefore shows the cursor on a mousemove. | 511 // and therefore shows the cursor on a mousemove. |
| 512 TEST_F(WorkspaceWindowResizerTest, MouseMoveWithTouchDrag) { | 512 TEST_F(WorkspaceWindowResizerTest, MouseMoveWithTouchDrag) { |
| 513 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); | 513 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
| 514 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); | 514 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); |
| 515 | 515 |
| 516 Shell* shell = Shell::GetInstance(); | 516 Shell* shell = Shell::GetInstance(); |
| 517 aura::test::EventGenerator generator(window_->GetRootWindow()); | 517 ui::test::EventGenerator generator(window_->GetRootWindow()); |
| 518 | 518 |
| 519 // The cursor should not be locked initially. | 519 // The cursor should not be locked initially. |
| 520 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked()); | 520 EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked()); |
| 521 | 521 |
| 522 std::vector<aura::Window*> windows; | 522 std::vector<aura::Window*> windows; |
| 523 windows.push_back(window2_.get()); | 523 windows.push_back(window2_.get()); |
| 524 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest( | 524 scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest( |
| 525 window_.get(), gfx::Point(), HTRIGHT, | 525 window_.get(), gfx::Point(), HTRIGHT, |
| 526 aura::client::WINDOW_MOVE_SOURCE_TOUCH, windows)); | 526 aura::client::WINDOW_MOVE_SOURCE_TOUCH, windows)); |
| 527 ASSERT_TRUE(resizer.get()); | 527 ASSERT_TRUE(resizer.get()); |
| (...skipping 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 | 1732 |
| 1733 // The following variants test that windows are resized correctly to the edges | 1733 // The following variants test that windows are resized correctly to the edges |
| 1734 // of the screen using touch, when touch point is off of the window border. | 1734 // of the screen using touch, when touch point is off of the window border. |
| 1735 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { | 1735 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) { |
| 1736 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1736 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1737 | 1737 |
| 1738 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); | 1738 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT); |
| 1739 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1739 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1740 touch_resize_window_->bounds().ToString()); | 1740 touch_resize_window_->bounds().ToString()); |
| 1741 | 1741 |
| 1742 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1742 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1743 touch_resize_window_.get()); | 1743 touch_resize_window_.get()); |
| 1744 | 1744 |
| 1745 // Drag out of the right border a bit and check if the border is aligned with | 1745 // Drag out of the right border a bit and check if the border is aligned with |
| 1746 // the touch point. | 1746 // the touch point. |
| 1747 generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2), | 1747 generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2), |
| 1748 gfx::Point(725, kRootHeight / 2), | 1748 gfx::Point(725, kRootHeight / 2), |
| 1749 base::TimeDelta::FromMilliseconds(10), | 1749 base::TimeDelta::FromMilliseconds(10), |
| 1750 5); | 1750 5); |
| 1751 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(), | 1751 EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(), |
| 1752 touch_resize_window_->bounds().ToString()); | 1752 touch_resize_window_->bounds().ToString()); |
| 1753 // Drag more, but stop before being snapped to the edge. | 1753 // Drag more, but stop before being snapped to the edge. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1766 touch_resize_window_->bounds().ToString()); | 1766 touch_resize_window_->bounds().ToString()); |
| 1767 } | 1767 } |
| 1768 | 1768 |
| 1769 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { | 1769 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) { |
| 1770 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1770 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1771 | 1771 |
| 1772 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); | 1772 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT); |
| 1773 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1773 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1774 touch_resize_window_->bounds().ToString()); | 1774 touch_resize_window_->bounds().ToString()); |
| 1775 | 1775 |
| 1776 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1776 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1777 touch_resize_window_.get()); | 1777 touch_resize_window_.get()); |
| 1778 | 1778 |
| 1779 // Drag out of the left border a bit and check if the border is aligned with | 1779 // Drag out of the left border a bit and check if the border is aligned with |
| 1780 // the touch point. | 1780 // the touch point. |
| 1781 generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2), | 1781 generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2), |
| 1782 gfx::Point(75, kRootHeight / 2), | 1782 gfx::Point(75, kRootHeight / 2), |
| 1783 base::TimeDelta::FromMilliseconds(10), | 1783 base::TimeDelta::FromMilliseconds(10), |
| 1784 5); | 1784 5); |
| 1785 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(), | 1785 EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(), |
| 1786 touch_resize_window_->bounds().ToString()); | 1786 touch_resize_window_->bounds().ToString()); |
| 1787 // Drag more, but stop before being snapped to the edge. | 1787 // Drag more, but stop before being snapped to the edge. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1800 touch_resize_window_->bounds().ToString()); | 1800 touch_resize_window_->bounds().ToString()); |
| 1801 } | 1801 } |
| 1802 | 1802 |
| 1803 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { | 1803 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) { |
| 1804 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1804 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1805 | 1805 |
| 1806 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); | 1806 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP); |
| 1807 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1807 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1808 touch_resize_window_->bounds().ToString()); | 1808 touch_resize_window_->bounds().ToString()); |
| 1809 | 1809 |
| 1810 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1810 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1811 touch_resize_window_.get()); | 1811 touch_resize_window_.get()); |
| 1812 | 1812 |
| 1813 // Drag out of the top border a bit and check if the border is aligned with | 1813 // Drag out of the top border a bit and check if the border is aligned with |
| 1814 // the touch point. | 1814 // the touch point. |
| 1815 generator.GestureScrollSequence(gfx::Point(400, 85), | 1815 generator.GestureScrollSequence(gfx::Point(400, 85), |
| 1816 gfx::Point(400, 75), | 1816 gfx::Point(400, 75), |
| 1817 base::TimeDelta::FromMilliseconds(10), | 1817 base::TimeDelta::FromMilliseconds(10), |
| 1818 5); | 1818 5); |
| 1819 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(), | 1819 EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(), |
| 1820 touch_resize_window_->bounds().ToString()); | 1820 touch_resize_window_->bounds().ToString()); |
| 1821 // Drag more, but stop before being snapped to the edge. | 1821 // Drag more, but stop before being snapped to the edge. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1834 touch_resize_window_->bounds().ToString()); | 1834 touch_resize_window_->bounds().ToString()); |
| 1835 } | 1835 } |
| 1836 | 1836 |
| 1837 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { | 1837 TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) { |
| 1838 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 1838 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 1839 | 1839 |
| 1840 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); | 1840 InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM); |
| 1841 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), | 1841 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(), |
| 1842 touch_resize_window_->bounds().ToString()); | 1842 touch_resize_window_->bounds().ToString()); |
| 1843 | 1843 |
| 1844 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 1844 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 1845 touch_resize_window_.get()); | 1845 touch_resize_window_.get()); |
| 1846 | 1846 |
| 1847 // Drag out of the bottom border a bit and check if the border is aligned with | 1847 // Drag out of the bottom border a bit and check if the border is aligned with |
| 1848 // the touch point. | 1848 // the touch point. |
| 1849 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85), | 1849 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85), |
| 1850 gfx::Point(400, kRootHeight - 75), | 1850 gfx::Point(400, kRootHeight - 75), |
| 1851 base::TimeDelta::FromMilliseconds(10), | 1851 base::TimeDelta::FromMilliseconds(10), |
| 1852 5); | 1852 5); |
| 1853 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(), | 1853 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(), |
| 1854 touch_resize_window_->bounds().ToString()); | 1854 touch_resize_window_->bounds().ToString()); |
| 1855 // Drag more, but stop before being snapped to the edge. | 1855 // Drag more, but stop before being snapped to the edge. |
| 1856 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75), | 1856 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75), |
| 1857 gfx::Point(400, kRootHeight - 40), | 1857 gfx::Point(400, kRootHeight - 40), |
| 1858 base::TimeDelta::FromMilliseconds(10), | 1858 base::TimeDelta::FromMilliseconds(10), |
| 1859 5); | 1859 5); |
| 1860 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(), | 1860 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(), |
| 1861 touch_resize_window_->bounds().ToString()); | 1861 touch_resize_window_->bounds().ToString()); |
| 1862 // Drag even more to snap to the edge. | 1862 // Drag even more to snap to the edge. |
| 1863 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), | 1863 generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40), |
| 1864 gfx::Point(400, kRootHeight - 25), | 1864 gfx::Point(400, kRootHeight - 25), |
| 1865 base::TimeDelta::FromMilliseconds(10), | 1865 base::TimeDelta::FromMilliseconds(10), |
| 1866 5); | 1866 5); |
| 1867 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), | 1867 EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(), |
| 1868 touch_resize_window_->bounds().ToString()); | 1868 touch_resize_window_->bounds().ToString()); |
| 1869 } | 1869 } |
| 1870 | 1870 |
| 1871 } // namespace ash | 1871 } // namespace ash |
| OLD | NEW |