Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: ui/wm/core/focus_controller_unittest.cc

Issue 173803002: Redesigns the text input focus handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/wm/core/focus_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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);
832 EXPECT_EQ(&text_input_client,
833 text_input_focus_manager->GetFocusedTextInputClient());
834 FocusWindowById(1);
835 // The focused text input client gets cleared when a window gets focused
836 // unless any of observers sets the focused text input client.
837 EXPECT_EQ(null_text_input_client,
838 text_input_focus_manager->GetFocusedTextInputClient());
839
840 ScopedFocusedTextInputClientChanger text_input_focus_changer(
841 root_window(), &text_input_client);
842 EXPECT_EQ(null_text_input_client,
843 text_input_focus_manager->GetFocusedTextInputClient());
844 FocusWindowById(2);
845 // |text_input_focus_changer| sets the focused text input client.
846 EXPECT_EQ(&text_input_client,
847 text_input_focus_manager->GetFocusedTextInputClient());
848
849 FocusWindow(NULL);
850 // The focused text input client gets cleared when a window loses the focus.
851 EXPECT_EQ(null_text_input_client,
852 text_input_focus_manager->GetFocusedTextInputClient());
853 }
854
798 private: 855 private:
799 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase); 856 DISALLOW_COPY_AND_ASSIGN(FocusControllerDirectTestBase);
800 }; 857 };
801 858
802 // Focus and Activation changes via aura::client::ActivationClient API. 859 // Focus and Activation changes via aura::client::ActivationClient API.
803 class FocusControllerApiTest : public FocusControllerDirectTestBase { 860 class FocusControllerApiTest : public FocusControllerDirectTestBase {
804 public: 861 public:
805 FocusControllerApiTest() {} 862 FocusControllerApiTest() {}
806 863
807 private: 864 private:
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 1231
1175 // Clicking on a window which has capture should not result in a focus change. 1232 // Clicking on a window which has capture should not result in a focus change.
1176 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); 1233 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow);
1177 1234
1178 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, 1235 FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
1179 ChangeFocusWhenNothingFocusedAndCaptured); 1236 ChangeFocusWhenNothingFocusedAndCaptured);
1180 1237
1181 // See description above DontPassDeletedWindow() for details. 1238 // See description above DontPassDeletedWindow() for details.
1182 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); 1239 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow);
1183 1240
1241 // - Verifies that the focused text input client is cleard when the window focus
1242 // changes.
1243 ALL_FOCUS_TESTS(FocusedTextInputClient);
1244
1184 } // namespace wm 1245 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/focus_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698