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, int dy) { |
109 int dy) { | |
110 initial_location_in_parent_ = | 105 initial_location_in_parent_ = |
111 window->bounds().origin() + gfx::Vector2d(dx, dy); | 106 window->bounds().origin() + gfx::Vector2d(dx, dy); |
112 resizer_.reset(CreateSomeWindowResizer(window, | 107 resizer_.reset(CreateSomeWindowResizer(window, |
113 initial_location_in_parent_, | 108 initial_location_in_parent_, |
114 HTCAPTION)); | 109 HTCAPTION)); |
115 ASSERT_TRUE(resizer_.get()); | 110 ASSERT_TRUE(resizer_.get()); |
116 } | 111 } |
117 | 112 |
118 void DragMove(int dx, int dy) { | 113 void DragMove(int dx, int dy) { |
119 resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0); | 114 resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 int dx, | 157 int dx, |
163 int y) { | 158 int y) { |
164 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 159 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
165 DragVerticallyAndRelativeToEdge(edge, window, dx, y - initial_bounds.y()); | 160 DragVerticallyAndRelativeToEdge(edge, window, dx, y - initial_bounds.y()); |
166 } | 161 } |
167 | 162 |
168 // Detach if our window is a panel, then drag it vertically by |dy| and | 163 // 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|. | 164 // horizontally to the edge with an added offset from the edge of |dx|. |
170 void DragVerticallyAndRelativeToEdge(DockedEdge edge, | 165 void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
171 aura::Window* window, | 166 aura::Window* window, |
172 int dx, | 167 int dx, int dy) { |
173 int dy) { | |
174 aura::RootWindow* root_window = window->GetRootWindow(); | 168 aura::RootWindow* root_window = window->GetRootWindow(); |
175 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 169 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
176 | 170 |
177 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { | 171 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { |
178 ASSERT_NO_FATAL_FAILURE(DragStart(window)); | 172 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); |
179 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); | 173 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
180 | 174 |
181 // Drag enough to detach since our tests assume panels to be initially | 175 // Drag enough to detach since our tests assume panels to be initially |
182 // detached. | 176 // detached. |
183 DragMove(0, dy); | 177 DragMove(0, dy); |
184 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 178 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
185 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); | 179 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
186 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 180 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
187 | 181 |
188 // The panel should be detached when the drag completes. | 182 // The panel should be detached when the drag completes. |
189 DragEnd(); | 183 DragEnd(); |
190 | 184 |
191 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); | 185 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
192 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 186 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
193 window->parent()->id()); | 187 window->parent()->id()); |
194 EXPECT_EQ(root_window, window->GetRootWindow()); | 188 EXPECT_EQ(root_window, window->GetRootWindow()); |
195 } | 189 } |
196 | 190 |
197 // avoid snap by clicking away from the border | 191 // avoid snap by clicking away from the border |
198 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); | 192 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); |
199 | 193 |
| 194 gfx::Rect work_area = |
| 195 Shell::GetScreen()->GetDisplayNearestWindow(window).work_area(); |
200 // Drag the window left or right to the edge (or almost to it). | 196 // Drag the window left or right to the edge (or almost to it). |
201 if (edge == DOCKED_EDGE_LEFT) | 197 if (edge == DOCKED_EDGE_LEFT) |
202 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); | 198 dx += work_area.x() - initial_location_in_parent_.x(); |
203 else if (edge == DOCKED_EDGE_RIGHT) | 199 else if (edge == DOCKED_EDGE_RIGHT) |
204 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); | 200 dx += work_area.right() - 1 - initial_location_in_parent_.x(); |
205 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); | 201 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); |
206 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 202 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
207 // Release the mouse and the panel should be attached to the dock. | 203 // Release the mouse and the panel should be attached to the dock. |
208 DragEnd(); | 204 DragEnd(); |
209 | 205 |
210 // x-coordinate can get adjusted by snapping or sticking. | 206 // x-coordinate can get adjusted by snapping or sticking. |
211 // y-coordinate could be changed by possible automatic layout if docked. | 207 // y-coordinate could be changed by possible automatic layout if docked. |
212 if (window->parent()->id() != internal::kShellWindowId_DockedContainer) | 208 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && |
| 209 GetRestoreBoundsInScreen(window) == NULL) { |
213 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 210 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 211 } |
214 } | 212 } |
215 | 213 |
216 private: | 214 private: |
217 scoped_ptr<WindowResizer> resizer_; | 215 scoped_ptr<WindowResizer> resizer_; |
218 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; | 216 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; |
219 aura::client::WindowType window_type_; | 217 aura::client::WindowType window_type_; |
220 | 218 |
221 // Location at start of the drag in |window->parent()|'s coordinates. | 219 // Location at start of the drag in |window->parent()|'s coordinates. |
222 gfx::Point initial_location_in_parent_; | 220 gfx::Point initial_location_in_parent_; |
223 | 221 |
(...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. | 279 // The windows should be attached and snapped to the right side of the screen. |
282 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 280 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
283 w1->GetBoundsInScreen().right()); | 281 w1->GetBoundsInScreen().right()); |
284 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 282 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
285 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 283 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
286 w2->GetBoundsInScreen().right()); | 284 w2->GetBoundsInScreen().right()); |
287 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 285 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
288 | 286 |
289 // Drag w2 above w1. | 287 // Drag w2 above w1. |
290 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); | 288 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); |
291 DragMove(0, w1->bounds().y() - w2->bounds().y() - 20); | 289 DragMove(0, w1->bounds().y() - w2->bounds().y() + 20); |
292 DragEnd(); | 290 DragEnd(); |
293 | 291 |
294 // Test the new windows order and that the gaps differ at most by a pixel. | 292 // Test the new windows order and that the gaps differ at most by a pixel. |
295 int gap1 = w2->GetBoundsInScreen().y(); | 293 int gap1 = w2->GetBoundsInScreen().y(); |
296 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 294 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
297 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - | 295 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - |
298 w1->GetBoundsInScreen().bottom(); | 296 w1->GetBoundsInScreen().bottom(); |
299 EXPECT_LE(abs(gap1 - gap2), 1); | 297 EXPECT_LE(abs(gap1 - gap2), 1); |
300 EXPECT_LE(abs(gap2 - gap3), 1); | 298 EXPECT_LE(abs(gap2 - gap3), 1); |
301 EXPECT_LE(abs(gap3 - gap1), 1); | 299 EXPECT_LE(abs(gap3 - gap1), 1); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 EXPECT_EQ(0, overlap4); | 425 EXPECT_EQ(0, overlap4); |
428 } | 426 } |
429 | 427 |
430 // Tests run twice - on both panels and normal windows | 428 // Tests run twice - on both panels and normal windows |
431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 429 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
432 DockedWindowLayoutManagerTest, | 430 DockedWindowLayoutManagerTest, |
433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 431 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
434 aura::client::WINDOW_TYPE_PANEL)); | 432 aura::client::WINDOW_TYPE_PANEL)); |
435 } // namespace internal | 433 } // namespace internal |
436 } // namespace ash | 434 } // namespace ash |
OLD | NEW |