Chromium Code Reviews| 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/display_layout_builder.h" | |
| 8 #include "ash/display/display_manager.h" | |
| 7 #include "ash/display/mouse_cursor_event_filter.h" | 9 #include "ash/display/mouse_cursor_event_filter.h" |
| 8 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 11 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 12 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/cursor_manager_test_api.h" | 15 #include "ash/test/cursor_manager_test_api.h" |
| 14 #include "ash/test/display_manager_test_api.h" | 16 #include "ash/test/display_manager_test_api.h" |
| 15 #include "ash/wm/drag_window_controller.h" | 17 #include "ash/wm/drag_window_controller.h" |
| 16 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 | 341 |
| 340 UpdateDisplay("800x600,800x600"); | 342 UpdateDisplay("800x600,800x600"); |
| 341 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 343 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 342 ASSERT_EQ(2U, root_windows.size()); | 344 ASSERT_EQ(2U, root_windows.size()); |
| 343 | 345 |
| 344 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 346 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 345 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 347 gfx::Screen::GetScreen()->GetPrimaryDisplay()); |
| 346 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 348 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 347 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 349 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 348 { | 350 { |
| 349 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 351 // Hold the center of the window so that the window doesn't stick to the |
| 350 window_.get(), gfx::Point(), HTCAPTION)); | 352 // edge |
| 353 // when cragging around the edge of the display. | |
|
stevenjb
2016/03/29 18:56:13
s/cragging/dragging/
combine lines
oshima
2016/03/30 21:21:02
Done. looks like git cl format isn't smart enough
| |
| 354 scoped_ptr<WindowResizer> resizer( | |
| 355 CreateDragWindowResizer(window_.get(), gfx::Point(25, 30), HTCAPTION)); | |
| 351 ASSERT_TRUE(resizer.get()); | 356 ASSERT_TRUE(resizer.get()); |
| 352 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | 357 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; |
| 353 ASSERT_TRUE(drag_resizer); | 358 ASSERT_TRUE(drag_resizer); |
| 354 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); | 359 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); |
| 355 | 360 |
| 356 // The pointer is inside the primary root. The drag window controller | 361 // The pointer is inside the primary root. The drag window controller |
| 357 // should be NULL. | 362 // should be NULL. |
| 358 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); | 363 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); |
| 359 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); | 364 DragWindowController* controller = |
| 365 drag_resizer->drag_window_controller_.get(); | |
| 366 EXPECT_EQ(0, controller->GetDragWindowsCountForTest()); | |
| 360 | 367 |
| 361 // The window spans both root windows. | 368 // The window spans both root windows. |
| 362 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); | 369 resizer->Drag(CalculateDragPoint(*resizer, 773, 10), 0); |
| 363 EXPECT_EQ(1u, drag_resizer->drag_window_controllers_.size()); | 370 EXPECT_EQ(1, controller->GetDragWindowsCountForTest()); |
| 364 DragWindowController* controller = | 371 const aura::Window* drag_window = controller->GetDragWindowForTest(0); |
| 365 drag_resizer->drag_window_controllers_[0]; | 372 ASSERT_TRUE(drag_window); |
| 366 ASSERT_TRUE(controller); | |
| 367 | 373 |
| 368 ASSERT_TRUE(controller->drag_widget_); | 374 const ui::Layer* drag_layer = drag_window->layer(); |
| 369 ui::Layer* drag_layer = | |
| 370 controller->drag_widget_->GetNativeWindow()->layer(); | |
| 371 ASSERT_TRUE(drag_layer); | 375 ASSERT_TRUE(drag_layer); |
| 372 // Check if |resizer->layer_| is properly set to the drag widget. | 376 // Check if |resizer->layer_| is properly set to the drag widget. |
| 373 const std::vector<ui::Layer*>& layers = drag_layer->children(); | 377 const std::vector<ui::Layer*>& layers = drag_layer->children(); |
| 374 EXPECT_FALSE(layers.empty()); | 378 EXPECT_FALSE(layers.empty()); |
| 375 EXPECT_EQ(controller->layer_owner_->root(), layers.back()); | 379 EXPECT_EQ(controller->GetDragLayerOwnerForTest(0)->root(), layers.back()); |
| 376 | 380 |
| 377 // |window_| should be opaque since the pointer is still on the primary | 381 // |window_| should be opaque since the pointer is still on the primary |
| 378 // root window. The drag window should be semi-transparent. | 382 // root window. The drag window should be semi-transparent. |
| 379 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 383 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 380 ASSERT_TRUE(controller->drag_widget_); | |
| 381 EXPECT_GT(1.0f, drag_layer->opacity()); | 384 EXPECT_GT(1.0f, drag_layer->opacity()); |
| 382 | 385 |
| 383 // Enter the pointer to the secondary display. | 386 // Enter the pointer to the secondary display. |
| 384 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 387 resizer->Drag(CalculateDragPoint(*resizer, 775, 10), 0); |
| 385 EXPECT_EQ(1u, drag_resizer->drag_window_controllers_.size()); | 388 EXPECT_EQ(1, controller->GetDragWindowsCountForTest()); |
| 386 controller = drag_resizer->drag_window_controllers_[0]; | |
| 387 ASSERT_TRUE(controller); | |
| 388 // |window_| should be transparent, and the drag window should be opaque. | 389 // |window_| should be transparent, and the drag window should be opaque. |
| 389 EXPECT_GT(1.0f, window_->layer()->opacity()); | 390 EXPECT_GT(1.0f, window_->layer()->opacity()); |
| 390 EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity()); | 391 EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity()); |
| 391 | 392 |
| 392 resizer->CompleteDrag(); | 393 resizer->CompleteDrag(); |
| 393 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 394 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| 394 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 395 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 395 } | 396 } |
| 396 | 397 |
| 397 // Do the same test with RevertDrag(). | 398 // Do the same test with RevertDrag(). |
| 398 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 399 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 399 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 400 gfx::Screen::GetScreen()->GetPrimaryDisplay()); |
| 400 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 401 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 401 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 402 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 402 { | 403 { |
| 403 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 404 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
| 404 window_.get(), gfx::Point(), HTCAPTION)); | 405 window_.get(), gfx::Point(), HTCAPTION)); |
| 405 ASSERT_TRUE(resizer.get()); | 406 ASSERT_TRUE(resizer.get()); |
| 406 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | 407 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; |
| 408 DragWindowController* controller = | |
| 409 drag_resizer->drag_window_controller_.get(); | |
| 407 ASSERT_TRUE(drag_resizer); | 410 ASSERT_TRUE(drag_resizer); |
| 408 EXPECT_EQ(0u, drag_resizer->drag_window_controllers_.size()); | 411 EXPECT_FALSE(controller); |
| 409 | 412 |
| 410 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); | 413 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| 411 resizer->RevertDrag(); | 414 resizer->RevertDrag(); |
| 412 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 415 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 413 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 416 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 414 } | 417 } |
| 415 } | 418 } |
| 416 | 419 |
| 420 TEST_F(DragWindowResizerTest, DragWindowControllerAcrossThreeDisplays) { | |
| 421 if (!SupportsMultipleDisplays()) | |
| 422 return; | |
| 423 | |
| 424 UpdateDisplay("400x600,400x600,800x600"); | |
| 425 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 426 | |
| 427 // Layout so that all three displays touches each other. | |
|
stevenjb
2016/03/29 18:56:14
s/touches/touch/
oshima
2016/03/30 21:21:02
Done.
| |
| 428 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 429 DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | |
| 430 ASSERT_EQ(3u, list.size()); | |
| 431 ASSERT_EQ(gfx::Screen::GetScreen()->GetPrimaryDisplay().id(), list[0]); | |
| 432 DisplayLayoutBuilder builder(list[0]); | |
| 433 builder.AddDisplayPlacement(list[1], list[0], DisplayPlacement::RIGHT, 0); | |
| 434 builder.AddDisplayPlacement(list[2], list[0], DisplayPlacement::BOTTOM, 0); | |
| 435 display_manager->SetLayoutForCurrentDisplays(builder.Build()); | |
| 436 // Sanity check. | |
| 437 ASSERT_EQ(gfx::Rect(0, 000, 400, 600), | |
| 438 display_manager->GetDisplayForId(list[0]).bounds()); | |
| 439 ASSERT_EQ(gfx::Rect(400, 0, 400, 600), | |
| 440 display_manager->GetDisplayForId(list[1]).bounds()); | |
| 441 ASSERT_EQ(gfx::Rect(0, 600, 800, 600), | |
| 442 display_manager->GetDisplayForId(list[2]).bounds()); | |
| 443 | |
| 444 // Create a window on 2nd display. | |
| 445 window_->SetBoundsInScreen(gfx::Rect(400, 0, 100, 100), | |
| 446 display_manager->GetDisplayForId(list[1])); | |
| 447 ASSERT_EQ(root_windows[1], window_->GetRootWindow()); | |
| 448 | |
| 449 // Hold the center of the window so that the window doesn't stick to the edge | |
| 450 // when cragging around the edge of the display. | |
|
stevenjb
2016/03/29 18:56:14
dragging
oshima
2016/03/30 21:21:02
Done.
| |
| 451 scoped_ptr<WindowResizer> resizer( | |
| 452 CreateDragWindowResizer(window_.get(), gfx::Point(50, 50), HTCAPTION)); | |
| 453 ASSERT_TRUE(resizer.get()); | |
| 454 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | |
| 455 ASSERT_TRUE(drag_resizer); | |
| 456 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); | |
| 457 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); | |
| 458 DragWindowController* controller = | |
| 459 drag_resizer->drag_window_controller_.get(); | |
| 460 ASSERT_TRUE(controller); | |
| 461 ASSERT_EQ(1, controller->GetDragWindowsCountForTest()); | |
| 462 const aura::Window* drag_window0 = controller->GetDragWindowForTest(0); | |
| 463 ASSERT_TRUE(drag_window0); | |
| 464 const ui::Layer* drag_layer0 = drag_window0->layer(); | |
| 465 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow()); | |
| 466 | |
| 467 // |window_| should be opaque since the pointer is still on the primary | |
| 468 // root window. The drag window should be semi-transparent. | |
| 469 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | |
| 470 EXPECT_GT(1.0f, drag_layer0->opacity()); | |
| 471 | |
| 472 // The window spans across 3 displays, dragging to 3rd display. | |
| 473 resizer->Drag(CalculateDragPoint(*resizer, -50, 549), 0); | |
| 474 ASSERT_EQ(2, controller->GetDragWindowsCountForTest()); | |
| 475 drag_window0 = controller->GetDragWindowForTest(0); | |
| 476 const aura::Window* drag_window1 = controller->GetDragWindowForTest(1); | |
| 477 drag_layer0 = drag_window0->layer(); | |
| 478 const ui::Layer* drag_layer1 = drag_window1->layer(); | |
| 479 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow()); | |
| 480 EXPECT_EQ(root_windows[2], drag_window1->GetRootWindow()); | |
| 481 | |
| 482 // |window_| should be opaque since the pointer is still on the 2nd | |
| 483 // root window. The drag window should be semi-transparent. | |
| 484 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | |
| 485 EXPECT_GT(1.0f, drag_layer0->opacity()); | |
| 486 EXPECT_GT(1.0f, drag_layer1->opacity()); | |
| 487 | |
| 488 resizer->Drag(CalculateDragPoint(*resizer, -51, 549), 0); | |
| 489 ASSERT_EQ(2, controller->GetDragWindowsCountForTest()); | |
| 490 drag_window0 = controller->GetDragWindowForTest(0); | |
| 491 drag_window1 = controller->GetDragWindowForTest(1); | |
| 492 drag_layer0 = drag_window0->layer(); | |
| 493 drag_layer1 = drag_window1->layer(); | |
| 494 EXPECT_EQ(root_windows[0], drag_window0->GetRootWindow()); | |
| 495 EXPECT_EQ(root_windows[2], drag_window1->GetRootWindow()); | |
| 496 | |
| 497 // |window_| should be transparent since the pointer is still on the primary | |
| 498 // root window. The drag window should be semi-transparent. | |
| 499 EXPECT_GT(1.0f, window_->layer()->opacity()); | |
| 500 EXPECT_FLOAT_EQ(1.0f, drag_layer0->opacity()); | |
| 501 EXPECT_GT(1.0f, drag_layer1->opacity()); | |
| 502 | |
| 503 // Enter the pointer to the 3rd. Since it's bottom, the window snaps and | |
| 504 // no drag windwos are created. | |
| 505 resizer->Drag(CalculateDragPoint(*resizer, -51, 551), 0); | |
| 506 ASSERT_EQ(1, controller->GetDragWindowsCountForTest()); | |
| 507 drag_window0 = controller->GetDragWindowForTest(0); | |
| 508 drag_layer0 = drag_window0->layer(); | |
| 509 EXPECT_EQ(root_windows[2], drag_window0->GetRootWindow()); | |
| 510 | |
| 511 // |window_| should be transparent, and the drag window should be opaque. | |
| 512 EXPECT_FLOAT_EQ(0.0f, window_->layer()->opacity()); | |
| 513 EXPECT_FLOAT_EQ(1.0f, drag_layer0->opacity()); | |
| 514 | |
| 515 resizer->CompleteDrag(); | |
| 516 EXPECT_EQ(root_windows[2], window_->GetRootWindow()); | |
| 517 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | |
| 518 } | |
| 519 | |
| 417 // Verifies if the resizer sets and resets | 520 // Verifies if the resizer sets and resets |
| 418 // MouseCursorEventFilter::mouse_warp_mode_ as expected. | 521 // MouseCursorEventFilter::mouse_warp_mode_ as expected. |
| 419 TEST_F(DragWindowResizerTest, WarpMousePointer) { | 522 TEST_F(DragWindowResizerTest, WarpMousePointer) { |
| 420 MouseCursorEventFilter* event_filter = | 523 MouseCursorEventFilter* event_filter = |
| 421 Shell::GetInstance()->mouse_cursor_filter(); | 524 Shell::GetInstance()->mouse_cursor_filter(); |
| 422 ASSERT_TRUE(event_filter); | 525 ASSERT_TRUE(event_filter); |
| 423 window_->SetBounds(gfx::Rect(0, 0, 50, 60)); | 526 window_->SetBounds(gfx::Rect(0, 0, 50, 60)); |
| 424 | 527 |
| 425 EXPECT_TRUE(event_filter->mouse_warp_enabled_); | 528 EXPECT_TRUE(event_filter->mouse_warp_enabled_); |
| 426 { | 529 { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 ASSERT_TRUE(resizer.get()); | 722 ASSERT_TRUE(resizer.get()); |
| 620 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); | 723 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); |
| 621 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); | 724 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); |
| 622 EXPECT_EQ("401,200", | 725 EXPECT_EQ("401,200", |
| 623 aura::Env::GetInstance()->last_mouse_location().ToString()); | 726 aura::Env::GetInstance()->last_mouse_location().ToString()); |
| 624 resizer->CompleteDrag(); | 727 resizer->CompleteDrag(); |
| 625 } | 728 } |
| 626 } | 729 } |
| 627 | 730 |
| 628 } // namespace ash | 731 } // namespace ash |
| OLD | NEW |