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/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
9 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
16 #include "ash/wm/property_util.h" | 16 #include "ash/wm/window_state.h" |
17 #include "ash/wm/window_settings.h" | |
18 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
19 #include "ash/wm/workspace/phantom_window_controller.h" | 18 #include "ash/wm/workspace/phantom_window_controller.h" |
20 #include "ash/wm/workspace/snap_sizer.h" | 19 #include "ash/wm/workspace/snap_sizer.h" |
21 #include "ash/wm/workspace_controller.h" | 20 #include "ash/wm/workspace_controller.h" |
22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
23 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
25 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
26 #include "ui/aura/root_window.h" | 25 #include "ui/aura/root_window.h" |
27 #include "ui/aura/test/event_generator.h" | 26 #include "ui/aura/test/event_generator.h" |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString()); | 538 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString()); |
540 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); | 539 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); |
541 } | 540 } |
542 | 541 |
543 | 542 |
544 // Assertions around dragging to the left/right edge of the screen. | 543 // Assertions around dragging to the left/right edge of the screen. |
545 TEST_F(WorkspaceWindowResizerTest, Edge) { | 544 TEST_F(WorkspaceWindowResizerTest, Edge) { |
546 int bottom = | 545 int bottom = |
547 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); | 546 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); |
548 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); | 547 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); |
| 548 wm::WindowState* window_state = wm::GetWindowState(window_.get()); |
| 549 |
549 { | 550 { |
550 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 551 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
551 window_.get(), gfx::Point(), HTCAPTION, | 552 window_.get(), gfx::Point(), HTCAPTION, |
552 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); | 553 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); |
553 ASSERT_TRUE(resizer.get()); | 554 ASSERT_TRUE(resizer.get()); |
554 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0); | 555 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0); |
555 resizer->CompleteDrag(0); | 556 resizer->CompleteDrag(0); |
556 EXPECT_EQ("0,0 720x" + base::IntToString(bottom), | 557 EXPECT_EQ("0,0 720x" + base::IntToString(bottom), |
557 window_->bounds().ToString()); | 558 window_->bounds().ToString()); |
558 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); | 559 ASSERT_TRUE(window_state->HasRestoreBounds()); |
559 EXPECT_EQ("20,30 50x60", | 560 EXPECT_EQ("20,30 50x60", |
560 GetRestoreBoundsInScreen(window_.get())->ToString()); | 561 window_state->GetRestoreBoundsInScreen().ToString()); |
561 } | 562 } |
562 // Try the same with the right side. | 563 // Try the same with the right side. |
563 { | 564 { |
564 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 565 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
565 window_.get(), gfx::Point(), HTCAPTION, | 566 window_.get(), gfx::Point(), HTCAPTION, |
566 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); | 567 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); |
567 ASSERT_TRUE(resizer.get()); | 568 ASSERT_TRUE(resizer.get()); |
568 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); | 569 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); |
569 resizer->CompleteDrag(0); | 570 resizer->CompleteDrag(0); |
570 EXPECT_EQ("80,0 720x" + base::IntToString(bottom), | 571 EXPECT_EQ("80,0 720x" + base::IntToString(bottom), |
571 window_->bounds().ToString()); | 572 window_->bounds().ToString()); |
572 ASSERT_TRUE(GetRestoreBoundsInScreen(window_.get())); | 573 ASSERT_TRUE(window_state->HasRestoreBounds()); |
573 EXPECT_EQ("20,30 50x60", | 574 EXPECT_EQ("20,30 50x60", |
574 GetRestoreBoundsInScreen(window_.get())->ToString()); | 575 window_state->GetRestoreBoundsInScreen().ToString()); |
575 } | 576 } |
576 | 577 |
577 // Test if the restore bounds is correct in multiple displays. | 578 // Test if the restore bounds is correct in multiple displays. |
578 ClearRestoreBounds(window_.get()); | 579 window_state->ClearRestoreBounds(); |
579 | 580 |
580 if (!SupportsMultipleDisplays()) | 581 if (!SupportsMultipleDisplays()) |
581 return; | 582 return; |
582 | 583 |
583 UpdateDisplay("800x600,200x600"); | 584 UpdateDisplay("800x600,200x600"); |
584 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 585 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
585 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 586 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
586 window_->SetBoundsInScreen(gfx::Rect(800, 10, 50, 60), | 587 window_->SetBoundsInScreen(gfx::Rect(800, 10, 50, 60), |
587 ScreenAsh::GetSecondaryDisplay()); | 588 ScreenAsh::GetSecondaryDisplay()); |
588 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 589 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
589 { | 590 { |
590 bottom = | 591 bottom = |
591 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); | 592 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); |
592 EXPECT_EQ("800,10 50x60", window_->GetBoundsInScreen().ToString()); | 593 EXPECT_EQ("800,10 50x60", window_->GetBoundsInScreen().ToString()); |
593 | 594 |
594 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 595 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
595 window_.get(), gfx::Point(), HTCAPTION, | 596 window_.get(), gfx::Point(), HTCAPTION, |
596 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); | 597 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); |
597 ASSERT_TRUE(resizer.get()); | 598 ASSERT_TRUE(resizer.get()); |
598 | 599 |
599 resizer->Drag(CalculateDragPoint(*resizer, 199, 00), 0); | 600 resizer->Drag(CalculateDragPoint(*resizer, 199, 00), 0); |
600 resizer->CompleteDrag(0); | 601 resizer->CompleteDrag(0); |
601 // With the resolution of 200x600 we will hit in this case the 50% screen | 602 // With the resolution of 200x600 we will hit in this case the 50% screen |
602 // size setting. | 603 // size setting. |
603 EXPECT_EQ("100,0 100x" + base::IntToString(bottom), | 604 EXPECT_EQ("100,0 100x" + base::IntToString(bottom), |
604 window_->bounds().ToString()); | 605 window_->bounds().ToString()); |
605 EXPECT_EQ("800,10 50x60", | 606 EXPECT_EQ("800,10 50x60", |
606 GetRestoreBoundsInScreen(window_.get())->ToString()); | 607 window_state->GetRestoreBoundsInScreen().ToString()); |
607 } | 608 } |
608 } | 609 } |
609 | 610 |
610 // Check that non resizable windows will not get resized. | 611 // Check that non resizable windows will not get resized. |
611 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) { | 612 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) { |
612 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); | 613 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); |
613 window_->SetProperty(aura::client::kCanResizeKey, false); | 614 window_->SetProperty(aura::client::kCanResizeKey, false); |
614 | 615 |
615 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 616 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
616 window_.get(), gfx::Point(), HTCAPTION, | 617 window_.get(), gfx::Point(), HTCAPTION, |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, | 1140 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, |
1140 // the window should move to the exact position. | 1141 // the window should move to the exact position. |
1141 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); | 1142 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); |
1142 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); | 1143 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); |
1143 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); | 1144 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); |
1144 } | 1145 } |
1145 | 1146 |
1146 // Verifies that a dragged window will restore to its pre-maximized size. | 1147 // Verifies that a dragged window will restore to its pre-maximized size. |
1147 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) { | 1148 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) { |
1148 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000)); | 1149 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000)); |
1149 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160)); | 1150 wm::WindowState* window_state = wm::GetWindowState(window_.get()); |
| 1151 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160)); |
1150 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1152 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1151 window_.get(), gfx::Point(), HTCAPTION, | 1153 window_.get(), gfx::Point(), HTCAPTION, |
1152 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); | 1154 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); |
1153 ASSERT_TRUE(resizer.get()); | 1155 ASSERT_TRUE(resizer.get()); |
1154 // Drag the window to new position by adding (10, 10) to original point, | 1156 // Drag the window to new position by adding (10, 10) to original point, |
1155 // the window should get restored. | 1157 // the window should get restored. |
1156 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); | 1158 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); |
1157 resizer->CompleteDrag(0); | 1159 resizer->CompleteDrag(0); |
1158 EXPECT_EQ("10,10 320x160", window_->bounds().ToString()); | 1160 EXPECT_EQ("10,10 320x160", window_->bounds().ToString()); |
1159 // The restore rectangle should get cleared as well. | 1161 // The restore rectangle should get cleared as well. |
1160 EXPECT_EQ(NULL, GetRestoreBoundsInScreen(window_.get())); | 1162 EXPECT_FALSE(window_state->HasRestoreBounds()); |
1161 } | 1163 } |
1162 | 1164 |
1163 // Verifies that a dragged window will restore to its pre-maximized size. | 1165 // Verifies that a dragged window will restore to its pre-maximized size. |
1164 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { | 1166 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { |
1165 const gfx::Rect initial_bounds(0, 0, 200, 400); | 1167 const gfx::Rect initial_bounds(0, 0, 200, 400); |
1166 window_->SetBounds(initial_bounds); | 1168 window_->SetBounds(initial_bounds); |
1167 SetRestoreBoundsInScreen(window_.get(), gfx::Rect(96, 112, 320, 160)); | 1169 |
| 1170 wm::WindowState* window_state = wm::GetWindowState(window_.get()); |
| 1171 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160)); |
1168 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1172 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1169 window_.get(), gfx::Point(), HTCAPTION, | 1173 window_.get(), gfx::Point(), HTCAPTION, |
1170 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); | 1174 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); |
1171 ASSERT_TRUE(resizer.get()); | 1175 ASSERT_TRUE(resizer.get()); |
1172 // Drag the window to new poistion by adding (180, 16) to original point, | 1176 // Drag the window to new poistion by adding (180, 16) to original point, |
1173 // the window should get restored. | 1177 // the window should get restored. |
1174 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0); | 1178 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0); |
1175 resizer->RevertDrag(); | 1179 resizer->RevertDrag(); |
1176 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString()); | 1180 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString()); |
1177 EXPECT_EQ("96,112 320x160", | 1181 EXPECT_EQ("96,112 320x160", |
1178 GetRestoreBoundsInScreen(window_.get())->ToString()); | 1182 window_state->GetRestoreBoundsInScreen().ToString()); |
1179 } | 1183 } |
1180 | 1184 |
1181 // Check that only usable sizes get returned by the resizer. | 1185 // Check that only usable sizes get returned by the resizer. |
1182 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) { | 1186 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) { |
1183 window_->SetBounds(gfx::Rect(10, 10, 20, 30)); | 1187 window_->SetBounds(gfx::Rect(10, 10, 20, 30)); |
1184 window2_->SetBounds(gfx::Rect(150, 160, 25, 20)); | 1188 window2_->SetBounds(gfx::Rect(150, 160, 25, 20)); |
1185 window2_->Show(); | 1189 window2_->Show(); |
1186 | 1190 |
1187 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1191 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1188 window_.get(), gfx::Point(), HTCAPTION, | 1192 window_.get(), gfx::Point(), HTCAPTION, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 { | 1383 { |
1380 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1384 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1381 window_.get(), gfx::Point(), HTCAPTION, | 1385 window_.get(), gfx::Point(), HTCAPTION, |
1382 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); | 1386 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); |
1383 ASSERT_TRUE(resizer.get()); | 1387 ASSERT_TRUE(resizer.get()); |
1384 // Move it 100 to the bottom. | 1388 // Move it 100 to the bottom. |
1385 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); | 1389 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); |
1386 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); | 1390 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); |
1387 resizer->RevertDrag(); | 1391 resizer->RevertDrag(); |
1388 | 1392 |
1389 EXPECT_FALSE( | 1393 EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user()); |
1390 wm::GetWindowSettings(window_.get())->bounds_changed_by_user()); | |
1391 } | 1394 } |
1392 | 1395 |
1393 // Check that a completed move / size does change the user coordinates. | 1396 // Check that a completed move / size does change the user coordinates. |
1394 { | 1397 { |
1395 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1398 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1396 window_.get(), gfx::Point(), HTCAPTION, | 1399 window_.get(), gfx::Point(), HTCAPTION, |
1397 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); | 1400 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); |
1398 ASSERT_TRUE(resizer.get()); | 1401 ASSERT_TRUE(resizer.get()); |
1399 // Move it 100 to the bottom. | 1402 // Move it 100 to the bottom. |
1400 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); | 1403 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); |
1401 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); | 1404 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); |
1402 resizer->CompleteDrag(0); | 1405 resizer->CompleteDrag(0); |
1403 EXPECT_TRUE( | 1406 EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user()); |
1404 wm::GetWindowSettings(window_.get())->bounds_changed_by_user()); | |
1405 } | 1407 } |
1406 } | 1408 } |
1407 | 1409 |
1408 // Test that a window with a specified max size doesn't exceed it when dragged. | 1410 // Test that a window with a specified max size doesn't exceed it when dragged. |
1409 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) { | 1411 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) { |
1410 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); | 1412 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); |
1411 delegate_.set_max_size(gfx::Size(401, 301)); | 1413 delegate_.set_max_size(gfx::Size(401, 301)); |
1412 | 1414 |
1413 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( | 1415 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
1414 window_.get(), gfx::Point(), HTBOTTOMRIGHT, | 1416 window_.get(), gfx::Point(), HTBOTTOMRIGHT, |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 RunAnimationTillComplete(phantom_controller->animation_.get()); | 1938 RunAnimationTillComplete(phantom_controller->animation_.get()); |
1937 | 1939 |
1938 // Hide phantom controller. Both widgets should close. | 1940 // Hide phantom controller. Both widgets should close. |
1939 phantom_controller->Hide(); | 1941 phantom_controller->Hide(); |
1940 EXPECT_FALSE(phantom_controller->phantom_widget_); | 1942 EXPECT_FALSE(phantom_controller->phantom_widget_); |
1941 EXPECT_FALSE(phantom_controller->phantom_widget_start_); | 1943 EXPECT_FALSE(phantom_controller->phantom_widget_start_); |
1942 } | 1944 } |
1943 | 1945 |
1944 } // namespace internal | 1946 } // namespace internal |
1945 } // namespace ash | 1947 } // namespace ash |
OLD | NEW |