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

Side by Side Diff: ui/views/mus/input_method_mus.cc

Issue 2412593002: IME for Mus: Send ack for key events after IME driver processes the event. (Closed)
Patch Set: Addressed feedback. Created 4 years, 2 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
« no previous file with comments | « ui/views/mus/input_method_mus.h ('k') | ui/views/mus/native_widget_mus.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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/mus/input_method_mus.h" 5 #include "ui/views/mus/input_method_mus.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "services/ui/public/cpp/window.h" 9 #include "services/ui/public/cpp/window.h"
10 #include "services/ui/public/interfaces/ime.mojom.h" 10 #include "services/ui/public/interfaces/ime.mojom.h"
11 #include "ui/base/ime/text_input_client.h" 11 #include "ui/base/ime/text_input_client.h"
12 #include "ui/events/event.h" 12 #include "ui/events/event.h"
13 #include "ui/platform_window/mojo/ime_type_converters.h" 13 #include "ui/platform_window/mojo/ime_type_converters.h"
14 #include "ui/platform_window/mojo/text_input_state.mojom.h" 14 #include "ui/platform_window/mojo/text_input_state.mojom.h"
15 #include "ui/views/mus/text_input_client_impl.h" 15 #include "ui/views/mus/text_input_client_impl.h"
16 16
17 using ui::mojom::EventResult;
18
17 namespace views { 19 namespace views {
18 20
19 //////////////////////////////////////////////////////////////////////////////// 21 ////////////////////////////////////////////////////////////////////////////////
20 // InputMethodMus, public: 22 // InputMethodMus, public:
21 23
22 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate, 24 InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate,
23 ui::Window* window) 25 ui::Window* window)
24 : window_(window) { 26 : window_(window) {
25 SetDelegate(delegate); 27 SetDelegate(delegate);
26 } 28 }
27 29
28 InputMethodMus::~InputMethodMus() {} 30 InputMethodMus::~InputMethodMus() {}
29 31
30 void InputMethodMus::Init(service_manager::Connector* connector) { 32 void InputMethodMus::Init(service_manager::Connector* connector) {
31 connector->ConnectToInterface("service:ui", &ime_server_); 33 connector->ConnectToInterface("service:ui", &ime_server_);
32 } 34 }
33 35
36 void InputMethodMus::DispatchKeyEvent(
37 ui::KeyEvent* event,
38 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) {
39 DCHECK(event->type() == ui::ET_KEY_PRESSED ||
40 event->type() == ui::ET_KEY_RELEASED);
41
42 // If no text input client, do nothing.
43 if (!GetTextInputClient()) {
44 ignore_result(DispatchKeyEventPostIME(event));
45 if (ack_callback) {
46 ack_callback->Run(event->handled() ? EventResult::HANDLED
47 : EventResult::UNHANDLED);
48 }
49 return;
50 }
51
52 // IME driver will notify us whether it handled the event or not by calling
53 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell
54 // the window server if client handled the event or not.
55 input_method_->ProcessKeyEvent(
56 ui::Event::Clone(*event),
57 base::Bind(&InputMethodMus::ProcessKeyEventCallback,
58 base::Unretained(this), *event, Passed(&ack_callback)));
59 }
60
34 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
35 // InputMethodMus, ui::InputMethod implementation: 62 // InputMethodMus, ui::InputMethod implementation:
36 63
37 void InputMethodMus::OnFocus() { 64 void InputMethodMus::OnFocus() {
38 InputMethodBase::OnFocus(); 65 InputMethodBase::OnFocus();
39 UpdateTextInputType(); 66 UpdateTextInputType();
40 } 67 }
41 68
42 void InputMethodMus::OnBlur() { 69 void InputMethodMus::OnBlur() {
43 InputMethodBase::OnBlur(); 70 InputMethodBase::OnBlur();
44 UpdateTextInputType(); 71 UpdateTextInputType();
45 } 72 }
46 73
47 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event, 74 bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event,
48 NativeEventResult* result) { 75 NativeEventResult* result) {
49 // This method is not called on non-Windows platforms. See the comments for 76 // This method is not called on non-Windows platforms. See the comments for
50 // ui::InputMethod::OnUntranslatedIMEMessage(). 77 // ui::InputMethod::OnUntranslatedIMEMessage().
51 return false; 78 return false;
52 } 79 }
53 80
54 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) { 81 void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) {
55 DCHECK(event->type() == ui::ET_KEY_PRESSED || 82 DispatchKeyEvent(event, nullptr);
56 event->type() == ui::ET_KEY_RELEASED);
57
58 // If no text input client, do nothing.
59 if (!GetTextInputClient()) {
60 ignore_result(DispatchKeyEventPostIME(event));
61 return;
62 }
63
64 // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of
65 // non-char events here, accelerators ddn't work. This is because we send the
66 // event ack too early in NativeWidgetMus. We should send both char and
67 // non-char events to the IME driver once we fix this.
68 if (event->is_char()) {
69 // IME driver will notify the text input client if it is not interested in
70 // event, which in turn will call DispatchKeyEventPostIME().
71 input_method_->ProcessKeyEvent(ui::Event::Clone(*event));
72 event->StopPropagation();
73 return;
74 }
75
76 ignore_result(DispatchKeyEventPostIME(event));
77 } 83 }
78 84
79 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) { 85 void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) {
80 if (IsTextInputClientFocused(client)) 86 if (IsTextInputClientFocused(client))
81 UpdateTextInputType(); 87 UpdateTextInputType();
82 InputMethodBase::OnTextInputTypeChanged(client); 88 InputMethodBase::OnTextInputTypeChanged(client);
83 89
84 if (input_method_) { 90 if (input_method_) {
85 input_method_->OnTextInputTypeChanged( 91 input_method_->OnTextInputTypeChanged(
86 static_cast<ui::mojom::TextInputType>(client->GetTextInputType())); 92 static_cast<ui::mojom::TextInputType>(client->GetTextInputType()));
(...skipping 20 matching lines...) Expand all
107 // mean for displaying candidate list popup. 113 // mean for displaying candidate list popup.
108 return false; 114 return false;
109 } 115 }
110 116
111 void InputMethodMus::OnDidChangeFocusedClient( 117 void InputMethodMus::OnDidChangeFocusedClient(
112 ui::TextInputClient* focused_before, 118 ui::TextInputClient* focused_before,
113 ui::TextInputClient* focused) { 119 ui::TextInputClient* focused) {
114 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); 120 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
115 UpdateTextInputType(); 121 UpdateTextInputType();
116 122
117 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused, this); 123 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused);
118 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(), 124 ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(),
119 GetProxy(&input_method_)); 125 GetProxy(&input_method_));
120 } 126 }
121 127
122 void InputMethodMus::UpdateTextInputType() { 128 void InputMethodMus::UpdateTextInputType() {
123 ui::TextInputType type = GetTextInputType(); 129 ui::TextInputType type = GetTextInputType();
124 mojo::TextInputStatePtr state = mojo::TextInputState::New(); 130 mojo::TextInputStatePtr state = mojo::TextInputState::New();
125 state->type = mojo::ConvertTo<mojo::TextInputType>(type); 131 state->type = mojo::ConvertTo<mojo::TextInputType>(type);
126 if (window_) { 132 if (window_) {
127 if (type != ui::TEXT_INPUT_TYPE_NONE) 133 if (type != ui::TEXT_INPUT_TYPE_NONE)
128 window_->SetImeVisibility(true, std::move(state)); 134 window_->SetImeVisibility(true, std::move(state));
129 else 135 else
130 window_->SetTextInputState(std::move(state)); 136 window_->SetTextInputState(std::move(state));
131 } 137 }
132 } 138 }
133 139
140 void InputMethodMus::ProcessKeyEventCallback(
141 const ui::KeyEvent& event,
142 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback,
143 bool handled) {
144 EventResult event_result;
145 if (!handled) {
146 // If not handled by IME, try dispatching the event to delegate to see if
147 // any client-side post-ime processing needs to be done. This includes cases
148 // like backspace, return key, etc.
149 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event);
150 ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent()));
151 event_result =
152 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED;
153 } else {
154 event_result = EventResult::HANDLED;
155 }
156 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is
157 // called instead of the version which provides a callback. In mus+ash we
158 // use the version with callback, but some unittests use the standard form.
159 if (ack_callback)
160 ack_callback->Run(event_result);
161 }
162
134 } // namespace views 163 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/input_method_mus.h ('k') | ui/views/mus/native_widget_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698