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/screen_ash.h" | 8 #include "ash/screen_ash.h" |
8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | |
9 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/property_util.h" | 12 #include "ash/wm/property_util.h" |
11 #include "ash/wm/workspace_controller.h" | 13 #include "ash/wm/workspace_controller.h" |
12 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
13 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
14 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
15 #include "ui/base/hit_test.h" | 17 #include "ui/base/hit_test.h" |
16 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
19 #include "ui/gfx/screen.h" | |
17 | 20 |
18 namespace ash { | 21 namespace ash { |
19 namespace internal { | 22 namespace internal { |
20 namespace { | 23 namespace { |
21 | 24 |
22 const int kRootHeight = 600; | 25 const int kRootHeight = 600; |
23 | 26 |
24 // A simple window delegate that returns the specified min size. | 27 // A simple window delegate that returns the specified min size. |
25 class TestWindowDelegate : public aura::test::TestWindowDelegate { | 28 class TestWindowDelegate : public aura::test::TestWindowDelegate { |
26 public: | 29 public: |
(...skipping 15 matching lines...) Expand all Loading... | |
42 | 45 |
43 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); | 46 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); |
44 }; | 47 }; |
45 | 48 |
46 class WorkspaceWindowResizerTest : public test::AshTestBase { | 49 class WorkspaceWindowResizerTest : public test::AshTestBase { |
47 public: | 50 public: |
48 WorkspaceWindowResizerTest() : window_(NULL) {} | 51 WorkspaceWindowResizerTest() : window_(NULL) {} |
49 virtual ~WorkspaceWindowResizerTest() {} | 52 virtual ~WorkspaceWindowResizerTest() {} |
50 | 53 |
51 virtual void SetUp() OVERRIDE { | 54 virtual void SetUp() OVERRIDE { |
55 DisplayController::SetExtendedDesktopEnabled(true); | |
52 AshTestBase::SetUp(); | 56 AshTestBase::SetUp(); |
53 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 57 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
54 root->SetHostSize(gfx::Size(800, kRootHeight)); | 58 root->SetHostSize(gfx::Size(800, kRootHeight)); |
55 | 59 |
60 aura::Window* default_container = | |
61 Shell::GetContainer(root, kShellWindowId_DefaultContainer); | |
62 | |
56 gfx::Rect root_bounds(root->bounds()); | 63 gfx::Rect root_bounds(root->bounds()); |
57 EXPECT_EQ(kRootHeight, root_bounds.height()); | 64 EXPECT_EQ(kRootHeight, root_bounds.height()); |
58 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); | 65 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); |
59 window_.reset(new aura::Window(&delegate_)); | 66 window_.reset(new aura::Window(&delegate_)); |
60 window_->Init(ui::LAYER_NOT_DRAWN); | 67 window_->Init(ui::LAYER_NOT_DRAWN); |
61 window_->SetParent(root); | 68 window_->SetParent(default_container); |
62 window_->set_id(1); | 69 window_->set_id(1); |
63 | 70 |
64 window2_.reset(new aura::Window(&delegate2_)); | 71 window2_.reset(new aura::Window(&delegate2_)); |
65 window2_->Init(ui::LAYER_NOT_DRAWN); | 72 window2_->Init(ui::LAYER_NOT_DRAWN); |
66 window2_->SetParent(root); | 73 window2_->SetParent(default_container); |
67 window2_->set_id(2); | 74 window2_->set_id(2); |
68 | 75 |
69 window3_.reset(new aura::Window(&delegate3_)); | 76 window3_.reset(new aura::Window(&delegate3_)); |
70 window3_->Init(ui::LAYER_NOT_DRAWN); | 77 window3_->Init(ui::LAYER_NOT_DRAWN); |
71 window3_->SetParent(root); | 78 window3_->SetParent(default_container); |
72 window3_->set_id(3); | 79 window3_->set_id(3); |
73 } | 80 } |
74 | 81 |
75 virtual void TearDown() OVERRIDE { | 82 virtual void TearDown() OVERRIDE { |
76 window_.reset(); | 83 window_.reset(); |
77 window2_.reset(); | 84 window2_.reset(); |
78 window3_.reset(); | 85 window3_.reset(); |
79 AshTestBase::TearDown(); | 86 AshTestBase::TearDown(); |
87 DisplayController::SetExtendedDesktopEnabled(false); | |
80 } | 88 } |
81 | 89 |
82 // Returns a string identifying the z-order of each of the known windows. | 90 // Returns a string identifying the z-order of each of the known windows. |
83 // The returned string constains the id of the known windows and is ordered | 91 // The returned string constains the id of the known windows and is ordered |
84 // from topmost to bottomost windows. | 92 // from topmost to bottomost windows. |
85 std::string WindowOrderAsString() const { | 93 std::string WindowOrderAsString() const { |
86 std::string result; | 94 std::string result; |
87 const aura::Window::Windows& windows = | 95 aura::Window* default_container = Shell::GetContainer( |
88 Shell::GetPrimaryRootWindow()->children(); | 96 Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); |
97 const aura::Window::Windows& windows = default_container->children(); | |
89 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); | 98 for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); |
90 i != windows.rend(); ++i) { | 99 i != windows.rend(); ++i) { |
91 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { | 100 if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { |
92 if (!result.empty()) | 101 if (!result.empty()) |
93 result += " "; | 102 result += " "; |
94 result += base::IntToString((*i)->id()); | 103 result += base::IntToString((*i)->id()); |
95 } | 104 } |
96 } | 105 } |
97 return result; | 106 return result; |
98 } | 107 } |
99 | 108 |
100 protected: | 109 protected: |
101 void SetGridSize(int grid_size) { | 110 void SetGridSize(int grid_size) { |
102 Shell::TestApi shell_test(Shell::GetInstance()); | 111 Shell::TestApi shell_test(Shell::GetInstance()); |
103 shell_test.workspace_controller()->SetGridSize(grid_size); | 112 shell_test.workspace_controller()->SetGridSize(grid_size); |
104 } | 113 } |
114 | |
105 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, | 115 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, |
106 int delta_x, | 116 int delta_x, |
107 int delta_y) const { | 117 int delta_y) const { |
108 gfx::Point location = resizer.initial_location_in_parent(); | 118 gfx::Point location = resizer.initial_location_in_parent(); |
109 location.set_x(location.x() + delta_x); | 119 location.set_x(location.x() + delta_x); |
110 location.set_y(location.y() + delta_y); | 120 location.set_y(location.y() + delta_y); |
111 return location; | 121 return location; |
112 } | 122 } |
113 | 123 |
114 std::vector<aura::Window*> empty_windows() const { | 124 std::vector<aura::Window*> empty_windows() const { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | 457 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
448 ASSERT_TRUE(resizer.get()); | 458 ASSERT_TRUE(resizer.get()); |
449 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 459 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); |
450 resizer->CompleteDrag(0); | 460 resizer->CompleteDrag(0); |
451 EXPECT_EQ("400,0 400x" + base::IntToString(bottom), | 461 EXPECT_EQ("400,0 400x" + base::IntToString(bottom), |
452 window_->bounds().ToString()); | 462 window_->bounds().ToString()); |
453 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); | 463 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); |
454 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString()); | 464 EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString()); |
455 } | 465 } |
456 | 466 |
467 // Verifies a window can be moved from the primary display to another. | |
468 TEST_F(WorkspaceWindowResizerTest, WindowDragWithMultiMonitors) { | |
469 // The secondary display is logically on the right, but on the system (e.g. X) | |
470 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. | |
471 UpdateDisplay("800x600,800x600"); | |
472 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
473 ASSERT_EQ(2U, root_windows.size()); | |
474 | |
475 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | |
476 gfx::Screen::GetPrimaryDisplay()); | |
477 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | |
478 { | |
479 SetGridSize(0); | |
480 // Grab (0, 0) of the window. | |
481 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | |
482 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | |
483 ASSERT_TRUE(resizer.get()); | |
484 // Drag the pointer to the right. Once it reaches the right edge of the | |
485 // primary display, it warps to the secondary. Since the secondary root | |
486 // window's native origin held by aura::RootWindowHost is (0, 600), and a | |
487 // mouse drag event has a location in the primary root window's coordinates, | |
488 // (0, 610) below means (0, 10) in the second root window's coordinates. | |
489 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); | |
490 resizer->CompleteDrag(0); | |
491 // The whole window is on the secondary display now. The parent should be | |
492 // changed. | |
493 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | |
494 EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); | |
495 } | |
496 | |
497 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | |
498 gfx::Screen::GetPrimaryDisplay()); | |
499 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | |
500 { | |
501 SetGridSize(0); | |
sky
2012/08/09 00:47:38
Why do you need SetGridSize so many times?
Yusuke Sato
2012/08/09 00:58:00
Thanks, removed.
| |
502 // Grab (0, 0) of the window and move the pointer to (790, 10). | |
503 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | |
504 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | |
505 ASSERT_TRUE(resizer.get()); | |
506 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); | |
507 resizer->CompleteDrag(0); | |
508 // Since the pointer is still on the primary root window, the parent should | |
509 // not be changed. | |
510 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | |
511 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); | |
512 } | |
513 | |
514 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | |
515 gfx::Screen::GetPrimaryDisplay()); | |
516 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | |
517 { | |
518 SetGridSize(0); | |
519 // Grab the top-right edge of the window and move the pointer to (0, 10) | |
520 // in the secondary root window's coordinates. | |
521 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | |
522 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); | |
523 ASSERT_TRUE(resizer.get()); | |
524 resizer->Drag(CalculateDragPoint(*resizer, -49, 610), 0); | |
525 resizer->CompleteDrag(0); | |
526 // Since the pointer is on the secondary, the parent should not be changed | |
527 // even though only small fraction of the window is within the secondary | |
528 // root window's bounds. | |
529 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | |
530 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString()); | |
531 } | |
532 } | |
533 | |
534 // Verifies a window can be moved from the secondary display to primary. | |
535 TEST_F(WorkspaceWindowResizerTest, WindowDragWithMultiMonitorsRightToLeft) { | |
536 UpdateDisplay("800x600,800x600"); | |
537 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
538 ASSERT_EQ(2U, root_windows.size()); | |
539 | |
540 window_->SetBoundsInScreen( | |
541 gfx::Rect(800, 00, 50, 60), | |
542 gfx::Screen::GetDisplayNearestWindow(root_windows[1])); | |
543 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | |
544 { | |
545 SetGridSize(0); | |
546 // Grab (0, 0) of the window. | |
547 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | |
548 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); | |
549 ASSERT_TRUE(resizer.get()); | |
550 // Move the mouse near the right edge, (798, 0), of the primary display. | |
551 resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); | |
552 resizer->CompleteDrag(0); | |
553 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | |
554 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); | |
555 } | |
556 } | |
557 | |
457 // Verifies windows are correctly restacked when reordering multiple windows. | 558 // Verifies windows are correctly restacked when reordering multiple windows. |
458 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { | 559 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { |
459 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); | 560 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); |
460 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); | 561 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); |
461 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); | 562 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); |
462 | 563 |
463 { | 564 { |
464 std::vector<aura::Window*> windows; | 565 std::vector<aura::Window*> windows; |
465 windows.push_back(window2_.get()); | 566 windows.push_back(window2_.get()); |
466 SetGridSize(10); | 567 SetGridSize(10); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
646 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, | 747 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, |
647 // the window should move to the exact position. | 748 // the window should move to the exact position. |
648 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); | 749 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); |
649 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); | 750 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); |
650 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); | 751 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); |
651 } | 752 } |
652 | 753 |
653 } // namespace | 754 } // namespace |
654 } // namespace test | 755 } // namespace test |
655 } // namespace ash | 756 } // namespace ash |
OLD | NEW |