Chromium Code Reviews| 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" |
| 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/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 14 #include "ui/aura/test/aura_test_base.h" | 15 #include "ui/aura/test/aura_test_base.h" |
| 15 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
| 16 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
| 17 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 19 #include "ui/aura/window_tracker.h" | 20 #include "ui/aura/window_tracker.h" |
| 20 #include "ui/base/events/event_handler.h" | 21 #include "ui/base/events/event_handler.h" |
| 21 #include "ui/views/corewm/base_focus_rules.h" | 22 #include "ui/views/corewm/base_focus_rules.h" |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 namespace corewm { | 25 namespace corewm { |
| 25 | 26 |
| 26 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 27 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
| 27 public aura::client::FocusChangeObserver { | 28 public aura::client::FocusChangeObserver { |
| 28 public: | 29 public: |
| 29 FocusNotificationObserver() | 30 FocusNotificationObserver() |
| 30 : activation_changed_count_(0), | 31 : activation_changed_count_(0), |
| 31 focus_changed_count_(0) {} | 32 focus_changed_count_(0), |
| 33 reactivation_count_(0), | |
| 34 reactivation_requested_window_(NULL), | |
| 35 reactivation_actual_window_(NULL) {} | |
| 32 virtual ~FocusNotificationObserver() {} | 36 virtual ~FocusNotificationObserver() {} |
| 33 | 37 |
| 34 void ExpectCounts(int activation_changed_count, int focus_changed_count) { | 38 void ExpectCounts(int activation_changed_count, int focus_changed_count) { |
| 35 EXPECT_EQ(activation_changed_count, activation_changed_count_); | 39 EXPECT_EQ(activation_changed_count, activation_changed_count_); |
| 36 EXPECT_EQ(focus_changed_count, focus_changed_count_); | 40 EXPECT_EQ(focus_changed_count, focus_changed_count_); |
| 37 } | 41 } |
| 38 | 42 int GetReactivationCount() { |
|
sky
2013/04/24 14:14:53
methods like this are typically named in unix_hack
sschmitz
2013/04/24 15:42:04
Done.
| |
| 43 return reactivation_count_; | |
| 44 } | |
| 45 aura::Window* GetReactivationRequestedWindow() { | |
| 46 return reactivation_requested_window_; | |
| 47 } | |
| 48 aura::Window* GetReactivationActualWindow() { | |
| 49 return reactivation_actual_window_; | |
| 50 } | |
| 39 | 51 |
| 40 private: | 52 private: |
| 41 // Overridden from aura::client::ActivationChangeObserver: | 53 // Overridden from aura::client::ActivationChangeObserver: |
| 42 virtual void OnWindowActivated(aura::Window* gained_active, | 54 virtual void OnWindowActivated(aura::Window* gained_active, |
| 43 aura::Window* lost_active) OVERRIDE { | 55 aura::Window* lost_active) OVERRIDE { |
| 44 ++activation_changed_count_; | 56 ++activation_changed_count_; |
| 45 } | 57 } |
| 58 virtual void OnAttemptToReactivateWindow( | |
| 59 aura::Window* request_active, | |
| 60 aura::Window* actual_active) OVERRIDE { | |
| 61 ++reactivation_count_; | |
| 62 reactivation_requested_window_ = request_active; | |
| 63 reactivation_actual_window_ = actual_active; | |
| 64 } | |
| 46 | 65 |
| 47 // Overridden from aura::client::FocusChangeObserver: | 66 // Overridden from aura::client::FocusChangeObserver: |
| 48 virtual void OnWindowFocused(aura::Window* gained_focus, | 67 virtual void OnWindowFocused(aura::Window* gained_focus, |
| 49 aura::Window* lost_focus) OVERRIDE { | 68 aura::Window* lost_focus) OVERRIDE { |
| 50 ++focus_changed_count_; | 69 ++focus_changed_count_; |
| 51 } | 70 } |
| 52 | 71 |
| 53 int activation_changed_count_; | 72 int activation_changed_count_; |
| 54 int focus_changed_count_; | 73 int focus_changed_count_; |
| 74 int reactivation_count_; | |
| 75 aura::Window* reactivation_requested_window_; | |
| 76 aura::Window* reactivation_actual_window_; | |
| 55 | 77 |
| 56 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver); | 78 DISALLOW_COPY_AND_ASSIGN(FocusNotificationObserver); |
| 57 }; | 79 }; |
| 58 | 80 |
| 59 class ScopedFocusNotificationObserver : public FocusNotificationObserver { | 81 class ScopedFocusNotificationObserver : public FocusNotificationObserver { |
| 60 public: | 82 public: |
| 61 ScopedFocusNotificationObserver(aura::RootWindow* root_window) | 83 ScopedFocusNotificationObserver(aura::RootWindow* root_window) |
| 62 : root_window_(root_window) { | 84 : root_window_(root_window) { |
| 63 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 85 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
| 64 aura::client::GetFocusClient(root_window_)->AddObserver(this); | 86 aura::client::GetFocusClient(root_window_)->AddObserver(this); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 } | 285 } |
| 264 | 286 |
| 265 TestFocusRules* test_focus_rules() { return test_focus_rules_; } | 287 TestFocusRules* test_focus_rules() { return test_focus_rules_; } |
| 266 | 288 |
| 267 // Test functions. | 289 // Test functions. |
| 268 virtual void BasicFocus() = 0; | 290 virtual void BasicFocus() = 0; |
| 269 virtual void BasicActivation() = 0; | 291 virtual void BasicActivation() = 0; |
| 270 virtual void FocusEvents() = 0; | 292 virtual void FocusEvents() = 0; |
| 271 virtual void DuplicateFocusEvents() {} | 293 virtual void DuplicateFocusEvents() {} |
| 272 virtual void ActivationEvents() = 0; | 294 virtual void ActivationEvents() = 0; |
| 295 virtual void ReactivationEvents() {} | |
| 273 virtual void DuplicateActivationEvents() {} | 296 virtual void DuplicateActivationEvents() {} |
| 274 virtual void ShiftFocusWithinActiveWindow() {} | 297 virtual void ShiftFocusWithinActiveWindow() {} |
| 275 virtual void ShiftFocusToChildOfInactiveWindow() {} | 298 virtual void ShiftFocusToChildOfInactiveWindow() {} |
| 276 virtual void ShiftFocusToParentOfFocusedWindow() {} | 299 virtual void ShiftFocusToParentOfFocusedWindow() {} |
| 277 virtual void FocusRulesOverride() = 0; | 300 virtual void FocusRulesOverride() = 0; |
| 278 virtual void ActivationRulesOverride() = 0; | 301 virtual void ActivationRulesOverride() = 0; |
| 279 virtual void ShiftFocusOnActivation() {} | 302 virtual void ShiftFocusOnActivation() {} |
| 280 virtual void ShiftFocusOnActivationDueToHide() {} | 303 virtual void ShiftFocusOnActivationDueToHide() {} |
| 281 virtual void NoShiftActiveOnActivation() {} | 304 virtual void NoShiftActiveOnActivation() {} |
| 282 virtual void NoFocusChangeOnClickOnCaptureWindow() {} | 305 virtual void NoFocusChangeOnClickOnCaptureWindow() {} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 | 400 |
| 378 root_observer.ExpectCounts(0, 0); | 401 root_observer.ExpectCounts(0, 0); |
| 379 observer1.ExpectCounts(0, 0); | 402 observer1.ExpectCounts(0, 0); |
| 380 observer2.ExpectCounts(0, 0); | 403 observer2.ExpectCounts(0, 0); |
| 381 | 404 |
| 382 ActivateWindowById(2); | 405 ActivateWindowById(2); |
| 383 root_observer.ExpectCounts(1, 1); | 406 root_observer.ExpectCounts(1, 1); |
| 384 observer1.ExpectCounts(1, 1); | 407 observer1.ExpectCounts(1, 1); |
| 385 observer2.ExpectCounts(1, 1); | 408 observer2.ExpectCounts(1, 1); |
| 386 } | 409 } |
| 410 virtual void ReactivationEvents() OVERRIDE { | |
| 411 ActivateWindowById(1); | |
| 412 ScopedFocusNotificationObserver root_observer(root_window()); | |
| 413 EXPECT_EQ(0, root_observer.GetReactivationCount()); | |
| 414 root_window()->GetChildById(2)->Hide(); | |
| 415 // When we attempt to activate "2", which cannot be activated because it | |
| 416 // is not visible, "1" will be reactivated. | |
| 417 ActivateWindowById(2); | |
| 418 EXPECT_EQ(1, root_observer.GetReactivationCount()); | |
| 419 EXPECT_EQ(root_window()->GetChildById(2), | |
| 420 root_observer.GetReactivationRequestedWindow()); | |
| 421 EXPECT_EQ(root_window()->GetChildById(1), | |
| 422 root_observer.GetReactivationActualWindow()); | |
| 423 } | |
| 387 virtual void DuplicateActivationEvents() OVERRIDE { | 424 virtual void DuplicateActivationEvents() OVERRIDE { |
| 388 // Activating an existing active window should not resend activation events. | 425 // Activating an existing active window should not resend activation events. |
| 389 ActivateWindowById(1); | 426 ActivateWindowById(1); |
| 390 | 427 |
| 391 ScopedFocusNotificationObserver root_observer(root_window()); | 428 ScopedFocusNotificationObserver root_observer(root_window()); |
| 392 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); | 429 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); |
| 393 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); | 430 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); |
| 394 | 431 |
| 395 root_observer.ExpectCounts(0, 0); | 432 root_observer.ExpectCounts(0, 0); |
| 396 observer1.ExpectCounts(0, 0); | 433 observer1.ExpectCounts(0, 0); |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 ALL_FOCUS_TESTS(FocusEvents); | 958 ALL_FOCUS_TESTS(FocusEvents); |
| 922 | 959 |
| 923 // - Focuses or activates a window multiple times, verifies that events are only | 960 // - Focuses or activates a window multiple times, verifies that events are only |
| 924 // dispatched when focus/activation actually changes. | 961 // dispatched when focus/activation actually changes. |
| 925 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents); | 962 DIRECT_FOCUS_CHANGE_TESTS(DuplicateFocusEvents); |
| 926 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents); | 963 DIRECT_FOCUS_CHANGE_TESTS(DuplicateActivationEvents); |
| 927 | 964 |
| 928 // - Activates a window, verifies that activation events were dispatched. | 965 // - Activates a window, verifies that activation events were dispatched. |
| 929 TARGET_FOCUS_TESTS(ActivationEvents); | 966 TARGET_FOCUS_TESTS(ActivationEvents); |
| 930 | 967 |
| 968 // - Attempts to active a hidden window, verifies that current window is | |
| 969 // attempted to be reactivated and the appropriate event dispatched. | |
| 970 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, ReactivationEvents); | |
| 971 | |
| 931 // - Input events/API calls shift focus between focusable windows within the | 972 // - Input events/API calls shift focus between focusable windows within the |
| 932 // active window. | 973 // active window. |
| 933 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow); | 974 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusWithinActiveWindow); |
| 934 | 975 |
| 935 // - Input events/API calls to a child window of an inactive window shifts | 976 // - Input events/API calls to a child window of an inactive window shifts |
| 936 // activation to the activatable parent and focuses the child. | 977 // activation to the activatable parent and focuses the child. |
| 937 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow); | 978 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToChildOfInactiveWindow); |
| 938 | 979 |
| 939 // - Input events/API calls to focus the parent of the focused window do not | 980 // - Input events/API calls to focus the parent of the focused window do not |
| 940 // shift focus away from the child. | 981 // shift focus away from the child. |
| 941 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow); | 982 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusToParentOfFocusedWindow); |
| 942 | 983 |
| 943 // - Verifies that FocusRules determine what can be focused. | 984 // - Verifies that FocusRules determine what can be focused. |
| 944 ALL_FOCUS_TESTS(FocusRulesOverride); | 985 ALL_FOCUS_TESTS(FocusRulesOverride); |
| 945 | 986 |
| 946 // - Verifies that FocusRules determine what can be activated. | 987 // - Verifies that FocusRules determine what can be activated. |
| 947 TARGET_FOCUS_TESTS(ActivationRulesOverride); | 988 TARGET_FOCUS_TESTS(ActivationRulesOverride); |
| 948 | 989 |
| 949 // - Verifies that attempts to change focus or activation from a focus or | 990 // - Verifies that attempts to change focus or activation from a focus or |
| 950 // activation change observer are ignored. | 991 // activation change observer are ignored. |
| 951 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); | 992 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivation); |
| 952 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); | 993 DIRECT_FOCUS_CHANGE_TESTS(ShiftFocusOnActivationDueToHide); |
| 953 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); | 994 DIRECT_FOCUS_CHANGE_TESTS(NoShiftActiveOnActivation); |
| 954 | 995 |
| 955 // Clicking on a window which has capture should not result in a focus change. | 996 // Clicking on a window which has capture should not result in a focus change. |
| 956 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 997 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
| 957 | 998 |
| 958 } // namespace corewm | 999 } // namespace corewm |
| 959 } // namespace views | 1000 } // namespace views |
| OLD | NEW |