| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_chromeos.h" | 5 #include "ui/base/ime/input_method_chromeos.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cstring> | 10 #include <cstring> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 InputMethodChromeOS::~InputMethodChromeOS() { | 51 InputMethodChromeOS::~InputMethodChromeOS() { |
| 52 ConfirmCompositionText(); | 52 ConfirmCompositionText(); |
| 53 // We are dead, so we need to ask the client to stop relying on us. | 53 // We are dead, so we need to ask the client to stop relying on us. |
| 54 OnInputMethodChanged(); | 54 OnInputMethodChanged(); |
| 55 | 55 |
| 56 if (ui::IMEBridge::Get()) | 56 if (ui::IMEBridge::Get()) |
| 57 ui::IMEBridge::Get()->SetInputContextHandler(NULL); | 57 ui::IMEBridge::Get()->SetInputContextHandler(NULL); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool InputMethodChromeOS::OnUntranslatedIMEMessage( | 60 void InputMethodChromeOS::DispatchKeyEvent( |
| 61 const base::NativeEvent& event, | 61 ui::KeyEvent* event, |
| 62 NativeEventResult* result) { | 62 std::unique_ptr<AckCallback> ack_callback) { |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 void InputMethodChromeOS::ProcessKeyEventDone(ui::KeyEvent* event, | |
| 67 bool is_handled) { | |
| 68 DCHECK(event); | |
| 69 if (event->type() == ET_KEY_PRESSED) { | |
| 70 if (is_handled) { | |
| 71 // IME event has a priority to be handled, so that character composer | |
| 72 // should be reset. | |
| 73 character_composer_.Reset(); | |
| 74 } else { | |
| 75 // If IME does not handle key event, passes keyevent to character composer | |
| 76 // to be able to compose complex characters. | |
| 77 is_handled = ExecuteCharacterComposer(*event); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 if (event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED) | |
| 82 ProcessKeyEventPostIME(event, is_handled); | |
| 83 | |
| 84 handling_key_event_ = false; | |
| 85 } | |
| 86 | |
| 87 void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { | |
| 88 DCHECK(event->IsKeyEvent()); | 63 DCHECK(event->IsKeyEvent()); |
| 89 DCHECK(!(event->flags() & ui::EF_IS_SYNTHESIZED)); | 64 DCHECK(!(event->flags() & ui::EF_IS_SYNTHESIZED)); |
| 90 | 65 |
| 91 // For linux_chromeos, the ime keyboard cannot track the caps lock state by | 66 // For linux_chromeos, the ime keyboard cannot track the caps lock state by |
| 92 // itself, so need to call SetCapsLockEnabled() method to reflect the caps | 67 // itself, so need to call SetCapsLockEnabled() method to reflect the caps |
| 93 // lock state by the key event. | 68 // lock state by the key event. |
| 94 if (!base::SysInfo::IsRunningOnChromeOS()) { | 69 if (!base::SysInfo::IsRunningOnChromeOS()) { |
| 95 chromeos::input_method::InputMethodManager* manager = | 70 chromeos::input_method::InputMethodManager* manager = |
| 96 chromeos::input_method::InputMethodManager::Get(); | 71 chromeos::input_method::InputMethodManager::Get(); |
| 97 if (manager) { | 72 if (manager) { |
| 98 chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); | 73 chromeos::input_method::ImeKeyboard* keyboard = manager->GetImeKeyboard(); |
| 99 if (keyboard && event->type() == ui::ET_KEY_PRESSED) { | 74 if (keyboard && event->type() == ui::ET_KEY_PRESSED) { |
| 100 keyboard->SetCapsLockEnabled((event->key_code() == ui::VKEY_CAPITAL) ? | 75 keyboard->SetCapsLockEnabled((event->key_code() == ui::VKEY_CAPITAL) ? |
| 101 !keyboard->CapsLockIsEnabled() : event->IsCapsLockOn()); | 76 !keyboard->CapsLockIsEnabled() : event->IsCapsLockOn()); |
| 102 } | 77 } |
| 103 } | 78 } |
| 104 } | 79 } |
| 105 | 80 |
| 106 // If |context_| is not usable, then we can only dispatch the key event as is. | 81 // If |context_| is not usable, then we can only dispatch the key event as is. |
| 107 // We only dispatch the key event to input method when the |context_| is an | 82 // We only dispatch the key event to input method when the |context_| is an |
| 108 // normal input field (not a password field). | 83 // normal input field (not a password field). |
| 109 // Note: We need to send the key event to ibus even if the |context_| is not | 84 // Note: We need to send the key event to ibus even if the |context_| is not |
| 110 // enabled, so that ibus can have a chance to enable the |context_|. | 85 // enabled, so that ibus can have a chance to enable the |context_|. |
| 111 if (!IsNonPasswordInputFieldFocused() || !GetEngine()) { | 86 if (!IsNonPasswordInputFieldFocused() || !GetEngine()) { |
| 112 if (event->type() == ET_KEY_PRESSED) { | 87 if (event->type() == ET_KEY_PRESSED) { |
| 113 if (ExecuteCharacterComposer(*event)) { | 88 if (ExecuteCharacterComposer(*event)) { |
| 114 // Treating as PostIME event if character composer handles key event and | 89 // Treating as PostIME event if character composer handles key event and |
| 115 // generates some IME event, | 90 // generates some IME event, |
| 116 ProcessKeyEventPostIME(event, true); | 91 ProcessKeyEventPostIME(event, true); |
| 92 if (ack_callback) |
| 93 ack_callback->Run(true); |
| 117 return; | 94 return; |
| 118 } | 95 } |
| 119 ProcessUnfilteredKeyPressEvent(event); | 96 ProcessUnfilteredKeyPressEvent(event); |
| 120 } else { | 97 } else { |
| 121 ignore_result(DispatchKeyEventPostIME(event)); | 98 ignore_result(DispatchKeyEventPostIME(event)); |
| 122 } | 99 } |
| 100 if (ack_callback) |
| 101 ack_callback->Run(false); |
| 123 return; | 102 return; |
| 124 } | 103 } |
| 125 | 104 |
| 126 handling_key_event_ = true; | 105 handling_key_event_ = true; |
| 127 if (GetEngine()->IsInterestedInKeyEvent()) { | 106 if (GetEngine()->IsInterestedInKeyEvent()) { |
| 128 ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = | 107 ui::IMEEngineHandlerInterface::KeyEventDoneCallback callback = base::Bind( |
| 129 base::Bind(&InputMethodChromeOS::ProcessKeyEventDone, | 108 &InputMethodChromeOS::ProcessKeyEventDone, |
| 130 weak_ptr_factory_.GetWeakPtr(), | 109 weak_ptr_factory_.GetWeakPtr(), |
| 131 // Pass the ownership of the new copied event. | 110 // Pass the ownership of the new copied event. |
| 132 base::Owned(new ui::KeyEvent(*event))); | 111 base::Owned(new ui::KeyEvent(*event)), Passed(&ack_callback)); |
| 133 GetEngine()->ProcessKeyEvent(*event, callback); | 112 GetEngine()->ProcessKeyEvent(*event, callback); |
| 134 } else { | 113 } else { |
| 135 ProcessKeyEventDone(event, false); | 114 ProcessKeyEventDone(event, std::move(ack_callback), false); |
| 136 } | 115 } |
| 137 } | 116 } |
| 138 | 117 |
| 118 bool InputMethodChromeOS::OnUntranslatedIMEMessage( |
| 119 const base::NativeEvent& event, |
| 120 NativeEventResult* result) { |
| 121 return false; |
| 122 } |
| 123 |
| 124 void InputMethodChromeOS::ProcessKeyEventDone( |
| 125 ui::KeyEvent* event, |
| 126 std::unique_ptr<AckCallback> ack_callback, |
| 127 bool is_handled) { |
| 128 DCHECK(event); |
| 129 if (event->type() == ET_KEY_PRESSED) { |
| 130 if (is_handled) { |
| 131 // IME event has a priority to be handled, so that character composer |
| 132 // should be reset. |
| 133 character_composer_.Reset(); |
| 134 } else { |
| 135 // If IME does not handle key event, passes keyevent to character composer |
| 136 // to be able to compose complex characters. |
| 137 is_handled = ExecuteCharacterComposer(*event); |
| 138 } |
| 139 } |
| 140 |
| 141 if (ack_callback) |
| 142 ack_callback->Run(is_handled); |
| 143 |
| 144 if (event->type() == ET_KEY_PRESSED || event->type() == ET_KEY_RELEASED) |
| 145 ProcessKeyEventPostIME(event, is_handled); |
| 146 |
| 147 handling_key_event_ = false; |
| 148 } |
| 149 |
| 150 void InputMethodChromeOS::DispatchKeyEvent(ui::KeyEvent* event) { |
| 151 DispatchKeyEvent(event, nullptr); |
| 152 } |
| 153 |
| 139 void InputMethodChromeOS::OnTextInputTypeChanged( | 154 void InputMethodChromeOS::OnTextInputTypeChanged( |
| 140 const TextInputClient* client) { | 155 const TextInputClient* client) { |
| 141 if (!IsTextInputClientFocused(client)) | 156 if (!IsTextInputClientFocused(client)) |
| 142 return; | 157 return; |
| 143 | 158 |
| 144 UpdateContextFocusState(); | 159 UpdateContextFocusState(); |
| 145 | 160 |
| 146 ui::IMEEngineHandlerInterface* engine = GetEngine(); | 161 ui::IMEEngineHandlerInterface* engine = GetEngine(); |
| 147 if (engine) { | 162 if (engine) { |
| 148 // When focused input client is not changed, a text input type change should | 163 // When focused input client is not changed, a text input type change should |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { | 648 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { |
| 634 TextInputType type = GetTextInputType(); | 649 TextInputType type = GetTextInputType(); |
| 635 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 650 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
| 636 } | 651 } |
| 637 | 652 |
| 638 bool InputMethodChromeOS::IsInputFieldFocused() { | 653 bool InputMethodChromeOS::IsInputFieldFocused() { |
| 639 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; | 654 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; |
| 640 } | 655 } |
| 641 | 656 |
| 642 } // namespace ui | 657 } // namespace ui |
| OLD | NEW |