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/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
12 #include "ash/wm/workspace_controller.h" | 12 #include "ash/wm/workspace_controller.h" |
| 13 #include "ash/wm/workspace/phantom_window_controller.h" |
13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
15 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
16 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
17 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 namespace internal { | 22 namespace internal { |
22 namespace { | 23 namespace { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 56 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
56 root->SetHostSize(gfx::Size(800, kRootHeight)); | 57 root->SetHostSize(gfx::Size(800, kRootHeight)); |
57 | 58 |
58 aura::Window* default_container = | 59 aura::Window* default_container = |
59 Shell::GetContainer(root, kShellWindowId_DefaultContainer); | 60 Shell::GetContainer(root, kShellWindowId_DefaultContainer); |
60 | 61 |
61 gfx::Rect root_bounds(root->bounds()); | 62 gfx::Rect root_bounds(root->bounds()); |
62 EXPECT_EQ(kRootHeight, root_bounds.height()); | 63 EXPECT_EQ(kRootHeight, root_bounds.height()); |
63 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); | 64 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); |
64 window_.reset(new aura::Window(&delegate_)); | 65 window_.reset(new aura::Window(&delegate_)); |
| 66 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
65 window_->Init(ui::LAYER_NOT_DRAWN); | 67 window_->Init(ui::LAYER_NOT_DRAWN); |
66 window_->SetParent(default_container); | 68 window_->SetParent(default_container); |
67 window_->set_id(1); | 69 window_->set_id(1); |
68 | 70 |
69 window2_.reset(new aura::Window(&delegate2_)); | 71 window2_.reset(new aura::Window(&delegate2_)); |
| 72 window2_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
70 window2_->Init(ui::LAYER_NOT_DRAWN); | 73 window2_->Init(ui::LAYER_NOT_DRAWN); |
71 window2_->SetParent(default_container); | 74 window2_->SetParent(default_container); |
72 window2_->set_id(2); | 75 window2_->set_id(2); |
73 | 76 |
74 window3_.reset(new aura::Window(&delegate3_)); | 77 window3_.reset(new aura::Window(&delegate3_)); |
| 78 window3_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
75 window3_->Init(ui::LAYER_NOT_DRAWN); | 79 window3_->Init(ui::LAYER_NOT_DRAWN); |
76 window3_->SetParent(default_container); | 80 window3_->SetParent(default_container); |
77 window3_->set_id(3); | 81 window3_->set_id(3); |
78 } | 82 } |
79 | 83 |
80 virtual void TearDown() OVERRIDE { | 84 virtual void TearDown() OVERRIDE { |
81 window_.reset(); | 85 window_.reset(); |
82 window2_.reset(); | 86 window2_.reset(); |
83 window3_.reset(); | 87 window3_.reset(); |
84 AshTestBase::TearDown(); | 88 AshTestBase::TearDown(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 TestWindowDelegate delegate2_; | 130 TestWindowDelegate delegate2_; |
127 TestWindowDelegate delegate3_; | 131 TestWindowDelegate delegate3_; |
128 scoped_ptr<aura::Window> window_; | 132 scoped_ptr<aura::Window> window_; |
129 scoped_ptr<aura::Window> window2_; | 133 scoped_ptr<aura::Window> window2_; |
130 scoped_ptr<aura::Window> window3_; | 134 scoped_ptr<aura::Window> window3_; |
131 | 135 |
132 private: | 136 private: |
133 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); | 137 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); |
134 }; | 138 }; |
135 | 139 |
| 140 } // namespace |
| 141 |
136 // Fails on win_aura since wm::GetRootWindowRelativeToWindow is not implemented | 142 // Fails on win_aura since wm::GetRootWindowRelativeToWindow is not implemented |
137 // yet for the platform. | 143 // yet for the platform. |
138 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
139 #define MAYBE_WindowDragWithMultiMonitors \ | 145 #define MAYBE_WindowDragWithMultiMonitors \ |
140 DISABLED_WindowDragWithMultiMonitors | 146 DISABLED_WindowDragWithMultiMonitors |
141 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ | 147 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ |
142 DISABLED_WindowDragWithMultiMonitorsRightToLeft | 148 DISABLED_WindowDragWithMultiMonitorsRightToLeft |
| 149 #define MAYBE_PhantomStyle DISABLED_PhantomStyle |
143 #else | 150 #else |
144 #define MAYBE_WindowDragWithMultiMonitors WindowDragWithMultiMonitors | 151 #define MAYBE_WindowDragWithMultiMonitors WindowDragWithMultiMonitors |
145 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ | 152 #define MAYBE_WindowDragWithMultiMonitorsRightToLeft \ |
146 WindowDragWithMultiMonitorsRightToLeft | 153 WindowDragWithMultiMonitorsRightToLeft |
| 154 #define MAYBE_PhantomStyle PhantomStyle |
147 #endif | 155 #endif |
148 | 156 |
149 // Assertions around attached window resize dragging from the right with 2 | 157 // Assertions around attached window resize dragging from the right with 2 |
150 // windows. | 158 // windows. |
151 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { | 159 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { |
152 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); | 160 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); |
153 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); | 161 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); |
154 | 162 |
155 std::vector<aura::Window*> windows; | 163 std::vector<aura::Window*> windows; |
156 windows.push_back(window2_.get()); | 164 windows.push_back(window2_.get()); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 570 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
563 ASSERT_TRUE(resizer.get()); | 571 ASSERT_TRUE(resizer.get()); |
564 // Move the mouse near the right edge, (798, 0), of the primary display. | 572 // Move the mouse near the right edge, (798, 0), of the primary display. |
565 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); | 573 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); |
566 resizer->CompleteDrag(0); | 574 resizer->CompleteDrag(0); |
567 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 575 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
568 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); | 576 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); |
569 } | 577 } |
570 } | 578 } |
571 | 579 |
| 580 // Verifies the style of the drag phantom window is correct. |
| 581 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { |
| 582 UpdateDisplay("800x600,800x600"); |
| 583 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 584 ASSERT_EQ(2U, root_windows.size()); |
| 585 |
| 586 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 587 gfx::Screen::GetPrimaryDisplay()); |
| 588 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 589 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 590 { |
| 591 SetGridSize(0); |
| 592 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 593 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 594 ASSERT_TRUE(resizer.get()); |
| 595 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 596 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
| 597 |
| 598 // The pointer is inside the primary root. Both phantoms should be NULL. |
| 599 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); |
| 600 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 601 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
| 602 |
| 603 // The window spans both root windows. |
| 604 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); |
| 605 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 606 PhantomWindowController* controller = |
| 607 resizer->drag_phantom_window_controller_.get(); |
| 608 ASSERT_TRUE(controller); |
| 609 EXPECT_EQ(PhantomWindowController::STYLE_WINDOW, controller->style()); |
| 610 // |window_| should be opaque since the pointer is still on the primary |
| 611 // root window. The phantom should be semi-transparent. |
| 612 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 613 EXPECT_GT(1.0f, controller->GetOpacity()); |
| 614 |
| 615 // Enter the pointer to the secondary display. |
| 616 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| 617 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 618 controller = resizer->drag_phantom_window_controller_.get(); |
| 619 ASSERT_TRUE(controller); |
| 620 EXPECT_EQ(PhantomWindowController::STYLE_WINDOW, controller->style()); |
| 621 // |window_| should be transparent, and the phantom should be opaque. |
| 622 EXPECT_GT(1.0f, window_->layer()->opacity()); |
| 623 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); |
| 624 |
| 625 resizer->CompleteDrag(0); |
| 626 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| 627 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 628 } |
| 629 |
| 630 // Do the same test with RevertDrag(). |
| 631 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 632 gfx::Screen::GetPrimaryDisplay()); |
| 633 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 634 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 635 { |
| 636 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| 637 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| 638 ASSERT_TRUE(resizer.get()); |
| 639 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); |
| 640 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); |
| 641 |
| 642 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| 643 resizer->RevertDrag(); |
| 644 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 645 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 646 } |
| 647 } |
| 648 |
572 // Verifies windows are correctly restacked when reordering multiple windows. | 649 // Verifies windows are correctly restacked when reordering multiple windows. |
573 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { | 650 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { |
574 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); | 651 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); |
575 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); | 652 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); |
576 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); | 653 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); |
577 | 654 |
578 { | 655 { |
579 std::vector<aura::Window*> windows; | 656 std::vector<aura::Window*> windows; |
580 windows.push_back(window2_.get()); | 657 windows.push_back(window2_.get()); |
581 SetGridSize(10); | 658 SetGridSize(10); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 835 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
759 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 836 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
760 ASSERT_TRUE(resizer.get()); | 837 ASSERT_TRUE(resizer.get()); |
761 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, | 838 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, |
762 // the window should move to the exact position. | 839 // the window should move to the exact position. |
763 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); | 840 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); |
764 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); | 841 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); |
765 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); | 842 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); |
766 } | 843 } |
767 | 844 |
768 } // namespace | |
769 } // namespace test | 845 } // namespace test |
770 } // namespace ash | 846 } // namespace ash |
OLD | NEW |