Chromium Code Reviews| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 bool InputMethodChromeOS::NeedInsertChar() const { | 431 bool InputMethodChromeOS::NeedInsertChar() const { |
| 432 return GetTextInputClient() && | 432 return GetTextInputClient() && |
| 433 (IsTextInputTypeNone() || | 433 (IsTextInputTypeNone() || |
| 434 (!composing_text_ && result_text_.length() == 1)); | 434 (!composing_text_ && result_text_.length() == 1)); |
| 435 } | 435 } |
| 436 | 436 |
| 437 bool InputMethodChromeOS::HasInputMethodResult() const { | 437 bool InputMethodChromeOS::HasInputMethodResult() const { |
| 438 return result_text_.length() || composition_changed_; | 438 return result_text_.length() || composition_changed_; |
| 439 } | 439 } |
| 440 | 440 |
| 441 void InputMethodChromeOS::SendFakeProcessKeyEvent(bool pressed) const { | |
| 442 if (!GetTextInputClient()) | |
| 443 return; | |
| 444 KeyEvent evt(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, | |
| 445 pressed ? VKEY_PROCESSKEY : VKEY_UNKNOWN, | |
| 446 EF_IME_FABRICATED_KEY, | |
| 447 false); // is_char | |
| 448 Event::DispatcherApi dispatch_helper(&evt); | |
| 449 dispatch_helper.set_target(reinterpret_cast<EventTarget*>( | |
| 450 GetTextInputClient()->GetAttachedWindow())); | |
|
oshima
2014/06/05 15:03:13
As I said, it is my understanding that DispatherAp
sadrul
2014/06/05 15:46:28
Indeed. You should not use this here.
Shu Chen
2014/06/05 16:26:54
Done.
Shu Chen
2014/06/05 16:26:54
Done.
| |
| 451 DispatchKeyEventPostIME(evt); | |
| 452 } | |
| 453 | |
| 441 void InputMethodChromeOS::AbandonAllPendingKeyEvents() { | 454 void InputMethodChromeOS::AbandonAllPendingKeyEvents() { |
| 442 pending_key_events_.clear(); | 455 pending_key_events_.clear(); |
| 443 } | 456 } |
| 444 | 457 |
| 445 void InputMethodChromeOS::CommitText(const std::string& text) { | 458 void InputMethodChromeOS::CommitText(const std::string& text) { |
| 446 if (text.empty()) | 459 if (text.empty()) |
| 447 return; | 460 return; |
| 448 | 461 |
| 449 // We need to receive input method result even if the text input type is | 462 // We need to receive input method result even if the text input type is |
| 450 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct | 463 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct |
| 451 // character for each key event to the focused text input client. | 464 // character for each key event to the focused text input client. |
| 452 if (!GetTextInputClient()) | 465 if (!GetTextInputClient()) |
| 453 return; | 466 return; |
| 454 | 467 |
| 455 const base::string16 utf16_text = base::UTF8ToUTF16(text); | 468 const base::string16 utf16_text = base::UTF8ToUTF16(text); |
| 456 if (utf16_text.empty()) | 469 if (utf16_text.empty()) |
| 457 return; | 470 return; |
| 458 | 471 |
| 459 // Append the text to the buffer, because commit signal might be fired | 472 // Append the text to the buffer, because commit signal might be fired |
| 460 // multiple times when processing a key event. | 473 // multiple times when processing a key event. |
| 461 result_text_.append(utf16_text); | 474 result_text_.append(utf16_text); |
| 462 | 475 |
| 463 // If we are not handling key event, do not bother sending text result if the | 476 // If we are not handling key event, do not bother sending text result if the |
| 464 // focused text input client does not support text input. | 477 // focused text input client does not support text input. |
| 465 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { | 478 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { |
| 479 SendFakeProcessKeyEvent(true); | |
| 466 GetTextInputClient()->InsertText(utf16_text); | 480 GetTextInputClient()->InsertText(utf16_text); |
| 481 SendFakeProcessKeyEvent(false); | |
| 467 result_text_.clear(); | 482 result_text_.clear(); |
| 468 } | 483 } |
| 469 } | 484 } |
| 470 | 485 |
| 471 void InputMethodChromeOS::UpdateCompositionText( | 486 void InputMethodChromeOS::UpdateCompositionText( |
| 472 const chromeos::CompositionText& text, | 487 const chromeos::CompositionText& text, |
| 473 uint32 cursor_pos, | 488 uint32 cursor_pos, |
| 474 bool visible) { | 489 bool visible) { |
| 475 if (IsTextInputTypeNone()) | 490 if (IsTextInputTypeNone()) |
| 476 return; | 491 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 498 | 513 |
| 499 composition_changed_ = true; | 514 composition_changed_ = true; |
| 500 | 515 |
| 501 // In case OnShowPreeditText() is not called. | 516 // In case OnShowPreeditText() is not called. |
| 502 if (composition_.text.length()) | 517 if (composition_.text.length()) |
| 503 composing_text_ = true; | 518 composing_text_ = true; |
| 504 | 519 |
| 505 // If we receive a composition text without pending key event, then we need to | 520 // If we receive a composition text without pending key event, then we need to |
| 506 // send it to the focused text input client directly. | 521 // send it to the focused text input client directly. |
| 507 if (pending_key_events_.empty()) { | 522 if (pending_key_events_.empty()) { |
| 523 SendFakeProcessKeyEvent(true); | |
| 508 GetTextInputClient()->SetCompositionText(composition_); | 524 GetTextInputClient()->SetCompositionText(composition_); |
| 525 SendFakeProcessKeyEvent(false); | |
| 509 composition_changed_ = false; | 526 composition_changed_ = false; |
| 510 composition_.Clear(); | 527 composition_.Clear(); |
| 511 } | 528 } |
| 512 } | 529 } |
| 513 | 530 |
| 514 void InputMethodChromeOS::HidePreeditText() { | 531 void InputMethodChromeOS::HidePreeditText() { |
| 515 if (composition_.text.empty() || IsTextInputTypeNone()) | 532 if (composition_.text.empty() || IsTextInputTypeNone()) |
| 516 return; | 533 return; |
| 517 | 534 |
| 518 // Intentionally leaves |composing_text_| unchanged. | 535 // Intentionally leaves |composing_text_| unchanged. |
| 519 composition_changed_ = true; | 536 composition_changed_ = true; |
| 520 composition_.Clear(); | 537 composition_.Clear(); |
| 521 | 538 |
| 522 if (pending_key_events_.empty()) { | 539 if (pending_key_events_.empty()) { |
| 523 TextInputClient* client = GetTextInputClient(); | 540 TextInputClient* client = GetTextInputClient(); |
| 524 if (client && client->HasCompositionText()) | 541 if (client && client->HasCompositionText()) { |
| 542 SendFakeProcessKeyEvent(true); | |
| 525 client->ClearCompositionText(); | 543 client->ClearCompositionText(); |
| 544 SendFakeProcessKeyEvent(false); | |
| 545 } | |
| 526 composition_changed_ = false; | 546 composition_changed_ = false; |
| 527 } | 547 } |
| 528 } | 548 } |
| 529 | 549 |
| 530 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { | 550 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { |
| 531 if (!composition_.text.empty()) | 551 if (!composition_.text.empty()) |
| 532 return; // do nothing if there is ongoing composition. | 552 return; // do nothing if there is ongoing composition. |
| 533 if (offset < 0 && static_cast<uint32>(-1 * offset) != length) | 553 if (offset < 0 && static_cast<uint32>(-1 * offset) != length) |
| 534 return; // only preceding text can be deletable. | 554 return; // only preceding text can be deletable. |
| 535 if (GetTextInputClient()) | 555 if (GetTextInputClient()) |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 0, length, SK_ColorBLACK, false /* thick */)); | 650 0, length, SK_ColorBLACK, false /* thick */)); |
| 631 } | 651 } |
| 632 } | 652 } |
| 633 | 653 |
| 634 bool InputMethodChromeOS::IsInputFieldFocused() { | 654 bool InputMethodChromeOS::IsInputFieldFocused() { |
| 635 TextInputType type = GetTextInputType(); | 655 TextInputType type = GetTextInputType(); |
| 636 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); | 656 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); |
| 637 } | 657 } |
| 638 | 658 |
| 639 } // namespace ui | 659 } // namespace ui |
| OLD | NEW |