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/wm/core/focus_controller.h" | 5 #include "ui/wm/core/focus_controller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "ui/aura/client/aura_constants.h" | 11 #include "ui/aura/client/aura_constants.h" |
11 #include "ui/aura/client/default_capture_client.h" | 12 #include "ui/aura/client/default_capture_client.h" |
12 #include "ui/aura/client/focus_change_observer.h" | 13 #include "ui/aura/client/focus_change_observer.h" |
13 #include "ui/aura/test/aura_test_base.h" | 14 #include "ui/aura/test/aura_test_base.h" |
14 #include "ui/aura/test/test_window_delegate.h" | 15 #include "ui/aura/test/test_window_delegate.h" |
15 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
18 #include "ui/aura/window_tracker.h" | 19 #include "ui/aura/window_tracker.h" |
19 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 virtual void ActivationRulesOverride() = 0; | 463 virtual void ActivationRulesOverride() = 0; |
463 virtual void ShiftFocusOnActivation() {} | 464 virtual void ShiftFocusOnActivation() {} |
464 virtual void ShiftFocusOnActivationDueToHide() {} | 465 virtual void ShiftFocusOnActivationDueToHide() {} |
465 virtual void NoShiftActiveOnActivation() {} | 466 virtual void NoShiftActiveOnActivation() {} |
466 virtual void FocusChangeDuringDrag() {} | 467 virtual void FocusChangeDuringDrag() {} |
467 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 468 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
468 virtual void DontPassDeletedWindow() {} | 469 virtual void DontPassDeletedWindow() {} |
469 virtual void StackWindowAtTopOnActivation() {} | 470 virtual void StackWindowAtTopOnActivation() {} |
470 | 471 |
471 private: | 472 private: |
472 scoped_ptr<FocusController> focus_controller_; | 473 std::unique_ptr<FocusController> focus_controller_; |
473 TestFocusRules* test_focus_rules_; | 474 TestFocusRules* test_focus_rules_; |
474 scoped_ptr<wm::WMState> wm_state_; | 475 std::unique_ptr<wm::WMState> wm_state_; |
475 | 476 |
476 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 477 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
477 }; | 478 }; |
478 | 479 |
479 // Test base for tests where focus is directly set to a target window. | 480 // Test base for tests where focus is directly set to a target window. |
480 class FocusControllerDirectTestBase : public FocusControllerTestBase { | 481 class FocusControllerDirectTestBase : public FocusControllerTestBase { |
481 protected: | 482 protected: |
482 FocusControllerDirectTestBase() {} | 483 FocusControllerDirectTestBase() {} |
483 | 484 |
484 // Different test types shift focus in different ways. | 485 // Different test types shift focus in different ways. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 EXPECT_EQ(2, GetFocusedWindowId()); | 686 EXPECT_EQ(2, GetFocusedWindowId()); |
686 ActivateWindowById(1); | 687 ActivateWindowById(1); |
687 EXPECT_EQ(1, GetFocusedWindowId()); | 688 EXPECT_EQ(1, GetFocusedWindowId()); |
688 | 689 |
689 ActivateWindowById(2); | 690 ActivateWindowById(2); |
690 | 691 |
691 aura::Window* target = root_window()->GetChildById(1); | 692 aura::Window* target = root_window()->GetChildById(1); |
692 aura::client::ActivationClient* client = | 693 aura::client::ActivationClient* client = |
693 aura::client::GetActivationClient(root_window()); | 694 aura::client::GetActivationClient(root_window()); |
694 | 695 |
695 scoped_ptr<FocusShiftingActivationObserver> observer( | 696 std::unique_ptr<FocusShiftingActivationObserver> observer( |
696 new FocusShiftingActivationObserver(target)); | 697 new FocusShiftingActivationObserver(target)); |
697 observer->set_shift_focus_to(target->GetChildById(11)); | 698 observer->set_shift_focus_to(target->GetChildById(11)); |
698 client->AddObserver(observer.get()); | 699 client->AddObserver(observer.get()); |
699 | 700 |
700 ActivateWindowById(1); | 701 ActivateWindowById(1); |
701 | 702 |
702 // w1's ActivationChangeObserver shifted focus to this child, pre-empting | 703 // w1's ActivationChangeObserver shifted focus to this child, pre-empting |
703 // FocusController's default setting. | 704 // FocusController's default setting. |
704 EXPECT_EQ(11, GetFocusedWindowId()); | 705 EXPECT_EQ(11, GetFocusedWindowId()); |
705 | 706 |
(...skipping 20 matching lines...) Expand all Loading... |
726 EXPECT_EQ(1, GetFocusedWindowId()); | 727 EXPECT_EQ(1, GetFocusedWindowId()); |
727 | 728 |
728 // Removes window 3 as candidate for next activatable window. | 729 // Removes window 3 as candidate for next activatable window. |
729 root_window()->GetChildById(3)->Hide(); | 730 root_window()->GetChildById(3)->Hide(); |
730 EXPECT_EQ(1, GetFocusedWindowId()); | 731 EXPECT_EQ(1, GetFocusedWindowId()); |
731 | 732 |
732 aura::Window* target = root_window()->GetChildById(2); | 733 aura::Window* target = root_window()->GetChildById(2); |
733 aura::client::ActivationClient* client = | 734 aura::client::ActivationClient* client = |
734 aura::client::GetActivationClient(root_window()); | 735 aura::client::GetActivationClient(root_window()); |
735 | 736 |
736 scoped_ptr<FocusShiftingActivationObserver> observer( | 737 std::unique_ptr<FocusShiftingActivationObserver> observer( |
737 new FocusShiftingActivationObserver(target)); | 738 new FocusShiftingActivationObserver(target)); |
738 observer->set_shift_focus_to(target->GetChildById(21)); | 739 observer->set_shift_focus_to(target->GetChildById(21)); |
739 client->AddObserver(observer.get()); | 740 client->AddObserver(observer.get()); |
740 | 741 |
741 // Hide the active window. | 742 // Hide the active window. |
742 root_window()->GetChildById(1)->Hide(); | 743 root_window()->GetChildById(1)->Hide(); |
743 | 744 |
744 EXPECT_EQ(21, GetFocusedWindowId()); | 745 EXPECT_EQ(21, GetFocusedWindowId()); |
745 | 746 |
746 client->RemoveObserver(observer.get()); | 747 client->RemoveObserver(observer.get()); |
747 } | 748 } |
748 void NoShiftActiveOnActivation() override { | 749 void NoShiftActiveOnActivation() override { |
749 // When a window is activated, we need to prevent any change to activation | 750 // When a window is activated, we need to prevent any change to activation |
750 // from being made in response to an activation change notification. | 751 // from being made in response to an activation change notification. |
751 } | 752 } |
752 | 753 |
753 void FocusChangeDuringDrag() override { | 754 void FocusChangeDuringDrag() override { |
754 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( | 755 std::unique_ptr<aura::client::DefaultCaptureClient> capture_client( |
755 new aura::client::DefaultCaptureClient(root_window())); | 756 new aura::client::DefaultCaptureClient(root_window())); |
756 // Activating an inactive window during drag should activate the window. | 757 // Activating an inactive window during drag should activate the window. |
757 // This emulates the behavior of tab dragging which is merged into the | 758 // This emulates the behavior of tab dragging which is merged into the |
758 // window below. | 759 // window below. |
759 ActivateWindowById(1); | 760 ActivateWindowById(1); |
760 | 761 |
761 EXPECT_EQ(1, GetActiveWindowId()); | 762 EXPECT_EQ(1, GetActiveWindowId()); |
762 EXPECT_EQ(1, GetFocusedWindowId()); | 763 EXPECT_EQ(1, GetFocusedWindowId()); |
763 | 764 |
764 aura::Window* w2 = root_window()->GetChildById(2); | 765 aura::Window* w2 = root_window()->GetChildById(2); |
(...skipping 11 matching lines...) Expand all Loading... |
776 aura::client::GetActivationClient(root_window())->ActivateWindow(w1); | 777 aura::client::GetActivationClient(root_window())->ActivateWindow(w1); |
777 EXPECT_EQ(1, GetActiveWindowId()); | 778 EXPECT_EQ(1, GetActiveWindowId()); |
778 EXPECT_EQ(1, GetFocusedWindowId()); | 779 EXPECT_EQ(1, GetFocusedWindowId()); |
779 | 780 |
780 generator.ReleaseLeftButton(); | 781 generator.ReleaseLeftButton(); |
781 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); | 782 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w1); |
782 } | 783 } |
783 | 784 |
784 // Verifies focus change is honored while capture held. | 785 // Verifies focus change is honored while capture held. |
785 void ChangeFocusWhenNothingFocusedAndCaptured() override { | 786 void ChangeFocusWhenNothingFocusedAndCaptured() override { |
786 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( | 787 std::unique_ptr<aura::client::DefaultCaptureClient> capture_client( |
787 new aura::client::DefaultCaptureClient(root_window())); | 788 new aura::client::DefaultCaptureClient(root_window())); |
788 aura::Window* w1 = root_window()->GetChildById(1); | 789 aura::Window* w1 = root_window()->GetChildById(1); |
789 aura::client::GetCaptureClient(root_window())->SetCapture(w1); | 790 aura::client::GetCaptureClient(root_window())->SetCapture(w1); |
790 | 791 |
791 EXPECT_EQ(-1, GetActiveWindowId()); | 792 EXPECT_EQ(-1, GetActiveWindowId()); |
792 EXPECT_EQ(-1, GetFocusedWindowId()); | 793 EXPECT_EQ(-1, GetFocusedWindowId()); |
793 | 794 |
794 FocusWindowById(1); | 795 FocusWindowById(1); |
795 | 796 |
796 EXPECT_EQ(1, GetActiveWindowId()); | 797 EXPECT_EQ(1, GetActiveWindowId()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 | 836 |
836 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); | 837 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); |
837 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); | 838 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); |
838 } | 839 } |
839 } | 840 } |
840 | 841 |
841 // Test that the activation of the current active window will bring the window | 842 // Test that the activation of the current active window will bring the window |
842 // to the top of the window stack. | 843 // to the top of the window stack. |
843 void StackWindowAtTopOnActivation() override { | 844 void StackWindowAtTopOnActivation() override { |
844 // Create a window, show it and then activate it. | 845 // Create a window, show it and then activate it. |
845 scoped_ptr<aura::Window> window1 = | 846 std::unique_ptr<aura::Window> window1 = |
846 make_scoped_ptr(new aura::Window(nullptr)); | 847 base::WrapUnique(new aura::Window(nullptr)); |
847 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 848 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
848 window1->Init(ui::LAYER_TEXTURED); | 849 window1->Init(ui::LAYER_TEXTURED); |
849 root_window()->AddChild(window1.get()); | 850 root_window()->AddChild(window1.get()); |
850 window1->Show(); | 851 window1->Show(); |
851 ActivateWindow(window1.get()); | 852 ActivateWindow(window1.get()); |
852 EXPECT_EQ(window1.get(), root_window()->children().back()); | 853 EXPECT_EQ(window1.get(), root_window()->children().back()); |
853 EXPECT_EQ(window1.get(), GetActiveWindow()); | 854 EXPECT_EQ(window1.get(), GetActiveWindow()); |
854 | 855 |
855 // Create another window, show it but don't activate it. The window is not | 856 // Create another window, show it but don't activate it. The window is not |
856 // the active window but is placed on top of window stack. | 857 // the active window but is placed on top of window stack. |
857 scoped_ptr<aura::Window> window2 = | 858 std::unique_ptr<aura::Window> window2 = |
858 make_scoped_ptr(new aura::Window(nullptr)); | 859 base::WrapUnique(new aura::Window(nullptr)); |
859 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 860 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
860 window2->Init(ui::LAYER_TEXTURED); | 861 window2->Init(ui::LAYER_TEXTURED); |
861 root_window()->AddChild(window2.get()); | 862 root_window()->AddChild(window2.get()); |
862 window2->Show(); | 863 window2->Show(); |
863 EXPECT_EQ(window2.get(), root_window()->children().back()); | 864 EXPECT_EQ(window2.get(), root_window()->children().back()); |
864 EXPECT_EQ(window1.get(), GetActiveWindow()); | 865 EXPECT_EQ(window1.get(), GetActiveWindow()); |
865 | 866 |
866 // Try to reactivate the active window. It should bring the active window | 867 // Try to reactivate the active window. It should bring the active window |
867 // to the top of the window stack. | 868 // to the top of the window stack. |
868 ActivateWindow(window1.get()); | 869 ActivateWindow(window1.get()); |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 aura::Window* disposition_window = GetDispositionWindow(window); | 1201 aura::Window* disposition_window = GetDispositionWindow(window); |
1201 disposition_window->parent()->RemoveChild(disposition_window); | 1202 disposition_window->parent()->RemoveChild(disposition_window); |
1202 window_owner_.reset(disposition_window); | 1203 window_owner_.reset(disposition_window); |
1203 } | 1204 } |
1204 void TearDown() override { | 1205 void TearDown() override { |
1205 window_owner_.reset(); | 1206 window_owner_.reset(); |
1206 FocusControllerImplicitTestBase::TearDown(); | 1207 FocusControllerImplicitTestBase::TearDown(); |
1207 } | 1208 } |
1208 | 1209 |
1209 private: | 1210 private: |
1210 scoped_ptr<aura::Window> window_owner_; | 1211 std::unique_ptr<aura::Window> window_owner_; |
1211 | 1212 |
1212 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest); | 1213 DISALLOW_COPY_AND_ASSIGN(FocusControllerRemovalTest); |
1213 }; | 1214 }; |
1214 | 1215 |
1215 // Focus and Activation changes in response to window parent removal. | 1216 // Focus and Activation changes in response to window parent removal. |
1216 class FocusControllerParentRemovalTest : public FocusControllerRemovalTest { | 1217 class FocusControllerParentRemovalTest : public FocusControllerRemovalTest { |
1217 public: | 1218 public: |
1218 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {} | 1219 FocusControllerParentRemovalTest() : FocusControllerRemovalTest(true) {} |
1219 | 1220 |
1220 private: | 1221 private: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation); | 1321 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, StackWindowAtTopOnActivation); |
1321 | 1322 |
1322 // See description above TransientChildWindowActivationTest() for details. | 1323 // See description above TransientChildWindowActivationTest() for details. |
1323 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, | 1324 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, |
1324 TransientChildWindowActivationTest); | 1325 TransientChildWindowActivationTest); |
1325 | 1326 |
1326 // If a mouse event was handled, it should not activate a window. | 1327 // If a mouse event was handled, it should not activate a window. |
1327 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1328 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
1328 | 1329 |
1329 } // namespace wm | 1330 } // namespace wm |
OLD | NEW |