| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "views/ime/input_method_ibus.h" | 5 #include "views/ime/input_method_ibus.h" |
| 6 | 6 |
| 7 #include <ibus.h> | 7 #include <ibus.h> |
| 8 #if defined(TOUCH_UI) | 8 #if defined(TOUCH_UI) |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 // CreateInputContextDone(). | 589 // CreateInputContextDone(). |
| 590 pending_create_fake_ic_request_->abandon(); | 590 pending_create_fake_ic_request_->abandon(); |
| 591 pending_create_fake_ic_request_ = NULL; | 591 pending_create_fake_ic_request_ = NULL; |
| 592 } else if (fake_context_) { | 592 } else if (fake_context_) { |
| 593 ibus_proxy_destroy(reinterpret_cast<IBusProxy *>(fake_context_)); | 593 ibus_proxy_destroy(reinterpret_cast<IBusProxy *>(fake_context_)); |
| 594 DCHECK(!fake_context_); | 594 DCHECK(!fake_context_); |
| 595 } | 595 } |
| 596 } | 596 } |
| 597 | 597 |
| 598 void InputMethodIBus::ConfirmCompositionText() { | 598 void InputMethodIBus::ConfirmCompositionText() { |
| 599 ui::TextInputClient* client = GetTextInputClient(); | 599 TextInputClient* client = GetTextInputClient(); |
| 600 if (client && client->HasCompositionText()) | 600 if (client && client->HasCompositionText()) |
| 601 client->ConfirmCompositionText(); | 601 client->ConfirmCompositionText(); |
| 602 | 602 |
| 603 ResetContext(); | 603 ResetContext(); |
| 604 } | 604 } |
| 605 | 605 |
| 606 void InputMethodIBus::ResetContext() { | 606 void InputMethodIBus::ResetContext() { |
| 607 if (!context_focused_ || !GetTextInputClient()) | 607 if (!context_focused_ || !GetTextInputClient()) |
| 608 return; | 608 return; |
| 609 | 609 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 | 737 |
| 738 // We shouldn't dispatch the character anymore if the key event caused focus | 738 // We shouldn't dispatch the character anymore if the key event caused focus |
| 739 // change. | 739 // change. |
| 740 if (old_focused_view != GetFocusedView()) | 740 if (old_focused_view != GetFocusedView()) |
| 741 return; | 741 return; |
| 742 | 742 |
| 743 // Process compose and dead keys | 743 // Process compose and dead keys |
| 744 if (character_composer_.FilterKeyPress(ibus_keyval)) { | 744 if (character_composer_.FilterKeyPress(ibus_keyval)) { |
| 745 string16 composed = character_composer_.composed_character(); | 745 string16 composed = character_composer_.composed_character(); |
| 746 if (!composed.empty()) { | 746 if (!composed.empty()) { |
| 747 ui::TextInputClient* client = GetTextInputClient(); | 747 TextInputClient* client = GetTextInputClient(); |
| 748 if (client) | 748 if (client) |
| 749 client->InsertText(composed); | 749 client->InsertText(composed); |
| 750 } | 750 } |
| 751 return; | 751 return; |
| 752 } | 752 } |
| 753 // If a key event was not filtered by |context_| and |character_composer_|, | 753 // If a key event was not filtered by |context_| and |character_composer_|, |
| 754 // then it means the key event didn't generate any result text. So we need | 754 // then it means the key event didn't generate any result text. So we need |
| 755 // to send corresponding character to the focused text input client. | 755 // to send corresponding character to the focused text input client. |
| 756 | 756 |
| 757 ui::TextInputClient* client = GetTextInputClient(); | 757 TextInputClient* client = GetTextInputClient(); |
| 758 char16 ch = key.GetCharacter(); | 758 char16 ch = key.GetCharacter(); |
| 759 if (ch && client) | 759 if (ch && client) |
| 760 client->InsertChar(ch, key.flags()); | 760 client->InsertChar(ch, key.flags()); |
| 761 } | 761 } |
| 762 | 762 |
| 763 void InputMethodIBus::ProcessInputMethodResult(const KeyEvent& key, | 763 void InputMethodIBus::ProcessInputMethodResult(const KeyEvent& key, |
| 764 bool filtered) { | 764 bool filtered) { |
| 765 ui::TextInputClient* client = GetTextInputClient(); | 765 TextInputClient* client = GetTextInputClient(); |
| 766 DCHECK(client); | 766 DCHECK(client); |
| 767 | 767 |
| 768 if (result_text_.length()) { | 768 if (result_text_.length()) { |
| 769 if (filtered && NeedInsertChar()) { | 769 if (filtered && NeedInsertChar()) { |
| 770 for (string16::const_iterator i = result_text_.begin(); | 770 for (string16::const_iterator i = result_text_.begin(); |
| 771 i != result_text_.end(); ++i) { | 771 i != result_text_.end(); ++i) { |
| 772 client->InsertChar(*i, key.flags()); | 772 client->InsertChar(*i, key.flags()); |
| 773 } | 773 } |
| 774 } else { | 774 } else { |
| 775 client->InsertText(result_text_); | 775 client->InsertText(result_text_); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 void InputMethodIBus::OnHidePreeditText(IBusInputContext* context) { | 932 void InputMethodIBus::OnHidePreeditText(IBusInputContext* context) { |
| 933 DCHECK_EQ(context_, context); | 933 DCHECK_EQ(context_, context); |
| 934 if (composition_.text.empty() || IsTextInputTypeNone()) | 934 if (composition_.text.empty() || IsTextInputTypeNone()) |
| 935 return; | 935 return; |
| 936 | 936 |
| 937 // Intentionally leaves |composing_text_| unchanged. | 937 // Intentionally leaves |composing_text_| unchanged. |
| 938 composition_changed_ = true; | 938 composition_changed_ = true; |
| 939 composition_.Clear(); | 939 composition_.Clear(); |
| 940 | 940 |
| 941 if (pending_key_events_.empty()) { | 941 if (pending_key_events_.empty()) { |
| 942 ui::TextInputClient* client = GetTextInputClient(); | 942 TextInputClient* client = GetTextInputClient(); |
| 943 if (client && client->HasCompositionText()) | 943 if (client && client->HasCompositionText()) |
| 944 client->ClearCompositionText(); | 944 client->ClearCompositionText(); |
| 945 composition_changed_ = false; | 945 composition_changed_ = false; |
| 946 } | 946 } |
| 947 } | 947 } |
| 948 | 948 |
| 949 void InputMethodIBus::OnDestroy(IBusInputContext* context) { | 949 void InputMethodIBus::OnDestroy(IBusInputContext* context) { |
| 950 DCHECK_EQ(context_, context); | 950 DCHECK_EQ(context_, context); |
| 951 g_object_unref(context_); | 951 g_object_unref(context_); |
| 952 context_ = NULL; | 952 context_ = NULL; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 DCHECK_EQ(GetIBus(), bus); | 1018 DCHECK_EQ(GetIBus(), bus); |
| 1019 DCHECK(data); | 1019 DCHECK(data); |
| 1020 IBusInputContext* ic = | 1020 IBusInputContext* ic = |
| 1021 ibus_bus_create_input_context_async_finish(bus, res, NULL); | 1021 ibus_bus_create_input_context_async_finish(bus, res, NULL); |
| 1022 if (ic) | 1022 if (ic) |
| 1023 data->StoreOrAbandonInputContext(ic); | 1023 data->StoreOrAbandonInputContext(ic); |
| 1024 delete data; | 1024 delete data; |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 } // namespace views | 1027 } // namespace views |
| OLD | NEW |