Chromium Code Reviews| Index: ui/base/ime/input_method_win.cc |
| diff --git a/ui/base/ime/input_method_win.cc b/ui/base/ime/input_method_win.cc |
| index 80a680565e10eee4d551a4aff1f79f5ad9d7fe75..c4624d0d3a70c7f687861fc22e49367d35542dba 100644 |
| --- a/ui/base/ime/input_method_win.cc |
| +++ b/ui/base/ime/input_method_win.cc |
| @@ -100,68 +100,66 @@ bool InputMethodWin::OnUntranslatedIMEMessage( |
| } |
| void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { |
| - if (!event->HasNativeEvent()) { |
| - DispatchFabricatedKeyEvent(event); |
| - return; |
| - } |
| - |
| - const base::NativeEvent& native_key_event = event->native_event(); |
| - BOOL handled = FALSE; |
| - if (native_key_event.message == WM_CHAR) { |
| - OnChar(native_key_event.hwnd, native_key_event.message, |
| - native_key_event.wParam, native_key_event.lParam, native_key_event, |
| - &handled); |
| - if (handled) |
| - event->StopPropagation(); |
| - return; |
| - } |
| - |
| std::vector<MSG> char_msgs; |
| - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kDisableMergeKeyCharEvents)) { |
| - // Combines the WM_KEY* and WM_CHAR messages in the event processing flow |
| - // which is necessary to let Chrome IME extension to process the key event |
| - // and perform corresponding IME actions. |
| - // Chrome IME extension may wants to consume certain key events based on |
| - // the character information of WM_CHAR messages. Holding WM_KEY* messages |
| - // until WM_CHAR is processed by the IME extension is not feasible because |
| - // there is no way to know wether there will or not be a WM_CHAR following |
| - // the WM_KEY*. |
| - // Chrome never handles dead chars so it is safe to remove/ignore |
| - // WM_*DEADCHAR messages. |
| - MSG msg; |
| - while (::PeekMessage(&msg, native_key_event.hwnd, WM_CHAR, WM_DEADCHAR, |
| - PM_REMOVE)) { |
| - if (msg.message == WM_CHAR) |
| - char_msgs.push_back(msg); |
| + if (event->HasNativeEvent()) { |
| + const base::NativeEvent& native_key_event = event->native_event(); |
| + BOOL handled = FALSE; |
| + if (native_key_event.message == WM_CHAR) { |
| + OnChar(native_key_event.hwnd, native_key_event.message, |
| + native_key_event.wParam, native_key_event.lParam, native_key_event, |
| + &handled); |
| + if (handled) |
| + event->StopPropagation(); |
| + return; |
| } |
| - while (::PeekMessage(&msg, native_key_event.hwnd, WM_SYSCHAR, |
| - WM_SYSDEADCHAR, PM_REMOVE)) { |
| - if (msg.message == WM_SYSCHAR) |
| - char_msgs.push_back(msg); |
| + |
| + if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableMergeKeyCharEvents)) { |
| + // Combines the WM_KEY* and WM_CHAR messages in the event processing flow |
| + // which is necessary to let Chrome IME extension to process the key event |
| + // and perform corresponding IME actions. |
| + // Chrome IME extension may wants to consume certain key events based on |
| + // the character information of WM_CHAR messages. Holding WM_KEY* messages |
| + // until WM_CHAR is processed by the IME extension is not feasible because |
| + // there is no way to know wether there will or not be a WM_CHAR following |
| + // the WM_KEY*. |
| + // Chrome never handles dead chars so it is safe to remove/ignore |
| + // WM_*DEADCHAR messages. |
| + MSG msg; |
| + while (::PeekMessage(&msg, native_key_event.hwnd, WM_CHAR, WM_DEADCHAR, |
| + PM_REMOVE)) { |
| + if (msg.message == WM_CHAR) |
| + char_msgs.push_back(msg); |
| + } |
| + while (::PeekMessage(&msg, native_key_event.hwnd, WM_SYSCHAR, |
| + WM_SYSDEADCHAR, PM_REMOVE)) { |
| + if (msg.message == WM_SYSCHAR) |
| + char_msgs.push_back(msg); |
| + } |
| } |
| - } |
| - // Handles ctrl-shift key to change text direction and layout alignment. |
| - if (ui::IMM32Manager::IsRTLKeyboardLayoutInstalled() && |
| - !IsTextInputTypeNone()) { |
| - // TODO: shouldn't need to generate a KeyEvent here. |
| - const ui::KeyEvent key(native_key_event); |
| - ui::KeyboardCode code = key.key_code(); |
| - if (key.type() == ui::ET_KEY_PRESSED) { |
| - if (code == ui::VKEY_SHIFT) { |
| - base::i18n::TextDirection dir; |
| - if (ui::IMM32Manager::IsCtrlShiftPressed(&dir)) |
| - pending_requested_direction_ = dir; |
| - } else if (code != ui::VKEY_CONTROL) { |
| + // Handles ctrl-shift key to change text direction and layout alignment. |
| + if (ui::IMM32Manager::IsRTLKeyboardLayoutInstalled() && |
| + !IsTextInputTypeNone()) { |
| + // TODO: shouldn't need to generate a KeyEvent here. |
| + const ui::KeyEvent key(native_key_event); |
| + ui::KeyboardCode code = key.key_code(); |
| + if (key.type() == ui::ET_KEY_PRESSED) { |
| + if (code == ui::VKEY_SHIFT) { |
| + base::i18n::TextDirection dir; |
| + if (ui::IMM32Manager::IsCtrlShiftPressed(&dir)) |
| + pending_requested_direction_ = dir; |
| + } else if (code != ui::VKEY_CONTROL) { |
| + pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| + } |
| + } else if (key.type() == ui::ET_KEY_RELEASED && |
| + (code == ui::VKEY_SHIFT || code == ui::VKEY_CONTROL) && |
| + pending_requested_direction_ != |
| + base::i18n::UNKNOWN_DIRECTION) { |
| + GetTextInputClient()->ChangeTextDirectionAndLayoutAlignment( |
| + pending_requested_direction_); |
| pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| } |
| - } else if (key.type() == ui::ET_KEY_RELEASED && |
| - (code == ui::VKEY_SHIFT || code == ui::VKEY_CONTROL) && |
| - pending_requested_direction_ != base::i18n::UNKNOWN_DIRECTION) { |
| - GetTextInputClient()->ChangeTextDirectionAndLayoutAlignment( |
| - pending_requested_direction_); |
| - pending_requested_direction_ = base::i18n::UNKNOWN_DIRECTION; |
| } |
| } |
| @@ -201,6 +199,14 @@ void InputMethodWin::ProcessKeyEventDone(ui::KeyEvent* event, |
| return; |
| } |
| + if (char_msgs->empty() && |
|
Shu Chen
2016/03/09 05:50:50
Replaces the condition char_msgs->empty() with eve
|
| + (event->is_char() || event->GetDomKey().IsCharacter()) && |
| + event->type() == ui::ET_KEY_PRESSED && GetTextInputClient()) { |
| + // The key event if from calling input.ime.sendKeyEvent or test. |
| + GetTextInputClient()->InsertChar(*event); |
| + return; |
| + } |
| + |
| BOOL handled; |
| for (const auto& msg : (*char_msgs)) |
| OnChar(msg.hwnd, msg.message, msg.wParam, msg.lParam, msg, &handled); |
| @@ -618,18 +624,6 @@ bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { |
| GetActiveWindow() == toplevel_window_handle_; |
| } |
| -void InputMethodWin::DispatchFabricatedKeyEvent(ui::KeyEvent* event) { |
| - if (event->is_char()) { |
| - if (GetTextInputClient()) { |
| - ui::KeyEvent ch_event(*event); |
| - ch_event.set_character(static_cast<base::char16>(event->key_code())); |
| - GetTextInputClient()->InsertChar(ch_event); |
| - return; |
| - } |
| - } |
| - ignore_result(DispatchKeyEventPostIME(event)); |
| -} |
| - |
| void InputMethodWin::ConfirmCompositionText() { |
| if (composing_window_handle_) |
| imm32_manager_.CleanupComposition(composing_window_handle_); |