| 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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/mouse_cursor_event_filter.h" | 8 #include "ash/display/mouse_cursor_event_filter.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "ash/test/cursor_manager_test_api.h" | 14 #include "ash/test/cursor_manager_test_api.h" |
| 15 #include "ash/wm/cursor_manager.h" | 15 #include "ash/wm/cursor_manager.h" |
| 16 #include "ash/wm/drag_window_controller.h" |
| 16 #include "ash/wm/property_util.h" | 17 #include "ash/wm/property_util.h" |
| 17 #include "ash/wm/shelf_layout_manager.h" | 18 #include "ash/wm/shelf_layout_manager.h" |
| 18 #include "ash/wm/window_util.h" | 19 #include "ash/wm/window_util.h" |
| 20 #include "ash/wm/workspace/phantom_window_controller.h" |
| 21 #include "ash/wm/workspace/snap_sizer.h" |
| 19 #include "ash/wm/workspace_controller.h" | 22 #include "ash/wm/workspace_controller.h" |
| 20 #include "ash/wm/workspace/snap_sizer.h" | |
| 21 #include "ash/wm/workspace/phantom_window_controller.h" | |
| 22 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
| 23 #include "base/stringprintf.h" | 24 #include "base/stringprintf.h" |
| 24 #include "ui/aura/client/aura_constants.h" | 25 #include "ui/aura/client/aura_constants.h" |
| 25 #include "ui/aura/root_window.h" | 26 #include "ui/aura/root_window.h" |
| 26 #include "ui/aura/test/test_window_delegate.h" | 27 #include "ui/aura/test/test_window_delegate.h" |
| 27 #include "ui/base/hit_test.h" | 28 #include "ui/base/hit_test.h" |
| 28 #include "ui/gfx/insets.h" | 29 #include "ui/gfx/insets.h" |
| 29 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| 30 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
| 31 | 32 |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 601 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 601 ASSERT_TRUE(resizer.get()); | 602 ASSERT_TRUE(resizer.get()); |
| 602 // Move the mouse near the right edge, (798, 0), of the primary display. | 603 // Move the mouse near the right edge, (798, 0), of the primary display. |
| 603 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN); | 604 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN); |
| 604 resizer->CompleteDrag(0); | 605 resizer->CompleteDrag(0); |
| 605 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 606 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 606 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); | 607 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); |
| 607 } | 608 } |
| 608 } | 609 } |
| 609 | 610 |
| 610 // Verifies the style of the drag phantom window is correct. | 611 // Verifies the drag window controller is instanciated appropriately. |
| 611 TEST_F(WorkspaceWindowResizerTest, PhantomStyle) { | 612 TEST_F(WorkspaceWindowResizerTest, DragWindowController) { |
| 612 UpdateDisplay("800x600,800x600"); | 613 UpdateDisplay("800x600,800x600"); |
| 613 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 614 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 614 ASSERT_EQ(2U, root_windows.size()); | 615 ASSERT_EQ(2U, root_windows.size()); |
| 615 | 616 |
| 616 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 617 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 617 Shell::GetScreen()->GetPrimaryDisplay()); | 618 Shell::GetScreen()->GetPrimaryDisplay()); |
| 618 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 619 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 619 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 620 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 620 { | 621 { |
| 621 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 622 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 622 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 623 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 623 ASSERT_TRUE(resizer.get()); | 624 ASSERT_TRUE(resizer.get()); |
| 624 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 625 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 625 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 626 EXPECT_FALSE(resizer->drag_window_controller_.get()); |
| 626 | 627 |
| 627 // The pointer is inside the primary root. Both phantoms should be NULL. | 628 // The pointer is inside the primary root. Both phantoms should be NULL. |
| 628 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); | 629 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); |
| 629 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 630 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 630 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 631 EXPECT_FALSE(resizer->drag_window_controller_.get()); |
| 631 | 632 |
| 632 // The window spans both root windows. | 633 // The window spans both root windows. |
| 633 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); | 634 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); |
| 634 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 635 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 635 PhantomWindowController* controller = | 636 DragWindowController* controller = |
| 636 resizer->drag_phantom_window_controller_.get(); | 637 resizer->drag_window_controller_.get(); |
| 637 ASSERT_TRUE(controller); | 638 ASSERT_TRUE(controller); |
| 638 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style()); | 639 ASSERT_TRUE(controller->drag_widget_); |
| 640 ui::Layer* drag_layer = |
| 641 controller->drag_widget_->GetNativeWindow()->layer(); |
| 642 ASSERT_TRUE(drag_layer); |
| 639 | 643 |
| 640 // Check if |resizer->layer_| is properly set to the phantom widget. | 644 // Check if |resizer->layer_| is properly set to the phantom widget. |
| 641 const std::vector<ui::Layer*>& layers = | 645 const std::vector<ui::Layer*>& layers = drag_layer->children(); |
| 642 controller->phantom_widget_->GetNativeWindow()->layer()->children(); | |
| 643 EXPECT_FALSE(layers.empty()); | 646 EXPECT_FALSE(layers.empty()); |
| 644 EXPECT_EQ(resizer->layer_, layers.back()); | 647 EXPECT_EQ(controller->layer_, layers.back()); |
| 645 | 648 |
| 646 // |window_| should be opaque since the pointer is still on the primary | 649 // |window_| should be opaque since the pointer is still on the primary |
| 647 // root window. The phantom should be semi-transparent. | 650 // root window. The phantom should be semi-transparent. |
| 648 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 651 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 649 EXPECT_GT(1.0f, controller->GetOpacity()); | 652 EXPECT_GT(1.0f, drag_layer->opacity()); |
| 650 | 653 |
| 651 // Enter the pointer to the secondary display. | 654 // Enter the pointer to the secondary display. |
| 652 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 655 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); |
| 653 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 656 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 654 controller = resizer->drag_phantom_window_controller_.get(); | 657 controller = resizer->drag_window_controller_.get(); |
| 655 ASSERT_TRUE(controller); | 658 ASSERT_TRUE(controller); |
| 656 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style()); | |
| 657 // |window_| should be transparent, and the phantom should be opaque. | 659 // |window_| should be transparent, and the phantom should be opaque. |
| 658 EXPECT_GT(1.0f, window_->layer()->opacity()); | 660 EXPECT_GT(1.0f, window_->layer()->opacity()); |
| 659 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); | 661 EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity()); |
| 660 | 662 |
| 661 resizer->CompleteDrag(0); | 663 resizer->CompleteDrag(0); |
| 662 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 664 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| 663 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 665 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 664 } | 666 } |
| 665 | 667 |
| 666 // Do the same test with RevertDrag(). | 668 // Do the same test with RevertDrag(). |
| 667 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 669 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 668 Shell::GetScreen()->GetPrimaryDisplay()); | 670 Shell::GetScreen()->GetPrimaryDisplay()); |
| 669 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 671 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 670 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 672 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 671 { | 673 { |
| 672 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 674 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 673 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 675 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 674 ASSERT_TRUE(resizer.get()); | 676 ASSERT_TRUE(resizer.get()); |
| 675 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 677 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 676 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 678 EXPECT_FALSE(resizer->drag_window_controller_.get()); |
| 677 | 679 |
| 678 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); | 680 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| 679 resizer->RevertDrag(); | 681 resizer->RevertDrag(); |
| 680 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 682 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 681 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 683 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 682 } | 684 } |
| 683 } | 685 } |
| 684 | 686 |
| 685 // Verifies the style of the drag phantom window is correct. | 687 // Verifies the style of the drag phantom window is correct. |
| 686 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) { | 688 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) { |
| 687 UpdateDisplay("800x600,800x600"); | 689 UpdateDisplay("800x600,800x600"); |
| 688 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 690 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 689 ASSERT_EQ(2U, root_windows.size()); | 691 ASSERT_EQ(2U, root_windows.size()); |
| 690 | 692 |
| 691 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 693 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 692 Shell::GetScreen()->GetPrimaryDisplay()); | 694 Shell::GetScreen()->GetPrimaryDisplay()); |
| 693 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 695 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 694 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 696 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 695 { | 697 { |
| 696 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 698 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 697 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 699 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 698 ASSERT_TRUE(resizer.get()); | 700 ASSERT_TRUE(resizer.get()); |
| 699 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 701 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 700 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 702 EXPECT_FALSE(resizer->drag_window_controller_.get()); |
| 701 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); | 703 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); |
| 702 | 704 |
| 703 // The pointer is on the edge but not shared. Both controllers should be | 705 // The pointer is on the edge but not shared. Both controllers should be |
| 704 // non-NULL. | 706 // non-NULL. |
| 705 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0); | 707 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0); |
| 706 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); | 708 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); |
| 707 EXPECT_EQ(WorkspaceWindowResizer::SNAP_RIGHT_EDGE, resizer->snap_type_); | 709 EXPECT_EQ(WorkspaceWindowResizer::SNAP_RIGHT_EDGE, resizer->snap_type_); |
| 708 PhantomWindowController* controller = | 710 DragWindowController* controller = |
| 709 resizer->drag_phantom_window_controller_.get(); | 711 resizer->drag_window_controller_.get(); |
| 710 ASSERT_TRUE(controller); | 712 ASSERT_TRUE(controller); |
| 711 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style()); | |
| 712 | 713 |
| 713 // Move the cursor across the edge. Now the snap phantom controller | 714 // Move the cursor across the edge. Now the snap phantom controller |
| 714 // should be canceled. | 715 // should be canceled. |
| 715 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0); | 716 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0); |
| 716 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 717 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 717 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); | 718 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); |
| 718 controller = | 719 controller = |
| 719 resizer->drag_phantom_window_controller_.get(); | 720 resizer->drag_window_controller_.get(); |
| 720 ASSERT_TRUE(controller); | 721 ASSERT_TRUE(controller); |
| 721 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style()); | |
| 722 } | 722 } |
| 723 } | 723 } |
| 724 | 724 |
| 725 // Verifies if the resizer sets and resets | 725 // Verifies if the resizer sets and resets |
| 726 // MouseCursorEventFilter::mouse_warp_mode_ as expected. | 726 // MouseCursorEventFilter::mouse_warp_mode_ as expected. |
| 727 TEST_F(WorkspaceWindowResizerTest, WarpMousePointer) { | 727 TEST_F(WorkspaceWindowResizerTest, WarpMousePointer) { |
| 728 MouseCursorEventFilter* event_filter = | 728 MouseCursorEventFilter* event_filter = |
| 729 Shell::GetInstance()->mouse_cursor_filter(); | 729 Shell::GetInstance()->mouse_cursor_filter(); |
| 730 ASSERT_TRUE(event_filter); | 730 ASSERT_TRUE(event_filter); |
| 731 window_->SetBounds(gfx::Rect(0, 0, 50, 60)); | 731 window_->SetBounds(gfx::Rect(0, 0, 50, 60)); |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 ASSERT_TRUE(resizer.get()); | 1722 ASSERT_TRUE(resizer.get()); |
| 1723 // Move it 50 to the left, which should contract w1 and expand w2-3. | 1723 // Move it 50 to the left, which should contract w1 and expand w2-3. |
| 1724 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); | 1724 resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0); |
| 1725 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); | 1725 EXPECT_EQ("100,100 98x100", window_->bounds().ToString()); |
| 1726 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); | 1726 EXPECT_EQ("198,100 101x100", window2_->bounds().ToString()); |
| 1727 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); | 1727 EXPECT_EQ("299,100 101x100", window3_->bounds().ToString()); |
| 1728 } | 1728 } |
| 1729 | 1729 |
| 1730 } // namespace internal | 1730 } // namespace internal |
| 1731 } // namespace ash | 1731 } // namespace ash |
| OLD | NEW |