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

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: Addressed review comments from sky. 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
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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // change activation. 514 // change activation.
494 DeactivateWindow(NULL); 515 DeactivateWindow(NULL);
495 EXPECT_EQ(2, GetActiveWindowId()); 516 EXPECT_EQ(2, GetActiveWindowId());
496 DeactivateWindow(GetActiveWindow()); 517 DeactivateWindow(GetActiveWindow());
497 EXPECT_EQ(1, GetActiveWindowId()); 518 EXPECT_EQ(1, GetActiveWindowId());
498 } 519 }
499 virtual void FocusEvents() OVERRIDE { 520 virtual void FocusEvents() OVERRIDE {
500 ScopedFocusNotificationObserver root_observer(root_window()); 521 ScopedFocusNotificationObserver root_observer(root_window());
501 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); 522 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
502 ScopedTargetFocusNotificationObserver observer2(root_window(), 2); 523 ScopedTargetFocusNotificationObserver observer2(root_window(), 2);
524 ui::TextInputFocusManager* text_input_focus_manager =
msw 2014/05/02 18:46:03 nit: would this new test code be better suited by
Yuki 2014/05/07 05:58:02 Done. Created FocusedTextInputClient as a test fu
525 ui::TextInputFocusManager::GetInstance();
526 ui::DummyTextInputClient text_input_client;
527 ui::TextInputClient* null_text_input_client = NULL;
503 528
504 root_observer.ExpectCounts(0, 0); 529 root_observer.ExpectCounts(0, 0);
505 observer1.ExpectCounts(0, 0); 530 observer1.ExpectCounts(0, 0);
506 observer2.ExpectCounts(0, 0); 531 observer2.ExpectCounts(0, 0);
532 EXPECT_EQ(null_text_input_client,
533 text_input_focus_manager->GetFocusedTextInputClient());
507 534
535 text_input_focus_manager->FocusTextInputClient(&text_input_client);
508 FocusWindowById(1); 536 FocusWindowById(1);
509 root_observer.ExpectCounts(1, 1); 537 root_observer.ExpectCounts(1, 1);
510 observer1.ExpectCounts(1, 1); 538 observer1.ExpectCounts(1, 1);
511 observer2.ExpectCounts(0, 0); 539 observer2.ExpectCounts(0, 0);
540 // The focused text input client gets cleared when a window gets focused
541 // unless any of observers sets the focused text input client.
542 EXPECT_EQ(null_text_input_client,
543 text_input_focus_manager->GetFocusedTextInputClient());
512 544
545 ScopedFocusedTextInputClientChanger text_input_focus_changer(
546 root_window(), &text_input_client);
547 EXPECT_EQ(null_text_input_client,
548 text_input_focus_manager->GetFocusedTextInputClient());
513 FocusWindowById(2); 549 FocusWindowById(2);
514 root_observer.ExpectCounts(2, 2); 550 root_observer.ExpectCounts(2, 2);
515 observer1.ExpectCounts(2, 2); 551 observer1.ExpectCounts(2, 2);
516 observer2.ExpectCounts(1, 1); 552 observer2.ExpectCounts(1, 1);
553 // |text_input_focus_changer| sets the focused text input client.
554 EXPECT_EQ(&text_input_client,
555 text_input_focus_manager->GetFocusedTextInputClient());
556
557 FocusWindow(NULL);
558 // The focused text input client gets cleared when a window loses the focus.
559 EXPECT_EQ(null_text_input_client,
560 text_input_focus_manager->GetFocusedTextInputClient());
517 } 561 }
518 virtual void DuplicateFocusEvents() OVERRIDE { 562 virtual void DuplicateFocusEvents() OVERRIDE {
519 // Focusing an existing focused window should not resend focus events. 563 // Focusing an existing focused window should not resend focus events.
520 ScopedFocusNotificationObserver root_observer(root_window()); 564 ScopedFocusNotificationObserver root_observer(root_window());
521 ScopedTargetFocusNotificationObserver observer1(root_window(), 1); 565 ScopedTargetFocusNotificationObserver observer1(root_window(), 1);
522 566
523 root_observer.ExpectCounts(0, 0); 567 root_observer.ExpectCounts(0, 0);
524 observer1.ExpectCounts(0, 0); 568 observer1.ExpectCounts(0, 0);
525 569
526 FocusWindowById(1); 570 FocusWindowById(1);
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 // Clicking on a window which has capture should not result in a focus change. 1219 // Clicking on a window which has capture should not result in a focus change.
1176 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow); 1220 DIRECT_FOCUS_CHANGE_TESTS(NoFocusChangeOnClickOnCaptureWindow);
1177 1221
1178 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, 1222 FOCUS_CONTROLLER_TEST(FocusControllerApiTest,
1179 ChangeFocusWhenNothingFocusedAndCaptured); 1223 ChangeFocusWhenNothingFocusedAndCaptured);
1180 1224
1181 // See description above DontPassDeletedWindow() for details. 1225 // See description above DontPassDeletedWindow() for details.
1182 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow); 1226 FOCUS_CONTROLLER_TEST(FocusControllerApiTest, DontPassDeletedWindow);
1183 1227
1184 } // namespace wm 1228 } // namespace wm
OLDNEW
« ui/wm/core/focus_controller.cc ('K') | « ui/wm/core/focus_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698