| 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 "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
| 10 #include "ui/aura/client/default_capture_client.h" | 10 #include "ui/aura/client/default_capture_client.h" |
| 11 #include "ui/aura/client/focus_change_observer.h" | 11 #include "ui/aura/client/focus_change_observer.h" |
| 12 #include "ui/aura/test/aura_test_base.h" | 12 #include "ui/aura/test/aura_test_base.h" |
| 13 #include "ui/aura/test/event_generator.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 17 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
| 18 #include "ui/base/ime/dummy_text_input_client.h" | 19 #include "ui/base/ime/dummy_text_input_client.h" |
| 19 #include "ui/base/ime/text_input_focus_manager.h" | 20 #include "ui/base/ime/text_input_focus_manager.h" |
| 20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 21 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/event_handler.h" | 23 #include "ui/events/event_handler.h" |
| 23 #include "ui/events/test/event_generator.h" | |
| 24 #include "ui/wm/core/base_focus_rules.h" | 24 #include "ui/wm/core/base_focus_rules.h" |
| 25 #include "ui/wm/core/wm_state.h" | 25 #include "ui/wm/core/wm_state.h" |
| 26 #include "ui/wm/public/activation_change_observer.h" | 26 #include "ui/wm/public/activation_change_observer.h" |
| 27 #include "ui/wm/public/activation_client.h" | 27 #include "ui/wm/public/activation_client.h" |
| 28 | 28 |
| 29 namespace wm { | 29 namespace wm { |
| 30 | 30 |
| 31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 31 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
| 32 public aura::client::FocusChangeObserver { | 32 public aura::client::FocusChangeObserver { |
| 33 public: | 33 public: |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 new aura::client::DefaultCaptureClient(root_window())); | 765 new aura::client::DefaultCaptureClient(root_window())); |
| 766 // Clicking on a window which has capture should not cause a focus change | 766 // Clicking on a window which has capture should not cause a focus change |
| 767 // to the window. This test verifies whether that is indeed the case. | 767 // to the window. This test verifies whether that is indeed the case. |
| 768 ActivateWindowById(1); | 768 ActivateWindowById(1); |
| 769 | 769 |
| 770 EXPECT_EQ(1, GetActiveWindowId()); | 770 EXPECT_EQ(1, GetActiveWindowId()); |
| 771 EXPECT_EQ(1, GetFocusedWindowId()); | 771 EXPECT_EQ(1, GetFocusedWindowId()); |
| 772 | 772 |
| 773 aura::Window* w2 = root_window()->GetChildById(2); | 773 aura::Window* w2 = root_window()->GetChildById(2); |
| 774 aura::client::GetCaptureClient(root_window())->SetCapture(w2); | 774 aura::client::GetCaptureClient(root_window())->SetCapture(w2); |
| 775 ui::test::EventGenerator generator(root_window(), w2); | 775 aura::test::EventGenerator generator(root_window(), w2); |
| 776 generator.ClickLeftButton(); | 776 generator.ClickLeftButton(); |
| 777 | 777 |
| 778 EXPECT_EQ(1, GetActiveWindowId()); | 778 EXPECT_EQ(1, GetActiveWindowId()); |
| 779 EXPECT_EQ(1, GetFocusedWindowId()); | 779 EXPECT_EQ(1, GetFocusedWindowId()); |
| 780 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); | 780 aura::client::GetCaptureClient(root_window())->ReleaseCapture(w2); |
| 781 } | 781 } |
| 782 | 782 |
| 783 // Verifies focus change is honored while capture held. | 783 // Verifies focus change is honored while capture held. |
| 784 virtual void ChangeFocusWhenNothingFocusedAndCaptured() OVERRIDE { | 784 virtual void ChangeFocusWhenNothingFocusedAndCaptured() OVERRIDE { |
| 785 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( | 785 scoped_ptr<aura::client::DefaultCaptureClient> capture_client( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 public: | 902 public: |
| 903 FocusControllerMouseEventTest() {} | 903 FocusControllerMouseEventTest() {} |
| 904 | 904 |
| 905 // Tests that a handled mouse or gesture event does not trigger a window | 905 // Tests that a handled mouse or gesture event does not trigger a window |
| 906 // activation. | 906 // activation. |
| 907 void IgnoreHandledEvent() { | 907 void IgnoreHandledEvent() { |
| 908 EXPECT_EQ(NULL, GetActiveWindow()); | 908 EXPECT_EQ(NULL, GetActiveWindow()); |
| 909 aura::Window* w1 = root_window()->GetChildById(1); | 909 aura::Window* w1 = root_window()->GetChildById(1); |
| 910 SimpleEventHandler handler; | 910 SimpleEventHandler handler; |
| 911 root_window()->PrependPreTargetHandler(&handler); | 911 root_window()->PrependPreTargetHandler(&handler); |
| 912 ui::test::EventGenerator generator(root_window(), w1); | 912 aura::test::EventGenerator generator(root_window(), w1); |
| 913 generator.ClickLeftButton(); | 913 generator.ClickLeftButton(); |
| 914 EXPECT_EQ(NULL, GetActiveWindow()); | 914 EXPECT_EQ(NULL, GetActiveWindow()); |
| 915 generator.GestureTapAt(w1->bounds().CenterPoint()); | 915 generator.GestureTapAt(w1->bounds().CenterPoint()); |
| 916 EXPECT_EQ(NULL, GetActiveWindow()); | 916 EXPECT_EQ(NULL, GetActiveWindow()); |
| 917 root_window()->RemovePreTargetHandler(&handler); | 917 root_window()->RemovePreTargetHandler(&handler); |
| 918 generator.ClickLeftButton(); | 918 generator.ClickLeftButton(); |
| 919 EXPECT_EQ(1, GetActiveWindowId()); | 919 EXPECT_EQ(1, GetActiveWindowId()); |
| 920 } | 920 } |
| 921 | 921 |
| 922 private: | 922 private: |
| 923 // Overridden from FocusControllerTestBase: | 923 // Overridden from FocusControllerTestBase: |
| 924 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { | 924 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { |
| 925 ui::test::EventGenerator generator(root_window(), window); | 925 aura::test::EventGenerator generator(root_window(), window); |
| 926 generator.ClickLeftButton(); | 926 generator.ClickLeftButton(); |
| 927 } | 927 } |
| 928 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { | 928 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { |
| 929 ui::test::EventGenerator generator(root_window(), window); | 929 aura::test::EventGenerator generator(root_window(), window); |
| 930 generator.ClickLeftButton(); | 930 generator.ClickLeftButton(); |
| 931 } | 931 } |
| 932 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { | 932 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { |
| 933 aura::Window* next_activatable = | 933 aura::Window* next_activatable = |
| 934 test_focus_rules()->GetNextActivatableWindow(window); | 934 test_focus_rules()->GetNextActivatableWindow(window); |
| 935 ui::test::EventGenerator generator(root_window(), next_activatable); | 935 aura::test::EventGenerator generator(root_window(), next_activatable); |
| 936 generator.ClickLeftButton(); | 936 generator.ClickLeftButton(); |
| 937 } | 937 } |
| 938 virtual bool IsInputEvent() OVERRIDE { return true; } | 938 virtual bool IsInputEvent() OVERRIDE { return true; } |
| 939 | 939 |
| 940 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); | 940 DISALLOW_COPY_AND_ASSIGN(FocusControllerMouseEventTest); |
| 941 }; | 941 }; |
| 942 | 942 |
| 943 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { | 943 class FocusControllerGestureEventTest : public FocusControllerDirectTestBase { |
| 944 public: | 944 public: |
| 945 FocusControllerGestureEventTest() {} | 945 FocusControllerGestureEventTest() {} |
| 946 | 946 |
| 947 private: | 947 private: |
| 948 // Overridden from FocusControllerTestBase: | 948 // Overridden from FocusControllerTestBase: |
| 949 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { | 949 virtual void FocusWindowDirect(aura::Window* window) OVERRIDE { |
| 950 ui::test::EventGenerator generator(root_window(), window); | 950 aura::test::EventGenerator generator(root_window(), window); |
| 951 generator.GestureTapAt(window->bounds().CenterPoint()); | 951 generator.GestureTapAt(window->bounds().CenterPoint()); |
| 952 } | 952 } |
| 953 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { | 953 virtual void ActivateWindowDirect(aura::Window* window) OVERRIDE { |
| 954 ui::test::EventGenerator generator(root_window(), window); | 954 aura::test::EventGenerator generator(root_window(), window); |
| 955 generator.GestureTapAt(window->bounds().CenterPoint()); | 955 generator.GestureTapAt(window->bounds().CenterPoint()); |
| 956 } | 956 } |
| 957 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { | 957 virtual void DeactivateWindowDirect(aura::Window* window) OVERRIDE { |
| 958 aura::Window* next_activatable = | 958 aura::Window* next_activatable = |
| 959 test_focus_rules()->GetNextActivatableWindow(window); | 959 test_focus_rules()->GetNextActivatableWindow(window); |
| 960 ui::test::EventGenerator generator(root_window(), next_activatable); | 960 aura::test::EventGenerator generator(root_window(), next_activatable); |
| 961 generator.GestureTapAt(window->bounds().CenterPoint()); | 961 generator.GestureTapAt(window->bounds().CenterPoint()); |
| 962 } | 962 } |
| 963 virtual bool IsInputEvent() OVERRIDE { return true; } | 963 virtual bool IsInputEvent() OVERRIDE { return true; } |
| 964 | 964 |
| 965 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); | 965 DISALLOW_COPY_AND_ASSIGN(FocusControllerGestureEventTest); |
| 966 }; | 966 }; |
| 967 | 967 |
| 968 // Test base for tests where focus is implicitly set to a window as the result | 968 // Test base for tests where focus is implicitly set to a window as the result |
| 969 // of a disposition change to the focused window or the hierarchy that contains | 969 // of a disposition change to the focused window or the hierarchy that contains |
| 970 // it. | 970 // it. |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1276 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
| 1277 | 1277 |
| 1278 // - Verifies that the focused text input client is cleard when the window focus | 1278 // - Verifies that the focused text input client is cleard when the window focus |
| 1279 // changes. | 1279 // changes. |
| 1280 ALL_FOCUS_TESTS(FocusedTextInputClient); | 1280 ALL_FOCUS_TESTS(FocusedTextInputClient); |
| 1281 | 1281 |
| 1282 // If a mouse event was handled, it should not activate a window. | 1282 // If a mouse event was handled, it should not activate a window. |
| 1283 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1283 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1284 | 1284 |
| 1285 } // namespace wm | 1285 } // namespace wm |
| OLD | NEW |