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/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/event_generator.h" |
| 14 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
| 15 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
| 16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_event_dispatcher.h" | 17 #include "ui/aura/window_event_dispatcher.h" |
| 18 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
| 19 #include "ui/base/ime/dummy_text_input_client.h" | |
| 20 #include "ui/base/ime/text_input_focus_manager.h" | |
| 19 #include "ui/events/event_handler.h" | 21 #include "ui/events/event_handler.h" |
| 20 #include "ui/wm/core/base_focus_rules.h" | 22 #include "ui/wm/core/base_focus_rules.h" |
| 21 #include "ui/wm/core/wm_state.h" | 23 #include "ui/wm/core/wm_state.h" |
| 22 #include "ui/wm/public/activation_change_observer.h" | 24 #include "ui/wm/public/activation_change_observer.h" |
| 23 #include "ui/wm/public/activation_client.h" | 25 #include "ui/wm/public/activation_client.h" |
| 24 | 26 |
| 25 namespace wm { | 27 namespace wm { |
| 26 | 28 |
| 27 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, | 29 class FocusNotificationObserver : public aura::client::ActivationChangeObserver, |
| 28 public aura::client::FocusChangeObserver { | 30 public aura::client::FocusChangeObserver { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 } | 247 } |
| 246 } | 248 } |
| 247 | 249 |
| 248 private: | 250 private: |
| 249 aura::Window* target_; | 251 aura::Window* target_; |
| 250 aura::WindowTracker tracker_; | 252 aura::WindowTracker tracker_; |
| 251 | 253 |
| 252 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); | 254 DISALLOW_COPY_AND_ASSIGN(ScopedTargetFocusNotificationObserver); |
| 253 }; | 255 }; |
| 254 | 256 |
| 257 class ScopedFocusedTextInputClientChanger | |
| 258 : public ScopedFocusNotificationObserver { | |
| 259 public: | |
| 260 ScopedFocusedTextInputClientChanger(aura::Window* root_window, | |
| 261 ui::TextInputClient* text_input_client) | |
| 262 : ScopedFocusNotificationObserver(root_window), | |
| 263 text_input_client_(text_input_client) {} | |
| 264 | |
| 265 private: | |
| 266 // Overridden from aura::client::FocusChangeObserver: | |
| 267 virtual void OnWindowFocused(aura::Window* gained_focus, | |
| 268 aura::Window* lost_focus) OVERRIDE { | |
| 269 ui::TextInputFocusManager::GetInstance()->FocusTextInputClient( | |
| 270 text_input_client_); | |
| 271 } | |
| 272 | |
| 273 ui::TextInputClient* text_input_client_; | |
| 274 }; | |
| 275 | |
| 255 class FocusShiftingActivationObserver | 276 class FocusShiftingActivationObserver |
| 256 : public aura::client::ActivationChangeObserver { | 277 : public aura::client::ActivationChangeObserver { |
| 257 public: | 278 public: |
| 258 explicit FocusShiftingActivationObserver(aura::Window* activated_window) | 279 explicit FocusShiftingActivationObserver(aura::Window* activated_window) |
| 259 : activated_window_(activated_window), | 280 : activated_window_(activated_window), |
| 260 shift_focus_to_(NULL) {} | 281 shift_focus_to_(NULL) {} |
| 261 virtual ~FocusShiftingActivationObserver() {} | 282 virtual ~FocusShiftingActivationObserver() {} |
| 262 | 283 |
| 263 void set_shift_focus_to(aura::Window* shift_focus_to) { | 284 void set_shift_focus_to(aura::Window* shift_focus_to) { |
| 264 shift_focus_to_ = shift_focus_to; | 285 shift_focus_to_ = shift_focus_to; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 virtual void ShiftFocusToChildOfInactiveWindow() {} | 456 virtual void ShiftFocusToChildOfInactiveWindow() {} |
| 436 virtual void ShiftFocusToParentOfFocusedWindow() {} | 457 virtual void ShiftFocusToParentOfFocusedWindow() {} |
| 437 virtual void FocusRulesOverride() = 0; | 458 virtual void FocusRulesOverride() = 0; |
| 438 virtual void ActivationRulesOverride() = 0; | 459 virtual void ActivationRulesOverride() = 0; |
| 439 virtual void ShiftFocusOnActivation() {} | 460 virtual void ShiftFocusOnActivation() {} |
| 440 virtual void ShiftFocusOnActivationDueToHide() {} | 461 virtual void ShiftFocusOnActivationDueToHide() {} |
| 441 virtual void NoShiftActiveOnActivation() {} | 462 virtual void NoShiftActiveOnActivation() {} |
| 442 virtual void NoFocusChangeOnClickOnCaptureWindow() {} | 463 virtual void NoFocusChangeOnClickOnCaptureWindow() {} |
| 443 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} | 464 virtual void ChangeFocusWhenNothingFocusedAndCaptured() {} |
| 444 virtual void DontPassDeletedWindow() {} | 465 virtual void DontPassDeletedWindow() {} |
| 466 virtual void FocusedTextInputClient() {} | |
| 445 | 467 |
| 446 private: | 468 private: |
| 447 scoped_ptr<FocusController> focus_controller_; | 469 scoped_ptr<FocusController> focus_controller_; |
| 448 TestFocusRules* test_focus_rules_; | 470 TestFocusRules* test_focus_rules_; |
| 449 scoped_ptr<wm::WMState> wm_state_; | 471 scoped_ptr<wm::WMState> wm_state_; |
| 450 | 472 |
| 451 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); | 473 DISALLOW_COPY_AND_ASSIGN(FocusControllerTestBase); |
| 452 }; | 474 }; |
| 453 | 475 |
| 454 // Test base for tests where focus is directly set to a target window. | 476 // Test base for tests where focus is directly set to a target window. |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 FocusWindowById(3); | 810 FocusWindowById(3); |
| 789 | 811 |
| 790 EXPECT_EQ(3, GetActiveWindowId()); | 812 EXPECT_EQ(3, GetActiveWindowId()); |
| 791 EXPECT_EQ(3, GetFocusedWindowId()); | 813 EXPECT_EQ(3, GetFocusedWindowId()); |
| 792 | 814 |
| 793 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); | 815 EXPECT_EQ(to_delete, observer1.GetDeletedWindow()); |
| 794 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); | 816 EXPECT_FALSE(observer2.was_notified_with_deleted_window()); |
| 795 } | 817 } |
| 796 } | 818 } |
| 797 | 819 |
| 820 // Verifies if the focused text input client is cleared when a window gains | |
| 821 // or loses the focus. | |
| 822 virtual void FocusedTextInputClient() OVERRIDE { | |
| 823 ui::TextInputFocusManager* text_input_focus_manager = | |
| 824 ui::TextInputFocusManager::GetInstance(); | |
| 825 ui::DummyTextInputClient text_input_client; | |
| 826 ui::TextInputClient* null_text_input_client = NULL; | |
| 827 | |
| 828 EXPECT_EQ(null_text_input_client, | |
| 829 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 830 | |
| 831 text_input_focus_manager->FocusTextInputClient(&text_input_client); | |
|
msw
2014/05/07 06:50:15
nit: Add an EXPECT_EQ(&text_input_client, text_inp
Yuki
2014/05/07 07:05:19
Done.
| |
| 832 FocusWindowById(1); | |
| 833 // The focused text input client gets cleared when a window gets focused | |
| 834 // unless any of observers sets the focused text input client. | |
| 835 EXPECT_EQ(null_text_input_client, | |
| 836 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 837 | |
| 838 ScopedFocusedTextInputClientChanger text_input_focus_changer( | |
| 839 root_window(), &text_input_client); | |
| 840 EXPECT_EQ(null_text_input_client, | |
| 841 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 842 FocusWindowById(2); | |
| 843 // |text_input_focus_changer| sets the focused text input client. | |
| 844 EXPECT_EQ(&text_input_client, | |
| 845 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 846 | |
| 847 FocusWindow(NULL); | |
| 848 // The focused text input client gets cleared when a window loses the focus. | |
| 849 EXPECT_EQ(null_text_input_client, | |
| 850 text_input_focus_manager->GetFocusedTextInputClient()); | |
| 851 } | |
| 852 | |
| 798 private: | 853 private: |
| 799 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); | 854 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); |
| 800 }; | 855 }; |
| 801 | 856 |
| 802 // Focus and Activation changes via aura::client::ActivationClient API. | 857 // Focus and Activation changes via aura::client::ActivationClient API. |
| 803 class FocusControllerApiTest : public FocusControllerDirectTestBase { | 858 class FocusControllerApiTest : public FocusControllerDirectTestBase { |
| 804 public: | 859 public: |
| 805 FocusControllerApiTest() {} | 860 FocusControllerApiTest() {} |
| 806 | 861 |
| 807 private: | 862 private: |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1174 | 1229 |
| 1175 // Clicking on a window which has capture should not result in a focus change. | 1230 // Clicking on a window which has capture should not result in a focus change. |
| 1176 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); | 1231 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); |
| 1177 | 1232 |
| 1178 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, | 1233 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, |
| 1179 ChangeFocusWhenNothingFocusedAndCaptured); | 1234 ChangeFocusWhenNothingFocusedAndCaptured); |
| 1180 | 1235 |
| 1181 // See description above DontPassDeletedWindow() for details. | 1236 // See description above DontPassDeletedWindow() for details. |
| 1182 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); | 1237 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); |
| 1183 | 1238 |
| 1239 // - Verifies that the focused text input client is cleard when the window focus | |
| 1240 // changes. | |
| 1241 ALL_FOCUS_TESTS(FocusedTextInputClient); | |
| 1242 | |
| 1184 } // namespace wm | 1243 } // namespace wm |
| OLD | NEW |