OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/drag_window_resizer.h" | 5 #include "ash/wm/drag_window_resizer.h" |
6 | 6 |
7 #include "ash/display/mouse_cursor_event_filter.h" | 7 #include "ash/display/mouse_cursor_event_filter.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplays) { | 158 TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplays) { |
159 if (!SupportsMultipleDisplays()) | 159 if (!SupportsMultipleDisplays()) |
160 return; | 160 return; |
161 | 161 |
162 // The secondary display is logically on the right, but on the system (e.g. X) | 162 // The secondary display is logically on the right, but on the system (e.g. X) |
163 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. | 163 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. |
164 UpdateDisplay("800x600,800x600"); | 164 UpdateDisplay("800x600,800x600"); |
165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 165 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
166 ASSERT_EQ(2U, root_windows.size()); | 166 ASSERT_EQ(2U, root_windows.size()); |
167 | 167 |
168 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 168 window_->SetBoundsInScreen(gfx::Rect(0, 0, 100, 60), |
flackr
2013/11/01 16:52:28
Maybe add a comment w.r.t. why you need the bounds
varkha
2013/11/05 20:34:23
Moved to https://codereview.chromium.org/57963003/
| |
169 Shell::GetScreen()->GetPrimaryDisplay()); | 169 Shell::GetScreen()->GetPrimaryDisplay()); |
170 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 170 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
171 { | 171 { |
172 // Grab (0, 0) of the window. | 172 // Grab (0, 0) of the window. |
173 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 173 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
174 window_.get(), gfx::Point(), HTCAPTION)); | 174 window_.get(), gfx::Point(), HTCAPTION)); |
175 ASSERT_TRUE(resizer.get()); | 175 ASSERT_TRUE(resizer.get()); |
176 // Drag the pointer to the right. Once it reaches the right edge of the | 176 // Drag the pointer to the right. Once it reaches the right edge of the |
177 // primary display, it warps to the secondary. | 177 // primary display, it warps to the secondary. |
178 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 178 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); |
179 resizer->CompleteDrag(0); | 179 resizer->CompleteDrag(0); |
180 // The whole window is on the secondary display now. The parent should be | 180 // The whole window is on the secondary display now. The parent should be |
181 // changed. | 181 // changed. |
182 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 182 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
183 EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); | 183 EXPECT_EQ("0,10 100x60", window_->bounds().ToString()); |
184 } | 184 } |
185 | 185 |
186 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 186 window_->SetBoundsInScreen(gfx::Rect(0, 0, 100, 60), |
187 Shell::GetScreen()->GetPrimaryDisplay()); | 187 Shell::GetScreen()->GetPrimaryDisplay()); |
188 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 188 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
189 { | 189 { |
190 // Grab (0, 0) of the window and move the pointer to (790, 10). | 190 // Grab (0, 0) of the window and move the pointer to (790, 10). |
191 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 191 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
192 window_.get(), gfx::Point(), HTCAPTION)); | 192 window_.get(), gfx::Point(), HTCAPTION)); |
193 ASSERT_TRUE(resizer.get()); | 193 ASSERT_TRUE(resizer.get()); |
194 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); | 194 resizer->Drag(CalculateDragPoint(*resizer, 768, 10), 0); |
195 resizer->CompleteDrag(0); | 195 resizer->CompleteDrag(0); |
196 // Since the pointer is still on the primary root window, the parent should | 196 // Since the pointer is still on the primary root window, the parent should |
197 // not be changed. | 197 // not be changed. |
198 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 198 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
199 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); | 199 EXPECT_EQ("768,10 100x60", window_->bounds().ToString()); |
200 } | 200 } |
201 | 201 |
202 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 202 window_->SetBoundsInScreen(gfx::Rect(0, 0, 100, 60), |
203 Shell::GetScreen()->GetPrimaryDisplay()); | 203 Shell::GetScreen()->GetPrimaryDisplay()); |
204 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 204 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
205 { | 205 { |
206 // Grab the top-right edge of the window and move the pointer to (0, 10) | 206 // Grab the top-right edge of the window and move the pointer to (0, 10) |
207 // in the secondary root window's coordinates. | 207 // in the secondary root window's coordinates. |
208 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 208 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
209 window_.get(), gfx::Point(49, 0), HTCAPTION)); | 209 window_.get(), gfx::Point(99, 0), HTCAPTION)); |
210 ASSERT_TRUE(resizer.get()); | 210 ASSERT_TRUE(resizer.get()); |
211 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN); | 211 resizer->Drag(CalculateDragPoint(*resizer, 731, 10), ui::EF_CONTROL_DOWN); |
212 resizer->CompleteDrag(0); | 212 resizer->CompleteDrag(0); |
213 // Since the pointer is on the secondary, the parent should be changed | 213 // Since the pointer is on the secondary, the parent should be changed |
214 // even though only small fraction of the window is within the secondary | 214 // even though only small fraction of the window is within the secondary |
215 // root window's bounds. | 215 // root window's bounds. |
216 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 216 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
217 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString()); | 217 EXPECT_EQ("-69,10 100x60", window_->bounds().ToString()); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 // Verifies that dragging the active window to another display makes the new | 221 // Verifies that dragging the active window to another display makes the new |
222 // root window the active root window. | 222 // root window the active root window. |
223 TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplaysActiveRoot) { | 223 TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplaysActiveRoot) { |
224 if (!SupportsMultipleDisplays()) | 224 if (!SupportsMultipleDisplays()) |
225 return; | 225 return; |
226 | 226 |
227 // The secondary display is logically on the right, but on the system (e.g. X) | 227 // The secondary display is logically on the right, but on the system (e.g. X) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 273 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
274 { | 274 { |
275 // Grab (0, 0) of the window. | 275 // Grab (0, 0) of the window. |
276 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 276 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
277 window_.get(), gfx::Point(), HTCAPTION)); | 277 window_.get(), gfx::Point(), HTCAPTION)); |
278 ASSERT_TRUE(resizer.get()); | 278 ASSERT_TRUE(resizer.get()); |
279 // Move the mouse near the right edge, (798, 0), of the primary display. | 279 // Move the mouse near the right edge, (798, 0), of the primary display. |
280 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN); | 280 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN); |
281 resizer->CompleteDrag(0); | 281 resizer->CompleteDrag(0); |
282 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 282 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
283 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); | 283 gfx::Rect expected_bounds = gfx::Rect(800 - 50 * 0.3, 0, 50, 60); |
284 EXPECT_EQ(expected_bounds.ToString(), window_->bounds().ToString()); | |
284 } | 285 } |
285 } | 286 } |
286 | 287 |
287 // Verifies the drag window is shown correctly. | 288 // Verifies the drag window is shown correctly. |
288 TEST_F(DragWindowResizerTest, DragWindowController) { | 289 TEST_F(DragWindowResizerTest, DragWindowController) { |
289 if (!SupportsMultipleDisplays()) | 290 if (!SupportsMultipleDisplays()) |
290 return; | 291 return; |
291 | 292 |
292 UpdateDisplay("800x600,800x600"); | 293 UpdateDisplay("800x600,800x600"); |
293 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 294 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
294 ASSERT_EQ(2U, root_windows.size()); | 295 ASSERT_EQ(2U, root_windows.size()); |
295 | 296 |
296 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 297 window_->SetBoundsInScreen(gfx::Rect(0, 0, 100, 60), |
297 Shell::GetScreen()->GetPrimaryDisplay()); | 298 Shell::GetScreen()->GetPrimaryDisplay()); |
298 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 299 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
299 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 300 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
300 { | 301 { |
301 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 302 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
302 window_.get(), gfx::Point(), HTCAPTION)); | 303 window_.get(), gfx::Point(), HTCAPTION)); |
303 ASSERT_TRUE(resizer.get()); | 304 ASSERT_TRUE(resizer.get()); |
304 internal::DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | 305 internal::DragWindowResizer* drag_resizer = DragWindowResizer::instance_; |
305 ASSERT_TRUE(drag_resizer); | 306 ASSERT_TRUE(drag_resizer); |
306 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); | 307 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
435 // window with 2.0 device scale factor. | 436 // window with 2.0 device scale factor. |
436 { | 437 { |
437 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 438 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
438 Shell::GetScreen()->GetPrimaryDisplay()); | 439 Shell::GetScreen()->GetPrimaryDisplay()); |
439 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 440 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
440 // Grab (0, 0) of the window. | 441 // Grab (0, 0) of the window. |
441 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 442 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
442 window_.get(), gfx::Point(), HTCAPTION)); | 443 window_.get(), gfx::Point(), HTCAPTION)); |
443 EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 444 EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
444 ASSERT_TRUE(resizer.get()); | 445 ASSERT_TRUE(resizer.get()); |
445 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); | 446 resizer->Drag(CalculateDragPoint(*resizer, 400, 200), 0); |
446 WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(399, 200)); | 447 WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(399, 200)); |
447 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 448 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
448 resizer->CompleteDrag(0); | 449 resizer->CompleteDrag(0); |
449 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 450 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
450 } | 451 } |
451 | 452 |
452 // Move window from the root window with 2.0 device scale factor to the root | 453 // Move window from the root window with 2.0 device scale factor to the root |
453 // window with 1.0 device scale factor. | 454 // window with 1.0 device scale factor. |
454 { | 455 { |
455 window_->SetBoundsInScreen( | 456 window_->SetBoundsInScreen( |
456 gfx::Rect(600, 0, 50, 60), | 457 gfx::Rect(600, 0, 100, 60), |
457 Shell::GetScreen()->GetDisplayNearestWindow(root_windows[1])); | 458 Shell::GetScreen()->GetDisplayNearestWindow(root_windows[1])); |
458 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 459 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
459 // Grab (0, 0) of the window. | 460 // Grab (0, 0) of the window. |
460 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 461 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
461 window_.get(), gfx::Point(), HTCAPTION)); | 462 window_.get(), gfx::Point(), HTCAPTION)); |
462 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 463 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
463 ASSERT_TRUE(resizer.get()); | 464 ASSERT_TRUE(resizer.get()); |
464 resizer->Drag(CalculateDragPoint(*resizer, -200, 200), 0); | 465 resizer->Drag(CalculateDragPoint(*resizer, -200, 200), 0); |
465 WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(400, 200)); | 466 WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(400, 200)); |
466 EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 467 EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 resizer->CompleteDrag(0); | 656 resizer->CompleteDrag(0); |
656 EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); | 657 EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); |
657 EXPECT_NE(initial_bounds.ToString(), window->bounds().ToString()); | 658 EXPECT_NE(initial_bounds.ToString(), window->bounds().ToString()); |
658 } | 659 } |
659 } | 660 } |
660 #endif | 661 #endif |
661 | 662 |
662 | 663 |
663 } // namespace internal | 664 } // namespace internal |
664 } // namespace ash | 665 } // namespace ash |
OLD | NEW |