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

Side by Side Diff: ui/views/focus/focus_manager.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/views/focus/focus_manager.h ('k') | ui/views/ime/null_input_method.h » ('j') | 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/views/focus/focus_manager.h" 5 #include "ui/views/focus/focus_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "ui/base/accelerators/accelerator.h" 13 #include "ui/base/accelerators/accelerator.h"
14 #include "ui/base/ime/input_method.h"
15 #include "ui/base/ime/text_input_client.h"
16 #include "ui/base/ime/text_input_focus_manager.h"
17 #include "ui/base/ui_base_switches_util.h"
14 #include "ui/events/event.h" 18 #include "ui/events/event.h"
15 #include "ui/events/keycodes/keyboard_codes.h" 19 #include "ui/events/keycodes/keyboard_codes.h"
16 #include "ui/views/focus/focus_manager_delegate.h" 20 #include "ui/views/focus/focus_manager_delegate.h"
17 #include "ui/views/focus/focus_search.h" 21 #include "ui/views/focus/focus_search.h"
18 #include "ui/views/focus/view_storage.h" 22 #include "ui/views/focus/view_storage.h"
19 #include "ui/views/focus/widget_focus_manager.h" 23 #include "ui/views/focus/widget_focus_manager.h"
20 #include "ui/views/view.h" 24 #include "ui/views/view.h"
21 #include "ui/views/widget/root_view.h" 25 #include "ui/views/widget/root_view.h"
22 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
23 #include "ui/views/widget/widget_delegate.h" 27 #include "ui/views/widget/widget_delegate.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 318
315 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); 319 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true);
316 // Update the reason for the focus change (since this is checked by 320 // Update the reason for the focus change (since this is checked by
317 // some listeners), then notify all listeners. 321 // some listeners), then notify all listeners.
318 focus_change_reason_ = reason; 322 focus_change_reason_ = reason;
319 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 323 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
320 OnWillChangeFocus(focused_view_, view)); 324 OnWillChangeFocus(focused_view_, view));
321 325
322 View* old_focused_view = focused_view_; 326 View* old_focused_view = focused_view_;
323 focused_view_ = view; 327 focused_view_ = view;
324 if (old_focused_view) 328 if (old_focused_view) {
325 old_focused_view->Blur(); 329 old_focused_view->Blur();
330 BlurTextInputClient(old_focused_view);
331 }
326 // Also make |focused_view_| the stored focus view. This way the stored focus 332 // Also make |focused_view_| the stored focus view. This way the stored focus
327 // view is remembered if focus changes are requested prior to a show or while 333 // view is remembered if focus changes are requested prior to a show or while
328 // hidden. 334 // hidden.
329 SetStoredFocusView(focused_view_); 335 SetStoredFocusView(focused_view_);
330 if (focused_view_) 336 if (focused_view_) {
337 FocusTextInputClient(focused_view_);
331 focused_view_->Focus(); 338 focused_view_->Focus();
339 }
332 340
333 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 341 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
334 OnDidChangeFocus(old_focused_view, focused_view_)); 342 OnDidChangeFocus(old_focused_view, focused_view_));
335 } 343 }
336 344
337 void FocusManager::ClearFocus() { 345 void FocusManager::ClearFocus() {
338 // SetFocusedView(NULL) is going to clear out the stored view to. We need to 346 // SetFocusedView(NULL) is going to clear out the stored view to. We need to
339 // persist it in this case. 347 // persist it in this case.
340 views::View* focused_view = GetStoredFocusView(); 348 views::View* focused_view = GetStoredFocusView();
341 SetFocusedView(NULL); 349 SetFocusedView(NULL);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return NULL; 428 return NULL;
421 } 429 }
422 430
423 return view_storage->RetrieveView(stored_focused_view_storage_id_); 431 return view_storage->RetrieveView(stored_focused_view_storage_id_);
424 } 432 }
425 433
426 void FocusManager::ClearStoredFocusedView() { 434 void FocusManager::ClearStoredFocusedView() {
427 SetStoredFocusView(NULL); 435 SetStoredFocusView(NULL);
428 } 436 }
429 437
438 void FocusManager::OnTextInputClientChanged(View* view) {
439 if (view == focused_view_)
440 FocusTextInputClient(view);
441 }
442
443 void FocusManager::FocusTextInputClient(View* view) {
444 if (!switches::IsTextInputFocusManagerEnabled())
445 return;
446
447 // If the widget is not active, do not steal the text input focus.
448 if (!widget_->IsActive())
449 return;
450
451 ui::TextInputClient* text_input_client =
452 view ? view->GetTextInputClient() : NULL;
453 ui::TextInputFocusManager::GetInstance()->
454 FocusTextInputClient(text_input_client);
455 ui::InputMethod* input_method = widget_->GetHostInputMethod();
456 if (input_method) {
457 input_method->OnTextInputTypeChanged(text_input_client);
458 input_method->OnCaretBoundsChanged(text_input_client);
459 }
460 }
461
462 void FocusManager::BlurTextInputClient(View* view) {
463 if (!switches::IsTextInputFocusManagerEnabled())
464 return;
465
466 ui::TextInputClient* text_input_client =
467 view ? view->GetTextInputClient() : NULL;
468 if (text_input_client && text_input_client->HasCompositionText()) {
469 text_input_client->ConfirmCompositionText();
470 ui::InputMethod* input_method = widget_->GetHostInputMethod();
471 if (input_method && input_method->GetTextInputClient() == text_input_client)
472 input_method->CancelComposition(text_input_client);
473 }
474 ui::TextInputFocusManager::GetInstance()->
475 BlurTextInputClient(text_input_client);
476 }
477
430 // Find the next (previous if reverse is true) focusable view for the specified 478 // Find the next (previous if reverse is true) focusable view for the specified
431 // FocusTraversable, starting at the specified view, traversing down the 479 // FocusTraversable, starting at the specified view, traversing down the
432 // FocusTraversable hierarchy. 480 // FocusTraversable hierarchy.
433 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable, 481 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable,
434 View* starting_view, 482 View* starting_view,
435 bool reverse) { 483 bool reverse) {
436 FocusTraversable* new_focus_traversable = NULL; 484 FocusTraversable* new_focus_traversable = NULL;
437 View* new_starting_view = NULL; 485 View* new_starting_view = NULL;
438 View* v = focus_traversable->GetFocusSearch()->FindNextFocusableView( 486 View* v = focus_traversable->GetFocusSearch()->FindNextFocusableView(
439 starting_view, 487 starting_view,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 579 }
532 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { 580 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) {
533 AdvanceFocus(false); 581 AdvanceFocus(false);
534 return true; 582 return true;
535 } 583 }
536 584
537 return false; 585 return false;
538 } 586 }
539 587
540 } // namespace views 588 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/focus/focus_manager.h ('k') | ui/views/ime/null_input_method.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698