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

Side by Side Diff: ui/views/focus/focus_manager.cc

Issue 1182523003: Removes TextInputFocusManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
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" 14 #include "ui/base/ime/input_method.h"
15 #include "ui/base/ime/text_input_client.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" 16 #include "ui/base/ui_base_switches_util.h"
18 #include "ui/events/event.h" 17 #include "ui/events/event.h"
19 #include "ui/events/keycodes/keyboard_codes.h" 18 #include "ui/events/keycodes/keyboard_codes.h"
20 #include "ui/views/focus/focus_manager_delegate.h" 19 #include "ui/views/focus/focus_manager_delegate.h"
21 #include "ui/views/focus/focus_search.h" 20 #include "ui/views/focus/focus_search.h"
22 #include "ui/views/focus/view_storage.h" 21 #include "ui/views/focus/view_storage.h"
23 #include "ui/views/focus/widget_focus_manager.h" 22 #include "ui/views/focus/widget_focus_manager.h"
24 #include "ui/views/view.h" 23 #include "ui/views/view.h"
25 #include "ui/views/widget/root_view.h" 24 #include "ui/views/widget/root_view.h"
26 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 if (widget->widget_delegate()->ShouldAdvanceFocusToTopLevelWidget()) 293 if (widget->widget_delegate()->ShouldAdvanceFocusToTopLevelWidget())
295 widget = widget_; 294 widget = widget_;
296 return GetNextFocusableView(NULL, widget, reverse, true); 295 return GetNextFocusableView(NULL, widget, reverse, true);
297 } 296 }
298 } 297 }
299 return NULL; 298 return NULL;
300 } 299 }
301 300
302 void FocusManager::SetFocusedViewWithReason( 301 void FocusManager::SetFocusedViewWithReason(
303 View* view, FocusChangeReason reason) { 302 View* view, FocusChangeReason reason) {
304 if (focused_view_ == view) { 303 if (focused_view_ == view)
305 // In the case that the widget lost the focus and gained it back without
306 // changing the focused view, we have to make the text input client focused.
307 // TODO(yukishiino): Remove this hack once we fix http://crbug.com/383236
308 FocusTextInputClient(focused_view_);
309 return; 304 return;
310 }
311 305
312 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); 306 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true);
313 // Update the reason for the focus change (since this is checked by 307 // Update the reason for the focus change (since this is checked by
314 // some listeners), then notify all listeners. 308 // some listeners), then notify all listeners.
315 focus_change_reason_ = reason; 309 focus_change_reason_ = reason;
316 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 310 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
317 OnWillChangeFocus(focused_view_, view)); 311 OnWillChangeFocus(focused_view_, view));
318 312
319 View* old_focused_view = focused_view_; 313 View* old_focused_view = focused_view_;
320 focused_view_ = view; 314 focused_view_ = view;
321 if (old_focused_view) { 315 if (old_focused_view)
322 old_focused_view->Blur(); 316 old_focused_view->Blur();
323 BlurTextInputClient(old_focused_view);
324 }
325 // Also make |focused_view_| the stored focus view. This way the stored focus 317 // Also make |focused_view_| the stored focus view. This way the stored focus
326 // view is remembered if focus changes are requested prior to a show or while 318 // view is remembered if focus changes are requested prior to a show or while
327 // hidden. 319 // hidden.
328 SetStoredFocusView(focused_view_); 320 SetStoredFocusView(focused_view_);
329 if (focused_view_) { 321 if (focused_view_)
330 FocusTextInputClient(focused_view_);
331 focused_view_->Focus(); 322 focused_view_->Focus();
332 }
333 323
334 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, 324 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_,
335 OnDidChangeFocus(old_focused_view, focused_view_)); 325 OnDidChangeFocus(old_focused_view, focused_view_));
336 } 326 }
337 327
338 void FocusManager::ClearFocus() { 328 void FocusManager::ClearFocus() {
339 // SetFocusedView(NULL) is going to clear out the stored view to. We need to 329 // SetFocusedView(NULL) is going to clear out the stored view to. We need to
340 // persist it in this case. 330 // persist it in this case.
341 views::View* focused_view = GetStoredFocusView(); 331 views::View* focused_view = GetStoredFocusView();
342 SetFocusedView(NULL); 332 SetFocusedView(NULL);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 return NULL; 426 return NULL;
437 } 427 }
438 428
439 return view_storage->RetrieveView(stored_focused_view_storage_id_); 429 return view_storage->RetrieveView(stored_focused_view_storage_id_);
440 } 430 }
441 431
442 void FocusManager::ClearStoredFocusedView() { 432 void FocusManager::ClearStoredFocusedView() {
443 SetStoredFocusView(NULL); 433 SetStoredFocusView(NULL);
444 } 434 }
445 435
446 void FocusManager::OnTextInputClientChanged(View* view) {
447 if (view == focused_view_)
448 FocusTextInputClient(view);
449 }
450
451 void FocusManager::FocusTextInputClient(View* view) {
452 if (!switches::IsTextInputFocusManagerEnabled())
453 return;
454
455 // If the widget is not active, do not steal the text input focus.
456 if (!widget_->IsActive())
457 return;
458
459 ui::TextInputClient* text_input_client =
460 view ? view->GetTextInputClient() : NULL;
461 ui::TextInputFocusManager::GetInstance()->
462 FocusTextInputClient(text_input_client);
463 ui::InputMethod* input_method = widget_->GetHostInputMethod();
464 if (input_method) {
465 input_method->OnTextInputTypeChanged(text_input_client);
466 input_method->OnCaretBoundsChanged(text_input_client);
467 }
468 }
469
470 void FocusManager::BlurTextInputClient(View* view) {
471 if (!switches::IsTextInputFocusManagerEnabled())
472 return;
473
474 ui::TextInputClient* text_input_client =
475 view ? view->GetTextInputClient() : NULL;
476 if (text_input_client && text_input_client->HasCompositionText()) {
477 text_input_client->ConfirmCompositionText();
478 ui::InputMethod* input_method = widget_->GetHostInputMethod();
479 if (input_method && input_method->GetTextInputClient() == text_input_client)
480 input_method->CancelComposition(text_input_client);
481 }
482 ui::TextInputFocusManager::GetInstance()->
483 BlurTextInputClient(text_input_client);
484 }
485
486 // Find the next (previous if reverse is true) focusable view for the specified 436 // Find the next (previous if reverse is true) focusable view for the specified
487 // FocusTraversable, starting at the specified view, traversing down the 437 // FocusTraversable, starting at the specified view, traversing down the
488 // FocusTraversable hierarchy. 438 // FocusTraversable hierarchy.
489 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable, 439 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable,
490 View* starting_view, 440 View* starting_view,
491 bool reverse) { 441 bool reverse) {
492 FocusTraversable* new_focus_traversable = NULL; 442 FocusTraversable* new_focus_traversable = NULL;
493 View* new_starting_view = NULL; 443 View* new_starting_view = NULL;
494 View* v = focus_traversable->GetFocusSearch()->FindNextFocusableView( 444 View* v = focus_traversable->GetFocusSearch()->FindNextFocusableView(
495 starting_view, 445 starting_view,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 } 537 }
588 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { 538 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) {
589 AdvanceFocus(false); 539 AdvanceFocus(false);
590 return true; 540 return true;
591 } 541 }
592 542
593 return false; 543 return false;
594 } 544 }
595 545
596 } // namespace views 546 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698