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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Drag w2 above w1. | 289 // Drag w2 above w1. |
290 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); | 290 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); |
291 DragMove(0, w1->bounds().y() - w2->bounds().y() - 20); | 291 DragMove(0, w1->bounds().y() - w2->bounds().y() + 20); |
292 DragEnd(); | 292 DragEnd(); |
293 | 293 |
294 // Test the new windows order and that the gaps differ at most by a pixel. | 294 // Test the new windows order and that the gaps differ at most by a pixel. |
295 int gap1 = w2->GetBoundsInScreen().y(); | 295 int gap1 = w2->GetBoundsInScreen().y(); |
296 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 296 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
297 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - | 297 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - |
298 w1->GetBoundsInScreen().bottom(); | 298 w1->GetBoundsInScreen().bottom(); |
299 EXPECT_LE(abs(gap1 - gap2), 1); | 299 EXPECT_LE(abs(gap1 - gap2), 1); |
300 EXPECT_LE(abs(gap2 - gap3), 1); | 300 EXPECT_LE(abs(gap2 - gap3), 1); |
301 EXPECT_LE(abs(gap3 - gap1), 1); | 301 EXPECT_LE(abs(gap3 - gap1), 1); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 EXPECT_EQ(0, overlap4); | 427 EXPECT_EQ(0, overlap4); |
428 } | 428 } |
429 | 429 |
430 // Tests run twice - on both panels and normal windows | 430 // Tests run twice - on both panels and normal windows |
431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
432 DockedWindowLayoutManagerTest, | 432 DockedWindowLayoutManagerTest, |
433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
434 aura::client::WINDOW_TYPE_PANEL)); | 434 aura::client::WINDOW_TYPE_PANEL)); |
435 } // namespace internal | 435 } // namespace internal |
436 } // namespace ash | 436 } // namespace ash |
OLD | NEW |