Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/base/ime/input_method_auralinux.h" | 5 #include "ui/base/ime/input_method_auralinux.h" |
| 6 | 6 |
| 7 #include "base/environment.h" | 7 #include "base/environment.h" |
| 8 #include "ui/base/ime/linux/linux_input_method_context_factory.h" | 8 #include "ui/base/ime/linux/linux_input_method_context_factory.h" |
| 9 #include "ui/base/ime/text_input_client.h" | 9 #include "ui/base/ime/text_input_client.h" |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| 11 | 11 |
| 12 namespace ui { | 12 namespace ui { |
| 13 | 13 |
| 14 InputMethodAuraLinux::InputMethodAuraLinux( | 14 InputMethodAuraLinux::InputMethodAuraLinux( |
| 15 internal::InputMethodDelegate* delegate) { | 15 internal::InputMethodDelegate* delegate) |
| 16 : allowed_to_fire_vkey_process_key_(false), vkey_processkey_flags_(0) { | |
| 16 SetDelegate(delegate); | 17 SetDelegate(delegate); |
| 17 } | 18 } |
| 18 | 19 |
| 19 InputMethodAuraLinux::~InputMethodAuraLinux() {} | 20 InputMethodAuraLinux::~InputMethodAuraLinux() {} |
| 20 | 21 |
| 21 // Overriden from InputMethod. | 22 // Overriden from InputMethod. |
| 22 | 23 |
| 23 void InputMethodAuraLinux::Init(bool focused) { | 24 void InputMethodAuraLinux::Init(bool focused) { |
| 24 CHECK(LinuxInputMethodContextFactory::instance()) | 25 CHECK(LinuxInputMethodContextFactory::instance()) |
| 25 << "This failure was likely caused because " | 26 << "This failure was likely caused because " |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 43 bool InputMethodAuraLinux::OnUntranslatedIMEMessage( | 44 bool InputMethodAuraLinux::OnUntranslatedIMEMessage( |
| 44 const base::NativeEvent& event, | 45 const base::NativeEvent& event, |
| 45 NativeEventResult* result) { | 46 NativeEventResult* result) { |
| 46 return false; | 47 return false; |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { | 50 bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { |
| 50 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); | 51 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); |
| 51 DCHECK(system_toplevel_window_focused()); | 52 DCHECK(system_toplevel_window_focused()); |
| 52 | 53 |
| 54 // In order to not dispatch key events out of order, stop firing a | |
| 55 // VKEY_PROCESSKEY key event once a new key event arrives. | |
| 56 StopFiringProcessKey(); | |
|
Seigo Nonaka
2014/05/14 04:15:03
I'm bit confused about this. What's happened in th
Yuki
2014/05/14 06:30:23
Exactly speaking, since we don't allow to fire VKE
Seigo Nonaka
2014/05/14 14:01:37
Hmm, okay...
Could you double check if the other
Yuki
2014/05/16 14:22:27
Done. I've tested this with XIM, SCIM and IBus.
| |
| 57 | |
| 53 // If no text input client, do nothing. | 58 // If no text input client, do nothing. |
| 54 if (!GetTextInputClient()) | 59 if (!GetTextInputClient()) |
| 55 return DispatchKeyEventPostIME(event); | 60 return DispatchKeyEventPostIME(event); |
| 56 | 61 |
| 57 // Let an IME handle the key event first. | 62 // Let an IME handle the key event first. |
| 58 if (input_method_context_->DispatchKeyEvent(event)) { | 63 if (event.type() == ET_KEY_PRESSED && |
| 59 if (event.type() == ET_KEY_PRESSED && | 64 (event.flags() & ui::EF_IME_FABRICATED_KEY) == 0) |
| 60 (event.flags() & ui::EF_IME_FABRICATED_KEY) == 0) { | 65 AllowToFireProcessKey(event); |
| 61 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, | 66 if (input_method_context_->DispatchKeyEvent(event)) |
| 62 VKEY_PROCESSKEY, | |
| 63 event.flags(), | |
| 64 false); // is_char | |
| 65 DispatchKeyEventPostIME(fabricated_event); | |
| 66 } | |
| 67 return true; | 67 return true; |
| 68 } | 68 StopFiringProcessKey(); |
| 69 | 69 |
| 70 // Otherwise, insert the character. | 70 // Otherwise, insert the character. |
| 71 const bool handled = DispatchKeyEventPostIME(event); | 71 const bool handled = DispatchKeyEventPostIME(event); |
| 72 if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) { | 72 if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) { |
| 73 const uint16 ch = event.GetCharacter(); | 73 const uint16 ch = event.GetCharacter(); |
| 74 if (ch) { | 74 if (ch) { |
| 75 GetTextInputClient()->InsertChar(ch, event.flags()); | 75 GetTextInputClient()->InsertChar(ch, event.flags()); |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 } | 78 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 bool InputMethodAuraLinux::IsCandidatePopupOpen() const { | 117 bool InputMethodAuraLinux::IsCandidatePopupOpen() const { |
| 118 // There seems no way to detect candidate windows or any popups. | 118 // There seems no way to detect candidate windows or any popups. |
| 119 return false; | 119 return false; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Overriden from ui::LinuxInputMethodContextDelegate | 122 // Overriden from ui::LinuxInputMethodContextDelegate |
| 123 | 123 |
| 124 void InputMethodAuraLinux::OnCommit(const base::string16& text) { | 124 void InputMethodAuraLinux::OnCommit(const base::string16& text) { |
| 125 if (!IsTextInputTypeNone()) | 125 if (!IsTextInputTypeNone()) |
| 126 GetTextInputClient()->InsertText(text); | 126 GetTextInputClient()->InsertText(text); |
| 127 MaybeFireProcessKey(); | |
| 127 } | 128 } |
| 128 | 129 |
| 129 void InputMethodAuraLinux::OnPreeditChanged( | 130 void InputMethodAuraLinux::OnPreeditChanged( |
| 130 const CompositionText& composition_text) { | 131 const CompositionText& composition_text) { |
| 131 TextInputClient* text_input_client = GetTextInputClient(); | 132 TextInputClient* text_input_client = GetTextInputClient(); |
| 132 if (text_input_client) | 133 if (text_input_client) |
| 133 text_input_client->SetCompositionText(composition_text); | 134 text_input_client->SetCompositionText(composition_text); |
| 135 MaybeFireProcessKey(); | |
| 134 } | 136 } |
| 135 | 137 |
| 136 void InputMethodAuraLinux::OnPreeditEnd() { | 138 void InputMethodAuraLinux::OnPreeditEnd() { |
| 137 TextInputClient* text_input_client = GetTextInputClient(); | 139 TextInputClient* text_input_client = GetTextInputClient(); |
| 138 if (text_input_client && text_input_client->HasCompositionText()) | 140 if (text_input_client && text_input_client->HasCompositionText()) |
| 139 text_input_client->ClearCompositionText(); | 141 text_input_client->ClearCompositionText(); |
| 142 MaybeFireProcessKey(); | |
| 140 } | 143 } |
| 141 | 144 |
| 142 void InputMethodAuraLinux::OnPreeditStart() {} | 145 void InputMethodAuraLinux::OnPreeditStart() { |
| 146 MaybeFireProcessKey(); | |
| 147 } | |
| 143 | 148 |
| 144 // Overridden from InputMethodBase. | 149 // Overridden from InputMethodBase. |
| 145 | 150 |
| 146 void InputMethodAuraLinux::OnDidChangeFocusedClient( | 151 void InputMethodAuraLinux::OnDidChangeFocusedClient( |
| 147 TextInputClient* focused_before, | 152 TextInputClient* focused_before, |
| 148 TextInputClient* focused) { | 153 TextInputClient* focused) { |
| 149 input_method_context_->Reset(); | 154 input_method_context_->Reset(); |
| 150 input_method_context_->OnTextInputTypeChanged( | 155 input_method_context_->OnTextInputTypeChanged( |
| 151 focused ? focused->GetTextInputType() : TEXT_INPUT_TYPE_NONE); | 156 focused ? focused->GetTextInputType() : TEXT_INPUT_TYPE_NONE); |
| 152 | 157 |
| 153 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | 158 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
| 154 } | 159 } |
| 155 | 160 |
| 161 // Helper functions to support VKEY_PROCESSKEY. | |
| 162 | |
| 163 void InputMethodAuraLinux::AllowToFireProcessKey(const ui::KeyEvent& event) { | |
| 164 allowed_to_fire_vkey_process_key_ = true; | |
| 165 vkey_processkey_flags_ = event.flags(); | |
| 166 } | |
| 167 | |
| 168 void InputMethodAuraLinux::MaybeFireProcessKey() { | |
| 169 if (allowed_to_fire_vkey_process_key_) { | |
|
Seigo Nonaka
2014/05/14 04:15:03
nit: I like early exit style but up to you.
Yuki
2014/05/14 06:30:23
I prefer early exit, too.
| |
| 170 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, | |
| 171 VKEY_PROCESSKEY, | |
| 172 vkey_processkey_flags_, | |
| 173 false); // is_char | |
| 174 DispatchKeyEventPostIME(fabricated_event); | |
| 175 StopFiringProcessKey(); | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 void InputMethodAuraLinux::StopFiringProcessKey() { | |
| 180 allowed_to_fire_vkey_process_key_ = false; | |
| 181 vkey_processkey_flags_ = 0; | |
| 182 } | |
| 183 | |
| 156 } // namespace ui | 184 } // namespace ui |
| OLD | NEW |