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 <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, | 339 void InputMethodChromeOS::ProcessKeyEventPostIME(const ui::KeyEvent& event, |
340 bool handled) { | 340 bool handled) { |
341 TextInputClient* client = GetTextInputClient(); | 341 TextInputClient* client = GetTextInputClient(); |
342 if (!client) { | 342 if (!client) { |
343 // As ibus works asynchronously, there is a chance that the focused client | 343 // As ibus works asynchronously, there is a chance that the focused client |
344 // loses focus before this method gets called. | 344 // loses focus before this method gets called. |
345 DispatchKeyEventPostIME(event); | 345 DispatchKeyEventPostIME(event); |
346 return; | 346 return; |
347 } | 347 } |
348 | 348 |
349 if (event.type() == ET_KEY_PRESSED && handled) | 349 if (event.type() == ET_KEY_PRESSED && handled) { |
350 ProcessFilteredKeyPressEvent(event); | 350 if (ProcessFilteredKeyPressEvent(event)) { |
| 351 ResetContext(); |
| 352 return; |
| 353 } |
| 354 } |
351 | 355 |
352 // In case the focus was changed by the key event. The |context_| should have | 356 // In case the focus was changed by the key event. The |context_| should have |
353 // been reset when the focused window changed. | 357 // been reset when the focused window changed. |
354 if (client != GetTextInputClient()) | 358 if (client != GetTextInputClient()) |
355 return; | 359 return; |
356 | 360 |
357 if (HasInputMethodResult()) | 361 if (HasInputMethodResult()) |
358 ProcessInputMethodResult(event, handled); | 362 ProcessInputMethodResult(event, handled); |
359 | 363 |
360 // In case the focus was changed when sending input method results to the | 364 // In case the focus was changed when sending input method results to the |
361 // focused window. | 365 // focused window. |
362 if (client != GetTextInputClient()) | 366 if (client != GetTextInputClient()) |
363 return; | 367 return; |
364 | 368 |
365 if (handled) | 369 if (handled) |
366 return; // IME handled the key event. do not forward. | 370 return; // IME handled the key event. do not forward. |
367 | 371 |
368 if (event.type() == ET_KEY_PRESSED) | 372 if (event.type() == ET_KEY_PRESSED) |
369 ProcessUnfilteredKeyPressEvent(event); | 373 ProcessUnfilteredKeyPressEvent(event); |
370 else if (event.type() == ET_KEY_RELEASED) | 374 else if (event.type() == ET_KEY_RELEASED) |
371 DispatchKeyEventPostIME(event); | 375 DispatchKeyEventPostIME(event); |
372 } | 376 } |
373 | 377 |
374 void InputMethodChromeOS::ProcessFilteredKeyPressEvent( | 378 bool InputMethodChromeOS::ProcessFilteredKeyPressEvent( |
375 const ui::KeyEvent& event) { | 379 const ui::KeyEvent& event) { |
376 if (NeedInsertChar()) { | 380 if (NeedInsertChar()) |
377 DispatchKeyEventPostIME(event); | 381 return DispatchKeyEventPostIME(event); |
378 } else { | 382 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, |
379 const ui::KeyEvent fabricated_event(ET_KEY_PRESSED, | 383 VKEY_PROCESSKEY, |
380 VKEY_PROCESSKEY, | 384 event.flags()); |
381 event.flags()); | 385 return DispatchKeyEventPostIME(fabricated_event); |
382 DispatchKeyEventPostIME(fabricated_event); | |
383 } | |
384 } | 386 } |
385 | 387 |
386 void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( | 388 void InputMethodChromeOS::ProcessUnfilteredKeyPressEvent( |
387 const ui::KeyEvent& event) { | 389 const ui::KeyEvent& event) { |
388 const TextInputClient* prev_client = GetTextInputClient(); | 390 const TextInputClient* prev_client = GetTextInputClient(); |
389 DispatchKeyEventPostIME(event); | 391 if (DispatchKeyEventPostIME(event)) { |
| 392 ResetContext(); |
| 393 return; |
| 394 } |
390 | 395 |
391 // We shouldn't dispatch the character anymore if the key event dispatch | 396 // We shouldn't dispatch the character anymore if the key event dispatch |
392 // caused focus change. For example, in the following scenario, | 397 // caused focus change. For example, in the following scenario, |
393 // 1. visit a web page which has a <textarea>. | 398 // 1. visit a web page which has a <textarea>. |
394 // 2. click Omnibox. | 399 // 2. click Omnibox. |
395 // 3. enable Korean IME, press A, then press Tab to move the focus to the web | 400 // 3. enable Korean IME, press A, then press Tab to move the focus to the web |
396 // page. | 401 // page. |
397 // We should return here not to send the Tab key event to RWHV. | 402 // We should return here not to send the Tab key event to RWHV. |
398 TextInputClient* client = GetTextInputClient(); | 403 TextInputClient* client = GetTextInputClient(); |
399 if (!client || client != prev_client) | 404 if (!client || client != prev_client) |
400 return; | 405 return; |
401 | 406 |
402 // If a key event was not filtered by |context_| and |character_composer_|, | 407 // If a key event was not filtered by |context_| and |character_composer_|, |
403 // then it means the key event didn't generate any result text. So we need | 408 // then it means the key event didn't generate any result text. So we need |
404 // to send corresponding character to the focused text input client. | 409 // to send corresponding character to the focused text input client. |
405 uint16 ch = event.GetCharacter(); | 410 uint16 ch = event.GetCharacter(); |
406 if (ch) | 411 if (ch) |
407 client->InsertChar(ch, event.flags()); | 412 client->InsertChar(ch, event.flags()); |
408 } | 413 } |
409 | 414 |
410 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, | 415 void InputMethodChromeOS::ProcessInputMethodResult(const ui::KeyEvent& event, |
411 bool handled) { | 416 bool handled) { |
412 TextInputClient* client = GetTextInputClient(); | 417 TextInputClient* client = GetTextInputClient(); |
413 DCHECK(client); | 418 DCHECK(client); |
414 | 419 |
415 if (result_text_.length()) { | 420 if (result_text_.length()) { |
416 if (handled && NeedInsertChar()) { | 421 if (handled && NeedInsertChar()) { |
417 for (base::string16::const_iterator i = result_text_.begin(); | 422 for (base::string16::const_iterator i = result_text_.begin(); |
418 i != result_text_.end(); ++i) { | 423 i != result_text_.end(); ++i) { |
419 client->InsertChar(*i, event.flags()); | 424 client->InsertChar(*i, event.flags()); |
420 } | 425 } |
421 } else { | 426 } else { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { | 670 bool InputMethodChromeOS::IsNonPasswordInputFieldFocused() { |
666 TextInputType type = GetTextInputType(); | 671 TextInputType type = GetTextInputType(); |
667 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 672 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
668 } | 673 } |
669 | 674 |
670 bool InputMethodChromeOS::IsInputFieldFocused() { | 675 bool InputMethodChromeOS::IsInputFieldFocused() { |
671 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; | 676 return GetTextInputType() != TEXT_INPUT_TYPE_NONE; |
672 } | 677 } |
673 | 678 |
674 } // namespace ui | 679 } // namespace ui |
OLD | NEW |