| 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_event_handler.h" | 5 #include "ash/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/screen_util.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 return window; | 66 return window; |
| 67 } | 67 } |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest); | 70 DISALLOW_COPY_AND_ASSIGN(WorkspaceEventHandlerTest); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 // Keeps track of the properties changed of a particular window. | 73 // Keeps track of the properties changed of a particular window. |
| 74 class WindowPropertyObserver : public aura::WindowObserver { | 74 class WindowPropertyObserver : public aura::WindowObserver { |
| 75 public: | 75 public: |
| 76 explicit WindowPropertyObserver(aura::Window* window) | 76 explicit WindowPropertyObserver(aura::Window* window) : window_(window) { |
| 77 : window_(window) { | |
| 78 window->AddObserver(this); | 77 window->AddObserver(this); |
| 79 } | 78 } |
| 80 | 79 |
| 81 ~WindowPropertyObserver() override { window_->RemoveObserver(this); } | 80 ~WindowPropertyObserver() override { window_->RemoveObserver(this); } |
| 82 | 81 |
| 83 bool DidPropertyChange(const void* property) const { | 82 bool DidPropertyChange(const void* property) const { |
| 84 return std::find(properties_changed_.begin(), | 83 return std::find(properties_changed_.begin(), properties_changed_.end(), |
| 85 properties_changed_.end(), | |
| 86 property) != properties_changed_.end(); | 84 property) != properties_changed_.end(); |
| 87 } | 85 } |
| 88 | 86 |
| 89 private: | 87 private: |
| 90 void OnWindowPropertyChanged(aura::Window* window, | 88 void OnWindowPropertyChanged(aura::Window* window, |
| 91 const void* key, | 89 const void* key, |
| 92 intptr_t old) override { | 90 intptr_t old) override { |
| 93 properties_changed_.push_back(key); | 91 properties_changed_.push_back(key); |
| 94 } | 92 } |
| 95 | 93 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 | 324 |
| 327 // Test the behavior as a result of double clicking the window header. | 325 // Test the behavior as a result of double clicking the window header. |
| 328 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { | 326 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { |
| 329 aura::test::TestWindowDelegate delegate; | 327 aura::test::TestWindowDelegate delegate; |
| 330 std::unique_ptr<aura::Window> window( | 328 std::unique_ptr<aura::Window> window( |
| 331 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 329 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 332 window->SetProperty(aura::client::kCanMaximizeKey, true); | 330 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 333 | 331 |
| 334 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 332 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 335 gfx::Rect restore_bounds = window->bounds(); | 333 gfx::Rect restore_bounds = window->bounds(); |
| 336 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 334 gfx::Rect work_area_in_parent = |
| 337 window.get()); | 335 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| 338 | 336 |
| 339 EXPECT_FALSE(window_state->IsMaximized()); | 337 EXPECT_FALSE(window_state->IsMaximized()); |
| 340 | 338 |
| 341 // 1) Double clicking a normal window should maximize. | 339 // 1) Double clicking a normal window should maximize. |
| 342 delegate.set_window_component(HTCAPTION); | 340 delegate.set_window_component(HTCAPTION); |
| 343 aura::Window* root = Shell::GetPrimaryRootWindow(); | 341 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 344 ui::test::EventGenerator generator(root, window.get()); | 342 ui::test::EventGenerator generator(root, window.get()); |
| 345 generator.DoubleClickLeftButton(); | 343 generator.DoubleClickLeftButton(); |
| 346 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString()); | 344 EXPECT_NE(restore_bounds.ToString(), window->bounds().ToString()); |
| 347 EXPECT_TRUE(window_state->IsMaximized()); | 345 EXPECT_TRUE(window_state->IsMaximized()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // Verifies deleting the window while in a run loop doesn't crash. | 448 // Verifies deleting the window while in a run loop doesn't crash. |
| 451 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) { | 449 TEST_F(WorkspaceEventHandlerTest, DeleteWhileInRunLoop) { |
| 452 aura::test::TestWindowDelegate delegate; | 450 aura::test::TestWindowDelegate delegate; |
| 453 const gfx::Rect bounds(10, 20, 30, 40); | 451 const gfx::Rect bounds(10, 20, 30, 40); |
| 454 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); | 452 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); |
| 455 delegate.set_window_component(HTCAPTION); | 453 delegate.set_window_component(HTCAPTION); |
| 456 | 454 |
| 457 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); | 455 ASSERT_TRUE(aura::client::GetWindowMoveClient(window->GetRootWindow())); |
| 458 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window.get()); | 456 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window.get()); |
| 459 aura::client::GetWindowMoveClient(window->GetRootWindow()) | 457 aura::client::GetWindowMoveClient(window->GetRootWindow()) |
| 460 ->RunMoveLoop(window.release(), | 458 ->RunMoveLoop(window.release(), gfx::Vector2d(), |
| 461 gfx::Vector2d(), | |
| 462 aura::client::WINDOW_MOVE_SOURCE_MOUSE); | 459 aura::client::WINDOW_MOVE_SOURCE_MOUSE); |
| 463 } | 460 } |
| 464 | 461 |
| 465 // Verifies that double clicking in the header does not maximize if the target | 462 // Verifies that double clicking in the header does not maximize if the target |
| 466 // component has changed. | 463 // component has changed. |
| 467 TEST_F(WorkspaceEventHandlerTest, | 464 TEST_F(WorkspaceEventHandlerTest, |
| 468 DoubleClickTwoDifferentTargetsDoesntMaximize) { | 465 DoubleClickTwoDifferentTargetsDoesntMaximize) { |
| 469 aura::test::TestWindowDelegate delegate; | 466 aura::test::TestWindowDelegate delegate; |
| 470 std::unique_ptr<aura::Window> window( | 467 std::unique_ptr<aura::Window> window( |
| 471 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 468 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 472 window->SetProperty(aura::client::kCanMaximizeKey, true); | 469 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 473 | 470 |
| 474 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 471 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 475 EXPECT_FALSE(window_state->IsMaximized()); | 472 EXPECT_FALSE(window_state->IsMaximized()); |
| 476 | 473 |
| 477 // First click will go to a client | 474 // First click will go to a client |
| 478 delegate.set_window_component(HTCLIENT); | 475 delegate.set_window_component(HTCLIENT); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 505 ui::test::EventGenerator generator(root, window.get()); | 502 ui::test::EventGenerator generator(root, window.get()); |
| 506 generator.GestureTapAt(gfx::Point(25, 25)); | 503 generator.GestureTapAt(gfx::Point(25, 25)); |
| 507 EXPECT_FALSE(window_state->IsMaximized()); | 504 EXPECT_FALSE(window_state->IsMaximized()); |
| 508 | 505 |
| 509 // Second tap will go to the header | 506 // Second tap will go to the header |
| 510 delegate.set_window_component(HTCAPTION); | 507 delegate.set_window_component(HTCAPTION); |
| 511 generator.GestureTapAt(gfx::Point(25, 25)); | 508 generator.GestureTapAt(gfx::Point(25, 25)); |
| 512 EXPECT_FALSE(window_state->IsMaximized()); | 509 EXPECT_FALSE(window_state->IsMaximized()); |
| 513 } | 510 } |
| 514 | 511 |
| 515 TEST_F(WorkspaceEventHandlerTest, | 512 TEST_F(WorkspaceEventHandlerTest, RightClickDuringDoubleClickDoesntMaximize) { |
| 516 RightClickDuringDoubleClickDoesntMaximize) { | |
| 517 aura::test::TestWindowDelegate delegate; | 513 aura::test::TestWindowDelegate delegate; |
| 518 std::unique_ptr<aura::Window> window( | 514 std::unique_ptr<aura::Window> window( |
| 519 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 515 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 520 window->SetProperty(aura::client::kCanMaximizeKey, true); | 516 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 521 | 517 |
| 522 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 518 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 523 EXPECT_FALSE(window_state->IsMaximized()); | 519 EXPECT_FALSE(window_state->IsMaximized()); |
| 524 | 520 |
| 525 // First click will go to a client | 521 // First click will go to a client |
| 526 delegate.set_window_component(HTCLIENT); | 522 delegate.set_window_component(HTCLIENT); |
| 527 aura::Window* root = Shell::GetPrimaryRootWindow(); | 523 aura::Window* root = Shell::GetPrimaryRootWindow(); |
| 528 ui::test::EventGenerator generator(root, window.get()); | 524 ui::test::EventGenerator generator(root, window.get()); |
| 529 generator.ClickLeftButton(); | 525 generator.ClickLeftButton(); |
| 530 EXPECT_FALSE(window_state->IsMaximized()); | 526 EXPECT_FALSE(window_state->IsMaximized()); |
| 531 | 527 |
| 532 // Second click will go to the header | 528 // Second click will go to the header |
| 533 delegate.set_window_component(HTCAPTION); | 529 delegate.set_window_component(HTCAPTION); |
| 534 generator.PressRightButton(); | 530 generator.PressRightButton(); |
| 535 generator.ReleaseRightButton(); | 531 generator.ReleaseRightButton(); |
| 536 EXPECT_FALSE(window_state->IsMaximized()); | 532 EXPECT_FALSE(window_state->IsMaximized()); |
| 537 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, | 533 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, |
| 538 ui::EF_IS_DOUBLE_CLICK); | 534 ui::EF_IS_DOUBLE_CLICK); |
| 539 EXPECT_FALSE(window_state->IsMaximized()); | 535 EXPECT_FALSE(window_state->IsMaximized()); |
| 540 } | 536 } |
| 541 | 537 |
| 542 } // namespace ash | 538 } // namespace ash |
| OLD | NEW |