| 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/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/aura/window_event_dispatcher.h" | 16 #include "ui/aura/window_event_dispatcher.h" |
| 17 #include "ui/aura/window_tracker.h" | 17 #include "ui/aura/window_tracker.h" |
| 18 #include "ui/base/ime/dummy_text_input_client.h" | |
| 19 #include "ui/base/ime/text_input_focus_manager.h" | |
| 20 #include "ui/events/event.h" | 18 #include "ui/events/event.h" |
| 21 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
| 22 #include "ui/events/event_handler.h" | 20 #include "ui/events/event_handler.h" |
| 23 #include "ui/events/test/event_generator.h" | 21 #include "ui/events/test/event_generator.h" |
| 24 #include "ui/wm/core/base_focus_rules.h" | 22 #include "ui/wm/core/base_focus_rules.h" |
| 25 #include "ui/wm/core/window_util.h" | 23 #include "ui/wm/core/window_util.h" |
| 26 #include "ui/wm/core/wm_state.h" | 24 #include "ui/wm/core/wm_state.h" |
| 27 #include "ui/wm/public/activation_change_observer.h" | 25 #include "ui/wm/public/activation_change_observer.h" |
| 28 #include "ui/wm/public/activation_client.h" | 26 #include "ui/wm/public/activation_client.h" |
| 29 | 27 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 256 } |
| 259 } | 257 } |
| 260 | 258 |
| 261 private: | 259 private: |
| 262 aura::Window* target_; | 260 aura::Window* target_; |
| 263 aura::WindowTracker tracker_; | 261 aura::WindowTracker tracker_; |
| 264 | 262 |
| 265 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); | 263 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); |
| 266 }; | 264 }; |
| 267 | 265 |
| 268 class ScopedFocusedTextInputClientChanger | |
| 269 : public ScopedFocusNotificationObserver { | |
| 270 public: | |
| 271 ScopedFocusedTextInputClientChanger(aura::Window* root_window, | |
| 272 ui::TextInputClient* text_input_client) | |
| 273 : ScopedFocusNotificationObserver(root_window), | |
| 274 text_input_client_(text_input_client) {} | |
| 275 | |
| 276 private: | |
| 277 // Overridden from aura::client::FocusChangeObserver: | |
| 278 void OnWindowFocused(aura::Window* gained_focus, | |
| 279 aura::Window* lost_focus) override { | |
| 280 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient( | |
| 281 text_input_client_); | |
| 282 } | |
| 283 | |
| 284 ui::TextInputClient* text_input_client_; | |
| 285 }; | |
| 286 | |
| 287 // Used to fake the handling of events in the pre-target phase. | 266 // Used to fake the handling of events in the pre-target phase. |
| 288 class SimpleEventHandler : public ui::EventHandler { | 267 class SimpleEventHandler : public ui::EventHandler { |
| 289 public: | 268 public: |
| 290 SimpleEventHandler() {} | 269 SimpleEventHandler() {} |
| 291 ~SimpleEventHandler() override {} | 270 ~SimpleEventHandler() override {} |
| 292 | 271 |
| 293 // Overridden from ui::EventHandler: | 272 // Overridden from ui::EventHandler: |
| 294 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); } | 273 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); } |
| 295 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); } | 274 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); } |
| 296 | 275 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 virtual void ShiftFocusToChildOfInactiveWindow() {} | 458 virtual void ShiftFocusToChildOfInactiveWindow() {} |
| 480 virtual void ShiftFocusToParentOfFocusedWindow() {} | 459 virtual void ShiftFocusToParentOfFocusedWindow() {} |
| 481 virtual void FocusRulesOverride() = 0; | 460 virtual void FocusRulesOverride() = 0; |
| 482 virtual void ActivationRulesOverride() = 0; | 461 virtual void ActivationRulesOverride() = 0; |
| 483 virtual void ShiftFocusOnActivation() {} | 462 virtual void ShiftFocusOnActivation() {} |
| 484 virtual void ShiftFocusOnActivationDueToHide() {} | 463 virtual void ShiftFocusOnActivationDueToHide() {} |
| 485 virtual void NoShiftActiveOnActivation() {} | 464 virtual void NoShiftActiveOnActivation() {} |
| 486 virtual void FocusChangeDuringDrag() {} | 465 virtual void FocusChangeDuringDrag() {} |
| 487 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 466 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 488 virtual void DontPassDeletedWindow() {} | 467 virtual void DontPassDeletedWindow() {} |
| 489 virtual void FocusedTextInputClient() {} | |
| 490 | 468 |
| 491 private: | 469 private: |
| 492 scoped_ptr<FocusController> focus_controller_; | 470 scoped_ptr<FocusController> focus_controller_; |
| 493 TestFocusRules* test_focus_rules_; | 471 TestFocusRules* test_focus_rules_; |
| 494 scoped_ptr<wm::WMState> wm_state_; | 472 scoped_ptr<wm::WMState> wm_state_; |
| 495 | 473 |
| 496 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 474 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
| 497 }; | 475 }; |
| 498 | 476 |
| 499 // Test base for tests where focus is directly set to a target window. | 477 // Test base for tests where focus is directly set to a target window. |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 FocusWindowById(3); | 829 FocusWindowById(3); |
| 852 | 830 |
| 853 EXPECT_EQ(3, GetActiveWindowId()); | 831 EXPECT_EQ(3, GetActiveWindowId()); |
| 854 EXPECT_EQ(3, GetFocusedWindowId()); | 832 EXPECT_EQ(3, GetFocusedWindowId()); |
| 855 | 833 |
| 856 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); | 834 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); |
| 857 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); | 835 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); |
| 858 } | 836 } |
| 859 } | 837 } |
| 860 | 838 |
| 861 // Verifies if the focused text input client is cleared when a window gains | |
| 862 // or loses the focus. | |
| 863 void FocusedTextInputClient() override { | |
| 864 ui::TextInputFocusManager* text_input_focus_manager = | |
| 865 ui::TextInputFocusManager::GetInstance(); | |
| 866 ui::DummyTextInputClient text_input_client; | |
| 867 ui::TextInputClient* null_text_input_client = NULL; | |
| 868 | |
| 869 EXPECT_EQ(null_text_input_client, | |
| 870 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 871 | |
| 872 text_input_focus_manager->FocusTextInputClient(&text_input_client); | |
| 873 EXPECT_EQ(&text_input_client, | |
| 874 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 875 FocusWindowById(1); | |
| 876 // The focused text input client gets cleared when a window gets focused | |
| 877 // unless any of observers sets the focused text input client. | |
| 878 EXPECT_EQ(null_text_input_client, | |
| 879 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 880 | |
| 881 ScopedFocusedTextInputClientChanger text_input_focus_changer( | |
| 882 root_window(), &text_input_client); | |
| 883 EXPECT_EQ(null_text_input_client, | |
| 884 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 885 FocusWindowById(2); | |
| 886 // |text_input_focus_changer| sets the focused text input client. | |
| 887 EXPECT_EQ(&text_input_client, | |
| 888 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 889 | |
| 890 FocusWindow(NULL); | |
| 891 // The focused text input client gets cleared when a window loses the focus. | |
| 892 EXPECT_EQ(null_text_input_client, | |
| 893 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 894 } | |
| 895 | |
| 896 private: | 839 private: |
| 897 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 840 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
| 898 }; | 841 }; |
| 899 | 842 |
| 900 // Focus and Activation changes via aura::client::ActivationClient API. | 843 // Focus and Activation changes via aura::client::ActivationClient API. |
| 901 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 844 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
| 902 public: | 845 public: |
| 903 FocusControllerApiTest() {} | 846 FocusControllerApiTest() {} |
| 904 | 847 |
| 905 private: | 848 private: |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1280 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1338 ChangeFocusWhenNothingFocusedAndCaptured); | 1281 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1339 | 1282 |
| 1340 // See description above DontPassDeletedWindow() for details. | 1283 // See description above DontPassDeletedWindow() for details. |
| 1341 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1284 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
| 1342 | 1285 |
| 1343 // See description above TransientChildWindowActivationTest() for details. | 1286 // See description above TransientChildWindowActivationTest() for details. |
| 1344 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, | 1287 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, |
| 1345 TransientChildWindowActivationTest); | 1288 TransientChildWindowActivationTest); |
| 1346 | 1289 |
| 1347 // - Verifies that the focused text input client is cleard when the window focus | |
| 1348 // changes. | |
| 1349 ALL_FOCUS_TESTS(FocusedTextInputClient); | |
| 1350 | |
| 1351 // If a mouse event was handled, it should not activate a window. | 1290 // If a mouse event was handled, it should not activate a window. |
| 1352 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1291 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1353 | 1292 |
| 1354 } // namespace wm | 1293 } // namespace wm |
| OLD | NEW |