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 "ui/views/corewm/focus_controller.h" | 5 #include "ui/views/corewm/focus_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "ui/aura/client/activation_change_observer.h" | 9 #include "ui/aura/client/activation_change_observer.h" |
10 #include "ui/aura/client/activation_client.h" | 10 #include "ui/aura/client/activation_client.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 virtual void ShiftFocusWithinActiveWindow() {} | 298 virtual void ShiftFocusWithinActiveWindow() {} |
299 virtual void ShiftFocusToChildOfInactiveWindow() {} | 299 virtual void ShiftFocusToChildOfInactiveWindow() {} |
300 virtual void ShiftFocusToParentOfFocusedWindow() {} | 300 virtual void ShiftFocusToParentOfFocusedWindow() {} |
301 virtual void FocusRulesOverride() = 0; | 301 virtual void FocusRulesOverride() = 0; |
302 virtual void ActivationRulesOverride() = 0; | 302 virtual void ActivationRulesOverride() = 0; |
303 virtual void ShiftFocusOnActivation() {} | 303 virtual void ShiftFocusOnActivation() {} |
304 virtual void ShiftFocusOnActivationDueToHide() {} | 304 virtual void ShiftFocusOnActivationDueToHide() {} |
305 virtual void NoShiftActiveOnActivation() {} | 305 virtual void NoShiftActiveOnActivation() {} |
306 virtual void NoFocusChangeOnClickOnCaptureWindow() {} | 306 virtual void NoFocusChangeOnClickOnCaptureWindow() {} |
307 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 307 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 308 virtual void ChangeFocusWithinActivate() {} |
308 | 309 |
309 private: | 310 private: |
310 scoped_ptr<FocusController> focus_controller_; | 311 scoped_ptr<FocusController> focus_controller_; |
311 TestFocusRules* test_focus_rules_; | 312 TestFocusRules* test_focus_rules_; |
312 | 313 |
313 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 314 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
314 }; | 315 }; |
315 | 316 |
| 317 // ActivationChangeObserver that attempts to focus another window on an |
| 318 // activation change. |
| 319 class TestActivationChangeObserver |
| 320 : public aura::client::ActivationChangeObserver { |
| 321 public: |
| 322 TestActivationChangeObserver() : gained_active_(NULL), to_focus_(NULL) {} |
| 323 virtual ~TestActivationChangeObserver() {} |
| 324 |
| 325 // Sets the window to focus (|to_focus|) when a window is made active. |
| 326 void SetWindows(aura::Window* gained_active, aura::Window* to_focus) { |
| 327 gained_active_ = gained_active; |
| 328 to_focus_ = to_focus; |
| 329 } |
| 330 |
| 331 // aura::client::ActivationChangeObserver: |
| 332 virtual void OnWindowActivated(aura::Window* gained_active, |
| 333 aura::Window* lost_active) OVERRIDE { |
| 334 if (gained_active == gained_active_ && to_focus_) { |
| 335 aura::Window* to_focus = to_focus_; |
| 336 to_focus_ = NULL; |
| 337 gained_active_ = NULL; |
| 338 to_focus->Focus(); |
| 339 } |
| 340 } |
| 341 |
| 342 private: |
| 343 aura::Window* gained_active_; |
| 344 aura::Window* to_focus_; |
| 345 |
| 346 DISALLOW_COPY_AND_ASSIGN(TestActivationChangeObserver); |
| 347 }; |
| 348 |
316 // Test base for tests where focus is directly set to a target window. | 349 // Test base for tests where focus is directly set to a target window. |
317 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 350 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
318 protected: | 351 protected: |
319 FocusControllerDirectTestBase() {} | 352 FocusControllerDirectTestBase() {} |
320 | 353 |
321 // Different test types shift focus in different ways. | 354 // Different test types shift focus in different ways. |
322 virtual void FocusWindowDirect(aura::Window* window) = 0; | 355 virtual void FocusWindowDirect(aura::Window* window) = 0; |
323 virtual void ActivateWindowDirect(aura::Window* window) = 0; | 356 virtual void ActivateWindowDirect(aura::Window* window) = 0; |
324 virtual void DeactivateWindowDirect(aura::Window* window) = 0; | 357 virtual void DeactivateWindowDirect(aura::Window* window) = 0; |
325 | 358 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 EXPECT_EQ(-1, GetFocusedWindowId()); | 644 EXPECT_EQ(-1, GetFocusedWindowId()); |
612 | 645 |
613 FocusWindowById(1); | 646 FocusWindowById(1); |
614 | 647 |
615 EXPECT_EQ(1, GetActiveWindowId()); | 648 EXPECT_EQ(1, GetActiveWindowId()); |
616 EXPECT_EQ(1, GetFocusedWindowId()); | 649 EXPECT_EQ(1, GetFocusedWindowId()); |
617 | 650 |
618 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); | 651 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); |
619 } | 652 } |
620 | 653 |
| 654 // Verifies a request to focus a window is honored if the |
| 655 // ActivationChangeObserver changes focus. |
| 656 virtual void ChangeFocusWithinActivate() OVERRIDE { |
| 657 TestActivationChangeObserver test_observer; |
| 658 aura::client::GetActivationClient(root_window())-> |
| 659 AddObserver(&test_observer); |
| 660 // Set things such that when |w1| is made active a request is made to focus |
| 661 // |w11|. |
| 662 test_observer.SetWindows(root_window()->GetChildById(1), |
| 663 root_window()->GetChildById(11)); |
| 664 // Attempt to activate |w12|. This should activate |w1| (its the child of |
| 665 // the root |
| 666 ActivateWindowById(12); |
| 667 EXPECT_EQ(1, GetActiveWindowId()); |
| 668 EXPECT_EQ(12, GetFocusedWindowId()); |
| 669 aura::client::GetActivationClient(root_window())->RemoveObserver( |
| 670 &test_observer); |
| 671 } |
| 672 |
621 private: | 673 private: |
622 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 674 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
623 }; | 675 }; |
624 | 676 |
625 // Focus and Activation changes via aura::client::ActivationClient API. | 677 // Focus and Activation changes via aura::client::ActivationClient API. |
626 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 678 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
627 public: | 679 public: |
628 FocusControllerApiTest() {} | 680 FocusControllerApiTest() {} |
629 | 681 |
630 private: | 682 private: |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); | 1064 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); |
1013 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); | 1065 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); |
1014 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 1066 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
1015 | 1067 |
1016 // Clicking on a window which has capture should not result in a focus change. | 1068 // Clicking on a window which has capture should not result in a focus change. |
1017 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1069 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
1018 | 1070 |
1019 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1071 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
1020 ChangeFocusWhenNothingFocusedAndCaptured); | 1072 ChangeFocusWhenNothingFocusedAndCaptured); |
1021 | 1073 |
| 1074 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ChangeFocusWithinActivate); |
| 1075 |
1022 } // namespace corewm | 1076 } // namespace corewm |
1023 } // namespace views | 1077 } // namespace views |
OLD | NEW |