| 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" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 private: | 261 private: |
| 262 aura::Window* target_; | 262 aura::Window* target_; |
| 263 aura::WindowTracker tracker_; | 263 aura::WindowTracker tracker_; |
| 264 | 264 |
| 265 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); | 265 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); |
| 266 }; | 266 }; |
| 267 | 267 |
| 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. | 268 // Used to fake the handling of events in the pre-target phase. |
| 288 class SimpleEventHandler : public ui::EventHandler { | 269 class SimpleEventHandler : public ui::EventHandler { |
| 289 public: | 270 public: |
| 290 SimpleEventHandler() {} | 271 SimpleEventHandler() {} |
| 291 ~SimpleEventHandler() override {} | 272 ~SimpleEventHandler() override {} |
| 292 | 273 |
| 293 // Overridden from ui::EventHandler: | 274 // Overridden from ui::EventHandler: |
| 294 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); } | 275 void OnMouseEvent(ui::MouseEvent* event) override { event->SetHandled(); } |
| 295 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); } | 276 void OnGestureEvent(ui::GestureEvent* event) override { event->SetHandled(); } |
| 296 | 277 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 virtual void ShiftFocusToChildOfInactiveWindow() {} | 460 virtual void ShiftFocusToChildOfInactiveWindow() {} |
| 480 virtual void ShiftFocusToParentOfFocusedWindow() {} | 461 virtual void ShiftFocusToParentOfFocusedWindow() {} |
| 481 virtual void FocusRulesOverride() = 0; | 462 virtual void FocusRulesOverride() = 0; |
| 482 virtual void ActivationRulesOverride() = 0; | 463 virtual void ActivationRulesOverride() = 0; |
| 483 virtual void ShiftFocusOnActivation() {} | 464 virtual void ShiftFocusOnActivation() {} |
| 484 virtual void ShiftFocusOnActivationDueToHide() {} | 465 virtual void ShiftFocusOnActivationDueToHide() {} |
| 485 virtual void NoShiftActiveOnActivation() {} | 466 virtual void NoShiftActiveOnActivation() {} |
| 486 virtual void FocusChangeDuringDrag() {} | 467 virtual void FocusChangeDuringDrag() {} |
| 487 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 468 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 488 virtual void DontPassDeletedWindow() {} | 469 virtual void DontPassDeletedWindow() {} |
| 489 virtual void FocusedTextInputClient() {} | |
| 490 | 470 |
| 491 private: | 471 private: |
| 492 scoped_ptr<FocusController> focus_controller_; | 472 scoped_ptr<FocusController> focus_controller_; |
| 493 TestFocusRules* test_focus_rules_; | 473 TestFocusRules* test_focus_rules_; |
| 494 scoped_ptr<wm::WMState> wm_state_; | 474 scoped_ptr<wm::WMState> wm_state_; |
| 495 | 475 |
| 496 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 476 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
| 497 }; | 477 }; |
| 498 | 478 |
| 499 // Test base for tests where focus is directly set to a target window. | 479 // 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); | 831 FocusWindowById(3); |
| 852 | 832 |
| 853 EXPECT_EQ(3, GetActiveWindowId()); | 833 EXPECT_EQ(3, GetActiveWindowId()); |
| 854 EXPECT_EQ(3, GetFocusedWindowId()); | 834 EXPECT_EQ(3, GetFocusedWindowId()); |
| 855 | 835 |
| 856 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); | 836 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); |
| 857 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); | 837 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); |
| 858 } | 838 } |
| 859 } | 839 } |
| 860 | 840 |
| 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: | 841 private: |
| 897 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 842 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
| 898 }; | 843 }; |
| 899 | 844 |
| 900 // Focus and Activation changes via aura::client::ActivationClient API. | 845 // Focus and Activation changes via aura::client::ActivationClient API. |
| 901 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 846 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
| 902 public: | 847 public: |
| 903 FocusControllerApiTest() {} | 848 FocusControllerApiTest() {} |
| 904 | 849 |
| 905 private: | 850 private: |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1282 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1338 ChangeFocusWhenNothingFocusedAndCaptured); | 1283 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1339 | 1284 |
| 1340 // See description above DontPassDeletedWindow() for details. | 1285 // See description above DontPassDeletedWindow() for details. |
| 1341 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1286 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
| 1342 | 1287 |
| 1343 // See description above TransientChildWindowActivationTest() for details. | 1288 // See description above TransientChildWindowActivationTest() for details. |
| 1344 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, | 1289 FOCUS_CONTROLLER_TEST(FocusControllerParentHideTest, |
| 1345 TransientChildWindowActivationTest); | 1290 TransientChildWindowActivationTest); |
| 1346 | 1291 |
| 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. | 1292 // If a mouse event was handled, it should not activate a window. |
| 1352 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); | 1293 FOCUS_CONTROLLER_TEST(FocusControllerMouseEventTest, IgnoreHandledEvent); |
| 1353 | 1294 |
| 1354 } // namespace wm | 1295 } // namespace wm |
| OLD | NEW |