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

Side by Side Diff: ui/views/widget/desktop_aura/desktop_native_widget_aura.cc

Issue 173803002: Redesigns the text input focus handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added an unittest and thread checker. Created 6 years, 8 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/views/widget/desktop_aura/desktop_native_widget_aura.h" 5 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "ui/aura/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/cursor_client.h" 10 #include "ui/aura/client/cursor_client.h"
11 #include "ui/aura/client/focus_client.h" 11 #include "ui/aura/client/focus_client.h"
12 #include "ui/aura/client/window_tree_client.h" 12 #include "ui/aura/client/window_tree_client.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_observer.h" 14 #include "ui/aura/window_observer.h"
15 #include "ui/aura/window_property.h" 15 #include "ui/aura/window_property.h"
16 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
17 #include "ui/base/hit_test.h" 17 #include "ui/base/hit_test.h"
18 #include "ui/base/ui_base_switches_util.h"
18 #include "ui/compositor/layer.h" 19 #include "ui/compositor/layer.h"
19 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
20 #include "ui/gfx/display.h" 21 #include "ui/gfx/display.h"
21 #include "ui/gfx/point_conversions.h" 22 #include "ui/gfx/point_conversions.h"
22 #include "ui/gfx/screen.h" 23 #include "ui/gfx/screen.h"
23 #include "ui/gfx/size_conversions.h" 24 #include "ui/gfx/size_conversions.h"
24 #include "ui/native_theme/native_theme.h" 25 #include "ui/native_theme/native_theme.h"
25 #include "ui/views/corewm/tooltip.h" 26 #include "ui/views/corewm/tooltip.h"
26 #include "ui/views/corewm/tooltip_controller.h" 27 #include "ui/views/corewm/tooltip_controller.h"
27 #include "ui/views/drag_utils.h" 28 #include "ui/views/drag_utils.h"
28 #include "ui/views/ime/input_method.h"
29 #include "ui/views/ime/input_method_bridge.h" 29 #include "ui/views/ime/input_method_bridge.h"
30 #include "ui/views/ime/null_input_method.h"
30 #include "ui/views/view_constants_aura.h" 31 #include "ui/views/view_constants_aura.h"
31 #include "ui/views/widget/desktop_aura/desktop_capture_client.h" 32 #include "ui/views/widget/desktop_aura/desktop_capture_client.h"
32 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h" 33 #include "ui/views/widget/desktop_aura/desktop_cursor_loader_updater.h"
33 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h" 34 #include "ui/views/widget/desktop_aura/desktop_dispatcher_client.h"
34 #include "ui/views/widget/desktop_aura/desktop_event_client.h" 35 #include "ui/views/widget/desktop_aura/desktop_event_client.h"
35 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h" 36 #include "ui/views/widget/desktop_aura/desktop_focus_rules.h"
36 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h" 37 #include "ui/views/widget/desktop_aura/desktop_native_cursor_manager.h"
37 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h" 38 #include "ui/views/widget/desktop_aura/desktop_screen_position_client.h"
38 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h" 39 #include "ui/views/widget/desktop_aura/desktop_window_tree_host.h"
39 #include "ui/views/widget/drop_helper.h" 40 #include "ui/views/widget/drop_helper.h"
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 623
623 content_window_->ReleaseCapture(); 624 content_window_->ReleaseCapture();
624 } 625 }
625 626
626 bool DesktopNativeWidgetAura::HasCapture() const { 627 bool DesktopNativeWidgetAura::HasCapture() const {
627 return content_window_ && content_window_->HasCapture() && 628 return content_window_ && content_window_->HasCapture() &&
628 desktop_window_tree_host_->HasCapture(); 629 desktop_window_tree_host_->HasCapture();
629 } 630 }
630 631
631 InputMethod* DesktopNativeWidgetAura::CreateInputMethod() { 632 InputMethod* DesktopNativeWidgetAura::CreateInputMethod() {
633 if (switches::IsTextInputFocusManagerEnabled())
634 return new NullInputMethod();
635
632 ui::InputMethod* host = input_method_event_filter_->input_method(); 636 ui::InputMethod* host = input_method_event_filter_->input_method();
633 return new InputMethodBridge(this, host, false); 637 return new InputMethodBridge(this, host, false);
634 } 638 }
635 639
636 internal::InputMethodDelegate* 640 internal::InputMethodDelegate*
637 DesktopNativeWidgetAura::GetInputMethodDelegate() { 641 DesktopNativeWidgetAura::GetInputMethodDelegate() {
638 return this; 642 return this;
639 } 643 }
640 644
645 ui::InputMethod* DesktopNativeWidgetAura::GetHostInputMethod() {
646 return input_method_event_filter_->input_method();
647 }
648
641 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) { 649 void DesktopNativeWidgetAura::CenterWindow(const gfx::Size& size) {
642 if (content_window_) 650 if (content_window_)
643 desktop_window_tree_host_->CenterWindow(size); 651 desktop_window_tree_host_->CenterWindow(size);
644 } 652 }
645 653
646 void DesktopNativeWidgetAura::GetWindowPlacement( 654 void DesktopNativeWidgetAura::GetWindowPlacement(
647 gfx::Rect* bounds, 655 gfx::Rect* bounds,
648 ui::WindowShowState* maximized) const { 656 ui::WindowShowState* maximized) const {
649 if (content_window_) 657 if (content_window_)
650 desktop_window_tree_host_->GetWindowPlacement(bounds, maximized); 658 desktop_window_tree_host_->GetWindowPlacement(bounds, maximized);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 1073
1066 //////////////////////////////////////////////////////////////////////////////// 1074 ////////////////////////////////////////////////////////////////////////////////
1067 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation: 1075 // DesktopNativeWidgetAura, aura::client::FocusChangeObserver implementation:
1068 1076
1069 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus, 1077 void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
1070 aura::Window* lost_focus) { 1078 aura::Window* lost_focus) {
1071 if (content_window_ == gained_focus) { 1079 if (content_window_ == gained_focus) {
1072 desktop_window_tree_host_->OnNativeWidgetFocus(); 1080 desktop_window_tree_host_->OnNativeWidgetFocus();
1073 native_widget_delegate_->OnNativeFocus(lost_focus); 1081 native_widget_delegate_->OnNativeFocus(lost_focus);
1074 1082
1075 // If focus is moving from a descendant Window to |content_window_| then 1083 if (!switches::IsTextInputFocusManagerEnabled()) {
1076 // native activation hasn't changed. We still need to inform the InputMethod 1084 // If focus is moving from a descendant Window to |content_window_| then
1077 // we've been focused though. 1085 // native activation hasn't changed. We still need to inform the
1078 InputMethod* input_method = GetWidget()->GetInputMethod(); 1086 // InputMethod we've been focused though.
1079 if (input_method) 1087 InputMethod* input_method = GetWidget()->GetInputMethod();
1080 input_method->OnFocus(); 1088 if (input_method)
1089 input_method->OnFocus();
1090 }
1091
1092 // Ensure the focused view's TextInputClient is used for text input.
1093 views::FocusManager* focus_manager = GetWidget()->GetFocusManager();
1094 focus_manager->FocusTextInputClient(focus_manager->GetFocusedView());
1081 } else if (content_window_ == lost_focus) { 1095 } else if (content_window_ == lost_focus) {
1082 desktop_window_tree_host_->OnNativeWidgetBlur(); 1096 desktop_window_tree_host_->OnNativeWidgetBlur();
1083 native_widget_delegate_->OnNativeBlur( 1097 native_widget_delegate_->OnNativeBlur(
1084 aura::client::GetFocusClient(content_window_)->GetFocusedWindow()); 1098 aura::client::GetFocusClient(content_window_)->GetFocusedWindow());
1099
1100 // Ensure the focused view's TextInputClient is not used for text input.
1101 views::FocusManager* focus_manager = GetWidget()->GetFocusManager();
1102 focus_manager->BlurTextInputClient(focus_manager->GetFocusedView());
1085 } 1103 }
1086 } 1104 }
1087 1105
1088 //////////////////////////////////////////////////////////////////////////////// 1106 ////////////////////////////////////////////////////////////////////////////////
1089 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate: 1107 // DesktopNativeWidgetAura, views::internal::InputMethodDelegate:
1090 1108
1091 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 1109 void DesktopNativeWidgetAura::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
1092 FocusManager* focus_manager = 1110 FocusManager* focus_manager =
1093 native_widget_delegate_->AsWidget()->GetFocusManager(); 1111 native_widget_delegate_->AsWidget()->GetFocusManager();
1094 native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 1112 native_widget_delegate_->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 if (cursor_reference_count_ == 0) { 1205 if (cursor_reference_count_ == 0) {
1188 // We are the last DesktopNativeWidgetAura instance, and we are responsible 1206 // We are the last DesktopNativeWidgetAura instance, and we are responsible
1189 // for cleaning up |cursor_manager_|. 1207 // for cleaning up |cursor_manager_|.
1190 delete cursor_manager_; 1208 delete cursor_manager_;
1191 native_cursor_manager_ = NULL; 1209 native_cursor_manager_ = NULL;
1192 cursor_manager_ = NULL; 1210 cursor_manager_ = NULL;
1193 } 1211 }
1194 } 1212 }
1195 1213
1196 } // namespace views 1214 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698