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/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 // If the key combination matches an accelerator, the accelerator is | 114 // If the key combination matches an accelerator, the accelerator is |
| 111 // triggered, otherwise the key event is processed as usual. | 115 // triggered, otherwise the key event is processed as usual. |
| 112 if (ProcessAccelerator(accelerator)) { | 116 if (ProcessAccelerator(accelerator)) { |
| 113 // If a shortcut was activated for this keydown message, do not propagate | 117 // If a shortcut was activated for this keydown message, do not propagate |
| 114 // the event further. | 118 // the event further. |
| 115 return false; | 119 return false; |
| 116 } | 120 } |
| 117 return true; | 121 return true; |
| 118 } | 122 } |
| 119 | 123 |
| 124 void FocusManager::OnTextInputClientChanged(View* view) { | |
| 125 if (view != focused_view_) | |
|
msw
2014/03/11 00:58:50
nit: reverse the condition and call Focus* in this
Yuki
2014/03/11 15:27:37
Done.
| |
| 126 return; | |
| 127 | |
| 128 FocusTextInputClient(view); | |
| 129 } | |
| 130 | |
| 120 void FocusManager::ValidateFocusedView() { | 131 void FocusManager::ValidateFocusedView() { |
| 121 if (focused_view_ && !ContainsView(focused_view_)) | 132 if (focused_view_ && !ContainsView(focused_view_)) |
| 122 ClearFocus(); | 133 ClearFocus(); |
| 123 } | 134 } |
| 124 | 135 |
| 125 // Tests whether a view is valid, whether it still belongs to the window | 136 // Tests whether a view is valid, whether it still belongs to the window |
| 126 // hierarchy of the FocusManager. | 137 // hierarchy of the FocusManager. |
| 127 bool FocusManager::ContainsView(View* view) { | 138 bool FocusManager::ContainsView(View* view) { |
| 128 Widget* widget = view->GetWidget(); | 139 Widget* widget = view->GetWidget(); |
| 129 return widget ? widget->GetFocusManager() == this : false; | 140 return widget ? widget->GetFocusManager() == this : false; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 325 |
| 315 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); | 326 base::AutoReset<bool> auto_changing_focus(&is_changing_focus_, true); |
| 316 // Update the reason for the focus change (since this is checked by | 327 // Update the reason for the focus change (since this is checked by |
| 317 // some listeners), then notify all listeners. | 328 // some listeners), then notify all listeners. |
| 318 focus_change_reason_ = reason; | 329 focus_change_reason_ = reason; |
| 319 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 330 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, |
| 320 OnWillChangeFocus(focused_view_, view)); | 331 OnWillChangeFocus(focused_view_, view)); |
| 321 | 332 |
| 322 View* old_focused_view = focused_view_; | 333 View* old_focused_view = focused_view_; |
| 323 focused_view_ = view; | 334 focused_view_ = view; |
| 324 if (old_focused_view) | 335 if (old_focused_view) { |
| 325 old_focused_view->Blur(); | 336 old_focused_view->Blur(); |
| 337 BlurTextInputClient(old_focused_view); | |
| 338 } | |
| 326 // Also make |focused_view_| the stored focus view. This way the stored focus | 339 // 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 | 340 // view is remembered if focus changes are requested prior to a show or while |
| 328 // hidden. | 341 // hidden. |
| 329 SetStoredFocusView(focused_view_); | 342 SetStoredFocusView(focused_view_); |
| 330 if (focused_view_) | 343 if (focused_view_) { |
| 344 FocusTextInputClient(focused_view_); | |
| 331 focused_view_->Focus(); | 345 focused_view_->Focus(); |
| 346 } | |
| 332 | 347 |
| 333 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, | 348 FOR_EACH_OBSERVER(FocusChangeListener, focus_change_listeners_, |
| 334 OnDidChangeFocus(old_focused_view, focused_view_)); | 349 OnDidChangeFocus(old_focused_view, focused_view_)); |
| 335 } | 350 } |
| 336 | 351 |
| 337 void FocusManager::ClearFocus() { | 352 void FocusManager::ClearFocus() { |
| 338 // SetFocusedView(NULL) is going to clear out the stored view to. We need to | 353 // SetFocusedView(NULL) is going to clear out the stored view to. We need to |
| 339 // persist it in this case. | 354 // persist it in this case. |
| 340 views::View* focused_view = GetStoredFocusView(); | 355 views::View* focused_view = GetStoredFocusView(); |
| 341 SetFocusedView(NULL); | 356 SetFocusedView(NULL); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 return true; | 545 return true; |
| 531 } | 546 } |
| 532 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { | 547 if (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN) { |
| 533 AdvanceFocus(false); | 548 AdvanceFocus(false); |
| 534 return true; | 549 return true; |
| 535 } | 550 } |
| 536 | 551 |
| 537 return false; | 552 return false; |
| 538 } | 553 } |
| 539 | 554 |
| 555 void FocusManager::FocusTextInputClient(View* view) { | |
| 556 if (!switches::IsNewTextInputFocusEnabled()) | |
| 557 return; | |
| 558 | |
| 559 // If the widget is not active, do not steal the text input focus. | |
| 560 if (!widget_->IsActive()) | |
| 561 return; | |
| 562 | |
| 563 ui::TextInputClient* text_input_client = | |
| 564 view ? view->GetTextInputClient() : NULL; | |
| 565 ui::TextInputFocusManager::GetInstance()-> | |
| 566 SetFocusedTextInputClient(text_input_client); | |
| 567 ui::InputMethod* input_method = widget_->GetHostInputMethod(); | |
| 568 if (input_method) { | |
|
msw
2014/03/11 00:58:50
Should this and BlurTextInputClient (or TextInputF
Yuki
2014/03/11 15:27:37
Thre is nothing to do.
We call InputMethod::OnTex
msw
2014/03/11 23:24:37
Sounds good.
| |
| 569 input_method->OnTextInputTypeChanged(text_input_client); | |
| 570 input_method->OnCaretBoundsChanged(text_input_client); | |
| 571 } | |
| 572 } | |
| 573 | |
| 574 void FocusManager::BlurTextInputClient(View* view) { | |
| 575 if (!switches::IsNewTextInputFocusEnabled()) | |
| 576 return; | |
| 577 | |
| 578 ui::TextInputClient* text_input_client = | |
| 579 view ? view->GetTextInputClient() : NULL; | |
| 580 if (text_input_client && text_input_client->HasCompositionText()) { | |
| 581 text_input_client->ConfirmCompositionText(); | |
| 582 ui::InputMethod* input_method = widget_->GetHostInputMethod(); | |
| 583 if (input_method && input_method->GetTextInputClient() == text_input_client) | |
| 584 input_method->CancelComposition(text_input_client); | |
| 585 } | |
| 586 ui::TextInputFocusManager::GetInstance()-> | |
| 587 UnsetFocusedTextInputClient(text_input_client); | |
| 588 } | |
| 589 | |
| 540 } // namespace views | 590 } // namespace views |
| OLD | NEW |