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

Unified 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: Fixed views_mus_unittests. 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/mus/input_method_mus.cc
diff --git a/ui/views/mus/input_method_mus.cc b/ui/views/mus/input_method_mus.cc
index 8d5bb8b2cfaf1c57bf473012bc42038462ccb098..9f194665462c333a3c4662f6a298129137c41966 100644
--- a/ui/views/mus/input_method_mus.cc
+++ b/ui/views/mus/input_method_mus.cc
@@ -14,6 +14,12 @@
#include "ui/platform_window/mojo/text_input_state.mojom.h"
#include "ui/views/mus/text_input_client_impl.h"
+using ui::mojom::EventResult;
+
+namespace {
+void DoNothing(EventResult) {}
+}
+
namespace views {
////////////////////////////////////////////////////////////////////////////////
@@ -52,28 +58,33 @@ bool InputMethodMus::OnUntranslatedIMEMessage(const base::NativeEvent& event,
}
void InputMethodMus::DispatchKeyEvent(ui::KeyEvent* event) {
+ DispatchKeyEvent(
+ event,
+ std::unique_ptr<base::Callback<void(EventResult)>>(
+ new base::Callback<void(EventResult)>(base::Bind(&DoNothing))));
sadrul 2016/10/13 16:36:29 Send nullptr instead?
+}
+
+void InputMethodMus::DispatchKeyEvent(
+ ui::KeyEvent* event,
+ std::unique_ptr<base::Callback<void(EventResult)>> ack_callback) {
DCHECK(event->type() == ui::ET_KEY_PRESSED ||
event->type() == ui::ET_KEY_RELEASED);
// If no text input client, do nothing.
if (!GetTextInputClient()) {
ignore_result(DispatchKeyEventPostIME(event));
+ ack_callback->Run(event->handled() ? EventResult::HANDLED
+ : EventResult::UNHANDLED);
return;
}
- // TODO(moshayedi): crbug.com/641355. Currently if we stop propagation of
- // non-char events here, accelerators ddn't work. This is because we send the
- // event ack too early in NativeWidgetMus. We should send both char and
- // non-char events to the IME driver once we fix this.
- if (event->is_char()) {
- // IME driver will notify the text input client if it is not interested in
- // event, which in turn will call DispatchKeyEventPostIME().
- input_method_->ProcessKeyEvent(ui::Event::Clone(*event));
- event->StopPropagation();
- return;
- }
-
- ignore_result(DispatchKeyEventPostIME(event));
+ // 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)));
}
void InputMethodMus::OnTextInputTypeChanged(const ui::TextInputClient* client) {
@@ -114,7 +125,7 @@ void InputMethodMus::OnDidChangeFocusedClient(
InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
UpdateTextInputType();
- text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused, this);
+ text_input_client_ = base::MakeUnique<TextInputClientImpl>(focused);
ime_server_->StartSession(text_input_client_->CreateInterfacePtrAndBind(),
GetProxy(&input_method_));
}
@@ -131,4 +142,23 @@ 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) {
+ // If not handled by IME, try dispatching the event to delegate to see if
+ // any client-side post-ime processing needs to be done. This includes cases
+ // like backspace, return key, etc.
+ std::unique_ptr<ui::Event> event_clone = ui::Event::Clone(event);
+ ignore_result(DispatchKeyEventPostIME(event_clone->AsKeyEvent()));
+ event_result =
+ event_clone->handled() ? EventResult::HANDLED : EventResult::UNHANDLED;
+ } else {
+ event_result = EventResult::HANDLED;
+ }
+ ack_callback->Run(event_result);
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698