OLD | NEW |
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/aura/mus/input_method_mus.h" | 5 #include "ui/aura/mus/input_method_mus.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "services/ui/public/interfaces/constants.mojom.h" | 10 #include "services/ui/public/interfaces/constants.mojom.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 AckPendingCallbacksUnhandled(); | 38 AckPendingCallbacksUnhandled(); |
39 } | 39 } |
40 | 40 |
41 void InputMethodMus::Init(service_manager::Connector* connector) { | 41 void InputMethodMus::Init(service_manager::Connector* connector) { |
42 if (connector) | 42 if (connector) |
43 connector->BindInterface(ui::mojom::kServiceName, &ime_server_); | 43 connector->BindInterface(ui::mojom::kServiceName, &ime_server_); |
44 } | 44 } |
45 | 45 |
46 void InputMethodMus::DispatchKeyEvent( | 46 void InputMethodMus::DispatchKeyEvent( |
47 ui::KeyEvent* event, | 47 ui::KeyEvent* event, |
48 std::unique_ptr<EventResultCallback> ack_callback) { | 48 std::unique_ptr<AckCallback> ack_callback) { |
49 DCHECK(event->type() == ui::ET_KEY_PRESSED || | 49 DCHECK(event->type() == ui::ET_KEY_PRESSED || |
50 event->type() == ui::ET_KEY_RELEASED); | 50 event->type() == ui::ET_KEY_RELEASED); |
51 | 51 |
52 // If no text input client, do nothing. | 52 // If no text input client, do nothing. |
53 if (!GetTextInputClient()) { | 53 if (!GetTextInputClient()) { |
54 DispatchKeyEventPostIME(event); | 54 DispatchKeyEventPostIME(event); |
55 if (ack_callback) { | 55 if (ack_callback) |
56 ack_callback->Run(event->handled() ? EventResult::HANDLED | 56 ack_callback->Run(event->handled()); |
57 : EventResult::UNHANDLED); | |
58 } | |
59 return; | 57 return; |
60 } | 58 } |
61 | 59 |
62 SendKeyEventToInputMethod(*event, std::move(ack_callback)); | 60 SendKeyEventToInputMethod(*event, std::move(ack_callback)); |
63 } | 61 } |
64 | 62 |
65 //////////////////////////////////////////////////////////////////////////////// | 63 //////////////////////////////////////////////////////////////////////////////// |
66 // InputMethodMus, ui::InputMethod implementation: | 64 // InputMethodMus, ui::InputMethod implementation: |
67 | 65 |
68 void InputMethodMus::OnFocus() { | 66 void InputMethodMus::OnFocus() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 112 } |
115 | 113 |
116 bool InputMethodMus::IsCandidatePopupOpen() const { | 114 bool InputMethodMus::IsCandidatePopupOpen() const { |
117 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a | 115 // TODO(moshayedi): crbug.com/637416. Implement this properly when we have a |
118 // mean for displaying candidate list popup. | 116 // mean for displaying candidate list popup. |
119 return false; | 117 return false; |
120 } | 118 } |
121 | 119 |
122 void InputMethodMus::SendKeyEventToInputMethod( | 120 void InputMethodMus::SendKeyEventToInputMethod( |
123 const ui::KeyEvent& event, | 121 const ui::KeyEvent& event, |
124 std::unique_ptr<EventResultCallback> ack_callback) { | 122 std::unique_ptr<AckCallback> ack_callback) { |
125 if (!input_method_) { | 123 if (!input_method_) { |
126 // This code path is hit in tests that don't connect to the server. | 124 // This code path is hit in tests that don't connect to the server. |
127 DCHECK(!ack_callback); | 125 DCHECK(!ack_callback); |
128 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); | 126 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); |
129 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); | 127 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); |
130 return; | 128 return; |
131 } | 129 } |
132 // IME driver will notify us whether it handled the event or not by calling | 130 // IME driver will notify us whether it handled the event or not by calling |
133 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell | 131 // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell |
134 // the window server if client handled the event or not. | 132 // the window server if client handled the event or not. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (type != ui::TEXT_INPUT_TYPE_NONE) | 178 if (type != ui::TEXT_INPUT_TYPE_NONE) |
181 window_impl_mus->SetImeVisibility(true, std::move(state)); | 179 window_impl_mus->SetImeVisibility(true, std::move(state)); |
182 else | 180 else |
183 window_impl_mus->SetTextInputState(std::move(state)); | 181 window_impl_mus->SetTextInputState(std::move(state)); |
184 } | 182 } |
185 } | 183 } |
186 | 184 |
187 void InputMethodMus::AckPendingCallbacksUnhandled() { | 185 void InputMethodMus::AckPendingCallbacksUnhandled() { |
188 for (auto& callback_ptr : pending_callbacks_) { | 186 for (auto& callback_ptr : pending_callbacks_) { |
189 if (callback_ptr) | 187 if (callback_ptr) |
190 callback_ptr->Run(EventResult::UNHANDLED); | 188 callback_ptr->Run(false); |
191 } | 189 } |
192 pending_callbacks_.clear(); | 190 pending_callbacks_.clear(); |
193 } | 191 } |
194 | 192 |
195 void InputMethodMus::ProcessKeyEventCallback( | 193 void InputMethodMus::ProcessKeyEventCallback( |
196 const ui::KeyEvent& event, | 194 const ui::KeyEvent& event, |
197 bool handled) { | 195 bool handled) { |
198 // Remove the callback as DispatchKeyEventPostIME() may lead to calling | 196 // Remove the callback as DispatchKeyEventPostIME() may lead to calling |
199 // AckPendingCallbacksUnhandled(), which mutates |pending_callbacks_|. | 197 // AckPendingCallbacksUnhandled(), which mutates |pending_callbacks_|. |
200 DCHECK(!pending_callbacks_.empty()); | 198 DCHECK(!pending_callbacks_.empty()); |
201 std::unique_ptr<EventResultCallback> ack_callback = | 199 std::unique_ptr<AckCallback> ack_callback = |
202 std::move(pending_callbacks_.front()); | 200 std::move(pending_callbacks_.front()); |
203 pending_callbacks_.pop_front(); | 201 pending_callbacks_.pop_front(); |
204 EventResult event_result; | 202 bool event_result = handled; |
205 if (!handled) { | 203 if (!handled) { |
206 // If not handled by IME, try dispatching the event to delegate to see if | 204 // If not handled by IME, try dispatching the event to delegate to see if |
207 // any client-side post-ime processing needs to be done. This includes cases | 205 // any client-side post-ime processing needs to be done. This includes cases |
208 // like backspace, return key, etc. | 206 // like backspace, return key, etc. |
209 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); | 207 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event); |
210 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); | 208 DispatchKeyEventPostIME(event_clone->AsKeyEvent()); |
211 event_result = | 209 event_result = event_clone->handled(); |
212 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED; | |
213 } else { | |
214 event_result = EventResult::HANDLED; | |
215 } | 210 } |
216 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is | 211 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is |
217 // called instead of the version which provides a callback. In mus+ash we | 212 // called instead of the version which provides a callback. In mus+ash we |
218 // use the version with callback, but some unittests use the standard form. | 213 // use the version with callback, but some unittests use the standard form. |
219 if (ack_callback) | 214 if (ack_callback) |
220 ack_callback->Run(event_result); | 215 ack_callback->Run(event_result); |
221 } | 216 } |
222 | 217 |
223 } // namespace aura | 218 } // namespace aura |
OLD | NEW |