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() {} | |
309 | 308 |
310 private: | 309 private: |
311 scoped_ptr<FocusController> focus_controller_; | 310 scoped_ptr<FocusController> focus_controller_; |
312 TestFocusRules* test_focus_rules_; | 311 TestFocusRules* test_focus_rules_; |
313 | 312 |
314 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 313 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
315 }; | 314 }; |
316 | 315 |
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 | |
349 // Test base for tests where focus is directly set to a target window. | 316 // Test base for tests where focus is directly set to a target window. |
350 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 317 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
351 protected: | 318 protected: |
352 FocusControllerDirectTestBase() {} | 319 FocusControllerDirectTestBase() {} |
353 | 320 |
354 // Different test types shift focus in different ways. | 321 // Different test types shift focus in different ways. |
355 virtual void FocusWindowDirect(aura::Window* window) = 0; | 322 virtual void FocusWindowDirect(aura::Window* window) = 0; |
356 virtual void ActivateWindowDirect(aura::Window* window) = 0; | 323 virtual void ActivateWindowDirect(aura::Window* window) = 0; |
357 virtual void DeactivateWindowDirect(aura::Window* window) = 0; | 324 virtual void DeactivateWindowDirect(aura::Window* window) = 0; |
358 | 325 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 EXPECT_EQ(-1, GetFocusedWindowId()); | 611 EXPECT_EQ(-1, GetFocusedWindowId()); |
645 | 612 |
646 FocusWindowById(1); | 613 FocusWindowById(1); |
647 | 614 |
648 EXPECT_EQ(1, GetActiveWindowId()); | 615 EXPECT_EQ(1, GetActiveWindowId()); |
649 EXPECT_EQ(1, GetFocusedWindowId()); | 616 EXPECT_EQ(1, GetFocusedWindowId()); |
650 | 617 |
651 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); | 618 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); |
652 } | 619 } |
653 | 620 |
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 | |
673 private: | 621 private: |
674 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 622 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
675 }; | 623 }; |
676 | 624 |
677 // Focus and Activation changes via aura::client::ActivationClient API. | 625 // Focus and Activation changes via aura::client::ActivationClient API. |
678 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 626 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
679 public: | 627 public: |
680 FocusControllerApiTest() {} | 628 FocusControllerApiTest() {} |
681 | 629 |
682 private: | 630 private: |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); | 1012 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); |
1065 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); | 1013 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); |
1066 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 1014 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
1067 | 1015 |
1068 // Clicking on a window which has capture should not result in a focus change. | 1016 // Clicking on a window which has capture should not result in a focus change. |
1069 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1017 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
1070 | 1018 |
1071 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1019 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
1072 ChangeFocusWhenNothingFocusedAndCaptured); | 1020 ChangeFocusWhenNothingFocusedAndCaptured); |
1073 | 1021 |
1074 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ChangeFocusWithinActivate); | |
1075 | |
1076 } // namespace corewm | 1022 } // namespace corewm |
1077 } // namespace views | 1023 } // namespace views |
OLD | NEW |