| 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 "chrome/browser/chromeos/input_method/ibus_engine_controller.h" | 5 #include "chrome/browser/chromeos/input_method/ibus_engine_controller.h" |
| 6 | 6 |
| 7 #if defined(HAVE_IBUS) | 7 #if defined(HAVE_IBUS) |
| 8 #include <ibus.h> | 8 #include <ibus.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 vertical_(false), | 74 vertical_(false), |
| 75 page_size_(kDefaultCandidatePageSize), | 75 page_size_(kDefaultCandidatePageSize), |
| 76 cursor_position_(0), | 76 cursor_position_(0), |
| 77 aux_text_visible_(false) { | 77 aux_text_visible_(false) { |
| 78 if (!g_connections_) { | 78 if (!g_connections_) { |
| 79 g_connections_ = new ConnectionMap; | 79 g_connections_ = new ConnectionMap; |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 ~IBusEngineControllerImpl() { | 83 ~IBusEngineControllerImpl() { |
| 84 for (std::set<IBusChromeOSEngine*>::iterator ix = engine_instances_.begin(); |
| 85 ix != engine_instances_.end(); ++ix) { |
| 86 (*ix)->connection = NULL; |
| 87 } |
| 84 if (preedit_text_) { | 88 if (preedit_text_) { |
| 85 g_object_unref(preedit_text_); | 89 g_object_unref(preedit_text_); |
| 86 preedit_text_ = NULL; | 90 preedit_text_ = NULL; |
| 87 } | 91 } |
| 88 if (ibus_) { | 92 if (ibus_) { |
| 89 DisconnectIBusSignals(); | 93 DisconnectIBusSignals(); |
| 90 g_object_unref(ibus_); | 94 g_object_unref(ibus_); |
| 91 } | 95 } |
| 92 g_connections_->erase(engine_id_); | 96 g_connections_->erase(engine_id_); |
| 93 ClearProperties(); | 97 ClearProperties(); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 parameters, | 707 parameters, |
| 704 invocation); | 708 invocation); |
| 705 } | 709 } |
| 706 } | 710 } |
| 707 | 711 |
| 708 static void OnProcessKeyEvent(IBusEngine* ibus_engine, guint keyval, | 712 static void OnProcessKeyEvent(IBusEngine* ibus_engine, guint keyval, |
| 709 guint keycode, guint modifiers, | 713 guint keycode, guint modifiers, |
| 710 GDBusMethodInvocation* key_data) { | 714 GDBusMethodInvocation* key_data) { |
| 711 VLOG(1) << "OnProcessKeyEvent"; | 715 VLOG(1) << "OnProcessKeyEvent"; |
| 712 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 716 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 713 engine->connection->observer_->OnKeyEvent( | 717 if (engine->connection) { |
| 714 !(modifiers & IBUS_RELEASE_MASK), | 718 engine->connection->observer_->OnKeyEvent( |
| 715 keyval, keycode, | 719 !(modifiers & IBUS_RELEASE_MASK), |
| 716 modifiers & IBUS_MOD1_MASK, | 720 keyval, keycode, |
| 717 modifiers & IBUS_CONTROL_MASK, | 721 modifiers & IBUS_MOD1_MASK, |
| 718 modifiers & IBUS_SHIFT_MASK, | 722 modifiers & IBUS_CONTROL_MASK, |
| 719 reinterpret_cast<KeyEventHandle*>(key_data)); | 723 modifiers & IBUS_SHIFT_MASK, |
| 724 reinterpret_cast<KeyEventHandle*>(key_data)); |
| 725 } |
| 720 } | 726 } |
| 721 | 727 |
| 722 static void OnReset(IBusEngine* ibus_engine) { | 728 static void OnReset(IBusEngine* ibus_engine) { |
| 723 VLOG(1) << "OnReset"; | 729 VLOG(1) << "OnReset"; |
| 724 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 730 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 725 engine->connection->observer_->OnReset(); | 731 if (engine->connection) { |
| 732 engine->connection->observer_->OnReset(); |
| 733 } |
| 726 } | 734 } |
| 727 | 735 |
| 728 static void OnEnable(IBusEngine* ibus_engine) { | 736 static void OnEnable(IBusEngine* ibus_engine) { |
| 729 VLOG(1) << "OnEnable"; | 737 VLOG(1) << "OnEnable"; |
| 730 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 738 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 731 engine->connection->active_engine_ = engine; | 739 if (engine->connection) { |
| 732 engine->connection->observer_->OnEnable(); | 740 engine->connection->active_engine_ = engine; |
| 733 engine->connection->SetProperties(); | 741 engine->connection->observer_->OnEnable(); |
| 742 engine->connection->SetProperties(); |
| 743 } |
| 734 } | 744 } |
| 735 | 745 |
| 736 static void OnDisable(IBusEngine* ibus_engine) { | 746 static void OnDisable(IBusEngine* ibus_engine) { |
| 737 VLOG(1) << "OnDisable"; | 747 VLOG(1) << "OnDisable"; |
| 738 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 748 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 739 engine->connection->observer_->OnDisable(); | 749 if (engine->connection) { |
| 740 if (engine->connection->active_engine_ == engine) { | 750 engine->connection->observer_->OnDisable(); |
| 741 engine->connection->active_engine_ = NULL; | 751 if (engine->connection->active_engine_ == engine) { |
| 752 engine->connection->active_engine_ = NULL; |
| 753 } |
| 742 } | 754 } |
| 743 } | 755 } |
| 744 | 756 |
| 745 static void OnFocusIn(IBusEngine* ibus_engine) { | 757 static void OnFocusIn(IBusEngine* ibus_engine) { |
| 746 VLOG(1) << "OnFocusIn"; | 758 VLOG(1) << "OnFocusIn"; |
| 747 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 759 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 748 engine->connection->observer_->OnFocusIn(); | 760 if (engine->connection) { |
| 749 engine->connection->SetProperties(); | 761 engine->connection->observer_->OnFocusIn(); |
| 762 engine->connection->SetProperties(); |
| 763 } |
| 750 } | 764 } |
| 751 | 765 |
| 752 static void OnFocusOut(IBusEngine* ibus_engine) { | 766 static void OnFocusOut(IBusEngine* ibus_engine) { |
| 753 VLOG(1) << "OnFocusOut"; | 767 VLOG(1) << "OnFocusOut"; |
| 754 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 768 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 755 engine->connection->observer_->OnFocusOut(); | 769 if (engine->connection) { |
| 770 engine->connection->observer_->OnFocusOut(); |
| 771 } |
| 756 } | 772 } |
| 757 | 773 |
| 758 static void OnPageUp(IBusEngine* ibus_engine) { | 774 static void OnPageUp(IBusEngine* ibus_engine) { |
| 759 // Not implemented | 775 // Not implemented |
| 760 } | 776 } |
| 761 | 777 |
| 762 static void OnPageDown(IBusEngine* ibus_engine) { | 778 static void OnPageDown(IBusEngine* ibus_engine) { |
| 763 // Not implemented | 779 // Not implemented |
| 764 } | 780 } |
| 765 | 781 |
| 766 static void OnCursorUp(IBusEngine* ibus_engine) { | 782 static void OnCursorUp(IBusEngine* ibus_engine) { |
| 767 // Not implemented | 783 // Not implemented |
| 768 } | 784 } |
| 769 | 785 |
| 770 static void OnCursorDown(IBusEngine* ibus_engine) { | 786 static void OnCursorDown(IBusEngine* ibus_engine) { |
| 771 // Not implemented | 787 // Not implemented |
| 772 } | 788 } |
| 773 | 789 |
| 774 static void OnPropertyActivate(IBusEngine* ibus_engine, | 790 static void OnPropertyActivate(IBusEngine* ibus_engine, |
| 775 const gchar *prop_name, guint prop_state) { | 791 const gchar *prop_name, guint prop_state) { |
| 776 VLOG(1) << "OnPropertyActivate"; | 792 VLOG(1) << "OnPropertyActivate"; |
| 777 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 793 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 778 engine->connection->observer_->OnPropertyActivate(prop_name, prop_state); | 794 if (engine->connection) { |
| 795 engine->connection->observer_->OnPropertyActivate(prop_name, prop_state); |
| 796 } |
| 779 } | 797 } |
| 780 | 798 |
| 781 static void OnCandidateClicked(IBusEngine* ibus_engine, guint index, | 799 static void OnCandidateClicked(IBusEngine* ibus_engine, guint index, |
| 782 guint button, guint state) { | 800 guint button, guint state) { |
| 783 VLOG(1) << "OnCandidateClicked"; | 801 VLOG(1) << "OnCandidateClicked"; |
| 784 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); | 802 IBusChromeOSEngine* engine = IBUS_CHROMEOS_ENGINE(ibus_engine); |
| 785 int pressed_button = 0; | 803 if (engine->connection) { |
| 786 if (button & IBUS_BUTTON1_MASK) { | 804 int pressed_button = 0; |
| 787 pressed_button |= MOUSE_BUTTON_1_MASK; | 805 if (button & IBUS_BUTTON1_MASK) { |
| 806 pressed_button |= MOUSE_BUTTON_1_MASK; |
| 807 } |
| 808 if (button & IBUS_BUTTON2_MASK) { |
| 809 pressed_button |= MOUSE_BUTTON_2_MASK; |
| 810 } |
| 811 if (button & IBUS_BUTTON3_MASK) { |
| 812 pressed_button |= MOUSE_BUTTON_3_MASK; |
| 813 } |
| 814 engine->connection->observer_->OnCandidateClicked(index, pressed_button, |
| 815 state); |
| 788 } | 816 } |
| 789 if (button & IBUS_BUTTON2_MASK) { | |
| 790 pressed_button |= MOUSE_BUTTON_2_MASK; | |
| 791 } | |
| 792 if (button & IBUS_BUTTON3_MASK) { | |
| 793 pressed_button |= MOUSE_BUTTON_3_MASK; | |
| 794 } | |
| 795 engine->connection->observer_->OnCandidateClicked(index, pressed_button, | |
| 796 state); | |
| 797 } | 817 } |
| 798 | 818 |
| 799 static GObject* EngineConstructor(GType type, guint n_construct_params, | 819 static GObject* EngineConstructor(GType type, guint n_construct_params, |
| 800 GObjectConstructParam *construct_params) { | 820 GObjectConstructParam *construct_params) { |
| 801 IBusChromeOSEngine* engine = (IBusChromeOSEngine*) | 821 IBusChromeOSEngine* engine = (IBusChromeOSEngine*) |
| 802 G_OBJECT_CLASS(ibus_chromeos_engine_parent_class) | 822 G_OBJECT_CLASS(ibus_chromeos_engine_parent_class) |
| 803 ->constructor(type, n_construct_params, construct_params); | 823 ->constructor(type, n_construct_params, construct_params); |
| 804 const gchar* name = ibus_engine_get_name((IBusEngine*)engine); | 824 const gchar* name = ibus_engine_get_name((IBusEngine*)engine); |
| 805 ConnectionMap::iterator connection = g_connections_->find(name); | 825 ConnectionMap::iterator connection = g_connections_->find(name); |
| 806 if (connection == g_connections_->end()) { | 826 if (connection == g_connections_->end()) { |
| 807 LOG(ERROR) << "Connection never created: " << name; | 827 LOG(ERROR) << "Connection never created: " << name; |
| 828 engine->connection = NULL; |
| 829 engine->table = NULL; |
| 808 return (GObject *) engine; | 830 return (GObject *) engine; |
| 809 } | 831 } |
| 810 | 832 |
| 811 connection->second->engine_instances_.insert(engine); | 833 connection->second->engine_instances_.insert(engine); |
| 812 | 834 |
| 813 if (!connection->second->active_engine_) { | 835 if (!connection->second->active_engine_) { |
| 814 connection->second->active_engine_ = engine; | 836 connection->second->active_engine_ = engine; |
| 815 } | 837 } |
| 816 | 838 |
| 817 engine->connection = connection->second; | 839 engine->connection = connection->second; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 #else | 939 #else |
| 918 return NULL; | 940 return NULL; |
| 919 #endif | 941 #endif |
| 920 } | 942 } |
| 921 | 943 |
| 922 IBusEngineController::~IBusEngineController() { | 944 IBusEngineController::~IBusEngineController() { |
| 923 } | 945 } |
| 924 | 946 |
| 925 } // namespace input_method | 947 } // namespace input_method |
| 926 } // namespace chromeos | 948 } // namespace chromeos |
| OLD | NEW |