| 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 "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" |
| 6 | 6 |
| 7 #define XK_MISCELLANY | 7 #define XK_MISCELLANY |
| 8 #include <X11/keysymdef.h> | 8 #include <X11/keysymdef.h> |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 17 #include "chromeos/dbus/ibus/ibus_client.h" | |
| 18 #include "chromeos/dbus/ibus/ibus_component.h" | 17 #include "chromeos/dbus/ibus/ibus_component.h" |
| 19 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h" | 18 #include "chromeos/dbus/ibus/ibus_engine_factory_service.h" |
| 20 #include "chromeos/dbus/ibus/ibus_engine_service.h" | 19 #include "chromeos/dbus/ibus/ibus_engine_service.h" |
| 21 #include "chromeos/dbus/ibus/ibus_text.h" | 20 #include "chromeos/dbus/ibus/ibus_text.h" |
| 22 #include "chromeos/ime/candidate_window.h" | 21 #include "chromeos/ime/candidate_window.h" |
| 23 #include "chromeos/ime/component_extension_ime_manager.h" | 22 #include "chromeos/ime/component_extension_ime_manager.h" |
| 24 #include "chromeos/ime/extension_ime_util.h" | 23 #include "chromeos/ime/extension_ime_util.h" |
| 25 #include "chromeos/ime/ibus_keymap.h" | 24 #include "chromeos/ime/ibus_keymap.h" |
| 26 #include "chromeos/ime/input_method_manager.h" | 25 #include "chromeos/ime/input_method_manager.h" |
| 27 #include "dbus/object_path.h" | 26 #include "dbus/object_path.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 IBusComponent::EngineDescription engine_desc; | 105 IBusComponent::EngineDescription engine_desc; |
| 107 engine_desc.engine_id = ibus_id_; | 106 engine_desc.engine_id = ibus_id_; |
| 108 engine_desc.display_name = description; | 107 engine_desc.display_name = description; |
| 109 engine_desc.description = description; | 108 engine_desc.description = description; |
| 110 engine_desc.language_code = (languages.empty()) ? "" : languages[0]; | 109 engine_desc.language_code = (languages.empty()) ? "" : languages[0]; |
| 111 engine_desc.author = ibus_id_; | 110 engine_desc.author = ibus_id_; |
| 112 | 111 |
| 113 component_->mutable_engine_description()->push_back(engine_desc); | 112 component_->mutable_engine_description()->push_back(engine_desc); |
| 114 manager->AddInputMethodExtension(ibus_id_, engine_name, layouts, languages, | 113 manager->AddInputMethodExtension(ibus_id_, engine_name, layouts, languages, |
| 115 options_page, input_view, this); | 114 options_page, input_view, this); |
| 116 // If connection is avaiable, register component. If there are no connection | 115 RegisterComponent(); |
| 117 // to ibus-daemon, OnConnected callback will register component instead. | |
| 118 if (IsConnected()) | |
| 119 RegisterComponent(); | |
| 120 } | 116 } |
| 121 | 117 |
| 122 void InputMethodEngineIBus::StartIme() { | 118 void InputMethodEngineIBus::StartIme() { |
| 123 input_method::InputMethodManager* manager = | 119 input_method::InputMethodManager* manager = |
| 124 input_method::InputMethodManager::Get(); | 120 input_method::InputMethodManager::Get(); |
| 125 if (manager && ibus_id_ == manager->GetCurrentInputMethod().id()) | 121 if (manager && ibus_id_ == manager->GetCurrentInputMethod().id()) |
| 126 Enable(); | 122 Enable(); |
| 127 } | 123 } |
| 128 | 124 |
| 129 bool InputMethodEngineIBus::SetComposition( | 125 bool InputMethodEngineIBus::SetComposition( |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 // TODO(nona): Support item.children. | 588 // TODO(nona): Support item.children. |
| 593 } | 589 } |
| 594 | 590 |
| 595 void InputMethodEngineIBus::OnConnected() { | 591 void InputMethodEngineIBus::OnConnected() { |
| 596 RegisterComponent(); | 592 RegisterComponent(); |
| 597 } | 593 } |
| 598 | 594 |
| 599 void InputMethodEngineIBus::OnDisconnected() { | 595 void InputMethodEngineIBus::OnDisconnected() { |
| 600 } | 596 } |
| 601 | 597 |
| 602 bool InputMethodEngineIBus::IsConnected() { | |
| 603 return DBusThreadManager::Get()->GetIBusClient() != NULL; | |
| 604 } | |
| 605 | |
| 606 void InputMethodEngineIBus::RegisterComponent() { | 598 void InputMethodEngineIBus::RegisterComponent() { |
| 607 IBusClient* client = DBusThreadManager::Get()->GetIBusClient(); | |
| 608 client->RegisterComponent( | |
| 609 *component_.get(), | |
| 610 base::Bind(&InputMethodEngineIBus::OnComponentRegistered, | |
| 611 weak_ptr_factory_.GetWeakPtr()), | |
| 612 base::Bind(&InputMethodEngineIBus::OnComponentRegistrationFailed, | |
| 613 weak_ptr_factory_.GetWeakPtr())); | |
| 614 } | |
| 615 | |
| 616 void InputMethodEngineIBus::OnComponentRegistered() { | |
| 617 ibus_engine_factory_service_->SetCreateEngineHandler( | 599 ibus_engine_factory_service_->SetCreateEngineHandler( |
| 618 ibus_id_, | 600 ibus_id_, |
| 619 base::Bind(&InputMethodEngineIBus::CreateEngineHandler, | 601 base::Bind(&InputMethodEngineIBus::CreateEngineHandler, |
| 620 weak_ptr_factory_.GetWeakPtr())); | 602 weak_ptr_factory_.GetWeakPtr())); |
| 621 } | 603 } |
| 622 | 604 |
| 623 void InputMethodEngineIBus::OnComponentRegistrationFailed() { | |
| 624 DVLOG(1) << "Failed to register input method components."; | |
| 625 // TODO(nona): Implement error handling. | |
| 626 } | |
| 627 | |
| 628 void InputMethodEngineIBus::CreateEngineHandler( | 605 void InputMethodEngineIBus::CreateEngineHandler( |
| 629 const IBusEngineFactoryService::CreateEngineResponseSender& sender) { | 606 const IBusEngineFactoryService::CreateEngineResponseSender& sender) { |
| 630 GetCurrentService()->UnsetEngine(this); | 607 GetCurrentService()->UnsetEngine(this); |
| 631 ibus_engine_service_.reset(); | 608 ibus_engine_service_.reset(); |
| 632 object_path_ = ibus_engine_factory_service_->GenerateUniqueObjectPath(); | 609 object_path_ = ibus_engine_factory_service_->GenerateUniqueObjectPath(); |
| 633 | 610 |
| 634 GetCurrentService()->SetEngine(this); | 611 GetCurrentService()->SetEngine(this); |
| 635 sender.Run(object_path_); | 612 sender.Run(object_path_); |
| 636 } | 613 } |
| 637 | 614 |
| 638 } // namespace chromeos | 615 } // namespace chromeos |
| OLD | NEW |