OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "ash/accessibility_delegate.h" | 8 #include "ash/accessibility_delegate.h" |
9 #include "ash/accessibility_types.h" | 9 #include "ash/accessibility_types.h" |
10 #include "ash/app_list/test_app_list_view_presenter_impl.h" | 10 #include "ash/app_list/test_app_list_view_presenter_impl.h" |
| 11 #include "ash/ash_switches.h" |
11 #include "ash/drag_drop/drag_drop_controller.h" | 12 #include "ash/drag_drop/drag_drop_controller.h" |
12 #include "ash/public/cpp/config.h" | 13 #include "ash/public/cpp/config.h" |
13 #include "ash/public/cpp/window_properties.h" | 14 #include "ash/public/cpp/window_properties.h" |
14 #include "ash/shelf/shelf.h" | 15 #include "ash/shelf/shelf.h" |
15 #include "ash/shelf/shelf_view_test_api.h" | 16 #include "ash/shelf/shelf_view_test_api.h" |
16 #include "ash/shell.h" | 17 #include "ash/shell.h" |
17 #include "ash/shell_test_api.h" | 18 #include "ash/shell_test_api.h" |
18 #include "ash/system/tray/system_tray.h" | 19 #include "ash/system/tray/system_tray.h" |
19 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
20 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 21 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
21 #include "ash/wm/overview/window_grid.h" | 22 #include "ash/wm/overview/window_grid.h" |
22 #include "ash/wm/overview/window_selector.h" | 23 #include "ash/wm/overview/window_selector.h" |
23 #include "ash/wm/overview/window_selector_controller.h" | 24 #include "ash/wm/overview/window_selector_controller.h" |
24 #include "ash/wm/overview/window_selector_item.h" | 25 #include "ash/wm/overview/window_selector_item.h" |
25 #include "ash/wm/panels/panel_layout_manager.h" | 26 #include "ash/wm/panels/panel_layout_manager.h" |
| 27 #include "ash/wm/splitview/split_view_controller.h" |
26 #include "ash/wm/window_state.h" | 28 #include "ash/wm/window_state.h" |
27 #include "ash/wm/window_util.h" | 29 #include "ash/wm/window_util.h" |
28 #include "ash/wm/wm_event.h" | 30 #include "ash/wm/wm_event.h" |
29 #include "ash/wm/workspace/workspace_window_resizer.h" | 31 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 32 #include "base/command_line.h" |
30 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
31 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
32 #include "base/test/user_action_tester.h" | 35 #include "base/test/user_action_tester.h" |
33 #include "ui/aura/client/aura_constants.h" | 36 #include "ui/aura/client/aura_constants.h" |
34 #include "ui/aura/client/focus_client.h" | 37 #include "ui/aura/client/focus_client.h" |
35 #include "ui/aura/test/test_windows.h" | 38 #include "ui/aura/test/test_windows.h" |
36 #include "ui/aura/window.h" | 39 #include "ui/aura/window.h" |
37 #include "ui/base/hit_test.h" | 40 #include "ui/base/hit_test.h" |
38 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 41 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
39 #include "ui/display/display_layout.h" | 42 #include "ui/display/display_layout.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 161 } |
159 | 162 |
160 WindowSelectorController* window_selector_controller() { | 163 WindowSelectorController* window_selector_controller() { |
161 return Shell::Get()->window_selector_controller(); | 164 return Shell::Get()->window_selector_controller(); |
162 } | 165 } |
163 | 166 |
164 WindowSelector* window_selector() { | 167 WindowSelector* window_selector() { |
165 return window_selector_controller()->window_selector_.get(); | 168 return window_selector_controller()->window_selector_.get(); |
166 } | 169 } |
167 | 170 |
| 171 SplitViewController* split_view_controller() { |
| 172 return Shell::Get()->split_view_controller(); |
| 173 } |
| 174 |
168 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } | 175 void ToggleOverview() { window_selector_controller()->ToggleOverview(); } |
169 | 176 |
170 aura::Window* GetOverviewWindowForMinimizedState(int index, | 177 aura::Window* GetOverviewWindowForMinimizedState(int index, |
171 aura::Window* window) { | 178 aura::Window* window) { |
172 WindowSelectorItem* selector = GetWindowItemForWindow(index, window); | 179 WindowSelectorItem* selector = GetWindowItemForWindow(index, window); |
173 return selector->GetOverviewWindowForMinimizedStateForTest(); | 180 return selector->GetOverviewWindowForMinimizedStateForTest(); |
174 } | 181 } |
175 | 182 |
176 gfx::Rect GetTransformedBounds(aura::Window* window) { | 183 gfx::Rect GetTransformedBounds(aura::Window* window) { |
177 gfx::Rect bounds_in_screen = window->layer()->bounds(); | 184 gfx::Rect bounds_in_screen = window->layer()->bounds(); |
(...skipping 1706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer( | 1891 std::unique_ptr<WindowResizer> resizer(CreateWindowResizer( |
1885 window.get(), gfx::Point(), HTCAPTION, ::wm::WINDOW_MOVE_SOURCE_MOUSE)); | 1892 window.get(), gfx::Point(), HTCAPTION, ::wm::WINDOW_MOVE_SOURCE_MOUSE)); |
1886 ASSERT_TRUE(resizer.get()); | 1893 ASSERT_TRUE(resizer.get()); |
1887 gfx::Point location = resizer->GetInitialLocation(); | 1894 gfx::Point location = resizer->GetInitialLocation(); |
1888 location.Offset(20, 20); | 1895 location.Offset(20, 20); |
1889 resizer->Drag(location, 0); | 1896 resizer->Drag(location, 0); |
1890 ToggleOverview(); | 1897 ToggleOverview(); |
1891 resizer->RevertDrag(); | 1898 resizer->RevertDrag(); |
1892 } | 1899 } |
1893 | 1900 |
| 1901 // Tests that dragging a overview window selector item to the edge of the screen |
| 1902 // snaps the window. If two windows are snapped to left and right side of the |
| 1903 // screen, exit the overview mode. |
| 1904 TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) { |
| 1905 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1906 switches::kAshEnableTabletSplitView); |
| 1907 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( |
| 1908 true); |
| 1909 |
| 1910 const gfx::Rect bounds(0, 0, 400, 400); |
| 1911 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 1912 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 1913 std::unique_ptr<aura::Window> window3(CreateWindow(bounds)); |
| 1914 |
| 1915 ToggleOverview(); |
| 1916 EXPECT_TRUE(window_selector_controller()->IsSelecting()); |
| 1917 EXPECT_EQ(split_view_controller()->IsSplitViewModeActive(), false); |
| 1918 |
| 1919 // Drag |window1| selector item to snap to left. |
| 1920 const int grid_index = 0; |
| 1921 WindowSelectorItem* selector_item1 = |
| 1922 GetWindowItemForWindow(grid_index, window1.get()); |
| 1923 const gfx::Rect selector_item_bounds1 = selector_item1->target_bounds(); |
| 1924 // Start drag in the middle of the seletor item. |
| 1925 const gfx::Point start_location1(selector_item_bounds1.CenterPoint()); |
| 1926 window_selector()->InitiateDrag(selector_item1, start_location1); |
| 1927 const gfx::Point end_location1(0, 0); |
| 1928 window_selector()->Drag(selector_item1, end_location1); |
| 1929 window_selector()->CompleteDrag(selector_item1); |
| 1930 |
| 1931 EXPECT_EQ(split_view_controller()->IsSplitViewModeActive(), true); |
| 1932 EXPECT_EQ(split_view_controller()->state(), |
| 1933 SplitViewController::LEFT_SNAPPED); |
| 1934 EXPECT_EQ(split_view_controller()->left_window(), window1.get()); |
| 1935 |
| 1936 // Drag |window2| selector item to snap to left. |
| 1937 WindowSelectorItem* selector_item2 = |
| 1938 GetWindowItemForWindow(grid_index, window2.get()); |
| 1939 const gfx::Rect selector_item_bounds2 = selector_item2->target_bounds(); |
| 1940 // Start drag in the middle of the seletor item. |
| 1941 const gfx::Point start_location2(selector_item_bounds2.CenterPoint()); |
| 1942 window_selector()->InitiateDrag(selector_item2, start_location2); |
| 1943 const gfx::Point end_location2(0, 0); |
| 1944 window_selector()->Drag(selector_item2, end_location2); |
| 1945 window_selector()->CompleteDrag(selector_item2); |
| 1946 |
| 1947 EXPECT_EQ(split_view_controller()->state(), |
| 1948 SplitViewController::LEFT_SNAPPED); |
| 1949 EXPECT_EQ(split_view_controller()->left_window(), window2.get()); |
| 1950 |
| 1951 // Drag |window3| selector item to snap to right. |
| 1952 WindowSelectorItem* selector_item3 = |
| 1953 GetWindowItemForWindow(grid_index, window3.get()); |
| 1954 const gfx::Rect selector_item_bounds3 = selector_item3->target_bounds(); |
| 1955 // Start drag in the middle of the seletor item. |
| 1956 const gfx::Point start_location3(selector_item_bounds3.CenterPoint()); |
| 1957 window_selector()->InitiateDrag(selector_item3, start_location3); |
| 1958 const gfx::Rect work_area_rect = |
| 1959 split_view_controller()->GetDisplayWorkAreaBoundsInScreen(window2.get()); |
| 1960 const gfx::Point end_location3(work_area_rect.width(), 0); |
| 1961 window_selector()->Drag(selector_item3, end_location3); |
| 1962 window_selector()->CompleteDrag(selector_item3); |
| 1963 |
| 1964 EXPECT_EQ(split_view_controller()->state(), |
| 1965 SplitViewController::BOTH_SNAPPED); |
| 1966 EXPECT_EQ(split_view_controller()->right_window(), window3.get()); |
| 1967 EXPECT_FALSE(window_selector_controller()->IsSelecting()); |
| 1968 } |
| 1969 |
1894 } // namespace ash | 1970 } // namespace ash |
OLD | NEW |