Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: ui/base/ime/input_method_chromeos.cc

Issue 298893003: Supports fake key events for setComposition/commitText by on-screen keyboards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 KeyEvent evt(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED,
443 pressed ? VKEY_PROCESSKEY : VKEY_UNKNOWN,
444 EF_IME_FABRICATED_KEY,
445 false); // is_char
446 DispatchKeyEventPostIME(evt);
447 }
448
441 void InputMethodChromeOS::AbandonAllPendingKeyEvents() { 449 void InputMethodChromeOS::AbandonAllPendingKeyEvents() {
442 pending_key_events_.clear(); 450 pending_key_events_.clear();
443 } 451 }
444 452
445 void InputMethodChromeOS::CommitText(const std::string& text) { 453 void InputMethodChromeOS::CommitText(const std::string& text) {
446 if (text.empty()) 454 if (text.empty())
447 return; 455 return;
448 456
449 // We need to receive input method result even if the text input type is 457 // 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 458 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct
451 // character for each key event to the focused text input client. 459 // character for each key event to the focused text input client.
452 if (!GetTextInputClient()) 460 if (!GetTextInputClient())
453 return; 461 return;
454 462
455 const base::string16 utf16_text = base::UTF8ToUTF16(text); 463 const base::string16 utf16_text = base::UTF8ToUTF16(text);
456 if (utf16_text.empty()) 464 if (utf16_text.empty())
457 return; 465 return;
458 466
459 // Append the text to the buffer, because commit signal might be fired 467 // Append the text to the buffer, because commit signal might be fired
460 // multiple times when processing a key event. 468 // multiple times when processing a key event.
461 result_text_.append(utf16_text); 469 result_text_.append(utf16_text);
462 470
463 // If we are not handling key event, do not bother sending text result if the 471 // 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. 472 // focused text input client does not support text input.
465 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { 473 if (pending_key_events_.empty() && !IsTextInputTypeNone()) {
474 SendFakeProcessKeyEvent(true);
466 GetTextInputClient()->InsertText(utf16_text); 475 GetTextInputClient()->InsertText(utf16_text);
476 SendFakeProcessKeyEvent(false);
467 result_text_.clear(); 477 result_text_.clear();
468 } 478 }
469 } 479 }
470 480
471 void InputMethodChromeOS::UpdateCompositionText( 481 void InputMethodChromeOS::UpdateCompositionText(
472 const chromeos::CompositionText& text, 482 const chromeos::CompositionText& text,
473 uint32 cursor_pos, 483 uint32 cursor_pos,
474 bool visible) { 484 bool visible) {
475 if (IsTextInputTypeNone()) 485 if (IsTextInputTypeNone())
476 return; 486 return;
(...skipping 21 matching lines...) Expand all
498 508
499 composition_changed_ = true; 509 composition_changed_ = true;
500 510
501 // In case OnShowPreeditText() is not called. 511 // In case OnShowPreeditText() is not called.
502 if (composition_.text.length()) 512 if (composition_.text.length())
503 composing_text_ = true; 513 composing_text_ = true;
504 514
505 // If we receive a composition text without pending key event, then we need to 515 // If we receive a composition text without pending key event, then we need to
506 // send it to the focused text input client directly. 516 // send it to the focused text input client directly.
507 if (pending_key_events_.empty()) { 517 if (pending_key_events_.empty()) {
518 SendFakeProcessKeyEvent(true);
508 GetTextInputClient()->SetCompositionText(composition_); 519 GetTextInputClient()->SetCompositionText(composition_);
520 SendFakeProcessKeyEvent(false);
509 composition_changed_ = false; 521 composition_changed_ = false;
510 composition_.Clear(); 522 composition_.Clear();
511 } 523 }
512 } 524 }
513 525
514 void InputMethodChromeOS::HidePreeditText() { 526 void InputMethodChromeOS::HidePreeditText() {
515 if (composition_.text.empty() || IsTextInputTypeNone()) 527 if (composition_.text.empty() || IsTextInputTypeNone())
516 return; 528 return;
517 529
518 // Intentionally leaves |composing_text_| unchanged. 530 // Intentionally leaves |composing_text_| unchanged.
519 composition_changed_ = true; 531 composition_changed_ = true;
520 composition_.Clear(); 532 composition_.Clear();
521 533
522 if (pending_key_events_.empty()) { 534 if (pending_key_events_.empty()) {
523 TextInputClient* client = GetTextInputClient(); 535 TextInputClient* client = GetTextInputClient();
524 if (client && client->HasCompositionText()) 536 if (client && client->HasCompositionText()) {
537 SendFakeProcessKeyEvent(true);
525 client->ClearCompositionText(); 538 client->ClearCompositionText();
539 SendFakeProcessKeyEvent(false);
540 }
526 composition_changed_ = false; 541 composition_changed_ = false;
527 } 542 }
528 } 543 }
529 544
530 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { 545 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) {
531 if (!composition_.text.empty()) 546 if (!composition_.text.empty())
532 return; // do nothing if there is ongoing composition. 547 return; // do nothing if there is ongoing composition.
533 if (offset < 0 && static_cast<uint32>(-1 * offset) != length) 548 if (offset < 0 && static_cast<uint32>(-1 * offset) != length)
534 return; // only preceding text can be deletable. 549 return; // only preceding text can be deletable.
535 if (GetTextInputClient()) 550 if (GetTextInputClient())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 0, length, SK_ColorBLACK, false /* thick */)); 645 0, length, SK_ColorBLACK, false /* thick */));
631 } 646 }
632 } 647 }
633 648
634 bool InputMethodChromeOS::IsInputFieldFocused() { 649 bool InputMethodChromeOS::IsInputFieldFocused() {
635 TextInputType type = GetTextInputType(); 650 TextInputType type = GetTextInputType();
636 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); 651 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD);
637 } 652 }
638 653
639 } // namespace ui 654 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698