| 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_linux_x11.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 InputMethodLinuxX11::InputMethodLinuxX11( | 14 InputMethodAuraLinux::InputMethodAuraLinux( |
| 15 internal::InputMethodDelegate* delegate) { | 15 internal::InputMethodDelegate* delegate) { |
| 16 SetDelegate(delegate); | 16 SetDelegate(delegate); |
| 17 } | 17 } |
| 18 | 18 |
| 19 InputMethodLinuxX11::~InputMethodLinuxX11() {} | 19 InputMethodAuraLinux::~InputMethodAuraLinux() {} |
| 20 | 20 |
| 21 // static | 21 // static |
| 22 void InputMethodLinuxX11::Initialize() { | 22 void InputMethodAuraLinux::Initialize() { |
| 23 #if (USE_X11) |
| 23 // Force a IBus IM context to run in synchronous mode. | 24 // Force a IBus IM context to run in synchronous mode. |
| 24 // | 25 // |
| 25 // Background: IBus IM context runs by default in asynchronous mode. In | 26 // Background: IBus IM context runs by default in asynchronous mode. In |
| 26 // this mode, gtk_im_context_filter_keypress() consumes all the key events | 27 // this mode, gtk_im_context_filter_keypress() consumes all the key events |
| 27 // and returns true while asynchronously sending the event to an underlying | 28 // and returns true while asynchronously sending the event to an underlying |
| 28 // IME implementation. When the event has not actually been consumed by | 29 // IME implementation. When the event has not actually been consumed by |
| 29 // the underlying IME implementation, the context pushes the event back to | 30 // the underlying IME implementation, the context pushes the event back to |
| 30 // the GDK event queue marking the event as already handled by the IBus IM | 31 // the GDK event queue marking the event as already handled by the IBus IM |
| 31 // context. | 32 // context. |
| 32 // | 33 // |
| 33 // The problem here is that those pushed-back GDK events are never handled | 34 // The problem here is that those pushed-back GDK events are never handled |
| 34 // when base::MessagePumpX11 is used, which only handles X events. So, we | 35 // when base::MessagePumpX11 is used, which only handles X events. So, we |
| 35 // make a IBus IM context run in synchronous mode by setting an environment | 36 // make a IBus IM context run in synchronous mode by setting an environment |
| 36 // variable. This is only the interface to change the mode. | 37 // variable. This is only the interface to change the mode. |
| 37 // | 38 // |
| 38 // Another possible solution is to use GDK event loop instead of X event | 39 // Another possible solution is to use GDK event loop instead of X event |
| 39 // loop. | 40 // loop. |
| 40 // | 41 // |
| 41 // Since there is no reentrant version of setenv(3C), it's a caller's duty | 42 // Since there is no reentrant version of setenv(3C), it's a caller's duty |
| 42 // to avoid race conditions. This function should be called in the main | 43 // to avoid race conditions. This function should be called in the main |
| 43 // thread on a very early stage, and supposed to be called from | 44 // thread on a very early stage, and supposed to be called from |
| 44 // ui::InitializeInputMethod(). | 45 // ui::InitializeInputMethod(). |
| 45 scoped_ptr<base::Environment> env(base::Environment::Create()); | 46 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 46 env->SetVar("IBUS_ENABLE_SYNC_MODE", "1"); | 47 env->SetVar("IBUS_ENABLE_SYNC_MODE", "1"); |
| 48 #endif |
| 47 } | 49 } |
| 48 | 50 |
| 49 // Overriden from InputMethod. | 51 // Overriden from InputMethod. |
| 50 | 52 |
| 51 void InputMethodLinuxX11::Init(bool focused) { | 53 void InputMethodAuraLinux::Init(bool focused) { |
| 52 CHECK(LinuxInputMethodContextFactory::instance()); | 54 CHECK(LinuxInputMethodContextFactory::instance()); |
| 53 input_method_context_ = | 55 input_method_context_ = |
| 54 LinuxInputMethodContextFactory::instance()->CreateInputMethodContext( | 56 LinuxInputMethodContextFactory::instance()->CreateInputMethodContext( |
| 55 this); | 57 this); |
| 56 CHECK(input_method_context_.get()); | 58 CHECK(input_method_context_.get()); |
| 57 | 59 |
| 58 InputMethodBase::Init(focused); | 60 InputMethodBase::Init(focused); |
| 59 | 61 |
| 60 if (focused) { | 62 if (focused) { |
| 61 input_method_context_->OnTextInputTypeChanged( | 63 input_method_context_->OnTextInputTypeChanged( |
| 62 GetTextInputClient() ? | 64 GetTextInputClient() ? |
| 63 GetTextInputClient()->GetTextInputType() : | 65 GetTextInputClient()->GetTextInputType() : |
| 64 TEXT_INPUT_TYPE_TEXT); | 66 TEXT_INPUT_TYPE_TEXT); |
| 65 } | 67 } |
| 66 } | 68 } |
| 67 | 69 |
| 68 bool InputMethodLinuxX11::OnUntranslatedIMEMessage( | 70 bool InputMethodAuraLinux::OnUntranslatedIMEMessage( |
| 69 const base::NativeEvent& event, | 71 const base::NativeEvent& event, |
| 70 NativeEventResult* result) { | 72 NativeEventResult* result) { |
| 71 return false; | 73 return false; |
| 72 } | 74 } |
| 73 | 75 |
| 74 bool InputMethodLinuxX11::DispatchKeyEvent(const ui::KeyEvent& event) { | 76 bool InputMethodAuraLinux::DispatchKeyEvent(const ui::KeyEvent& event) { |
| 75 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); | 77 DCHECK(event.type() == ET_KEY_PRESSED || event.type() == ET_KEY_RELEASED); |
| 76 DCHECK(system_toplevel_window_focused()); | 78 DCHECK(system_toplevel_window_focused()); |
| 77 | 79 |
| 78 // If no text input client, do nothing. | 80 // If no text input client, do nothing. |
| 79 if (!GetTextInputClient()) | 81 if (!GetTextInputClient()) |
| 80 return DispatchKeyEventPostIME(event); | 82 return DispatchKeyEventPostIME(event); |
| 81 | 83 |
| 82 // Let an IME handle the key event first. | 84 // Let an IME handle the key event first. |
| 83 if (input_method_context_->DispatchKeyEvent(event)) { | 85 if (input_method_context_->DispatchKeyEvent(event)) { |
| 84 if (event.type() == ET_KEY_PRESSED) { | 86 if (event.type() == ET_KEY_PRESSED) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 96 if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) { | 98 if (event.type() == ET_KEY_PRESSED && GetTextInputClient()) { |
| 97 const uint16 ch = event.GetCharacter(); | 99 const uint16 ch = event.GetCharacter(); |
| 98 if (ch) { | 100 if (ch) { |
| 99 GetTextInputClient()->InsertChar(ch, event.flags()); | 101 GetTextInputClient()->InsertChar(ch, event.flags()); |
| 100 return true; | 102 return true; |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 return handled; | 105 return handled; |
| 104 } | 106 } |
| 105 | 107 |
| 106 void InputMethodLinuxX11::OnTextInputTypeChanged( | 108 void InputMethodAuraLinux::OnTextInputTypeChanged( |
| 107 const TextInputClient* client) { | 109 const TextInputClient* client) { |
| 108 if (!IsTextInputClientFocused(client)) | 110 if (!IsTextInputClientFocused(client)) |
| 109 return; | 111 return; |
| 110 input_method_context_->Reset(); | 112 input_method_context_->Reset(); |
| 111 // TODO(yoichio): Support inputmode HTML attribute. | 113 // TODO(yoichio): Support inputmode HTML attribute. |
| 112 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType()); | 114 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType()); |
| 113 } | 115 } |
| 114 | 116 |
| 115 void InputMethodLinuxX11::OnCaretBoundsChanged(const TextInputClient* client) { | 117 void InputMethodAuraLinux::OnCaretBoundsChanged(const TextInputClient* client) { |
| 116 if (!IsTextInputClientFocused(client)) | 118 if (!IsTextInputClientFocused(client)) |
| 117 return; | 119 return; |
| 118 input_method_context_->OnCaretBoundsChanged( | 120 input_method_context_->OnCaretBoundsChanged( |
| 119 GetTextInputClient()->GetCaretBounds()); | 121 GetTextInputClient()->GetCaretBounds()); |
| 120 } | 122 } |
| 121 | 123 |
| 122 void InputMethodLinuxX11::CancelComposition(const TextInputClient* client) { | 124 void InputMethodAuraLinux::CancelComposition(const TextInputClient* client) { |
| 123 if (!IsTextInputClientFocused(client)) | 125 if (!IsTextInputClientFocused(client)) |
| 124 return; | 126 return; |
| 125 input_method_context_->Reset(); | 127 input_method_context_->Reset(); |
| 126 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType()); | 128 input_method_context_->OnTextInputTypeChanged(client->GetTextInputType()); |
| 127 } | 129 } |
| 128 | 130 |
| 129 void InputMethodLinuxX11::OnInputLocaleChanged() { | 131 void InputMethodAuraLinux::OnInputLocaleChanged() { |
| 130 } | 132 } |
| 131 | 133 |
| 132 std::string InputMethodLinuxX11::GetInputLocale() { | 134 std::string InputMethodAuraLinux::GetInputLocale() { |
| 133 return ""; | 135 return ""; |
| 134 } | 136 } |
| 135 | 137 |
| 136 base::i18n::TextDirection InputMethodLinuxX11::GetInputTextDirection() { | 138 base::i18n::TextDirection InputMethodAuraLinux::GetInputTextDirection() { |
| 137 return input_method_context_->GetInputTextDirection(); | 139 return input_method_context_->GetInputTextDirection(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 bool InputMethodLinuxX11::IsActive() { | 142 bool InputMethodAuraLinux::IsActive() { |
| 141 // InputMethodLinuxX11 is always ready and up. | 143 // InputMethodAuraLinux is always ready and up. |
| 142 return true; | 144 return true; |
| 143 } | 145 } |
| 144 | 146 |
| 145 bool InputMethodLinuxX11::IsCandidatePopupOpen() const { | 147 bool InputMethodAuraLinux::IsCandidatePopupOpen() const { |
| 146 // There seems no way to detect candidate windows or any popups. | 148 // There seems no way to detect candidate windows or any popups. |
| 147 return false; | 149 return false; |
| 148 } | 150 } |
| 149 | 151 |
| 150 // Overriden from ui::LinuxInputMethodContextDelegate | 152 // Overriden from ui::LinuxInputMethodContextDelegate |
| 151 | 153 |
| 152 void InputMethodLinuxX11::OnCommit(const base::string16& text) { | 154 void InputMethodAuraLinux::OnCommit(const base::string16& text) { |
| 153 TextInputClient* text_input_client = GetTextInputClient(); | 155 TextInputClient* text_input_client = GetTextInputClient(); |
| 154 if (text_input_client) | 156 if (text_input_client) |
| 155 text_input_client->InsertText(text); | 157 text_input_client->InsertText(text); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void InputMethodLinuxX11::OnPreeditChanged( | 160 void InputMethodAuraLinux::OnPreeditChanged( |
| 159 const CompositionText& composition_text) { | 161 const CompositionText& composition_text) { |
| 160 TextInputClient* text_input_client = GetTextInputClient(); | 162 TextInputClient* text_input_client = GetTextInputClient(); |
| 161 if (text_input_client) | 163 if (text_input_client) |
| 162 text_input_client->SetCompositionText(composition_text); | 164 text_input_client->SetCompositionText(composition_text); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void InputMethodLinuxX11::OnPreeditEnd() { | 167 void InputMethodAuraLinux::OnPreeditEnd() { |
| 166 TextInputClient* text_input_client = GetTextInputClient(); | 168 TextInputClient* text_input_client = GetTextInputClient(); |
| 167 if (text_input_client && text_input_client->HasCompositionText()) | 169 if (text_input_client && text_input_client->HasCompositionText()) |
| 168 text_input_client->ClearCompositionText(); | 170 text_input_client->ClearCompositionText(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void InputMethodLinuxX11::OnPreeditStart() {} | 173 void InputMethodAuraLinux::OnPreeditStart() {} |
| 172 | 174 |
| 173 // Overridden from InputMethodBase. | 175 // Overridden from InputMethodBase. |
| 174 | 176 |
| 175 void InputMethodLinuxX11::OnDidChangeFocusedClient( | 177 void InputMethodAuraLinux::OnDidChangeFocusedClient( |
| 176 TextInputClient* focused_before, | 178 TextInputClient* focused_before, |
| 177 TextInputClient* focused) { | 179 TextInputClient* focused) { |
| 178 input_method_context_->Reset(); | 180 input_method_context_->Reset(); |
| 179 input_method_context_->OnTextInputTypeChanged( | 181 input_method_context_->OnTextInputTypeChanged( |
| 180 focused ? focused->GetTextInputType() : TEXT_INPUT_TYPE_NONE); | 182 focused ? focused->GetTextInputType() : TEXT_INPUT_TYPE_NONE); |
| 181 | 183 |
| 182 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); | 184 InputMethodBase::OnDidChangeFocusedClient(focused_before, focused); |
| 183 } | 185 } |
| 184 | 186 |
| 185 } // namespace ui | 187 } // namespace ui |
| OLD | NEW |