Commit be062302 authored by azurewei's avatar azurewei Committed by Commit bot

When there is an IME extension listening on input.ime.onKeyEvent, the key...

When there is an IME extension listening on input.ime.onKeyEvent, the key event will be passed to the extension before the OS handling it, and  ProcessKeyEventDone() will be called after the extension calls input.ime.keyEventHandled.

When users texting fast, the callback method of ProcessKeyEventDone() may be excused in different orders. The current implementation has bugs as the variables in system such as |composition_changed_| and |result_text_| will be changed when input.ime.keyEventHandled trys to run the callback.

This bug only occurs on Linux as there are two keydown/keyup events generated when pressing/releasing the key and only one event is passed to the extension.

This CL fixes this bug by adding helper function ProcessKeyEventByEngineDone() in InputMethodAuraLinux to recover the passed environment.

BUG=517773
TEST=None

Review URL: https://codereview.chromium.org/1801363005

Cr-Commit-Position: refs/heads/master@{#381671}
parent a8b4521d
......@@ -104,16 +104,31 @@ void InputMethodAuraLinux::DispatchKeyEvent(ui::KeyEvent* event) {
if (text_input_type_ != TEXT_INPUT_TYPE_PASSWORD &&
GetEngine() && GetEngine()->IsInterestedInKeyEvent() &&
(!filtered || NeedInsertChar())) {
ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback =
base::Bind(&InputMethodAuraLinux::ProcessKeyEventDone,
weak_ptr_factory_.GetWeakPtr(),
base::Owned(new ui::KeyEvent(*event)), filtered);
ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = base::Bind(
&InputMethodAuraLinux::ProcessKeyEventByEngineDone,
weak_ptr_factory_.GetWeakPtr(), base::Owned(new ui::KeyEvent(*event)),
filtered, composition_changed_,
base::Owned(new ui::CompositionText(composition_)),
base::Owned(new base::string16(result_text_)));
GetEngine()->ProcessKeyEvent(*event, callback);
} else {
ProcessKeyEventDone(event, filtered, false);
}
}
void InputMethodAuraLinux::ProcessKeyEventByEngineDone(
ui::KeyEvent* event,
bool filtered,
bool composition_changed,
ui::CompositionText* composition,
base::string16* result_text,
bool is_handled) {
composition_changed_ = composition_changed;
composition_.CopyFrom(*composition);
result_text_ = *result_text;
ProcessKeyEventDone(event, filtered, is_handled);
}
void InputMethodAuraLinux::ProcessKeyEventDone(ui::KeyEvent* event,
bool filtered,
bool is_handled) {
......
......@@ -57,9 +57,22 @@ class UI_BASE_IME_EXPORT InputMethodAuraLinux
void UpdateContextFocusState();
void ResetContext();
// Callback function for IMEEngineHandlerInterface::ProcessKeyEvent.
// Processes the key event after the event is processed by the system IME or
// the extension.
void ProcessKeyEventDone(ui::KeyEvent* event, bool filtered, bool is_handled);
// Callback function for IMEEngineHandlerInterface::ProcessKeyEvent().
// It recovers the context when the event is being passed to the extension and
// call ProcessKeyEventDone() for the following processing. This is necessary
// as this method is async. The environment may be changed by other generated
// key events by the time the callback is run.
void ProcessKeyEventByEngineDone(ui::KeyEvent* event,
bool filtered,
bool composition_changed,
ui::CompositionText* composition,
base::string16* result_text,
bool is_handled);
scoped_ptr<LinuxInputMethodContext> context_;
scoped_ptr<LinuxInputMethodContext> context_simple_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment