| 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_ibus.h" | 5 #include "ui/base/ime/input_method_ibus.h" |
| 6 | 6 |
| 7 #include <X11/X.h> | 7 #include <X11/X.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> | 9 #include <X11/Xutil.h> |
| 10 #undef FocusIn | 10 #undef FocusIn |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 bool InputMethodIBus::NeedInsertChar() const { | 550 bool InputMethodIBus::NeedInsertChar() const { |
| 551 return GetTextInputClient() && | 551 return GetTextInputClient() && |
| 552 (IsTextInputTypeNone() || | 552 (IsTextInputTypeNone() || |
| 553 (!composing_text_ && result_text_.length() == 1)); | 553 (!composing_text_ && result_text_.length() == 1)); |
| 554 } | 554 } |
| 555 | 555 |
| 556 bool InputMethodIBus::HasInputMethodResult() const { | 556 bool InputMethodIBus::HasInputMethodResult() const { |
| 557 return result_text_.length() || composition_changed_; | 557 return result_text_.length() || composition_changed_; |
| 558 } | 558 } |
| 559 | 559 |
| 560 void InputMethodIBus::SendFakeProcessKeyEvent(bool pressed) const { | |
| 561 DispatchFabricatedKeyEventPostIME(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, | |
| 562 VKEY_PROCESSKEY, | |
| 563 0); | |
| 564 } | |
| 565 | |
| 566 void InputMethodIBus::AbandonAllPendingKeyEvents() { | 560 void InputMethodIBus::AbandonAllPendingKeyEvents() { |
| 567 pending_key_events_.clear(); | 561 pending_key_events_.clear(); |
| 568 } | 562 } |
| 569 | 563 |
| 570 void InputMethodIBus::CommitText(const chromeos::IBusText& text) { | 564 void InputMethodIBus::CommitText(const chromeos::IBusText& text) { |
| 571 if (text.text().empty()) | 565 if (text.text().empty()) |
| 572 return; | 566 return; |
| 573 | 567 |
| 574 // We need to receive input method result even if the text input type is | 568 // We need to receive input method result even if the text input type is |
| 575 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct | 569 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct |
| 576 // character for each key event to the focused text input client. | 570 // character for each key event to the focused text input client. |
| 577 if (!GetTextInputClient()) | 571 if (!GetTextInputClient()) |
| 578 return; | 572 return; |
| 579 | 573 |
| 580 const string16 utf16_text = UTF8ToUTF16(text.text()); | 574 const string16 utf16_text = UTF8ToUTF16(text.text()); |
| 581 if (utf16_text.empty()) | 575 if (utf16_text.empty()) |
| 582 return; | 576 return; |
| 583 | 577 |
| 584 // Append the text to the buffer, because commit signal might be fired | 578 // Append the text to the buffer, because commit signal might be fired |
| 585 // multiple times when processing a key event. | 579 // multiple times when processing a key event. |
| 586 result_text_.append(utf16_text); | 580 result_text_.append(utf16_text); |
| 587 | 581 |
| 588 // If we are not handling key event, do not bother sending text result if the | 582 // If we are not handling key event, do not bother sending text result if the |
| 589 // focused text input client does not support text input. | 583 // focused text input client does not support text input. |
| 590 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { | 584 if (pending_key_events_.empty() && !IsTextInputTypeNone()) { |
| 591 SendFakeProcessKeyEvent(true); | |
| 592 GetTextInputClient()->InsertText(utf16_text); | 585 GetTextInputClient()->InsertText(utf16_text); |
| 593 SendFakeProcessKeyEvent(false); | |
| 594 result_text_.clear(); | 586 result_text_.clear(); |
| 595 } | 587 } |
| 596 } | 588 } |
| 597 | 589 |
| 598 void InputMethodIBus::ForwardKeyEvent(uint32 keyval, | 590 void InputMethodIBus::ForwardKeyEvent(uint32 keyval, |
| 599 uint32 keycode, | 591 uint32 keycode, |
| 600 uint32 state) { | 592 uint32 state) { |
| 601 KeyboardCode ui_key_code = KeyboardCodeFromXKeysym(keyval); | 593 KeyboardCode ui_key_code = KeyboardCodeFromXKeysym(keyval); |
| 602 if (!ui_key_code) | 594 if (!ui_key_code) |
| 603 return; | 595 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 647 |
| 656 composition_changed_ = true; | 648 composition_changed_ = true; |
| 657 | 649 |
| 658 // In case OnShowPreeditText() is not called. | 650 // In case OnShowPreeditText() is not called. |
| 659 if (composition_.text.length()) | 651 if (composition_.text.length()) |
| 660 composing_text_ = true; | 652 composing_text_ = true; |
| 661 | 653 |
| 662 // If we receive a composition text without pending key event, then we need to | 654 // If we receive a composition text without pending key event, then we need to |
| 663 // send it to the focused text input client directly. | 655 // send it to the focused text input client directly. |
| 664 if (pending_key_events_.empty()) { | 656 if (pending_key_events_.empty()) { |
| 665 SendFakeProcessKeyEvent(true); | |
| 666 GetTextInputClient()->SetCompositionText(composition_); | 657 GetTextInputClient()->SetCompositionText(composition_); |
| 667 SendFakeProcessKeyEvent(false); | |
| 668 composition_changed_ = false; | 658 composition_changed_ = false; |
| 669 composition_.Clear(); | 659 composition_.Clear(); |
| 670 } | 660 } |
| 671 } | 661 } |
| 672 | 662 |
| 673 void InputMethodIBus::HidePreeditText() { | 663 void InputMethodIBus::HidePreeditText() { |
| 674 if (composition_.text.empty() || IsTextInputTypeNone()) | 664 if (composition_.text.empty() || IsTextInputTypeNone()) |
| 675 return; | 665 return; |
| 676 | 666 |
| 677 // Intentionally leaves |composing_text_| unchanged. | 667 // Intentionally leaves |composing_text_| unchanged. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 } | 787 } |
| 798 | 788 |
| 799 // Use a black thin underline by default. | 789 // Use a black thin underline by default. |
| 800 if (out_composition->underlines.empty()) { | 790 if (out_composition->underlines.empty()) { |
| 801 out_composition->underlines.push_back(CompositionUnderline( | 791 out_composition->underlines.push_back(CompositionUnderline( |
| 802 0, length, SK_ColorBLACK, false /* thick */)); | 792 0, length, SK_ColorBLACK, false /* thick */)); |
| 803 } | 793 } |
| 804 } | 794 } |
| 805 | 795 |
| 806 } // namespace ui | 796 } // namespace ui |
| OLD | NEW |