Fixes the timing to dispatch VKEY_PROCESSKEY.

Defers the dicision to dispatch a VKEY_PROCESSKEY key event until the preedit changes or the text gets committed.

BUG=368100
TEST=Done manually.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271363 0039d316-1c4b-4281-b951-d872f2087c98
parent 58490647
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
namespace ui { namespace ui {
InputMethodAuraLinux::InputMethodAuraLinux( InputMethodAuraLinux::InputMethodAuraLinux(
internal::InputMethodDelegate* delegate) { internal::InputMethodDelegate* delegate)
: allowed_to_fire_vkey_process_key_(false), vkey_processkey_flags_(0) {
SetDelegate(delegate); SetDelegate(delegate);
} }
...@@ -54,18 +55,15 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { ...@@ -54,18 +55,15 @@ bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) {
if (!GetTextInputClient()) if (!GetTextInputClient())
return DispatchKeyEventPostIME(event); return DispatchKeyEventPostIME(event);
// Let an IME handle the key event first. // Let an IME handle the key event first, and allow to fire a VKEY_PROCESSKEY
if (input_method_context_->DispatchKeyEvent(event)) { // event for keydown events. Note that DOM Level 3 Events Sepc requires that
if (event.type() == ET_KEY_PRESSED && // only keydown events fire keyCode=229 events and not for keyup events.
(event.flags() & ui::EF_IME_FABRICATED_KEY) == 0) { if (event.type() == ET_KEY_PRESSED &&
const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, (event.flags() & ui::EF_IME_FABRICATED_KEY) == 0)
VKEY_PROCESSKEY, AllowToFireProcessKey(event);
event.flags(), if (input_method_context_->DispatchKeyEvent(event))
false); // is_char
DispatchKeyEventPostIME(fabricated_event);
}
return true; return true;
} StopFiringProcessKey();
// Otherwise, insert the character. // Otherwise, insert the character.
const bool handled = DispatchKeyEventPostIME(event); const bool handled = DispatchKeyEventPostIME(event);
...@@ -122,24 +120,29 @@ bool InputMethodAuraLinux::IsCandidatePopupOpen() const { ...@@ -122,24 +120,29 @@ bool InputMethodAuraLinux::IsCandidatePopupOpen() const {
// Overriden from ui::LinuxInputMethodContextDelegate // Overriden from ui::LinuxInputMethodContextDelegate
void InputMethodAuraLinux::OnCommit(const base::string16& text) { void InputMethodAuraLinux::OnCommit(const base::string16& text) {
MaybeFireProcessKey();
if (!IsTextInputTypeNone()) if (!IsTextInputTypeNone())
GetTextInputClient()->InsertText(text); GetTextInputClient()->InsertText(text);
} }
void InputMethodAuraLinux::OnPreeditChanged( void InputMethodAuraLinux::OnPreeditChanged(
const CompositionText& composition_text) { const CompositionText& composition_text) {
MaybeFireProcessKey();
TextInputClient* text_input_client = GetTextInputClient(); TextInputClient* text_input_client = GetTextInputClient();
if (text_input_client) if (text_input_client)
text_input_client->SetCompositionText(composition_text); text_input_client->SetCompositionText(composition_text);
} }
void InputMethodAuraLinux::OnPreeditEnd() { void InputMethodAuraLinux::OnPreeditEnd() {
MaybeFireProcessKey();
TextInputClient* text_input_client = GetTextInputClient(); TextInputClient* text_input_client = GetTextInputClient();
if (text_input_client && text_input_client->HasCompositionText()) if (text_input_client && text_input_client->HasCompositionText())
text_input_client->ClearCompositionText(); text_input_client->ClearCompositionText();
} }
void InputMethodAuraLinux::OnPreeditStart() {} void InputMethodAuraLinux::OnPreeditStart() {
MaybeFireProcessKey();
}
// Overridden from InputMethodBase. // Overridden from InputMethodBase.
...@@ -153,4 +156,28 @@ void InputMethodAuraLinux::OnDidChangeFocusedClient( ...@@ -153,4 +156,28 @@ void InputMethodAuraLinux::OnDidChangeFocusedClient(
InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); InputMethodBase::OnDidChangeFocusedClient(focused_before, focused);
} }
// Helper functions to support VKEY_PROCESSKEY.
void InputMethodAuraLinux::AllowToFireProcessKey(const ui::KeyEvent& event) {
allowed_to_fire_vkey_process_key_ = true;
vkey_processkey_flags_ = event.flags();
}
void InputMethodAuraLinux::MaybeFireProcessKey() {
if (!allowed_to_fire_vkey_process_key_)
return;
const ui::KeyEvent fabricated_event(ET_KEY_PRESSED,
VKEY_PROCESSKEY,
vkey_processkey_flags_,
false); // is_char
DispatchKeyEventPostIME(fabricated_event);
StopFiringProcessKey();
}
void InputMethodAuraLinux::StopFiringProcessKey() {
allowed_to_fire_vkey_process_key_ = false;
vkey_processkey_flags_ = 0;
}
} // namespace ui } // namespace ui
...@@ -45,8 +45,36 @@ class InputMethodAuraLinux : public InputMethodBase, ...@@ -45,8 +45,36 @@ class InputMethodAuraLinux : public InputMethodBase,
virtual void OnDidChangeFocusedClient(TextInputClient* focused_before, virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
TextInputClient* focused) OVERRIDE; TextInputClient* focused) OVERRIDE;
private:
// Allows to fire a VKEY_PROCESSKEY key event.
void AllowToFireProcessKey(const ui::KeyEvent& event);
// Fires a VKEY_PROCESSKEY key event if allowed.
void MaybeFireProcessKey();
// Stops firing VKEY_PROCESSKEY key events.
void StopFiringProcessKey();
scoped_ptr<LinuxInputMethodContext> input_method_context_; scoped_ptr<LinuxInputMethodContext> input_method_context_;
// IBus in async mode eagerly consumes all the key events first regardless of
// whether the underlying IME consumes the key event or not, and makes
// gtk_im_context_filter_keypress() always return true, and later pushes
// the key event back to the GDK event queue when it turns out that the
// underlying IME doesn't consume the key event.
//
// Thus we have to defer a decision whether or not to dispatch a
// VKEY_PROCESSKEY key event. Unlike other InputMethod's subclasses,
// DispatchKeyEvent() in this class does not directly dispatch a
// VKEY_PROCESSKEY event, OnCommit or OnPreedit{Start,Changed,End} dispatch
// a VKEY_PROCESSKEY event instead.
//
// Because of this hack, there could be chances that we accidentally dispatch
// VKEY_PROCESSKEY events and other key events in out of order.
//
// |allowed_to_fire_vkey_process_key_| is used not to dispatch a
// VKEY_PROCESSKEY event twice for a single key event.
bool allowed_to_fire_vkey_process_key_;
int vkey_processkey_flags_;
DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinux); DISALLOW_COPY_AND_ASSIGN(InputMethodAuraLinux);
}; };
......
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