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