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 7db88b6298a3aba4b56d8eff5902250e1a2f00de..33de60cd445b25a1de89da760949b06afdd970c6 100644 |
--- a/ui/base/ime/input_method_win.cc |
+++ b/ui/base/ime/input_method_win.cc |
@@ -32,8 +32,7 @@ InputMethodWin::InputMethodWin(internal::InputMethodDelegate* delegate, |
accept_carriage_return_(false), |
enabled_(false), |
is_candidate_popup_open_(false), |
- composing_window_handle_(NULL), |
- suppress_next_char_(false) { |
+ composing_window_handle_(NULL) { |
SetDelegate(delegate); |
} |
@@ -104,9 +103,38 @@ void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { |
return; |
} |
+ std::vector<MSG> char_msgs; |
const base::NativeEvent& native_key_event = event->native_event(); |
+ // Peek & remove the following messages in the message queue. |
+ // - WM_CHAR (0x0102) |
+ // - WM_DEADCHAR (0x0103) |
+ // - WM_SYSCHAR (0x0106) |
+ // - WM_SYSDEADCHAR (0x0107) |
+ // And only process WM_CHAR & WM_SYSCHAR message in browser. |
+ // This is to combine 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); |
+ } |
+ |
+ BOOL handled = FALSE; |
if (native_key_event.message == WM_CHAR) { |
- BOOL handled; |
OnChar(native_key_event.hwnd, native_key_event.message, |
native_key_event.wParam, native_key_event.lParam, &handled); |
if (handled) |
@@ -137,8 +165,15 @@ void InputMethodWin::DispatchKeyEvent(ui::KeyEvent* event) { |
} |
ui::EventDispatchDetails details = DispatchKeyEventPostIME(event); |
- if (!details.dispatcher_destroyed) |
- suppress_next_char_ = event->stopped_propagation(); |
+ if (details.dispatcher_destroyed || details.target_destroyed || |
+ event->stopped_propagation()) { |
+ return; |
+ } |
+ |
+ for (size_t i = 0; i < char_msgs.size(); ++i) { |
+ msg = char_msgs[i]; |
+ OnChar(msg.hwnd, msg.message, msg.wParam, msg.lParam, &handled); |
+ } |
} |
void InputMethodWin::OnTextInputTypeChanged(const TextInputClient* client) { |
@@ -224,11 +259,6 @@ LRESULT InputMethodWin::OnChar(HWND window_handle, |
*handled = TRUE; |
- if (suppress_next_char_) { |
- suppress_next_char_ = false; |
- return 0; |
- } |
- |
// We need to send character events to the focused text input client event if |
// its text input type is ui::TEXT_INPUT_TYPE_NONE. |
if (GetTextInputClient()) { |
@@ -587,10 +617,6 @@ bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { |
void InputMethodWin::DispatchFabricatedKeyEvent(ui::KeyEvent* event) { |
if (event->is_char()) { |
- if (suppress_next_char_) { |
- suppress_next_char_ = false; |
- return; |
- } |
if (GetTextInputClient()) { |
GetTextInputClient()->InsertChar( |
static_cast<base::char16>(event->key_code()), |