OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "ui/base/ime/input_method_win.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 } | 255 } |
256 | 256 |
257 LRESULT InputMethodWin::OnChar(HWND window_handle, | 257 LRESULT InputMethodWin::OnChar(HWND window_handle, |
258 UINT message, | 258 UINT message, |
259 WPARAM wparam, | 259 WPARAM wparam, |
260 LPARAM lparam, | 260 LPARAM lparam, |
261 const base::NativeEvent& event, | 261 const base::NativeEvent& event, |
262 BOOL* handled) { | 262 BOOL* handled) { |
263 *handled = TRUE; | 263 *handled = TRUE; |
264 | 264 |
265 if (!system_toplevel_window_focused()) { | |
266 GetLogCollector()->AddString( | |
267 "Unexpected OnChar: InputMethod is not active. Window focused: "); | |
268 GetLogCollector()->AddBoolean( | |
269 ::GetActiveWindow() == toplevel_window_handle_); | |
270 GetLogCollector()->DumpLogs(); | |
271 // There are random issues that the keyboard typing doesn't work. | |
272 // The root cause might be the InputMethod::OnFocus() is not correctly | |
273 // called when the top-level window is activated | |
274 // (in DNWA::HandleActivationChanged). | |
275 // Calls OnFocus here to unblock the keyboard typing. | |
276 OnFocus(); | |
277 } else { | |
278 GetLogCollector()->ClearLogs(); | |
279 } | |
280 | |
281 // We need to send character events to the focused text input client event if | 265 // We need to send character events to the focused text input client event if |
282 // its text input type is ui::TEXT_INPUT_TYPE_NONE. | 266 // its text input type is ui::TEXT_INPUT_TYPE_NONE. |
283 if (GetTextInputClient()) { | 267 if (GetTextInputClient()) { |
284 const base::char16 kCarriageReturn = L'\r'; | 268 const base::char16 kCarriageReturn = L'\r'; |
285 const base::char16 ch = static_cast<base::char16>(wparam); | 269 const base::char16 ch = static_cast<base::char16>(wparam); |
286 // A mask to determine the previous key state from |lparam|. The value is 1 | 270 // A mask to determine the previous key state from |lparam|. The value is 1 |
287 // if the key is down before the message is sent, or it is 0 if the key is | 271 // if the key is down before the message is sent, or it is 0 if the key is |
288 // up. | 272 // up. |
289 const uint32_t kPrevKeyDownBit = 0x40000000; | 273 const uint32_t kPrevKeyDownBit = 0x40000000; |
290 if (ch == kCarriageReturn && !(lparam & kPrevKeyDownBit)) | 274 if (ch == kCarriageReturn && !(lparam & kPrevKeyDownBit)) |
(...skipping 13 matching lines...) Expand all Loading... |
304 gfx::ShowSystemMenu(window_handle); | 288 gfx::ShowSystemMenu(window_handle); |
305 | 289 |
306 return 0; | 290 return 0; |
307 } | 291 } |
308 | 292 |
309 LRESULT InputMethodWin::OnImeSetContext(HWND window_handle, | 293 LRESULT InputMethodWin::OnImeSetContext(HWND window_handle, |
310 UINT message, | 294 UINT message, |
311 WPARAM wparam, | 295 WPARAM wparam, |
312 LPARAM lparam, | 296 LPARAM lparam, |
313 BOOL* handled) { | 297 BOOL* handled) { |
314 GetLogCollector()->AddString("WM_IME_SETCONTEXT"); | |
315 if (!!wparam) { | 298 if (!!wparam) { |
316 imm32_manager_.CreateImeWindow(window_handle); | 299 imm32_manager_.CreateImeWindow(window_handle); |
317 if (system_toplevel_window_focused()) { | 300 if (system_toplevel_window_focused()) { |
318 // Delay initialize the tsf to avoid perf regression. | 301 // Delay initialize the tsf to avoid perf regression. |
319 // Loading tsf dll causes some time, so doing it in UpdateIMEState() will | 302 // Loading tsf dll causes some time, so doing it in UpdateIMEState() will |
320 // slow down the browser window creation. | 303 // slow down the browser window creation. |
321 // See crbug.com/509984. | 304 // See crbug.com/509984. |
322 tsf_inputscope::InitializeTsfForInputScopes(); | 305 tsf_inputscope::InitializeTsfForInputScopes(); |
323 tsf_inputscope::SetInputScopeForTsfUnawareWindow( | 306 tsf_inputscope::SetInputScopeForTsfUnawareWindow( |
324 toplevel_window_handle_, GetTextInputType(), GetTextInputMode()); | 307 toplevel_window_handle_, GetTextInputType(), GetTextInputMode()); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 enabled_ = true; | 634 enabled_ = true; |
652 break; | 635 break; |
653 } | 636 } |
654 | 637 |
655 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); | 638 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); |
656 tsf_inputscope::SetInputScopeForTsfUnawareWindow( | 639 tsf_inputscope::SetInputScopeForTsfUnawareWindow( |
657 window_handle, text_input_type, text_input_mode); | 640 window_handle, text_input_type, text_input_mode); |
658 } | 641 } |
659 | 642 |
660 } // namespace ui | 643 } // namespace ui |
OLD | NEW |