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

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

Issue 2957173004: Make DispatchKeyEventPostIME() asynchronous.
Patch Set: cleanup. Created 3 years, 5 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) 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 void InputMethodMus::OnDidChangeFocusedClient( 144 void InputMethodMus::OnDidChangeFocusedClient(
145 ui::TextInputClient* focused_before, 145 ui::TextInputClient* focused_before,
146 ui::TextInputClient* focused) { 146 ui::TextInputClient* focused) {
147 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); 147 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
148 UpdateTextInputType(); 148 UpdateTextInputType();
149 149
150 // TODO(moshayedi): crbug.com/681563. Handle when there is no focused clients. 150 // TODO(moshayedi): crbug.com/681563. Handle when there is no focused clients.
151 if (!focused) 151 if (!focused)
152 return; 152 return;
153 153
154 text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused); 154 text_input_client_ =
155 base::MakeUnique<TextInputClientImpl>(focused, delegate_);
155 156
156 // We are about to close the pipe with pending callbacks. Closing the pipe 157 // We are about to close the pipe with pending callbacks. Closing the pipe
157 // results in none of the callbacks being run. We have to run the callbacks 158 // results in none of the callbacks being run. We have to run the callbacks
158 // else mus won't process the next event immediately. 159 // else mus won't process the next event immediately.
159 AckPendingCallbacksUnhandled(); 160 AckPendingCallbacksUnhandled();
160 161
161 if (ime_driver_) { 162 if (ime_driver_) {
162 ui::mojom::StartSessionDetailsPtr details = 163 ui::mojom::StartSessionDetailsPtr details =
163 ui::mojom::StartSessionDetails::New(); 164 ui::mojom::StartSessionDetails::New();
164 details->client = text_input_client_->CreateInterfacePtrAndBind(); 165 details->client = text_input_client_->CreateInterfacePtrAndBind();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 197
197 void InputMethodMus::ProcessKeyEventCallback( 198 void InputMethodMus::ProcessKeyEventCallback(
198 const ui::KeyEvent& event, 199 const ui::KeyEvent& event,
199 bool handled) { 200 bool handled) {
200 // Remove the callback as DispatchKeyEventPostIME() may lead to calling 201 // Remove the callback as DispatchKeyEventPostIME() may lead to calling
201 // AckPendingCallbacksUnhandled(), which mutates |pending_callbacks_|. 202 // AckPendingCallbacksUnhandled(), which mutates |pending_callbacks_|.
202 DCHECK(!pending_callbacks_.empty()); 203 DCHECK(!pending_callbacks_.empty());
203 std::unique_ptr<EventResultCallback> ack_callback = 204 std::unique_ptr<EventResultCallback> ack_callback =
204 std::move(pending_callbacks_.front()); 205 std::move(pending_callbacks_.front());
205 pending_callbacks_.pop_front(); 206 pending_callbacks_.pop_front();
206 EventResult event_result; 207
207 if (!handled) {
208 // If not handled by IME, try dispatching the event to delegate to see if
209 // any client-side post-ime processing needs to be done. This includes cases
210 // like backspace, return key, etc.
211 std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event);
212 ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent()));
213 event_result =
214 event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED;
215 } else {
216 event_result = EventResult::HANDLED;
217 }
218 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is 208 // |ack_callback| can be null if the standard form of DispatchKeyEvent() is
219 // called instead of the version which provides a callback. In mus+ash we 209 // called instead of the version which provides a callback. In mus+ash we
220 // use the version with callback, but some unittests use the standard form. 210 // use the version with callback, but some unittests use the standard form.
221 if (ack_callback) 211 if (ack_callback)
222 ack_callback->Run(event_result); 212 ack_callback->Run(handled ? EventResult::HANDLED : EventResult::UNHANDLED);
223 } 213 }
224 214
225 } // namespace aura 215 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698