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

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
« no previous file with comments | « ui/base/ime/input_method_chromeos.h ('k') | ui/wm/core/input_method_event_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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 DispatchKeyEventPostIME(evt);
449 }
450
441 void InputMethodChromeOS::AbandonAllPendingKeyEvents() { 451 void InputMethodChromeOS::AbandonAllPendingKeyEvents() {
442 pending_key_events_.clear(); 452 pending_key_events_.clear();
443 } 453 }
444 454
445 void InputMethodChromeOS::CommitText(const std::string& text) { 455 void InputMethodChromeOS::CommitText(const std::string& text) {
446 if (text.empty()) 456 if (text.empty())
447 return; 457 return;
448 458
449 // We need to receive input method result even if the text input type is 459 // 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 460 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct
451 // character for each key event to the focused text input client. 461 // character for each key event to the focused text input client.
452 if (!GetTextInputClient()) 462 if (!GetTextInputClient())
453 return; 463 return;
454 464
455 const base::string16 utf16_text = base::UTF8ToUTF16(text); 465 const base::string16 utf16_text = base::UTF8ToUTF16(text);
456 if (utf16_text.empty()) 466 if (utf16_text.empty())
457 return; 467 return;
458 468
459 // Append the text to the buffer, because commit signal might be fired 469 // Append the text to the buffer, because commit signal might be fired
460 // multiple times when processing a key event. 470 // multiple times when processing a key event.
461 result_text_.append(utf16_text); 471 result_text_.append(utf16_text);
462 472
463 // If we are not handling key event, do not bother sending text result if the 473 // 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. 474 // focused text input client does not support text input.
465 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { 475 if (pending_key_events_.empty() && !IsTextInputTypeNone()) {
476 SendFakeProcessKeyEvent(true);
466 GetTextInputClient()->InsertText(utf16_text); 477 GetTextInputClient()->InsertText(utf16_text);
478 SendFakeProcessKeyEvent(false);
467 result_text_.clear(); 479 result_text_.clear();
468 } 480 }
469 } 481 }
470 482
471 void InputMethodChromeOS::UpdateCompositionText( 483 void InputMethodChromeOS::UpdateCompositionText(
472 const chromeos::CompositionText& text, 484 const chromeos::CompositionText& text,
473 uint32 cursor_pos, 485 uint32 cursor_pos,
474 bool visible) { 486 bool visible) {
475 if (IsTextInputTypeNone()) 487 if (IsTextInputTypeNone())
476 return; 488 return;
(...skipping 21 matching lines...) Expand all
498 510
499 composition_changed_ = true; 511 composition_changed_ = true;
500 512
501 // In case OnShowPreeditText() is not called. 513 // In case OnShowPreeditText() is not called.
502 if (composition_.text.length()) 514 if (composition_.text.length())
503 composing_text_ = true; 515 composing_text_ = true;
504 516
505 // If we receive a composition text without pending key event, then we need to 517 // If we receive a composition text without pending key event, then we need to
506 // send it to the focused text input client directly. 518 // send it to the focused text input client directly.
507 if (pending_key_events_.empty()) { 519 if (pending_key_events_.empty()) {
520 SendFakeProcessKeyEvent(true);
508 GetTextInputClient()->SetCompositionText(composition_); 521 GetTextInputClient()->SetCompositionText(composition_);
522 SendFakeProcessKeyEvent(false);
509 composition_changed_ = false; 523 composition_changed_ = false;
510 composition_.Clear(); 524 composition_.Clear();
511 } 525 }
512 } 526 }
513 527
514 void InputMethodChromeOS::HidePreeditText() { 528 void InputMethodChromeOS::HidePreeditText() {
515 if (composition_.text.empty() || IsTextInputTypeNone()) 529 if (composition_.text.empty() || IsTextInputTypeNone())
516 return; 530 return;
517 531
518 // Intentionally leaves |composing_text_| unchanged. 532 // Intentionally leaves |composing_text_| unchanged.
519 composition_changed_ = true; 533 composition_changed_ = true;
520 composition_.Clear(); 534 composition_.Clear();
521 535
522 if (pending_key_events_.empty()) { 536 if (pending_key_events_.empty()) {
523 TextInputClient* client = GetTextInputClient(); 537 TextInputClient* client = GetTextInputClient();
524 if (client && client->HasCompositionText()) 538 if (client && client->HasCompositionText()) {
539 SendFakeProcessKeyEvent(true);
525 client->ClearCompositionText(); 540 client->ClearCompositionText();
541 SendFakeProcessKeyEvent(false);
542 }
526 composition_changed_ = false; 543 composition_changed_ = false;
527 } 544 }
528 } 545 }
529 546
530 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) { 547 void InputMethodChromeOS::DeleteSurroundingText(int32 offset, uint32 length) {
531 if (!composition_.text.empty()) 548 if (!composition_.text.empty())
532 return; // do nothing if there is ongoing composition. 549 return; // do nothing if there is ongoing composition.
533 if (offset < 0 && static_cast<uint32>(-1 * offset) != length) 550 if (offset < 0 && static_cast<uint32>(-1 * offset) != length)
534 return; // only preceding text can be deletable. 551 return; // only preceding text can be deletable.
535 if (GetTextInputClient()) 552 if (GetTextInputClient())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 0, length, SK_ColorBLACK, false /* thick */)); 647 0, length, SK_ColorBLACK, false /* thick */));
631 } 648 }
632 } 649 }
633 650
634 bool InputMethodChromeOS::IsInputFieldFocused() { 651 bool InputMethodChromeOS::IsInputFieldFocused() {
635 TextInputType type = GetTextInputType(); 652 TextInputType type = GetTextInputType();
636 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD); 653 return (type != TEXT_INPUT_TYPE_NONE) && (type != TEXT_INPUT_TYPE_PASSWORD);
637 } 654 }
638 655
639 } // namespace ui 656 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_chromeos.h ('k') | ui/wm/core/input_method_event_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698