| 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/toplevel_window_event_handler.h" | 5 #include "ash/wm/toplevel_window_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
| 8 #include "ash/common/wm/workspace_controller.h" | 8 #include "ash/common/wm/workspace_controller.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/resize_shadow.h" | 13 #include "ash/wm/resize_shadow.h" |
| 14 #include "ash/wm/resize_shadow_controller.h" | 14 #include "ash/wm/resize_shadow_controller.h" |
| 15 #include "ash/wm/window_state_aura.h" | 15 #include "ash/wm/window_state_aura.h" |
| 16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/client/capture_client.h" | 22 #include "ui/aura/client/capture_client.h" |
| 22 #include "ui/aura/test/aura_test_base.h" | 23 #include "ui/aura/test/aura_test_base.h" |
| 23 #include "ui/aura/test/test_window_delegate.h" | 24 #include "ui/aura/test/test_window_delegate.h" |
| 24 #include "ui/aura/window_event_dispatcher.h" | 25 #include "ui/aura/window_event_dispatcher.h" |
| 25 #include "ui/base/hit_test.h" | 26 #include "ui/base/hit_test.h" |
| 26 #include "ui/display/screen.h" | 27 #include "ui/display/screen.h" |
| 27 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
| 28 #include "ui/events/test/event_generator.h" | 29 #include "ui/events/test/event_generator.h" |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 427 |
| 427 // Verifies that touch-gestures drag the window correctly. | 428 // Verifies that touch-gestures drag the window correctly. |
| 428 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { | 429 TEST_F(ToplevelWindowEventHandlerTest, GestureDrag) { |
| 429 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( | 430 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( |
| 430 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); | 431 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); |
| 431 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 432 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 432 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 433 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 433 target.get()); | 434 target.get()); |
| 434 gfx::Rect old_bounds = target->bounds(); | 435 gfx::Rect old_bounds = target->bounds(); |
| 435 gfx::Point location(5, 5); | 436 gfx::Point location(5, 5); |
| 436 target->SetProperty(aura::client::kCanMaximizeKey, true); | 437 target->SetProperty(aura::client::kResizeBehaviorKey, |
| 438 ui::mojom::kResizeBehaviorCanResize | |
| 439 ui::mojom::kResizeBehaviorCanMaximize | |
| 440 ui::mojom::kResizeBehaviorCanMinimize); |
| 437 | 441 |
| 438 gfx::Point end = location; | 442 gfx::Point end = location; |
| 439 | 443 |
| 440 // Snap right; | 444 // Snap right; |
| 441 end.Offset(100, 0); | 445 end.Offset(100, 0); |
| 442 generator.GestureScrollSequence(location, end, | 446 generator.GestureScrollSequence(location, end, |
| 443 base::TimeDelta::FromMilliseconds(5), 10); | 447 base::TimeDelta::FromMilliseconds(5), 10); |
| 444 RunAllPendingInMessageLoop(); | 448 RunAllPendingInMessageLoop(); |
| 445 | 449 |
| 446 // Verify that the window has moved after the gesture. | 450 // Verify that the window has moved after the gesture. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 window_state->GetRestoreBoundsInScreen().ToString()); | 496 window_state->GetRestoreBoundsInScreen().ToString()); |
| 493 } | 497 } |
| 494 | 498 |
| 495 // Tests that a gesture cannot minimize an unminimizeable window. | 499 // Tests that a gesture cannot minimize an unminimizeable window. |
| 496 TEST_F(ToplevelWindowEventHandlerTest, | 500 TEST_F(ToplevelWindowEventHandlerTest, |
| 497 GestureAttemptMinimizeUnminimizeableWindow) { | 501 GestureAttemptMinimizeUnminimizeableWindow) { |
| 498 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 502 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 499 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 503 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 500 target.get()); | 504 target.get()); |
| 501 gfx::Point location(5, 5); | 505 gfx::Point location(5, 5); |
| 502 target->SetProperty(aura::client::kCanMaximizeKey, true); | 506 target->SetProperty(aura::client::kResizeBehaviorKey, |
| 503 target->SetProperty(aura::client::kCanMinimizeKey, false); | 507 ui::mojom::kResizeBehaviorCanMaximize); |
| 504 | 508 |
| 505 gfx::Point end = location; | 509 gfx::Point end = location; |
| 506 end.Offset(0, 100); | 510 end.Offset(0, 100); |
| 507 generator.GestureScrollSequence(location, end, | 511 generator.GestureScrollSequence(location, end, |
| 508 base::TimeDelta::FromMilliseconds(5), 10); | 512 base::TimeDelta::FromMilliseconds(5), 10); |
| 509 RunAllPendingInMessageLoop(); | 513 RunAllPendingInMessageLoop(); |
| 510 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); | 514 EXPECT_FALSE(wm::GetWindowState(target.get())->IsMinimized()); |
| 511 } | 515 } |
| 512 | 516 |
| 513 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { | 517 TEST_F(ToplevelWindowEventHandlerTest, GestureDragToRestore) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 536 // Tests that an unresizable window cannot be dragged or snapped using gestures. | 540 // Tests that an unresizable window cannot be dragged or snapped using gestures. |
| 537 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { | 541 TEST_F(ToplevelWindowEventHandlerTest, GestureDragForUnresizableWindow) { |
| 538 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); | 542 std::unique_ptr<aura::Window> target(CreateWindow(HTCAPTION)); |
| 539 wm::WindowState* window_state = wm::GetWindowState(target.get()); | 543 wm::WindowState* window_state = wm::GetWindowState(target.get()); |
| 540 | 544 |
| 541 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 545 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 542 target.get()); | 546 target.get()); |
| 543 gfx::Rect old_bounds = target->bounds(); | 547 gfx::Rect old_bounds = target->bounds(); |
| 544 gfx::Point location(5, 5); | 548 gfx::Point location(5, 5); |
| 545 | 549 |
| 546 target->SetProperty(aura::client::kCanResizeKey, false); | 550 target->SetProperty(aura::client::kResizeBehaviorKey, |
| 551 ui::mojom::kResizeBehaviorNone); |
| 547 | 552 |
| 548 gfx::Point end = location; | 553 gfx::Point end = location; |
| 549 | 554 |
| 550 // Try to snap right. The window is not resizable. So it should not snap. | 555 // Try to snap right. The window is not resizable. So it should not snap. |
| 551 end.Offset(100, 0); | 556 end.Offset(100, 0); |
| 552 generator.GestureScrollSequence(location, end, | 557 generator.GestureScrollSequence(location, end, |
| 553 base::TimeDelta::FromMilliseconds(5), 10); | 558 base::TimeDelta::FromMilliseconds(5), 10); |
| 554 RunAllPendingInMessageLoop(); | 559 RunAllPendingInMessageLoop(); |
| 555 | 560 |
| 556 // Verify that the window has moved after the gesture. | 561 // Verify that the window has moved after the gesture. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 582 // Tests that dragging multiple windows at the same time is not allowed. | 587 // Tests that dragging multiple windows at the same time is not allowed. |
| 583 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMultipleWindows) { | 588 TEST_F(ToplevelWindowEventHandlerTest, GestureDragMultipleWindows) { |
| 584 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( | 589 std::unique_ptr<aura::Window> target(CreateTestWindowInShellWithDelegate( |
| 585 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); | 590 new TestWindowDelegate(HTCAPTION), 0, gfx::Rect(0, 0, 100, 100))); |
| 586 std::unique_ptr<aura::Window> notmoved(CreateTestWindowInShellWithDelegate( | 591 std::unique_ptr<aura::Window> notmoved(CreateTestWindowInShellWithDelegate( |
| 587 new TestWindowDelegate(HTCAPTION), 1, gfx::Rect(100, 0, 100, 100))); | 592 new TestWindowDelegate(HTCAPTION), 1, gfx::Rect(100, 0, 100, 100))); |
| 588 | 593 |
| 589 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 594 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 590 target.get()); | 595 target.get()); |
| 591 gfx::Point location(5, 5); | 596 gfx::Point location(5, 5); |
| 592 target->SetProperty(aura::client::kCanMaximizeKey, true); | |
| 593 | 597 |
| 594 // Send some touch events to start dragging |target|. | 598 // Send some touch events to start dragging |target|. |
| 595 generator.MoveTouch(location); | 599 generator.MoveTouch(location); |
| 596 generator.PressTouch(); | 600 generator.PressTouch(); |
| 597 location.Offset(40, 5); | 601 location.Offset(40, 5); |
| 598 generator.MoveTouch(location); | 602 generator.MoveTouch(location); |
| 599 | 603 |
| 600 // Try to drag |notmoved| window. This should not move the window. | 604 // Try to drag |notmoved| window. This should not move the window. |
| 601 { | 605 { |
| 602 gfx::Rect bounds = notmoved->bounds(); | 606 gfx::Rect bounds = notmoved->bounds(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, | 764 EXPECT_EQ(aura::client::MOVE_SUCCESSFUL, |
| 761 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), | 765 move_client->RunMoveLoop(window.get(), gfx::Vector2d(), |
| 762 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); | 766 aura::client::WINDOW_MOVE_SOURCE_TOUCH)); |
| 763 } | 767 } |
| 764 | 768 |
| 765 // Showing the resize shadows when the mouse is over the window edges is tested | 769 // Showing the resize shadows when the mouse is over the window edges is tested |
| 766 // in resize_shadow_and_cursor_test.cc | 770 // in resize_shadow_and_cursor_test.cc |
| 767 | 771 |
| 768 } // namespace test | 772 } // namespace test |
| 769 } // namespace ash | 773 } // namespace ash |
| OLD | NEW |