| 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 "services/window_manager/focus_controller.h" | 5 #include "services/window_manager/focus_controller.h" |
| 6 | 6 |
| 7 #include "mojo/converters/geometry/geometry_type_converters.h" | 7 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 8 #include "services/window_manager/basic_focus_rules.h" | 8 #include "services/window_manager/basic_focus_rules.h" |
| 9 #include "services/window_manager/capture_controller.h" |
| 9 #include "services/window_manager/focus_controller_observer.h" | 10 #include "services/window_manager/focus_controller_observer.h" |
| 10 #include "services/window_manager/view_event_dispatcher.h" | 11 #include "services/window_manager/view_event_dispatcher.h" |
| 11 #include "services/window_manager/view_targeter.h" | 12 #include "services/window_manager/view_targeter.h" |
| 12 #include "services/window_manager/window_manager_test_util.h" | 13 #include "services/window_manager/window_manager_test_util.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/events/test/event_generator.h" | 15 #include "ui/events/test/event_generator.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
| 16 | 17 |
| 17 using mojo::View; | 18 using mojo::View; |
| 18 | 19 |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 v211(TestView::Build(211, gfx::Rect(1, 1, 5, 5), v21)), | 341 v211(TestView::Build(211, gfx::Rect(1, 1, 5, 5), v21)), |
| 341 v3(TestView::Build(3, gfx::Rect(125, 125, 50, 50), root_view())) {} | 342 v3(TestView::Build(3, gfx::Rect(125, 125, 50, 50), root_view())) {} |
| 342 | 343 |
| 343 // Overridden from testing::Test: | 344 // Overridden from testing::Test: |
| 344 void SetUp() override { | 345 void SetUp() override { |
| 345 testing::Test::SetUp(); | 346 testing::Test::SetUp(); |
| 346 | 347 |
| 347 test_focus_rules_ = new TestFocusRules(root_view()); | 348 test_focus_rules_ = new TestFocusRules(root_view()); |
| 348 focus_controller_.reset( | 349 focus_controller_.reset( |
| 349 new FocusController(scoped_ptr<FocusRules>(test_focus_rules_))); | 350 new FocusController(scoped_ptr<FocusRules>(test_focus_rules_))); |
| 351 SetFocusController(root_view(), focus_controller_.get()); |
| 352 |
| 353 capture_controller_.reset(new CaptureController); |
| 354 SetCaptureController(root_view(), capture_controller_.get()); |
| 350 | 355 |
| 351 ViewTarget* root_target = root_view_->target(); | 356 ViewTarget* root_target = root_view_->target(); |
| 352 root_target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter())); | 357 root_target->SetEventTargeter(scoped_ptr<ViewTargeter>(new ViewTargeter())); |
| 353 view_event_dispatcher_.reset(new ViewEventDispatcher()); | 358 view_event_dispatcher_.reset(new ViewEventDispatcher()); |
| 354 view_event_dispatcher_->SetRootViewTarget(root_target); | 359 view_event_dispatcher_->SetRootViewTarget(root_target); |
| 355 | 360 |
| 356 GetRootViewTarget()->AddPreTargetHandler(focus_controller_.get()); | 361 GetRootViewTarget()->AddPreTargetHandler(focus_controller_.get()); |
| 357 } | 362 } |
| 358 | 363 |
| 359 void TearDown() override { | 364 void TearDown() override { |
| 360 GetRootViewTarget()->RemovePreTargetHandler(focus_controller_.get()); | 365 GetRootViewTarget()->RemovePreTargetHandler(focus_controller_.get()); |
| 361 view_event_dispatcher_.reset(); | 366 view_event_dispatcher_.reset(); |
| 362 | 367 |
| 363 root_view_->Destroy(); | 368 root_view_->Destroy(); |
| 364 | 369 |
| 370 capture_controller_.reset(); |
| 365 test_focus_rules_ = nullptr; // Owned by FocusController. | 371 test_focus_rules_ = nullptr; // Owned by FocusController. |
| 366 focus_controller_.reset(); | 372 focus_controller_.reset(); |
| 367 | 373 |
| 368 testing::Test::TearDown(); | 374 testing::Test::TearDown(); |
| 369 } | 375 } |
| 370 | 376 |
| 371 void FocusView(View* view) { focus_controller_->FocusView(view); } | 377 void FocusView(View* view) { focus_controller_->FocusView(view); } |
| 372 View* GetFocusedView() { return focus_controller_->GetFocusedView(); } | 378 View* GetFocusedView() { return focus_controller_->GetFocusedView(); } |
| 373 int GetFocusedViewId() { | 379 int GetFocusedViewId() { |
| 374 View* focused_view = GetFocusedView(); | 380 View* focused_view = GetFocusedView(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 403 CHECK(!details.dispatcher_destroyed); | 409 CHECK(!details.dispatcher_destroyed); |
| 404 } | 410 } |
| 405 | 411 |
| 406 ViewTarget* GetRootViewTarget() { | 412 ViewTarget* GetRootViewTarget() { |
| 407 return ViewTarget::TargetFromView(root_view()); | 413 return ViewTarget::TargetFromView(root_view()); |
| 408 } | 414 } |
| 409 | 415 |
| 410 View* root_view() { return root_view_; } | 416 View* root_view() { return root_view_; } |
| 411 TestFocusRules* test_focus_rules() { return test_focus_rules_; } | 417 TestFocusRules* test_focus_rules() { return test_focus_rules_; } |
| 412 FocusController* focus_controller() { return focus_controller_.get(); } | 418 FocusController* focus_controller() { return focus_controller_.get(); } |
| 419 CaptureController* capture_controller() { return capture_controller_.get(); } |
| 413 | 420 |
| 414 // Test functions. | 421 // Test functions. |
| 415 virtual void BasicFocus() = 0; | 422 virtual void BasicFocus() = 0; |
| 416 virtual void BasicActivation() = 0; | 423 virtual void BasicActivation() = 0; |
| 417 virtual void FocusEvents() = 0; | 424 virtual void FocusEvents() = 0; |
| 418 virtual void DuplicateFocusEvents() {} | 425 virtual void DuplicateFocusEvents() {} |
| 419 virtual void ActivationEvents() = 0; | 426 virtual void ActivationEvents() = 0; |
| 420 virtual void ReactivationEvents() {} | 427 virtual void ReactivationEvents() {} |
| 421 virtual void DuplicateActivationEvents() {} | 428 virtual void DuplicateActivationEvents() {} |
| 422 virtual void ShiftFocusWithinActiveView() {} | 429 virtual void ShiftFocusWithinActiveView() {} |
| 423 virtual void ShiftFocusToChildOfInactiveView() {} | 430 virtual void ShiftFocusToChildOfInactiveView() {} |
| 424 virtual void ShiftFocusToParentOfFocusedView() {} | 431 virtual void ShiftFocusToParentOfFocusedView() {} |
| 425 virtual void FocusRulesOverride() = 0; | 432 virtual void FocusRulesOverride() = 0; |
| 426 virtual void ActivationRulesOverride() = 0; | 433 virtual void ActivationRulesOverride() = 0; |
| 427 virtual void ShiftFocusOnActivation() {} | 434 virtual void ShiftFocusOnActivation() {} |
| 428 virtual void ShiftFocusOnActivationDueToHide() {} | 435 virtual void ShiftFocusOnActivationDueToHide() {} |
| 429 virtual void NoShiftActiveOnActivation() {} | 436 virtual void NoShiftActiveOnActivation() {} |
| 430 // TODO(erg): void NoFocusChangeOnClickOnCaptureWindow() once we have a | 437 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 431 // system of capture. | |
| 432 // TODO(erg): Also, void ChangeFocusWhenNothingFocusedAndCaptured(). | |
| 433 virtual void DontPassDestroyedView() {} | 438 virtual void DontPassDestroyedView() {} |
| 434 // TODO(erg): Also, void FocusedTextInputClient() once we build the IME. | 439 // TODO(erg): Also, void FocusedTextInputClient() once we build the IME. |
| 435 | 440 |
| 436 private: | 441 private: |
| 437 TestView* root_view_; | 442 TestView* root_view_; |
| 438 scoped_ptr<FocusController> focus_controller_; | 443 scoped_ptr<FocusController> focus_controller_; |
| 439 TestFocusRules* test_focus_rules_; | 444 TestFocusRules* test_focus_rules_; |
| 445 scoped_ptr<CaptureController> capture_controller_; |
| 440 // TODO(erg): The aura version of this class also keeps track of WMState. Do | 446 // TODO(erg): The aura version of this class also keeps track of WMState. Do |
| 441 // we need something analogous here? | 447 // we need something analogous here? |
| 442 | 448 |
| 443 scoped_ptr<ViewEventDispatcher> view_event_dispatcher_; | 449 scoped_ptr<ViewEventDispatcher> view_event_dispatcher_; |
| 444 | 450 |
| 445 TestView* v1; | 451 TestView* v1; |
| 446 TestView* v11; | 452 TestView* v11; |
| 447 TestView* v12; | 453 TestView* v12; |
| 448 TestView* v2; | 454 TestView* v2; |
| 449 TestView* v21; | 455 TestView* v21; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 | 722 |
| 717 EXPECT_EQ(21, GetFocusedViewId()); | 723 EXPECT_EQ(21, GetFocusedViewId()); |
| 718 | 724 |
| 719 focus_controller()->RemoveObserver(observer.get()); | 725 focus_controller()->RemoveObserver(observer.get()); |
| 720 } | 726 } |
| 721 void NoShiftActiveOnActivation() override { | 727 void NoShiftActiveOnActivation() override { |
| 722 // When a view is activated, we need to prevent any change to activation | 728 // When a view is activated, we need to prevent any change to activation |
| 723 // from being made in response to an activation change notification. | 729 // from being made in response to an activation change notification. |
| 724 } | 730 } |
| 725 | 731 |
| 726 // TODO(erg): Port the capture tests here, once we have a capture mechanism. | 732 // Verifies focus change is honored while capture held. |
| 733 void ChangeFocusWhenNothingFocusedAndCaptured() override { |
| 734 View* v1 = root_view()->GetChildById(1); |
| 735 capture_controller()->SetCapture(v1); |
| 736 |
| 737 EXPECT_EQ(-1, GetActiveViewId()); |
| 738 EXPECT_EQ(-1, GetFocusedViewId()); |
| 739 |
| 740 FocusViewById(1); |
| 741 |
| 742 EXPECT_EQ(1, GetActiveViewId()); |
| 743 EXPECT_EQ(1, GetFocusedViewId()); |
| 744 |
| 745 capture_controller()->ReleaseCapture(v1); |
| 746 } |
| 727 | 747 |
| 728 // Verifies if a view that loses activation or focus is destroyed during | 748 // Verifies if a view that loses activation or focus is destroyed during |
| 729 // observer notification we don't pass the destroyed view to other observers. | 749 // observer notification we don't pass the destroyed view to other observers. |
| 730 void DontPassDestroyedView() override { | 750 void DontPassDestroyedView() override { |
| 731 FocusViewById(1); | 751 FocusViewById(1); |
| 732 | 752 |
| 733 EXPECT_EQ(1, GetActiveViewId()); | 753 EXPECT_EQ(1, GetActiveViewId()); |
| 734 EXPECT_EQ(1, GetFocusedViewId()); | 754 EXPECT_EQ(1, GetFocusedViewId()); |
| 735 | 755 |
| 736 { | 756 { |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1135 |
| 1116 // - Verifies that FocusRules determine what can be activated. | 1136 // - Verifies that FocusRules determine what can be activated. |
| 1117 TARGET_FOCUS_TESTS(ActivationRulesOverride); | 1137 TARGET_FOCUS_TESTS(ActivationRulesOverride); |
| 1118 | 1138 |
| 1119 // - Verifies that attempts to change focus or activation from a focus or | 1139 // - Verifies that attempts to change focus or activation from a focus or |
| 1120 // activation change observer are ignored. | 1140 // activation change observer are ignored. |
| 1121 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); | 1141 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); |
| 1122 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); | 1142 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); |
| 1123 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 1143 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
| 1124 | 1144 |
| 1125 // TODO(erg): Add the capture tests here. | 1145 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1146 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1126 | 1147 |
| 1127 // See description above DontPassDestroyedView() for details. | 1148 // See description above DontPassDestroyedView() for details. |
| 1128 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDestroyedView); | 1149 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDestroyedView); |
| 1129 | 1150 |
| 1130 // TODO(erg): Add the TextInputClient tests here. | 1151 // TODO(erg): Add the TextInputClient tests here. |
| 1131 | 1152 |
| 1132 // If a mouse event was handled, it should not activate a view. | 1153 // If a mouse event was handled, it should not activate a view. |
| 1133 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1154 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1134 | 1155 |
| 1135 } // namespace window_manager | 1156 } // namespace window_manager |
| OLD | NEW |