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