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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 void InputMethodIBus::SendFakeProcessKeyEvent(bool pressed) const { | 629 void InputMethodIBus::SendFakeProcessKeyEvent(bool pressed) const { |
630 DispatchFabricatedKeyEventPostIME(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, | 630 DispatchFabricatedKeyEventPostIME(pressed ? ET_KEY_PRESSED : ET_KEY_RELEASED, |
631 VKEY_PROCESSKEY, | 631 VKEY_PROCESSKEY, |
632 0); | 632 0); |
633 } | 633 } |
634 | 634 |
635 void InputMethodIBus::AbandonAllPendingKeyEvents() { | 635 void InputMethodIBus::AbandonAllPendingKeyEvents() { |
636 pending_key_events_.clear(); | 636 pending_key_events_.clear(); |
637 } | 637 } |
638 | 638 |
639 void InputMethodIBus::CommitText(const chromeos::ibus::IBusText& text) { | 639 void InputMethodIBus::CommitText(const chromeos::IBusText& text) { |
640 if (suppress_next_result_ || text.text().empty()) | 640 if (suppress_next_result_ || text.text().empty()) |
641 return; | 641 return; |
642 | 642 |
643 // We need to receive input method result even if the text input type is | 643 // We need to receive input method result even if the text input type is |
644 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct | 644 // TEXT_INPUT_TYPE_NONE, to make sure we can always send correct |
645 // character for each key event to the focused text input client. | 645 // character for each key event to the focused text input client. |
646 if (!GetTextInputClient()) | 646 if (!GetTextInputClient()) |
647 return; | 647 return; |
648 | 648 |
649 const string16 utf16_text = UTF8ToUTF16(text.text()); | 649 const string16 utf16_text = UTF8ToUTF16(text.text()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 } | 688 } |
689 } | 689 } |
690 | 690 |
691 void InputMethodIBus::ShowPreeditText() { | 691 void InputMethodIBus::ShowPreeditText() { |
692 if (suppress_next_result_ || IsTextInputTypeNone()) | 692 if (suppress_next_result_ || IsTextInputTypeNone()) |
693 return; | 693 return; |
694 | 694 |
695 composing_text_ = true; | 695 composing_text_ = true; |
696 } | 696 } |
697 | 697 |
698 void InputMethodIBus::UpdatePreeditText(const chromeos::ibus::IBusText& text, | 698 void InputMethodIBus::UpdatePreeditText(const chromeos::IBusText& text, |
699 uint32 cursor_pos, | 699 uint32 cursor_pos, |
700 bool visible) { | 700 bool visible) { |
701 if (suppress_next_result_ || IsTextInputTypeNone()) | 701 if (suppress_next_result_ || IsTextInputTypeNone()) |
702 return; | 702 return; |
703 | 703 |
704 // Preedit update means there is a working IME, discard our composer's state. | 704 // Preedit update means there is a working IME, discard our composer's state. |
705 character_composer_.Reset(); | 705 character_composer_.Reset(); |
706 | 706 |
707 // |visible| argument is very confusing. For example, what's the correct | 707 // |visible| argument is very confusing. For example, what's the correct |
708 // behavior when: | 708 // behavior when: |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 824 |
825 DestroyContext(); | 825 DestroyContext(); |
826 CreateContext(); | 826 CreateContext(); |
827 } | 827 } |
828 | 828 |
829 void InputMethodIBus::OnDisconnected() { | 829 void InputMethodIBus::OnDisconnected() { |
830 DestroyContext(); | 830 DestroyContext(); |
831 } | 831 } |
832 | 832 |
833 void InputMethodIBus::ExtractCompositionText( | 833 void InputMethodIBus::ExtractCompositionText( |
834 const chromeos::ibus::IBusText& text, | 834 const chromeos::IBusText& text, |
835 uint32 cursor_position, | 835 uint32 cursor_position, |
836 CompositionText* out_composition) const { | 836 CompositionText* out_composition) const { |
837 out_composition->Clear(); | 837 out_composition->Clear(); |
838 out_composition->text = UTF8ToUTF16(text.text()); | 838 out_composition->text = UTF8ToUTF16(text.text()); |
839 | 839 |
840 if (out_composition->text.empty()) | 840 if (out_composition->text.empty()) |
841 return; | 841 return; |
842 | 842 |
843 // ibus uses character index for cursor position and attribute range, but we | 843 // ibus uses character index for cursor position and attribute range, but we |
844 // use char16 offset for them. So we need to do conversion here. | 844 // use char16 offset for them. So we need to do conversion here. |
845 std::vector<size_t> char16_offsets; | 845 std::vector<size_t> char16_offsets; |
846 size_t length = out_composition->text.length(); | 846 size_t length = out_composition->text.length(); |
847 base::i18n::UTF16CharIterator char_iterator(&out_composition->text); | 847 base::i18n::UTF16CharIterator char_iterator(&out_composition->text); |
848 do { | 848 do { |
849 char16_offsets.push_back(char_iterator.array_pos()); | 849 char16_offsets.push_back(char_iterator.array_pos()); |
850 } while (char_iterator.Advance()); | 850 } while (char_iterator.Advance()); |
851 | 851 |
852 // The text length in Unicode characters. | 852 // The text length in Unicode characters. |
853 uint32 char_length = static_cast<uint32>(char16_offsets.size()); | 853 uint32 char_length = static_cast<uint32>(char16_offsets.size()); |
854 // Make sure we can convert the value of |char_length| as well. | 854 // Make sure we can convert the value of |char_length| as well. |
855 char16_offsets.push_back(length); | 855 char16_offsets.push_back(length); |
856 | 856 |
857 size_t cursor_offset = | 857 size_t cursor_offset = |
858 char16_offsets[std::min(char_length, cursor_position)]; | 858 char16_offsets[std::min(char_length, cursor_position)]; |
859 | 859 |
860 out_composition->selection = Range(cursor_offset); | 860 out_composition->selection = Range(cursor_offset); |
861 | 861 |
862 const std::vector<chromeos::ibus::IBusText::UnderlineAttribute>& | 862 const std::vector<chromeos::IBusText::UnderlineAttribute>& |
863 underline_attributes = text.underline_attributes(); | 863 underline_attributes = text.underline_attributes(); |
864 const std::vector<chromeos::ibus::IBusText::SelectionAttribute>& | 864 const std::vector<chromeos::IBusText::SelectionAttribute>& |
865 selection_attributes = text.selection_attributes(); | 865 selection_attributes = text.selection_attributes(); |
866 | 866 |
867 if (!underline_attributes.empty()) { | 867 if (!underline_attributes.empty()) { |
868 for (size_t i = 0; i < underline_attributes.size(); ++i) { | 868 for (size_t i = 0; i < underline_attributes.size(); ++i) { |
869 const uint32 start = underline_attributes[i].start_index; | 869 const uint32 start = underline_attributes[i].start_index; |
870 const uint32 end = underline_attributes[i].end_index; | 870 const uint32 end = underline_attributes[i].end_index; |
871 if (start >= end) | 871 if (start >= end) |
872 continue; | 872 continue; |
873 CompositionUnderline underline( | 873 CompositionUnderline underline( |
874 char16_offsets[start], char16_offsets[end], | 874 char16_offsets[start], char16_offsets[end], |
875 SK_ColorBLACK, false /* thick */); | 875 SK_ColorBLACK, false /* thick */); |
876 if (underline_attributes[i].type == | 876 if (underline_attributes[i].type == |
877 chromeos::ibus::IBusText::IBUS_TEXT_UNDERLINE_DOUBLE) | 877 chromeos::IBusText::IBUS_TEXT_UNDERLINE_DOUBLE) |
878 underline.thick = true; | 878 underline.thick = true; |
879 else if (underline_attributes[i].type == | 879 else if (underline_attributes[i].type == |
880 chromeos::ibus::IBusText::IBUS_TEXT_UNDERLINE_ERROR) | 880 chromeos::IBusText::IBUS_TEXT_UNDERLINE_ERROR) |
881 underline.color = SK_ColorRED; | 881 underline.color = SK_ColorRED; |
882 out_composition->underlines.push_back(underline); | 882 out_composition->underlines.push_back(underline); |
883 } | 883 } |
884 } | 884 } |
885 | 885 |
886 if (!selection_attributes.empty()) { | 886 if (!selection_attributes.empty()) { |
887 LOG_IF(ERROR, selection_attributes.size() != 1) | 887 LOG_IF(ERROR, selection_attributes.size() != 1) |
888 << "Chrome does not support multiple selection"; | 888 << "Chrome does not support multiple selection"; |
889 for (uint32 i = 0; i < selection_attributes.size(); ++i) { | 889 for (uint32 i = 0; i < selection_attributes.size(); ++i) { |
890 const uint32 start = selection_attributes[i].start_index; | 890 const uint32 start = selection_attributes[i].start_index; |
(...skipping 18 matching lines...) Expand all Loading... |
909 } | 909 } |
910 | 910 |
911 // Use a black thin underline by default. | 911 // Use a black thin underline by default. |
912 if (out_composition->underlines.empty()) { | 912 if (out_composition->underlines.empty()) { |
913 out_composition->underlines.push_back(CompositionUnderline( | 913 out_composition->underlines.push_back(CompositionUnderline( |
914 0, length, SK_ColorBLACK, false /* thick */)); | 914 0, length, SK_ColorBLACK, false /* thick */)); |
915 } | 915 } |
916 } | 916 } |
917 | 917 |
918 } // namespace ui | 918 } // namespace ui |
OLD | NEW |