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_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_controller.h" | 8 #include "ash/display/display_controller.h" |
9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 const gfx::Point& point_in_parent, | 90 const gfx::Point& point_in_parent, |
91 int window_component) { | 91 int window_component) { |
92 return CreateWindowResizer( | 92 return CreateWindowResizer( |
93 window, | 93 window, |
94 point_in_parent, | 94 point_in_parent, |
95 window_component, | 95 window_component, |
96 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release(); | 96 aura::client::WINDOW_MOVE_SOURCE_MOUSE).release(); |
97 } | 97 } |
98 | 98 |
99 void DragStart(aura::Window* window) { | 99 void DragStart(aura::Window* window) { |
100 initial_location_in_parent_ = window->bounds().origin(); | 100 DragStartAtOffsetFromwindowOrigin(window, 0, 0); |
101 resizer_.reset(CreateSomeWindowResizer(window, | |
102 initial_location_in_parent_, | |
103 HTCAPTION)); | |
104 ASSERT_TRUE(resizer_.get()); | |
105 } | 101 } |
106 | 102 |
107 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, | 103 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, |
108 int dx, | 104 int dx, |
109 int dy) { | 105 int dy) { |
110 initial_location_in_parent_ = | 106 initial_location_in_parent_ = |
111 window->bounds().origin() + gfx::Vector2d(dx, dy); | 107 window->bounds().origin() + gfx::Vector2d(dx, dy); |
112 resizer_.reset(CreateSomeWindowResizer(window, | 108 resizer_.reset(CreateSomeWindowResizer(window, |
113 initial_location_in_parent_, | 109 initial_location_in_parent_, |
114 HTCAPTION)); | 110 HTCAPTION)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // Detach if our window is a panel, then drag it vertically by |dy| and | 164 // Detach if our window is a panel, then drag it vertically by |dy| and |
169 // horizontally to the edge with an added offset from the edge of |dx|. | 165 // horizontally to the edge with an added offset from the edge of |dx|. |
170 void DragVerticallyAndRelativeToEdge(DockedEdge edge, | 166 void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
171 aura::Window* window, | 167 aura::Window* window, |
172 int dx, | 168 int dx, |
173 int dy) { | 169 int dy) { |
174 aura::RootWindow* root_window = window->GetRootWindow(); | 170 aura::RootWindow* root_window = window->GetRootWindow(); |
175 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 171 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
176 | 172 |
177 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { | 173 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { |
178 ASSERT_NO_FATAL_FAILURE(DragStart(window)); | 174 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); |
179 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); | 175 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
180 | 176 |
181 // Drag enough to detach since our tests assume panels to be initially | 177 // Drag enough to detach since our tests assume panels to be initially |
182 // detached. | 178 // detached. |
183 DragMove(0, dy); | 179 DragMove(0, dy); |
184 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 180 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
185 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); | 181 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
186 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 182 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
187 | 183 |
188 // The panel should be detached when the drag completes. | 184 // The panel should be detached when the drag completes. |
189 DragEnd(); | 185 DragEnd(); |
190 | 186 |
191 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); | 187 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
192 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 188 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
193 window->parent()->id()); | 189 window->parent()->id()); |
194 EXPECT_EQ(root_window, window->GetRootWindow()); | 190 EXPECT_EQ(root_window, window->GetRootWindow()); |
195 } | 191 } |
196 | 192 |
197 // avoid snap by clicking away from the border | 193 // avoid snap by clicking away from the border |
198 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); | 194 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); |
199 | 195 |
| 196 gfx::Rect work_area = |
| 197 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
200 // Drag the window left or right to the edge (or almost to it). | 198 // Drag the window left or right to the edge (or almost to it). |
201 if (edge == DOCKED_EDGE_LEFT) | 199 if (edge == DOCKED_EDGE_LEFT) |
202 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); | 200 dx += work_area.x() - initial_location_in_parent_.x(); |
203 else if (edge == DOCKED_EDGE_RIGHT) | 201 else if (edge == DOCKED_EDGE_RIGHT) |
204 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); | 202 dx += work_area.right() - 1 - initial_location_in_parent_.x(); |
205 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); | 203 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); |
206 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 204 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
207 // Release the mouse and the panel should be attached to the dock. | 205 // Release the mouse and the panel should be attached to the dock. |
208 DragEnd(); | 206 DragEnd(); |
209 | 207 |
210 // x-coordinate can get adjusted by snapping or sticking. | 208 // x-coordinate can get adjusted by snapping or sticking. |
211 // y-coordinate could be changed by possible automatic layout if docked. | 209 // y-coordinate could be changed by possible automatic layout if docked. |
212 if (window->parent()->id() != internal::kShellWindowId_DockedContainer) | 210 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && |
| 211 GetRestoreBoundsInScreen(window) == NULL) { |
213 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 212 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 213 } |
214 } | 214 } |
215 | 215 |
216 private: | 216 private: |
217 scoped_ptr<WindowResizer> resizer_; | 217 scoped_ptr<WindowResizer> resizer_; |
218 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; | 218 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; |
219 aura::client::WindowType window_type_; | 219 aura::client::WindowType window_type_; |
220 | 220 |
221 // Location at start of the drag in |window->parent()|'s coordinates. | 221 // Location at start of the drag in |window->parent()|'s coordinates. |
222 gfx::Point initial_location_in_parent_; | 222 gfx::Point initial_location_in_parent_; |
223 | 223 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); | 279 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
280 | 280 |
281 // The windows should be attached and snapped to the right side of the screen. | 281 // The windows should be attached and snapped to the right side of the screen. |
282 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 282 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
283 w1->GetBoundsInScreen().right()); | 283 w1->GetBoundsInScreen().right()); |
284 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 284 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
285 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 285 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
286 w2->GetBoundsInScreen().right()); | 286 w2->GetBoundsInScreen().right()); |
287 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 287 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
288 | 288 |
| 289 LOG(INFO) << "w1 at " << w1->GetBoundsInScreen().ToString(); |
| 290 LOG(INFO) << "w2 at " << w2->GetBoundsInScreen().ToString(); |
289 // Drag w2 above w1. | 291 // Drag w2 above w1. |
290 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); | 292 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); |
291 DragMove(0, w1->bounds().y() - w2->bounds().y() - 20); | 293 DragMove(0, w1->bounds().y() - w2->bounds().y() + 20); |
292 DragEnd(); | 294 DragEnd(); |
| 295 LOG(INFO) << "w1 at " << w1->GetBoundsInScreen().ToString(); |
| 296 LOG(INFO) << "w2 at " << w2->GetBoundsInScreen().ToString(); |
293 | 297 |
294 // Test the new windows order and that the gaps differ at most by a pixel. | 298 // Test the new windows order and that the gaps differ at most by a pixel. |
295 int gap1 = w2->GetBoundsInScreen().y(); | 299 int gap1 = w2->GetBoundsInScreen().y(); |
296 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 300 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
297 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - | 301 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - |
298 w1->GetBoundsInScreen().bottom(); | 302 w1->GetBoundsInScreen().bottom(); |
299 EXPECT_LE(abs(gap1 - gap2), 1); | 303 EXPECT_LE(abs(gap1 - gap2), 1); |
300 EXPECT_LE(abs(gap2 - gap3), 1); | 304 EXPECT_LE(abs(gap2 - gap3), 1); |
301 EXPECT_LE(abs(gap3 - gap1), 1); | 305 EXPECT_LE(abs(gap3 - gap1), 1); |
302 } | 306 } |
303 | 307 |
304 // Adds three overlapping windows and tests layout after a drag. | 308 // Adds three overlapping windows and tests layout after a drag. |
305 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { | 309 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { |
306 if (!SupportsHostWindowResize()) | 310 if (!SupportsHostWindowResize()) |
307 return; | 311 return; |
308 | 312 |
309 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 313 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
310 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 314 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
311 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 315 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
312 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); | 316 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 200); |
313 scoped_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 204))); | 317 scoped_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 204))); |
314 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 300); | 318 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 300); |
| 319 LOG(INFO) << "w1 at " << w1->GetBoundsInScreen().ToString(); |
| 320 LOG(INFO) << "w2 at " << w2->GetBoundsInScreen().ToString(); |
| 321 LOG(INFO) << "w3 at " << w3->GetBoundsInScreen().ToString(); |
315 | 322 |
316 // All windows should be attached and snapped to the right side of the screen. | 323 // All windows should be attached and snapped to the right side of the screen. |
317 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 324 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
318 w1->GetBoundsInScreen().right()); | 325 w1->GetBoundsInScreen().right()); |
319 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 326 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
320 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 327 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
321 w2->GetBoundsInScreen().right()); | 328 w2->GetBoundsInScreen().right()); |
322 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 329 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
323 EXPECT_EQ(w3->GetRootWindow()->bounds().right(), | 330 EXPECT_EQ(w3->GetRootWindow()->bounds().right(), |
324 w3->GetBoundsInScreen().right()); | 331 w3->GetBoundsInScreen().right()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 ASSERT_GT(Shell::GetScreen()->GetNumDisplays(), 1); | 381 ASSERT_GT(Shell::GetScreen()->GetNumDisplays(), 1); |
375 Shell::GetInstance()->display_controller()-> | 382 Shell::GetInstance()->display_controller()-> |
376 SetLayoutForCurrentDisplays(layout); | 383 SetLayoutForCurrentDisplays(layout); |
377 | 384 |
378 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 600, 201, 201))); | 385 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 600, 201, 201))); |
379 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 600 + 20); | 386 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 600 + 20); |
380 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 600, 210, 202))); | 387 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 600, 210, 202))); |
381 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 600 + 200); | 388 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 600 + 200); |
382 scoped_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 600, 220, 204))); | 389 scoped_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 600, 220, 204))); |
383 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 600 + 300); | 390 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 600 + 300); |
| 391 LOG(INFO) << "w1 at " << w1->GetBoundsInScreen().ToString(); |
| 392 LOG(INFO) << "w2 at " << w2->GetBoundsInScreen().ToString(); |
| 393 LOG(INFO) << "w3 at " << w3->GetBoundsInScreen().ToString(); |
384 | 394 |
385 // All windows should be attached and snapped to the right side of the screen. | 395 // All windows should be attached and snapped to the right side of the screen. |
386 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 396 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
387 w1->GetBoundsInScreen().right()); | 397 w1->GetBoundsInScreen().right()); |
388 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 398 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
389 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 399 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
390 w2->GetBoundsInScreen().right()); | 400 w2->GetBoundsInScreen().right()); |
391 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 401 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
392 EXPECT_EQ(w3->GetRootWindow()->bounds().right(), | 402 EXPECT_EQ(w3->GetRootWindow()->bounds().right(), |
393 w3->GetBoundsInScreen().right()); | 403 w3->GetBoundsInScreen().right()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 EXPECT_EQ(0, overlap4); | 437 EXPECT_EQ(0, overlap4); |
428 } | 438 } |
429 | 439 |
430 // Tests run twice - on both panels and normal windows | 440 // Tests run twice - on both panels and normal windows |
431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 441 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
432 DockedWindowLayoutManagerTest, | 442 DockedWindowLayoutManagerTest, |
433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 443 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
434 aura::client::WINDOW_TYPE_PANEL)); | 444 aura::client::WINDOW_TYPE_PANEL)); |
435 } // namespace internal | 445 } // namespace internal |
436 } // namespace ash | 446 } // namespace ash |
OLD | NEW |