| 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/common/wm/workspace/workspace_event_handler.h" | 5 #include "ash/common/wm/workspace/workspace_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/wm_event.h" | 8 #include "ash/common/wm/wm_event.h" |
| 9 #include "ash/common/wm/workspace_controller.h" | 9 #include "ash/common/wm/workspace_controller.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.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/window_state_aura.h" | 13 #include "ash/wm/window_state_aura.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/workspace_controller_test_helper.h" | 15 #include "ash/wm/workspace_controller_test_helper.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 17 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 18 #include "ui/aura/test/test_window_delegate.h" | 19 #include "ui/aura/test/test_window_delegate.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
| 22 #include "ui/display/manager/display_manager.h" | 23 #include "ui/display/manager/display_manager.h" |
| 23 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
| 24 #include "ui/events/event_processor.h" | 25 #include "ui/events/event_processor.h" |
| 25 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
| 26 #include "ui/events/test/event_generator.h" | 27 #include "ui/events/test/event_generator.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 297 } |
| 297 | 298 |
| 298 TEST_F(WorkspaceEventHandlerTest, | 299 TEST_F(WorkspaceEventHandlerTest, |
| 299 DoubleClickOrTapWithModalChildDoesntMaximize) { | 300 DoubleClickOrTapWithModalChildDoesntMaximize) { |
| 300 aura::test::TestWindowDelegate delegate1; | 301 aura::test::TestWindowDelegate delegate1; |
| 301 aura::test::TestWindowDelegate delegate2; | 302 aura::test::TestWindowDelegate delegate2; |
| 302 std::unique_ptr<aura::Window> window( | 303 std::unique_ptr<aura::Window> window( |
| 303 CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40))); | 304 CreateTestWindow(&delegate1, gfx::Rect(10, 20, 30, 40))); |
| 304 std::unique_ptr<aura::Window> child( | 305 std::unique_ptr<aura::Window> child( |
| 305 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1))); | 306 CreateTestWindow(&delegate2, gfx::Rect(0, 0, 1, 1))); |
| 306 window->SetProperty(aura::client::kCanMaximizeKey, true); | 307 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 308 ui::mojom::kResizeBehaviorCanMaximize); |
| 307 delegate1.set_window_component(HTCAPTION); | 309 delegate1.set_window_component(HTCAPTION); |
| 308 | 310 |
| 309 child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); | 311 child->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 310 ::wm::AddTransientChild(window.get(), child.get()); | 312 ::wm::AddTransientChild(window.get(), child.get()); |
| 311 | 313 |
| 312 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 314 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 313 EXPECT_FALSE(window_state->IsMaximized()); | 315 EXPECT_FALSE(window_state->IsMaximized()); |
| 314 aura::Window* root = Shell::GetPrimaryRootWindow(); | 316 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 315 ui::test::EventGenerator generator(root, window.get()); | 317 ui::test::EventGenerator generator(root, window.get()); |
| 316 generator.DoubleClickLeftButton(); | 318 generator.DoubleClickLeftButton(); |
| 317 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); | 319 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); |
| 318 EXPECT_FALSE(window_state->IsMaximized()); | 320 EXPECT_FALSE(window_state->IsMaximized()); |
| 319 | 321 |
| 320 generator.GestureTapAt(gfx::Point(25, 25)); | 322 generator.GestureTapAt(gfx::Point(25, 25)); |
| 321 generator.GestureTapAt(gfx::Point(25, 25)); | 323 generator.GestureTapAt(gfx::Point(25, 25)); |
| 322 RunAllPendingInMessageLoop(); | 324 RunAllPendingInMessageLoop(); |
| 323 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); | 325 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); |
| 324 EXPECT_FALSE(window_state->IsMaximized()); | 326 EXPECT_FALSE(window_state->IsMaximized()); |
| 325 } | 327 } |
| 326 | 328 |
| 327 // Test the behavior as a result of double clicking the window header. | 329 // Test the behavior as a result of double clicking the window header. |
| 328 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { | 330 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { |
| 329 aura::test::TestWindowDelegate delegate; | 331 aura::test::TestWindowDelegate delegate; |
| 330 std::unique_ptr<aura::Window> window( | 332 std::unique_ptr<aura::Window> window( |
| 331 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 333 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 332 window->SetProperty(aura::client::kCanMaximizeKey, true); | 334 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 335 ui::mojom::kResizeBehaviorCanMaximize); |
| 333 | 336 |
| 334 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 337 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 335 gfx::Rect restore_bounds = window->bounds(); | 338 gfx::Rect restore_bounds = window->bounds(); |
| 336 gfx::Rect work_area_in_parent = | 339 gfx::Rect work_area_in_parent = |
| 337 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); | 340 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 338 | 341 |
| 339 EXPECT_FALSE(window_state->IsMaximized()); | 342 EXPECT_FALSE(window_state->IsMaximized()); |
| 340 | 343 |
| 341 // 1) Double clicking a normal window should maximize. | 344 // 1) Double clicking a normal window should maximize. |
| 342 delegate.set_window_component(HTCAPTION); | 345 delegate.set_window_component(HTCAPTION); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); | 383 EXPECT_EQ(restore_bounds.ToString(), window->bounds().ToString()); |
| 381 } | 384 } |
| 382 | 385 |
| 383 // Test that double clicking the middle button on the window header does not | 386 // Test that double clicking the middle button on the window header does not |
| 384 // toggle the maximized state. | 387 // toggle the maximized state. |
| 385 TEST_F(WorkspaceEventHandlerTest, | 388 TEST_F(WorkspaceEventHandlerTest, |
| 386 DoubleClickMiddleButtonDoesNotToggleMaximize) { | 389 DoubleClickMiddleButtonDoesNotToggleMaximize) { |
| 387 aura::test::TestWindowDelegate delegate; | 390 aura::test::TestWindowDelegate delegate; |
| 388 std::unique_ptr<aura::Window> window( | 391 std::unique_ptr<aura::Window> window( |
| 389 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 392 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 390 window->SetProperty(aura::client::kCanMaximizeKey, true); | 393 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 394 ui::mojom::kResizeBehaviorCanMaximize); |
| 391 delegate.set_window_component(HTCAPTION); | 395 delegate.set_window_component(HTCAPTION); |
| 392 aura::Window* root = Shell::GetPrimaryRootWindow(); | 396 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 393 ui::test::EventGenerator generator(root, window.get()); | 397 ui::test::EventGenerator generator(root, window.get()); |
| 394 | 398 |
| 395 WindowPropertyObserver observer(window.get()); | 399 WindowPropertyObserver observer(window.get()); |
| 396 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_NONE); | 400 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_NONE); |
| 397 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, | 401 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, |
| 398 ui::EF_IS_DOUBLE_CLICK); | 402 ui::EF_IS_DOUBLE_CLICK); |
| 399 | 403 |
| 400 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); | 404 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); |
| 401 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); | 405 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); |
| 402 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); | 406 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); |
| 403 } | 407 } |
| 404 | 408 |
| 405 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { | 409 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { |
| 406 aura::test::TestWindowDelegate delegate; | 410 aura::test::TestWindowDelegate delegate; |
| 407 gfx::Rect bounds(10, 20, 30, 40); | 411 gfx::Rect bounds(10, 20, 30, 40); |
| 408 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); | 412 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); |
| 409 window->SetProperty(aura::client::kCanMaximizeKey, true); | 413 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 414 ui::mojom::kResizeBehaviorCanMaximize); |
| 410 delegate.set_window_component(HTCAPTION); | 415 delegate.set_window_component(HTCAPTION); |
| 411 | 416 |
| 412 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 417 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 413 EXPECT_FALSE(window_state->IsMaximized()); | 418 EXPECT_FALSE(window_state->IsMaximized()); |
| 414 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 419 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 415 window.get()); | 420 window.get()); |
| 416 generator.GestureTapAt(gfx::Point(25, 25)); | 421 generator.GestureTapAt(gfx::Point(25, 25)); |
| 417 generator.GestureTapAt(gfx::Point(25, 25)); | 422 generator.GestureTapAt(gfx::Point(25, 25)); |
| 418 RunAllPendingInMessageLoop(); | 423 RunAllPendingInMessageLoop(); |
| 419 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); | 424 EXPECT_NE(bounds.ToString(), window->bounds().ToString()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 466 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 462 } | 467 } |
| 463 | 468 |
| 464 // Verifies that double clicking in the header does not maximize if the target | 469 // Verifies that double clicking in the header does not maximize if the target |
| 465 // component has changed. | 470 // component has changed. |
| 466 TEST_F(WorkspaceEventHandlerTest, | 471 TEST_F(WorkspaceEventHandlerTest, |
| 467 DoubleClickTwoDifferentTargetsDoesntMaximize) { | 472 DoubleClickTwoDifferentTargetsDoesntMaximize) { |
| 468 aura::test::TestWindowDelegate delegate; | 473 aura::test::TestWindowDelegate delegate; |
| 469 std::unique_ptr<aura::Window> window( | 474 std::unique_ptr<aura::Window> window( |
| 470 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 475 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 471 window->SetProperty(aura::client::kCanMaximizeKey, true); | 476 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 477 ui::mojom::kResizeBehaviorCanMaximize); |
| 472 | 478 |
| 473 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 479 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 474 EXPECT_FALSE(window_state->IsMaximized()); | 480 EXPECT_FALSE(window_state->IsMaximized()); |
| 475 | 481 |
| 476 // First click will go to a client | 482 // First click will go to a client |
| 477 delegate.set_window_component(HTCLIENT); | 483 delegate.set_window_component(HTCLIENT); |
| 478 aura::Window* root = Shell::GetPrimaryRootWindow(); | 484 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 479 ui::test::EventGenerator generator(root, window.get()); | 485 ui::test::EventGenerator generator(root, window.get()); |
| 480 generator.ClickLeftButton(); | 486 generator.ClickLeftButton(); |
| 481 EXPECT_FALSE(window_state->IsMaximized()); | 487 EXPECT_FALSE(window_state->IsMaximized()); |
| 482 | 488 |
| 483 // Second click will go to the header | 489 // Second click will go to the header |
| 484 delegate.set_window_component(HTCAPTION); | 490 delegate.set_window_component(HTCAPTION); |
| 485 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, | 491 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, |
| 486 ui::EF_IS_DOUBLE_CLICK); | 492 ui::EF_IS_DOUBLE_CLICK); |
| 487 EXPECT_FALSE(window_state->IsMaximized()); | 493 EXPECT_FALSE(window_state->IsMaximized()); |
| 488 } | 494 } |
| 489 | 495 |
| 490 // Verifies that double tapping in the header does not maximize if the target | 496 // Verifies that double tapping in the header does not maximize if the target |
| 491 // component has changed. | 497 // component has changed. |
| 492 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) { | 498 TEST_F(WorkspaceEventHandlerTest, DoubleTapTwoDifferentTargetsDoesntMaximize) { |
| 493 aura::test::TestWindowDelegate delegate; | 499 aura::test::TestWindowDelegate delegate; |
| 494 std::unique_ptr<aura::Window> window( | 500 std::unique_ptr<aura::Window> window( |
| 495 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 501 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 496 window->SetProperty(aura::client::kCanMaximizeKey, true); | 502 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 503 ui::mojom::kResizeBehaviorCanMaximize); |
| 497 | 504 |
| 498 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 505 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 499 EXPECT_FALSE(window_state->IsMaximized()); | 506 EXPECT_FALSE(window_state->IsMaximized()); |
| 500 | 507 |
| 501 // First tap will go to a client | 508 // First tap will go to a client |
| 502 delegate.set_window_component(HTCLIENT); | 509 delegate.set_window_component(HTCLIENT); |
| 503 aura::Window* root = Shell::GetPrimaryRootWindow(); | 510 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 504 ui::test::EventGenerator generator(root, window.get()); | 511 ui::test::EventGenerator generator(root, window.get()); |
| 505 generator.GestureTapAt(gfx::Point(25, 25)); | 512 generator.GestureTapAt(gfx::Point(25, 25)); |
| 506 EXPECT_FALSE(window_state->IsMaximized()); | 513 EXPECT_FALSE(window_state->IsMaximized()); |
| 507 | 514 |
| 508 // Second tap will go to the header | 515 // Second tap will go to the header |
| 509 delegate.set_window_component(HTCAPTION); | 516 delegate.set_window_component(HTCAPTION); |
| 510 generator.GestureTapAt(gfx::Point(25, 25)); | 517 generator.GestureTapAt(gfx::Point(25, 25)); |
| 511 EXPECT_FALSE(window_state->IsMaximized()); | 518 EXPECT_FALSE(window_state->IsMaximized()); |
| 512 } | 519 } |
| 513 | 520 |
| 514 TEST_F(WorkspaceEventHandlerTest, RightClickDuringDoubleClickDoesntMaximize) { | 521 TEST_F(WorkspaceEventHandlerTest, RightClickDuringDoubleClickDoesntMaximize) { |
| 515 aura::test::TestWindowDelegate delegate; | 522 aura::test::TestWindowDelegate delegate; |
| 516 std::unique_ptr<aura::Window> window( | 523 std::unique_ptr<aura::Window> window( |
| 517 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 524 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 518 window->SetProperty(aura::client::kCanMaximizeKey, true); | 525 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 526 ui::mojom::kResizeBehaviorCanMaximize); |
| 519 | 527 |
| 520 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 528 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 521 EXPECT_FALSE(window_state->IsMaximized()); | 529 EXPECT_FALSE(window_state->IsMaximized()); |
| 522 | 530 |
| 523 // First click will go to a client | 531 // First click will go to a client |
| 524 delegate.set_window_component(HTCLIENT); | 532 delegate.set_window_component(HTCLIENT); |
| 525 aura::Window* root = Shell::GetPrimaryRootWindow(); | 533 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 526 ui::test::EventGenerator generator(root, window.get()); | 534 ui::test::EventGenerator generator(root, window.get()); |
| 527 generator.ClickLeftButton(); | 535 generator.ClickLeftButton(); |
| 528 EXPECT_FALSE(window_state->IsMaximized()); | 536 EXPECT_FALSE(window_state->IsMaximized()); |
| 529 | 537 |
| 530 // Second click will go to the header | 538 // Second click will go to the header |
| 531 delegate.set_window_component(HTCAPTION); | 539 delegate.set_window_component(HTCAPTION); |
| 532 generator.PressRightButton(); | 540 generator.PressRightButton(); |
| 533 generator.ReleaseRightButton(); | 541 generator.ReleaseRightButton(); |
| 534 EXPECT_FALSE(window_state->IsMaximized()); | 542 EXPECT_FALSE(window_state->IsMaximized()); |
| 535 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, | 543 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, |
| 536 ui::EF_IS_DOUBLE_CLICK); | 544 ui::EF_IS_DOUBLE_CLICK); |
| 537 EXPECT_FALSE(window_state->IsMaximized()); | 545 EXPECT_FALSE(window_state->IsMaximized()); |
| 538 } | 546 } |
| 539 | 547 |
| 540 } // namespace ash | 548 } // namespace ash |
| OLD | NEW |