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/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 // Verifies a window can be moved from the primary display to another. | 478 // Verifies a window can be moved from the primary display to another. |
479 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiDisplays) { | 479 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiDisplays) { |
480 // The secondary display is logically on the right, but on the system (e.g. X) | 480 // The secondary display is logically on the right, but on the system (e.g. X) |
481 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. | 481 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. |
482 UpdateDisplay("800x600,800x600"); | 482 UpdateDisplay("800x600,800x600"); |
483 Shell::GetInstance()->shelf()->LayoutShelf(); | 483 Shell::GetInstance()->shelf()->LayoutShelf(); |
484 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 484 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
485 ASSERT_EQ(2U, root_windows.size()); | 485 ASSERT_EQ(2U, root_windows.size()); |
486 | 486 |
487 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 487 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
488 gfx::Screen::GetPrimaryDisplay()); | 488 gfx::Screen::GetPrimaryDisplay( |
| 489 ash::Shell::GetRootNativeView())); |
489 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 490 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
490 { | 491 { |
491 // Grab (0, 0) of the window. | 492 // Grab (0, 0) of the window. |
492 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 493 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
493 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 494 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
494 ASSERT_TRUE(resizer.get()); | 495 ASSERT_TRUE(resizer.get()); |
495 // Drag the pointer to the right. Once it reaches the right edge of the | 496 // Drag the pointer to the right. Once it reaches the right edge of the |
496 // primary display, it warps to the secondary. | 497 // primary display, it warps to the secondary. |
497 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 498 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); |
498 resizer->CompleteDrag(0); | 499 resizer->CompleteDrag(0); |
499 // The whole window is on the secondary display now. The parent should be | 500 // The whole window is on the secondary display now. The parent should be |
500 // changed. | 501 // changed. |
501 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 502 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
502 EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); | 503 EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); |
503 } | 504 } |
504 | 505 |
505 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 506 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
506 gfx::Screen::GetPrimaryDisplay()); | 507 gfx::Screen::GetPrimaryDisplay( |
| 508 ash::Shell::GetRootNativeView())); |
507 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 509 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
508 { | 510 { |
509 // Grab (0, 0) of the window and move the pointer to (790, 10). | 511 // Grab (0, 0) of the window and move the pointer to (790, 10). |
510 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 512 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
511 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 513 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
512 ASSERT_TRUE(resizer.get()); | 514 ASSERT_TRUE(resizer.get()); |
513 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); | 515 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); |
514 resizer->CompleteDrag(0); | 516 resizer->CompleteDrag(0); |
515 // Since the pointer is still on the primary root window, the parent should | 517 // Since the pointer is still on the primary root window, the parent should |
516 // not be changed. | 518 // not be changed. |
517 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 519 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
518 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); | 520 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); |
519 } | 521 } |
520 | 522 |
521 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 523 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
522 gfx::Screen::GetPrimaryDisplay()); | 524 gfx::Screen::GetPrimaryDisplay( |
| 525 ash::Shell::GetRootNativeView())); |
523 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 526 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
524 { | 527 { |
525 // Grab the top-right edge of the window and move the pointer to (0, 10) | 528 // Grab the top-right edge of the window and move the pointer to (0, 10) |
526 // in the secondary root window's coordinates. | 529 // in the secondary root window's coordinates. |
527 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 530 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
528 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); | 531 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); |
529 ASSERT_TRUE(resizer.get()); | 532 ASSERT_TRUE(resizer.get()); |
530 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN); | 533 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN); |
531 resizer->CompleteDrag(0); | 534 resizer->CompleteDrag(0); |
532 // Since the pointer is on the secondary, the parent should be changed | 535 // Since the pointer is on the secondary, the parent should be changed |
(...skipping 29 matching lines...) Expand all Loading... |
562 } | 565 } |
563 } | 566 } |
564 | 567 |
565 // Verifies the style of the drag phantom window is correct. | 568 // Verifies the style of the drag phantom window is correct. |
566 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { | 569 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { |
567 UpdateDisplay("800x600,800x600"); | 570 UpdateDisplay("800x600,800x600"); |
568 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 571 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
569 ASSERT_EQ(2U, root_windows.size()); | 572 ASSERT_EQ(2U, root_windows.size()); |
570 | 573 |
571 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 574 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
572 gfx::Screen::GetPrimaryDisplay()); | 575 gfx::Screen::GetPrimaryDisplay( |
| 576 ash::Shell::GetRootNativeView())); |
573 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 577 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
574 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 578 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
575 { | 579 { |
576 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 580 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
577 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 581 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
578 ASSERT_TRUE(resizer.get()); | 582 ASSERT_TRUE(resizer.get()); |
579 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 583 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
580 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 584 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
581 | 585 |
582 // The pointer is inside the primary root. Both phantoms should be NULL. | 586 // The pointer is inside the primary root. Both phantoms should be NULL. |
(...skipping 30 matching lines...) Expand all Loading... |
613 EXPECT_GT(1.0f, window_->layer()->opacity()); | 617 EXPECT_GT(1.0f, window_->layer()->opacity()); |
614 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); | 618 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); |
615 | 619 |
616 resizer->CompleteDrag(0); | 620 resizer->CompleteDrag(0); |
617 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 621 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
618 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 622 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
619 } | 623 } |
620 | 624 |
621 // Do the same test with RevertDrag(). | 625 // Do the same test with RevertDrag(). |
622 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 626 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
623 gfx::Screen::GetPrimaryDisplay()); | 627 gfx::Screen::GetPrimaryDisplay( |
| 628 ash::Shell::GetRootNativeView())); |
624 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 629 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
625 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 630 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
626 { | 631 { |
627 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 632 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
628 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 633 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
629 ASSERT_TRUE(resizer.get()); | 634 ASSERT_TRUE(resizer.get()); |
630 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 635 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
631 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 636 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
632 | 637 |
633 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); | 638 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
634 resizer->RevertDrag(); | 639 resizer->RevertDrag(); |
635 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 640 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
636 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 641 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
637 } | 642 } |
638 } | 643 } |
639 | 644 |
640 // Verifies the style of the drag phantom window is correct. | 645 // Verifies the style of the drag phantom window is correct. |
641 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) { | 646 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) { |
642 UpdateDisplay("800x600,800x600"); | 647 UpdateDisplay("800x600,800x600"); |
643 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 648 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
644 ASSERT_EQ(2U, root_windows.size()); | 649 ASSERT_EQ(2U, root_windows.size()); |
645 | 650 |
646 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 651 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
647 gfx::Screen::GetPrimaryDisplay()); | 652 gfx::Screen::GetPrimaryDisplay( |
| 653 ash::Shell::GetRootNativeView())); |
648 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 654 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
649 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 655 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
650 { | 656 { |
651 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 657 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
652 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 658 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
653 ASSERT_TRUE(resizer.get()); | 659 ASSERT_TRUE(resizer.get()); |
654 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); | 660 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
655 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); | 661 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
656 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); | 662 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); |
657 | 663 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 // 2 should be topmost since it's initially the highest in the stack. | 767 // 2 should be topmost since it's initially the highest in the stack. |
762 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent())); | 768 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent())); |
763 } | 769 } |
764 } | 770 } |
765 | 771 |
766 // Makes sure we don't allow dragging below the work area. | 772 // Makes sure we don't allow dragging below the work area. |
767 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { | 773 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { |
768 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 774 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
769 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); | 775 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); |
770 | 776 |
771 ASSERT_EQ(1, gfx::Screen::GetNumDisplays()); | 777 ASSERT_EQ(1, gfx::Screen::GetNumDisplays(ash::Shell::GetRootNativeView())); |
772 | 778 |
773 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); | 779 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); |
774 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 780 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
775 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 781 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
776 ASSERT_TRUE(resizer.get()); | 782 ASSERT_TRUE(resizer.get()); |
777 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); | 783 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); |
778 int expected_y = | 784 int expected_y = |
779 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; | 785 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; |
780 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", | 786 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", |
781 window_->bounds().ToString()); | 787 window_->bounds().ToString()); |
782 } | 788 } |
783 | 789 |
784 // Makes sure we don't allow dragging on the work area with multidisplay. | 790 // Makes sure we don't allow dragging on the work area with multidisplay. |
785 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) { | 791 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) { |
786 UpdateDisplay("800x600,800x600"); | 792 UpdateDisplay("800x600,800x600"); |
787 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); | 793 ASSERT_EQ(2, gfx::Screen::GetNumDisplays(ash::Shell::GetRootNativeView())); |
788 | 794 |
789 Shell::GetInstance()->SetDisplayWorkAreaInsets( | 795 Shell::GetInstance()->SetDisplayWorkAreaInsets( |
790 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); | 796 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); |
791 | 797 |
792 // Positions the secondary display at the bottom the primary display. | 798 // Positions the secondary display at the bottom the primary display. |
793 ash::DisplayLayout display_layout(ash::DisplayLayout::BOTTOM, 0); | 799 ash::DisplayLayout display_layout(ash::DisplayLayout::BOTTOM, 0); |
794 Shell::GetInstance()->display_controller()->SetDefaultDisplayLayout( | 800 Shell::GetInstance()->display_controller()->SetDefaultDisplayLayout( |
795 display_layout); | 801 display_layout); |
796 | 802 |
797 { | 803 { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); | 1008 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); |
1003 EXPECT_EQ("152,130 20x30", window_->bounds().ToString()); | 1009 EXPECT_EQ("152,130 20x30", window_->bounds().ToString()); |
1004 | 1010 |
1005 // Move |window| one pixel above the bottom of |window2|. | 1011 // Move |window| one pixel above the bottom of |window2|. |
1006 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); | 1012 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); |
1007 EXPECT_EQ("152,180 20x30", window_->bounds().ToString()); | 1013 EXPECT_EQ("152,180 20x30", window_->bounds().ToString()); |
1008 } | 1014 } |
1009 | 1015 |
1010 } // namespace internal | 1016 } // namespace internal |
1011 } // namespace ash | 1017 } // namespace ash |
OLD | NEW |