| 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/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.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" |
| 20 #include "ash/test/test_launcher_delegate.h" | 20 #include "ash/test/test_launcher_delegate.h" |
| 21 #include "ash/wm/coordinate_conversion.h" |
| 21 #include "ash/wm/dock/docked_window_layout_manager.h" | 22 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 22 #include "ash/wm/drag_window_resizer.h" | 23 #include "ash/wm/drag_window_resizer.h" |
| 23 #include "ash/wm/panels/panel_layout_manager.h" | 24 #include "ash/wm/panels/panel_layout_manager.h" |
| 24 #include "ash/wm/window_settings.h" | 25 #include "ash/wm/window_settings.h" |
| 25 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
| 26 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 27 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 28 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
| 29 #include "ui/aura/test/test_window_delegate.h" | 30 #include "ui/aura/test/test_window_delegate.h" |
| 30 #include "ui/base/hit_test.h" | 31 #include "ui/base/hit_test.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 const gfx::Point& point_in_parent, | 89 const gfx::Point& point_in_parent, |
| 89 int window_component) { | 90 int window_component) { |
| 90 return CreateWindowResizer( | 91 return CreateWindowResizer( |
| 91 window, | 92 window, |
| 92 point_in_parent, | 93 point_in_parent, |
| 93 window_component, | 94 window_component, |
| 94 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release(); | 95 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void DragStart(aura::Window* window) { | 98 void DragStart(aura::Window* window) { |
| 98 initial_location_in_parent_ = window->bounds().origin(); | 99 DragStartAtOffsetFromwindowOrigin(window, 0, 0); |
| 99 resizer_.reset(CreateSomeWindowResizer(window, | |
| 100 initial_location_in_parent_, | |
| 101 HTCAPTION)); | |
| 102 ASSERT_TRUE(resizer_.get()); | |
| 103 } | 100 } |
| 104 | 101 |
| 105 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, | 102 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, |
| 106 int dx, | 103 int dx, int dy) { |
| 107 int dy) { | |
| 108 initial_location_in_parent_ = | 104 initial_location_in_parent_ = |
| 109 window->bounds().origin() + gfx::Vector2d(dx, dy); | 105 window->bounds().origin() + gfx::Vector2d(dx, dy); |
| 110 resizer_.reset(CreateSomeWindowResizer(window, | 106 resizer_.reset(CreateSomeWindowResizer(window, |
| 111 initial_location_in_parent_, | 107 initial_location_in_parent_, |
| 112 HTCAPTION)); | 108 HTCAPTION)); |
| 113 ASSERT_TRUE(resizer_.get()); | 109 ASSERT_TRUE(resizer_.get()); |
| 114 } | 110 } |
| 115 | 111 |
| 116 void ResizeStartAtOffsetFromwindowOrigin(aura::Window* window, | 112 void ResizeStartAtOffsetFromwindowOrigin(aura::Window* window, |
| 117 int dx, | 113 int dx, int dy, |
| 118 int dy, | |
| 119 int window_component) { | 114 int window_component) { |
| 120 initial_location_in_parent_ = | 115 initial_location_in_parent_ = |
| 121 window->bounds().origin() + gfx::Vector2d(dx, dy); | 116 window->bounds().origin() + gfx::Vector2d(dx, dy); |
| 122 resizer_.reset(CreateSomeWindowResizer(window, | 117 resizer_.reset(CreateSomeWindowResizer(window, |
| 123 initial_location_in_parent_, | 118 initial_location_in_parent_, |
| 124 window_component)); | 119 window_component)); |
| 125 ASSERT_TRUE(resizer_.get()); | 120 ASSERT_TRUE(resizer_.get()); |
| 126 } | 121 } |
| 127 | 122 |
| 128 void DragMove(int dx, int dy) { | 123 void DragMove(int dx, int dy) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 149 } | 144 } |
| 150 | 145 |
| 151 // Test dragging the window vertically (to detach if it is a panel) and then | 146 // Test dragging the window vertically (to detach if it is a panel) and then |
| 152 // horizontally to the edge with an added offset from the edge of |dx|. | 147 // horizontally to the edge with an added offset from the edge of |dx|. |
| 153 void DragRelativeToEdge(DockedEdge edge, | 148 void DragRelativeToEdge(DockedEdge edge, |
| 154 aura::Window* window, | 149 aura::Window* window, |
| 155 int dx) { | 150 int dx) { |
| 156 DragVerticallyAndRelativeToEdge( | 151 DragVerticallyAndRelativeToEdge( |
| 157 edge, | 152 edge, |
| 158 window, | 153 window, |
| 159 dx, | 154 dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? -100 : 20, |
| 160 window_type_ == aura::client::WINDOW_TYPE_PANEL ? -100 : 20); | 155 25, 5); |
| 161 } | 156 } |
| 162 | 157 |
| 163 void DragToVerticalPositionAndToEdge(DockedEdge edge, | 158 void DragToVerticalPositionAndToEdge(DockedEdge edge, |
| 164 aura::Window* window, | 159 aura::Window* window, |
| 165 int y) { | 160 int y) { |
| 166 DragToVerticalPositionRelativeToEdge(edge, window, 0, y); | 161 DragToVerticalPositionRelativeToEdge(edge, window, 0, y); |
| 167 } | 162 } |
| 168 | 163 |
| 169 void DragToVerticalPositionRelativeToEdge(DockedEdge edge, | 164 void DragToVerticalPositionRelativeToEdge(DockedEdge edge, |
| 170 aura::Window* window, | 165 aura::Window* window, |
| 171 int dx, | 166 int dx, |
| 172 int y) { | 167 int y) { |
| 173 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 168 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 174 DragVerticallyAndRelativeToEdge(edge, window, dx, y - initial_bounds.y()); | 169 DragVerticallyAndRelativeToEdge(edge, |
| 170 window, |
| 171 dx, y - initial_bounds.y(), |
| 172 25, 5); |
| 175 } | 173 } |
| 176 | 174 |
| 177 // Detach if our window is a panel, then drag it vertically by |dy| and | 175 // Detach if our window is a panel, then drag it vertically by |dy| and |
| 178 // horizontally to the edge with an added offset from the edge of |dx|. | 176 // horizontally to the edge with an added offset from the edge of |dx|. |
| 179 void DragVerticallyAndRelativeToEdge(DockedEdge edge, | 177 void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
| 180 aura::Window* window, | 178 aura::Window* window, |
| 181 int dx, | 179 int dx, int dy, |
| 182 int dy) { | 180 int grab_x, int grab_y) { |
| 183 aura::RootWindow* root_window = window->GetRootWindow(); | |
| 184 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 181 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 182 // avoid snap by clicking away from the border |
| 183 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, |
| 184 grab_x, grab_y)); |
| 185 | 185 |
| 186 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { | 186 gfx::Rect work_area = |
| 187 ASSERT_NO_FATAL_FAILURE(DragStart(window)); | 187 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
| 188 EXPECT_TRUE(wm::GetWindowSettings(window)->panel_attached()); | 188 gfx::Point initial_location_in_screen = initial_location_in_parent_; |
| 189 | 189 wm::ConvertPointToScreen(window->parent(), &initial_location_in_screen); |
| 190 // Drag enough to detach since our tests assume panels to be initially | |
| 191 // detached. | |
| 192 DragMove(0, dy); | |
| 193 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | |
| 194 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); | |
| 195 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | |
| 196 | |
| 197 // The panel should be detached when the drag completes. | |
| 198 DragEnd(); | |
| 199 | |
| 200 EXPECT_FALSE(wm::GetWindowSettings(window)->panel_attached()); | |
| 201 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | |
| 202 window->parent()->id()); | |
| 203 EXPECT_EQ(root_window, window->GetRootWindow()); | |
| 204 } | |
| 205 | |
| 206 // avoid snap by clicking away from the border | |
| 207 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); | |
| 208 | |
| 209 // Drag the window left or right to the edge (or almost to it). | 190 // Drag the window left or right to the edge (or almost to it). |
| 210 if (edge == DOCKED_EDGE_LEFT) | 191 if (edge == DOCKED_EDGE_LEFT) |
| 211 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); | 192 dx += work_area.x() - initial_location_in_screen.x(); |
| 212 else if (edge == DOCKED_EDGE_RIGHT) | 193 else if (edge == DOCKED_EDGE_RIGHT) |
| 213 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); | 194 dx += work_area.right() - 1 - initial_location_in_screen.x(); |
| 214 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); | 195 DragMove(dx, dy); |
| 215 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 196 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 216 // Release the mouse and the panel should be attached to the dock. | 197 // Release the mouse and the panel should be attached to the dock. |
| 217 DragEnd(); | 198 DragEnd(); |
| 218 | 199 |
| 219 // x-coordinate can get adjusted by snapping or sticking. | 200 // x-coordinate can get adjusted by snapping or sticking. |
| 220 // y-coordinate could be changed by possible automatic layout if docked. | 201 // y-coordinate could be changed by possible automatic layout if docked. |
| 221 if (window->parent()->id() != internal::kShellWindowId_DockedContainer) | 202 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && |
| 203 GetRestoreBoundsInScreen(window) == NULL) { |
| 222 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 204 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 205 } |
| 223 } | 206 } |
| 224 | 207 |
| 225 bool test_panels() const { | 208 bool test_panels() const { |
| 226 return window_type_ == aura::client::WINDOW_TYPE_PANEL; | 209 return window_type_ == aura::client::WINDOW_TYPE_PANEL; |
| 227 } | 210 } |
| 228 | 211 |
| 229 private: | 212 private: |
| 230 scoped_ptr<WindowResizer> resizer_; | 213 scoped_ptr<WindowResizer> resizer_; |
| 231 LauncherModel* model_; | 214 LauncherModel* model_; |
| 232 aura::client::WindowType window_type_; | 215 aura::client::WindowType window_type_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 246 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 229 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 247 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 230 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 248 | 231 |
| 249 // The window should be attached and snapped to the right edge. | 232 // The window should be attached and snapped to the right edge. |
| 250 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 233 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 251 window->GetBoundsInScreen().right()); | 234 window->GetBoundsInScreen().right()); |
| 252 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 235 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 253 } | 236 } |
| 254 | 237 |
| 255 // Verifies a window can be dragged and attached to the dock | 238 // Verifies a window can be dragged and attached to the dock |
| 256 // even if we overshoot the screen edge by a few pixels (sticky edge) | 239 // even if pointer overshoots the screen edge by a few pixels (sticky edge) |
| 257 TEST_P(DockedWindowResizerTest, AttachRightOvershoot) { | 240 TEST_P(DockedWindowResizerTest, AttachRightOvershoot) { |
| 258 if (!SupportsHostWindowResize()) | 241 if (!SupportsHostWindowResize()) |
| 259 return; | 242 return; |
| 260 | 243 |
| 261 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 244 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 262 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4); | 245 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4); |
| 263 | 246 |
| 264 // The window should be attached and snapped to the right edge. | 247 // The window should be attached and snapped to the right edge. |
| 265 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 248 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 266 window->GetBoundsInScreen().right()); | 249 window->GetBoundsInScreen().right()); |
| 267 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 250 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 268 } | 251 } |
| 269 | 252 |
| 270 // Verifies a window can be dragged and then if not quite reaching the screen | 253 // Verifies a window can be dragged and then if a pointer is not quite reaching |
| 271 // edge it does not get docked to a screen edge and stays in the desktop. | 254 // the screen edge the window does not get docked and stays in the desktop. |
| 272 TEST_P(DockedWindowResizerTest, AttachRightUndershoot) { | 255 TEST_P(DockedWindowResizerTest, AttachRightUndershoot) { |
| 273 if (!SupportsHostWindowResize()) | 256 if (!SupportsHostWindowResize()) |
| 274 return; | 257 return; |
| 275 | 258 |
| 276 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 259 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 277 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), -1); | 260 // Grabbing at 70px ensures that at least 30% of the window is in screen, |
| 261 // otherwise the window would be adjusted in |
| 262 // WorkspaceLayoutManager::AdjustWindowBoundsWhenAdded. |
| 263 const int kGrabOffsetX = 70; |
| 264 const int kUndershootBy = 1; |
| 265 DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, |
| 266 window.get(), |
| 267 -kUndershootBy, test_panels() ? -100 : 20, |
| 268 kGrabOffsetX, 5); |
| 278 | 269 |
| 279 // The window should not be attached to the dock. | 270 // The window right should be past the screen edge but not docked. |
| 280 EXPECT_EQ(window->GetRootWindow()->bounds().right() - 1, | 271 // Initial touch point is 70px to the right which helps to find where the edge |
| 272 // should be. |
| 273 EXPECT_EQ(window->GetRootWindow()->bounds().right() + |
| 274 window->bounds().width() - kGrabOffsetX - kUndershootBy - 1, |
| 281 window->GetBoundsInScreen().right()); | 275 window->GetBoundsInScreen().right()); |
| 282 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 276 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
| 283 window->parent()->id()); | 277 window->parent()->id()); |
| 284 } | 278 } |
| 285 | 279 |
| 286 // Verifies a window can be dragged and attached to the dock. | 280 // Verifies a window can be dragged and attached to the dock. |
| 287 TEST_P(DockedWindowResizerTest, AttachLeftPrecise) { | 281 TEST_P(DockedWindowResizerTest, AttachLeftPrecise) { |
| 288 if (!SupportsHostWindowResize()) | 282 if (!SupportsHostWindowResize()) |
| 289 return; | 283 return; |
| 290 | 284 |
| 291 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 285 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 292 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); | 286 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); |
| 293 | 287 |
| 294 // The window should be attached and snapped to the left dock. | 288 // The window should be attached and snapped to the left dock. |
| 295 EXPECT_EQ(window->GetRootWindow()->bounds().x(), | 289 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 296 window->GetBoundsInScreen().x()); | 290 window->GetBoundsInScreen().x()); |
| 297 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 291 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 298 } | 292 } |
| 299 | 293 |
| 300 // Verifies a window can be dragged and attached to the dock | 294 // Verifies a window can be dragged and attached to the dock |
| 301 // even if we overshoot the screen edge by a few pixels (sticky edge) | 295 // even if pointer overshoots the screen edge by a few pixels (sticky edge) |
| 302 TEST_P(DockedWindowResizerTest, AttachLeftOvershoot) { | 296 TEST_P(DockedWindowResizerTest, AttachLeftOvershoot) { |
| 303 if (!SupportsHostWindowResize()) | 297 if (!SupportsHostWindowResize()) |
| 304 return; | 298 return; |
| 305 | 299 |
| 306 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 300 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 307 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4); | 301 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4); |
| 308 | 302 |
| 309 // The window should be attached and snapped to the left dock. | 303 // The window should be attached and snapped to the left dock. |
| 310 EXPECT_EQ(window->GetRootWindow()->bounds().x(), | 304 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 311 window->GetBoundsInScreen().x()); | 305 window->GetBoundsInScreen().x()); |
| 312 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 306 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 313 } | 307 } |
| 314 | 308 |
| 315 // Verifies a window can be dragged and then if not quite reaching the screen | 309 // Verifies a window can be dragged and then if a pointer is not quite reaching |
| 316 // edge it does not get docked to a screen edge and stays in the desktop. | 310 // the screen edge the window does not get docked and stays in the desktop. |
| 317 TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) { | 311 TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) { |
| 318 if (!SupportsHostWindowResize()) | 312 if (!SupportsHostWindowResize()) |
| 319 return; | 313 return; |
| 320 | 314 |
| 321 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 315 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 322 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1); | 316 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1); |
| 323 | 317 |
| 324 // The window should not be attached to the dock. | 318 // The window should be touching the screen edge but not docked. |
| 325 EXPECT_EQ(window->GetRootWindow()->bounds().x() + 1, | 319 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 326 window->GetBoundsInScreen().x()); | 320 window->GetBoundsInScreen().x()); |
| 327 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 321 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
| 328 window->parent()->id()); | 322 window->parent()->id()); |
| 329 } | 323 } |
| 330 | 324 |
| 331 // Dock on the right side, change shelf alignment, check that windows move to | 325 // Dock on the right side, change shelf alignment, check that windows move to |
| 332 // the opposite side. | 326 // the opposite side. |
| 333 TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) { | 327 TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) { |
| 334 if (!SupportsHostWindowResize()) | 328 if (!SupportsHostWindowResize()) |
| 335 return; | 329 return; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 474 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 481 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 475 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 482 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50); | 476 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50); |
| 483 | 477 |
| 484 // The first window should be attached and snapped to the right edge. | 478 // The first window should be attached and snapped to the right edge. |
| 485 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 479 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 486 w1->GetBoundsInScreen().right()); | 480 w1->GetBoundsInScreen().right()); |
| 487 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 481 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 488 | 482 |
| 489 // The second window should be near the left edge but not snapped. | 483 // The second window should be near the left edge but not snapped. |
| 484 // Normal window will get side-maximized while panels will not. |
| 490 EXPECT_EQ(w2->GetRootWindow()->bounds().x(), w2->GetBoundsInScreen().x()); | 485 EXPECT_EQ(w2->GetRootWindow()->bounds().x(), w2->GetBoundsInScreen().x()); |
| 491 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 486 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 492 } | 487 } |
| 493 | 488 |
| 494 // Reverting drag | 489 // Reverting drag |
| 495 TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) { | 490 TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) { |
| 496 if (!SupportsHostWindowResize()) | 491 if (!SupportsHostWindowResize()) |
| 497 return; | 492 return; |
| 498 | 493 |
| 499 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 494 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 518 window->parent()->id()); | 513 window->parent()->id()); |
| 519 } | 514 } |
| 520 | 515 |
| 521 // Move a docked window to the second display | 516 // Move a docked window to the second display |
| 522 TEST_P(DockedWindowResizerTest, DragAcrossDisplays) { | 517 TEST_P(DockedWindowResizerTest, DragAcrossDisplays) { |
| 523 if (!SupportsMultipleDisplays()) | 518 if (!SupportsMultipleDisplays()) |
| 524 return; | 519 return; |
| 525 | 520 |
| 526 UpdateDisplay("800x800,800x800"); | 521 UpdateDisplay("800x800,800x800"); |
| 527 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 522 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 523 EXPECT_EQ(2, static_cast<int>(root_windows.size())); |
| 528 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 524 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 529 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 525 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 530 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 526 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 531 | 527 |
| 532 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 528 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| 533 // The window should be attached and snapped to the right edge. | 529 // The window should be attached and snapped to the right edge. |
| 534 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 530 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 535 window->GetBoundsInScreen().right()); | 531 window->GetBoundsInScreen().right()); |
| 536 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 532 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 537 | 533 |
| 538 // Undock and move to the right - enough to get it peeking at the other screen | 534 // Try dragging to the right - enough to get it peeking at the other screen |
| 539 // but not enough to land in the other screen | 535 // but not enough to land in the other screen. |
| 536 // The window should stay on the left screen. |
| 540 ASSERT_NO_FATAL_FAILURE(DragStart(window.get())); | 537 ASSERT_NO_FATAL_FAILURE(DragStart(window.get())); |
| 541 DragMove(70, 0); | 538 DragMove(100, 0); |
| 542 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | |
| 543 DragEnd(); | |
| 544 EXPECT_NE(window->GetRootWindow()->bounds().right(), | |
| 545 window->GetBoundsInScreen().right()); | |
| 546 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | |
| 547 window->parent()->id()); | |
| 548 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | |
| 549 | |
| 550 // Move back left - should dock again. | |
| 551 ASSERT_NO_FATAL_FAILURE(DragStart(window.get())); | |
| 552 DragMove(-70, 0); | |
| 553 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 539 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 554 DragEnd(); | 540 DragEnd(); |
| 555 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 541 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 556 window->GetBoundsInScreen().right()); | 542 window->GetBoundsInScreen().right()); |
| 557 EXPECT_EQ(internal::kShellWindowId_DockedContainer, | 543 EXPECT_EQ(internal::kShellWindowId_DockedContainer, |
| 558 window->parent()->id()); | 544 window->parent()->id()); |
| 559 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 545 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 560 | 546 |
| 561 // Undock and move to the right - enough to get the mouse pointer past the | 547 // Undock and move to the right - enough to get the mouse pointer past the |
| 562 // edge of the screen and into the second screen. The window should now be | 548 // edge of the screen and into the second screen. The window should now be |
| 563 // in the second screen and not docked. | 549 // in the second screen and not docked. |
| 564 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin( | 550 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin( |
| 565 window.get(), | 551 window.get(), |
| 566 window->bounds().width()/2 + 10, | 552 window->bounds().width()/2 + 10, |
| 567 0)); | 553 0)); |
| 568 DragMove(window->bounds().width()/2 - 5, 0); | 554 DragMove(window->bounds().width()/2 - 5, 0); |
| 569 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 555 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 570 DragEnd(); | 556 DragEnd(); |
| 571 EXPECT_NE(window->GetRootWindow()->bounds().right(), | 557 EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| 572 window->GetBoundsInScreen().right()); | 558 window->GetBoundsInScreen().right()); |
| 573 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 559 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
| 574 window->parent()->id()); | 560 window->parent()->id()); |
| 575 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 561 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 576 | 562 |
| 577 // Keep dragging it to the right until it docks. The window should now be | 563 // Keep dragging it to the right until its left edge touches the screen edge. |
| 578 // in the second screen. | 564 // The window should now be in the second screen and not docked. |
| 579 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin( | 565 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin( |
| 580 window.get(), | 566 window.get(), |
| 581 window->bounds().width()/2 + 10, | 567 window->bounds().width()/2 + 10, |
| 582 0)); | 568 0)); |
| 583 DragMove(window->GetRootWindow()->GetBoundsInScreen().x() - | 569 DragMove(window->GetRootWindow()->GetBoundsInScreen().x() - |
| 584 window->GetBoundsInScreen().x(), | 570 window->GetBoundsInScreen().x(), |
| 585 0); | 571 0); |
| 586 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 572 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 587 DragEnd(); | 573 DragEnd(); |
| 588 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), | 574 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), |
| 589 window->GetBoundsInScreen().x()); | 575 window->GetBoundsInScreen().x()); |
| 590 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 576 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id()); |
| 591 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 577 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 592 } | 578 } |
| 593 | 579 |
| 594 // Dock two windows, undock one. | 580 // Dock two windows, undock one. |
| 595 // Test the docked windows area size and default container resizing. | 581 // Test the docked windows area size and default container resizing. |
| 596 TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) | 582 TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) |
| 597 { | 583 { |
| 598 if (!SupportsHostWindowResize()) | 584 if (!SupportsHostWindowResize()) |
| 599 return; | 585 return; |
| 600 | 586 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - | 644 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - |
| 659 (w2->bounds().width()/2 + 20), | 645 (w2->bounds().width()/2 + 20), |
| 660 w2->GetBoundsInScreen().right()); | 646 w2->GetBoundsInScreen().right()); |
| 661 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 647 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 662 // Dock width should be set to remaining single docked window. | 648 // Dock width should be set to remaining single docked window. |
| 663 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 649 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 664 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 650 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 665 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 651 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 666 } | 652 } |
| 667 | 653 |
| 668 // Dock one windows. Maximize other testing desktop resizing. | 654 // Dock one of the windows. Maximize other testing desktop resizing. |
| 669 TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) | 655 TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) |
| 670 { | 656 { |
| 671 if (!SupportsHostWindowResize()) | 657 if (!SupportsHostWindowResize()) |
| 672 return; | 658 return; |
| 673 | 659 |
| 674 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 660 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 675 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); | 661 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201))); |
| 676 // Work area should cover the whole screen. | 662 // Work area should cover the whole screen. |
| 677 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 663 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), |
| 678 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 664 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 679 | 665 |
| 680 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 666 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 681 // A window should be attached and snapped to the right edge. | 667 // A window should be attached and snapped to the right edge. |
| 682 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 668 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 683 w1->GetBoundsInScreen().right()); | 669 w1->GetBoundsInScreen().right()); |
| 684 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 670 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 685 DockedWindowLayoutManager* manager = | 671 DockedWindowLayoutManager* manager = |
| 686 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 672 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 687 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 673 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 688 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 674 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 689 | 675 |
| 690 DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_RIGHT, | 676 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 25, 5)); |
| 691 w2.get(), | 677 DragMove(w2->GetRootWindow()->bounds().right() |
| 692 -(w2->bounds().width()/2 + 20), | 678 -w2->bounds().width() |
| 693 50); | 679 -(w2->bounds().width()/2 + 20) |
| 680 -w2->bounds().x(), |
| 681 50 - w2->bounds().y()); |
| 682 DragEnd(); |
| 694 // The first window should be still docked. | 683 // The first window should be still docked. |
| 695 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 684 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 696 w1->GetBoundsInScreen().right()); | 685 w1->GetBoundsInScreen().right()); |
| 697 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 686 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 698 | 687 |
| 699 // The second window should be floating on the desktop. | 688 // The second window should be floating on the desktop. |
| 700 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - | 689 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - |
| 701 (w2->bounds().width()/2 + 20), | 690 (w2->bounds().width()/2 + 20), |
| 702 w2->GetBoundsInScreen().right()); | 691 w2->GetBoundsInScreen().right()); |
| 703 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 692 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 731 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 720 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 732 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); | 721 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); |
| 733 EXPECT_EQ(0, manager->docked_width_); | 722 EXPECT_EQ(0, manager->docked_width_); |
| 734 // The second window should now get resized and take up the whole screen. | 723 // The second window should now get resized and take up the whole screen. |
| 735 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), | 724 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width(), |
| 736 w2->bounds().width()); | 725 w2->bounds().width()); |
| 737 | 726 |
| 738 // Dock the first window to the left edge. | 727 // Dock the first window to the left edge. |
| 739 // Click at an offset from origin to prevent snapping. | 728 // Click at an offset from origin to prevent snapping. |
| 740 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 10, 0)); | 729 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 10, 0)); |
| 741 DragMove(-w1->bounds().x(), 0); | 730 // Drag left to get pointer touching the screen edge. |
| 731 DragMove(-w1->bounds().x() - 10, 0); |
| 742 // Alignment set to "NONE" during the drag of the window when none are docked. | 732 // Alignment set to "NONE" during the drag of the window when none are docked. |
| 743 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); | 733 EXPECT_EQ(DOCKED_ALIGNMENT_NONE, manager->alignment_); |
| 744 // Release the mouse and the window should be now attached to the edge. | 734 // Release the mouse and the window should be now attached to the edge. |
| 745 DragEnd(); | 735 DragEnd(); |
| 746 // Dock should get expanded and desktop should get shrunk. | 736 // Dock should get expanded and desktop should get shrunk. |
| 747 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 737 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 748 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); | 738 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); |
| 749 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 739 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 750 // Second window should still be in the desktop. | 740 // Second window should still be in the desktop. |
| 751 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 741 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 780 DockedWindowLayoutManager* manager = | 770 DockedWindowLayoutManager* manager = |
| 781 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); | 771 static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager()); |
| 782 // The first window should be docked. | 772 // The first window should be docked. |
| 783 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), | 773 EXPECT_EQ(w1->GetRootWindow()->bounds().x(), |
| 784 w1->GetBoundsInScreen().x()); | 774 w1->GetBoundsInScreen().x()); |
| 785 // Dock width should be set to that of a single docked window. | 775 // Dock width should be set to that of a single docked window. |
| 786 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 776 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 787 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); | 777 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); |
| 788 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 778 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 789 | 779 |
| 790 // Position second window in the desktop just to the right of the docked w1. | 780 // Position second window in the desktop 20px to the right of the docked w1. |
| 791 DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, | 781 DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, |
| 792 w2.get(), | 782 w2.get(), |
| 793 w1->bounds().right() + 20, | 783 20 + 25 - |
| 784 DockedWindowLayoutManager::kMinDockGap, |
| 794 50); | 785 50); |
| 795 // The second window should be floating on the desktop. | 786 // The second window should be floating on the desktop. |
| 796 EXPECT_EQ(w2->GetRootWindow()->bounds().x() + (w1->bounds().right() + 20), | 787 EXPECT_EQ(w2->GetRootWindow()->bounds().x() + (w1->bounds().right() + 20), |
| 797 w2->GetBoundsInScreen().x()); | 788 w2->GetBoundsInScreen().x()); |
| 798 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 789 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 799 // Dock width should be set to that of a single docked window. | 790 // Dock width should be set to that of a single docked window. |
| 800 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 791 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 801 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); | 792 EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, manager->alignment_); |
| 802 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 793 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 803 | 794 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 879 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 889 // Dock width should be set to a wider window. | 880 // Dock width should be set to a wider window. |
| 890 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 881 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 891 EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()), | 882 EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()), |
| 892 manager->docked_width_); | 883 manager->docked_width_); |
| 893 | 884 |
| 894 // Resize the first window left by a bit and test that the dock expands. | 885 // Resize the first window left by a bit and test that the dock expands. |
| 895 int previous_width = w1->bounds().width(); | 886 int previous_width = w1->bounds().width(); |
| 896 const int kResizeSpan1 = 30; | 887 const int kResizeSpan1 = 30; |
| 897 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), | 888 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), |
| 898 0, | 889 0, 20, |
| 899 20, | |
| 900 HTLEFT)); | 890 HTLEFT)); |
| 901 DragMove(-kResizeSpan1, 0); | 891 DragMove(-kResizeSpan1, 0); |
| 902 // Alignment set to "RIGHT" during the drag because dock has a window in it. | 892 // Alignment set to "RIGHT" during the drag because dock has a window in it. |
| 903 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 893 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 904 // Release the mouse and the window should be attached to the edge. | 894 // Release the mouse and the window should be attached to the edge. |
| 905 DragEnd(); | 895 DragEnd(); |
| 906 // Dock should still have both windows in it. | 896 // Dock should still have both windows in it. |
| 907 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 897 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 908 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 898 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 909 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 899 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 910 // w1 is now wider than w2 and the dock should expand and be as wide as w1. | 900 // w1 is now wider than w2 and the dock should expand and be as wide as w1. |
| 911 EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width()); | 901 EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width()); |
| 912 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); | 902 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); |
| 913 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 903 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 914 // Desktop work area should shrink. | 904 // Desktop work area should shrink. |
| 915 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 905 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 916 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 906 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 917 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 907 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 918 | 908 |
| 919 // Resize the first window left by more than the dock maximum width. | 909 // Resize the first window left by more than the dock maximum width. |
| 920 // This should cause the window to overhang and the dock to shrink to w2. | 910 // This should cause the window width to be restricted by maximum dock width. |
| 921 previous_width = w1->bounds().width(); | 911 previous_width = w1->bounds().width(); |
| 922 const int kResizeSpan2 = 250; | 912 const int kResizeSpan2 = 250; |
| 923 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), | 913 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), |
| 924 0, | 914 0, 20, |
| 925 20, | |
| 926 HTLEFT)); | 915 HTLEFT)); |
| 927 DragMove(-kResizeSpan2, 0); | 916 DragMove(-kResizeSpan2, 0); |
| 928 // Alignment set to "RIGHT" during the drag because dock has a window in it. | 917 // Alignment set to "RIGHT" during the drag because dock has a window in it. |
| 929 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 918 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 930 // Release the mouse and the window should be attached to the edge. | 919 // Release the mouse and the window should be attached to the edge. |
| 931 DragEnd(); | 920 DragEnd(); |
| 932 // Dock should still have both windows in it. | 921 // Dock should still have both windows in it. |
| 933 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 922 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 934 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 923 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 935 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 924 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 936 // w1 is now wider than the maximum dock width and the dock should shrink to | 925 // w1 is now as wide as the maximum dock width and the dock should get |
| 937 // the next widest window (w2). | 926 // resized to the maximum width. |
| 938 EXPECT_EQ(previous_width + kResizeSpan2, w1->bounds().width()); | 927 EXPECT_EQ(DockedWindowLayoutManager::kMaxDockWidth, w1->bounds().width()); |
| 939 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); | 928 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); |
| 940 EXPECT_EQ(w2->bounds().width(), manager->docked_width_); | 929 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 941 // Desktop work area should shrink. | 930 // Desktop work area should shrink. |
| 942 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 931 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 943 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 932 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 944 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 933 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 945 | 934 |
| 946 // Resize the first window right to get it completely inside the docked area. | 935 // Resize the first window right to get it completely inside the docked area. |
| 947 previous_width = w1->bounds().width(); | 936 previous_width = w1->bounds().width(); |
| 948 const int kResizeSpan3 = 100; | 937 const int kResizeSpan3 = 100; |
| 949 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), | 938 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), |
| 950 0, | 939 0, 20, |
| 951 20, | |
| 952 HTLEFT)); | 940 HTLEFT)); |
| 953 DragMove(kResizeSpan3, 0); | 941 DragMove(kResizeSpan3, 0); |
| 954 // Alignment set to "RIGHT" during the drag because dock has a window in it. | 942 // Alignment set to "RIGHT" during the drag because dock has a window in it. |
| 955 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 943 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 956 // Release the mouse and the window should be attached to the edge. | 944 // Release the mouse and the window should be attached to the edge. |
| 957 DragEnd(); | 945 DragEnd(); |
| 958 // Dock should still have both windows in it. | 946 // Dock should still have both windows in it. |
| 959 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 947 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 960 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 948 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 961 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 949 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 962 // w1 is still wider than w2 so the dock should expand and be as wide as w1. | 950 // w1 is still wider than w2 so the dock should expand and be as wide as w1. |
| 963 EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width()); | 951 EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width()); |
| 964 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); | 952 EXPECT_GT(w1->bounds().width(), w2->bounds().width()); |
| 965 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); | 953 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 966 // Desktop work area should shrink. | 954 // Desktop work area should shrink. |
| 967 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 955 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 968 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 956 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 969 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 957 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 970 | 958 |
| 971 // Resize the first window left to be overhang again. | 959 // Resize the first window left to be overhang again. |
| 972 previous_width = w1->bounds().width(); | 960 previous_width = w1->bounds().width(); |
| 973 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), | 961 ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromwindowOrigin(w1.get(), |
| 974 0, | 962 0, 20, |
| 975 20, | |
| 976 HTLEFT)); | 963 HTLEFT)); |
| 977 DragMove(-kResizeSpan3, 0); | 964 DragMove(-kResizeSpan3, 0); |
| 978 DragEnd(); | 965 DragEnd(); |
| 979 EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width()); | 966 EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width()); |
| 980 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 967 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 981 // Docked area should be as wide as the second window - the first is too wide. | 968 // Docked area should be as wide as possible (maximum) and same as w1. |
| 982 EXPECT_EQ(w2->bounds().width(), manager->docked_width_); | 969 EXPECT_EQ(DockedWindowLayoutManager::kMaxDockWidth, manager->docked_width_); |
| 970 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 983 | 971 |
| 984 // Undock the second window. Docked area should shrink to its minimum size. | 972 // Undock the second window. Docked area should shrink to its minimum size. |
| 985 ASSERT_NO_FATAL_FAILURE(DragStart(w2.get())); | 973 ASSERT_NO_FATAL_FAILURE(DragStart(w2.get())); |
| 986 // Drag up as well to avoid attaching panels to launcher shelf. | 974 // Drag up as well to avoid attaching panels to launcher shelf. |
| 987 DragMove(-40, -100); | 975 DragMove(-(400 - 201), -100); |
| 988 // Alignment set to "RIGHT" since we have another window docked. | 976 // Alignment set to "RIGHT" since we have another window docked. |
| 989 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 977 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 990 // Release the mouse and the window should be no longer attached to the edge. | 978 // Release the mouse and the window should be no longer attached to the edge. |
| 991 DragEnd(); | 979 DragEnd(); |
| 992 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 980 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 993 // Dock should get shrunk to minimum size. | 981 // Dock should be as wide as w1 (and same as maximum width). |
| 994 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); | 982 EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, manager->alignment_); |
| 995 EXPECT_EQ(manager->kMinDockWidth, manager->docked_width_); | 983 EXPECT_EQ(DockedWindowLayoutManager::kMaxDockWidth, manager->docked_width_); |
| 984 EXPECT_EQ(w1->bounds().width(), manager->docked_width_); |
| 996 // The first window should be still docked. | 985 // The first window should be still docked. |
| 997 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 986 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 998 // Desktop work area should be inset. | 987 // Desktop work area should be inset. |
| 999 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - | 988 EXPECT_EQ(ScreenAsh::GetDisplayBoundsInParent(w2.get()).width() - |
| 1000 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, | 989 manager->docked_width_ - DockedWindowLayoutManager::kMinDockGap, |
| 1001 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); | 990 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w2.get()).width()); |
| 1002 } | 991 } |
| 1003 | 992 |
| 1004 TEST_P(DockedWindowResizerTest, DragToShelf) | 993 TEST_P(DockedWindowResizerTest, DragToShelf) |
| 1005 { | 994 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 } | 1036 } |
| 1048 } | 1037 } |
| 1049 | 1038 |
| 1050 // Tests run twice - on both panels and normal windows | 1039 // Tests run twice - on both panels and normal windows |
| 1051 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1040 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1052 DockedWindowResizerTest, | 1041 DockedWindowResizerTest, |
| 1053 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 1042 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
| 1054 aura::client::WINDOW_TYPE_PANEL)); | 1043 aura::client::WINDOW_TYPE_PANEL)); |
| 1055 } // namespace internal | 1044 } // namespace internal |
| 1056 } // namespace ash | 1045 } // namespace ash |
| OLD | NEW |