Chromium Code Reviews| 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_engine_factory_service.h" | |
| 18 #include "chromeos/dbus/ibus/ibus_engine_service.h" | 17 #include "chromeos/dbus/ibus/ibus_engine_service.h" |
| 19 #include "chromeos/dbus/ibus/ibus_text.h" | 18 #include "chromeos/dbus/ibus/ibus_text.h" |
| 20 #include "chromeos/ime/candidate_window.h" | 19 #include "chromeos/ime/candidate_window.h" |
| 21 #include "chromeos/ime/component_extension_ime_manager.h" | 20 #include "chromeos/ime/component_extension_ime_manager.h" |
| 22 #include "chromeos/ime/extension_ime_util.h" | 21 #include "chromeos/ime/extension_ime_util.h" |
| 23 #include "chromeos/ime/ibus_keymap.h" | 22 #include "chromeos/ime/ibus_keymap.h" |
| 24 #include "chromeos/ime/input_method_manager.h" | 23 #include "chromeos/ime/input_method_manager.h" |
| 25 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
| 26 | 25 |
| 27 namespace chromeos { | 26 namespace chromeos { |
| 28 const char* kErrorNotActive = "IME is not active"; | 27 const char* kErrorNotActive = "IME is not active"; |
| 29 const char* kErrorWrongContext = "Context is not active"; | 28 const char* kErrorWrongContext = "Context is not active"; |
| 30 const char* kCandidateNotFound = "Candidate not found"; | 29 const char* kCandidateNotFound = "Candidate not found"; |
| 31 const char* kEngineBusPrefix = "org.freedesktop.IBus."; | 30 const char* kEngineBusPrefix = "org.freedesktop.IBus."; |
| 32 | 31 |
| 33 namespace { | 32 namespace { |
| 34 const uint32 kIBusAltKeyMask = 1 << 3; | 33 const uint32 kIBusAltKeyMask = 1 << 3; |
| 35 const uint32 kIBusCtrlKeyMask = 1 << 2; | 34 const uint32 kIBusCtrlKeyMask = 1 << 2; |
| 36 const uint32 kIBusShiftKeyMask = 1 << 0; | 35 const uint32 kIBusShiftKeyMask = 1 << 0; |
| 37 const uint32 kIBusCapsLockMask = 1 << 1; | 36 const uint32 kIBusCapsLockMask = 1 << 1; |
| 38 const uint32 kIBusKeyReleaseMask = 1 << 30; | 37 const uint32 kIBusKeyReleaseMask = 1 << 30; |
| 39 } | 38 } |
| 40 | 39 |
| 41 InputMethodEngineIBus::InputMethodEngineIBus() | 40 InputMethodEngineIBus::InputMethodEngineIBus() |
| 42 : focused_(false), | 41 : focused_(false), |
| 43 active_(false), | 42 active_(false), |
| 44 context_id_(0), | 43 context_id_(0), |
| 45 next_context_id_(1), | 44 next_context_id_(1), |
| 45 is_create_engine_handler_called_(false), | |
| 46 aux_text_(new IBusText()), | 46 aux_text_(new IBusText()), |
| 47 aux_text_visible_(false), | 47 aux_text_visible_(false), |
| 48 observer_(NULL), | 48 observer_(NULL), |
| 49 preedit_text_(new IBusText()), | 49 preedit_text_(new IBusText()), |
| 50 preedit_cursor_(0), | 50 preedit_cursor_(0), |
| 51 candidate_window_(new input_method::CandidateWindow()), | 51 candidate_window_(new input_method::CandidateWindow()), |
| 52 window_visible_(false), | 52 window_visible_(false), |
| 53 ibus_engine_factory_service_(IBusEngineFactoryService::Create()), | |
| 54 weak_ptr_factory_(this) {} | 53 weak_ptr_factory_(this) {} |
| 55 | 54 |
| 56 InputMethodEngineIBus::~InputMethodEngineIBus() { | 55 InputMethodEngineIBus::~InputMethodEngineIBus() { |
| 57 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_); | 56 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_); |
| 58 | 57 |
| 59 // Do not unset engine before removing input method extension, above function | 58 // Do not unset engine before removing input method extension, above |
| 60 // may call reset function of engine object. | 59 // function may call reset function of engine object. |
| 61 // TODO(nona): Call Reset manually here and remove relevant code from | 60 if (is_create_engine_handler_called_) { |
| 62 // InputMethodManager once ibus-daemon is gone. (crbug.com/158273) | |
| 63 if (!object_path_.value().empty()) { | |
| 64 GetCurrentService()->UnsetEngine(this); | 61 GetCurrentService()->UnsetEngine(this); |
| 65 ibus_engine_service_.reset(); | 62 ibus_engine_service_.reset(); |
| 66 } | 63 } |
| 67 } | 64 } |
| 68 | 65 |
| 69 void InputMethodEngineIBus::Initialize( | 66 void InputMethodEngineIBus::Initialize( |
| 70 InputMethodEngine::Observer* observer, | 67 InputMethodEngine::Observer* observer, |
| 71 const char* engine_name, | 68 const char* engine_name, |
| 72 const char* extension_id, | 69 const char* extension_id, |
| 73 const char* engine_id, | 70 const char* engine_id, |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 } | 569 } |
| 573 | 570 |
| 574 void InputMethodEngineIBus::OnConnected() { | 571 void InputMethodEngineIBus::OnConnected() { |
| 575 RegisterComponent(); | 572 RegisterComponent(); |
| 576 } | 573 } |
| 577 | 574 |
| 578 void InputMethodEngineIBus::OnDisconnected() { | 575 void InputMethodEngineIBus::OnDisconnected() { |
| 579 } | 576 } |
| 580 | 577 |
| 581 void InputMethodEngineIBus::RegisterComponent() { | 578 void InputMethodEngineIBus::RegisterComponent() { |
| 582 ibus_engine_factory_service_->SetCreateEngineHandler( | 579 IBusBridge::Get()->SetCreateEngineHandler( |
| 583 ibus_id_, | 580 ibus_id_, |
| 584 base::Bind(&InputMethodEngineIBus::CreateEngineHandler, | 581 base::Bind(&InputMethodEngineIBus::CreateEngineHandler, |
| 585 weak_ptr_factory_.GetWeakPtr())); | 582 weak_ptr_factory_.GetWeakPtr())); |
| 586 } | 583 } |
| 587 | 584 |
| 588 void InputMethodEngineIBus::CreateEngineHandler( | 585 void InputMethodEngineIBus::CreateEngineHandler() { |
| 589 const IBusEngineFactoryService::CreateEngineResponseSender& sender) { | |
| 590 GetCurrentService()->UnsetEngine(this); | 586 GetCurrentService()->UnsetEngine(this); |
|
Seigo Nonaka
2013/11/12 03:37:22
Seems no need to call this function?
Hiro Komatsu
2013/11/12 05:01:39
I am deleting IBusEngineService in a different pat
| |
| 591 ibus_engine_service_.reset(); | 587 ibus_engine_service_.reset(); |
| 592 object_path_ = ibus_engine_factory_service_->GenerateUniqueObjectPath(); | |
| 593 | |
| 594 GetCurrentService()->SetEngine(this); | 588 GetCurrentService()->SetEngine(this); |
| 595 sender.Run(object_path_); | 589 is_create_engine_handler_called_ = true; |
| 596 } | 590 } |
| 597 | 591 |
| 598 } // namespace chromeos | 592 } // namespace chromeos |
| OLD | NEW |