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

Unified Diff: ui/aura/mus/input_method_mus.cc

Issue 2685183005: Makes ~InputMethodMus ack any in flight events (Closed)
Patch Set: null Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/mus/input_method_mus.h ('k') | ui/aura/mus/input_method_mus_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/input_method_mus.cc
diff --git a/ui/aura/mus/input_method_mus.cc b/ui/aura/mus/input_method_mus.cc
index 230dfff77c49344b6d47022842ddf6e5476d8b8b..d629df2a8702c6c9c379b7433293bef5a8c64700 100644
--- a/ui/aura/mus/input_method_mus.cc
+++ b/ui/aura/mus/input_method_mus.cc
@@ -31,7 +31,15 @@ InputMethodMus::InputMethodMus(ui::internal::InputMethodDelegate* delegate,
SetDelegate(delegate);
}
-InputMethodMus::~InputMethodMus() {}
+InputMethodMus::~InputMethodMus() {
+ // Mus won't dispatch the next key event until the existing one is acked. We
+ // may have KeyEvents sent to IME and awaiting the result, we need to ack
+ // them otherwise mus won't process the next event until it times out.
+ for (auto& callback_ptr : pending_callbacks_) {
+ if (callback_ptr)
+ callback_ptr->Run(EventResult::UNHANDLED);
+ }
+}
void InputMethodMus::Init(service_manager::Connector* connector) {
if (connector)
@@ -40,7 +48,7 @@ void InputMethodMus::Init(service_manager::Connector* connector) {
void InputMethodMus::DispatchKeyEvent(
ui::KeyEvent* event,
- std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) {
+ std::unique_ptr<EventResultCallback> ack_callback) {
DCHECK(event->type() == ui::ET_KEY_PRESSED ||
event->type() == ui::ET_KEY_RELEASED);
@@ -54,13 +62,7 @@ void InputMethodMus::DispatchKeyEvent(
return;
}
- // IME driver will notify us whether it handled the event or not by calling
- // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell
- // the window server if client handled the event or not.
- input_method_->ProcessKeyEvent(
- ui::Event::Clone(*event),
- base::Bind(&InputMethodMus::ProcessKeyEventCallback,
- base::Unretained(this), *event, Passed(&ack_callback)));
+ SendKeyEventToInputMethod(*event, std::move(ack_callback));
}
////////////////////////////////////////////////////////////////////////////////
@@ -117,6 +119,19 @@ bool InputMethodMus::IsCandidatePopupOpen() const {
return false;
}
+void InputMethodMus::SendKeyEventToInputMethod(
+ const ui::KeyEvent& event,
+ std::unique_ptr<EventResultCallback> ack_callback) {
+ // IME driver will notify us whether it handled the event or not by calling
+ // ProcessKeyEventCallback(), in which we will run the |ack_callback| to tell
+ // the window server if client handled the event or not.
+ pending_callbacks_.push_back(std::move(ack_callback));
+ input_method_->ProcessKeyEvent(
+ ui::Event::Clone(event),
+ base::Bind(&InputMethodMus::ProcessKeyEventCallback,
+ base::Unretained(this), event));
+}
+
void InputMethodMus::OnDidChangeFocusedClient(
ui::TextInputClient* focused_before,
ui::TextInputClient* focused) {
@@ -132,7 +147,8 @@ void InputMethodMus::OnDidChangeFocusedClient(
ui::mojom::StartSessionDetailsPtr details =
ui::mojom::StartSessionDetails::New();
details->client = text_input_client_->CreateInterfacePtrAndBind();
- details->input_method_request = MakeRequest(&input_method_);
+ details->input_method_request = MakeRequest(&input_method_ptr_);
+ input_method_ = input_method_ptr_.get();
details->text_input_type = focused->GetTextInputType();
details->text_input_mode = focused->GetTextInputMode();
details->text_direction = focused->GetTextDirection();
@@ -157,7 +173,6 @@ void InputMethodMus::UpdateTextInputType() {
void InputMethodMus::ProcessKeyEventCallback(
const ui::KeyEvent& event,
- std::unique_ptr<base::Callback<void(EventResult)>> ack_callback,
bool handled) {
EventResult event_result;
if (!handled) {
@@ -171,6 +186,10 @@ void InputMethodMus::ProcessKeyEventCallback(
} else {
event_result = EventResult::HANDLED;
}
+ DCHECK(!pending_callbacks_.empty());
+ std::unique_ptr<EventResultCallback> ack_callback =
+ std::move(pending_callbacks_.front());
+ pending_callbacks_.pop_front();
// |ack_callback| can be null if the standard form of DispatchKeyEvent() is
// called instead of the version which provides a callback. In mus+ash we
// use the version with callback, but some unittests use the standard form.
« no previous file with comments | « ui/aura/mus/input_method_mus.h ('k') | ui/aura/mus/input_method_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698