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 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 context_id_(0), | 46 context_id_(0), |
47 next_context_id_(1), | 47 next_context_id_(1), |
48 aux_text_(new IBusText()), | 48 aux_text_(new IBusText()), |
49 aux_text_visible_(false), | 49 aux_text_visible_(false), |
50 observer_(NULL), | 50 observer_(NULL), |
51 preedit_text_(new IBusText()), | 51 preedit_text_(new IBusText()), |
52 preedit_cursor_(0), | 52 preedit_cursor_(0), |
53 component_(new IBusComponent()), | 53 component_(new IBusComponent()), |
54 candidate_window_(new input_method::CandidateWindow()), | 54 candidate_window_(new input_method::CandidateWindow()), |
55 window_visible_(false), | 55 window_visible_(false), |
56 weak_ptr_factory_(this) { | 56 ibus_engine_factory_service_(IBusEngineFactoryService::Create()), |
57 } | 57 weak_ptr_factory_(this) {} |
58 | 58 |
59 InputMethodEngineIBus::~InputMethodEngineIBus() { | 59 InputMethodEngineIBus::~InputMethodEngineIBus() { |
60 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_); | 60 input_method::InputMethodManager::Get()->RemoveInputMethodExtension(ibus_id_); |
61 | 61 |
62 // Do not unset engine before removing input method extension, above function | 62 // Do not unset engine before removing input method extension, above function |
63 // may call reset function of engine object. | 63 // may call reset function of engine object. |
64 // TODO(nona): Call Reset manually here and remove relevant code from | 64 // TODO(nona): Call Reset manually here and remove relevant code from |
65 // InputMethodManager once ibus-daemon is gone. (crbug.com/158273) | 65 // InputMethodManager once ibus-daemon is gone. (crbug.com/158273) |
66 if (!object_path_.value().empty()) { | 66 if (!object_path_.value().empty()) { |
67 GetCurrentService()->UnsetEngine(this); | 67 GetCurrentService()->UnsetEngine(this); |
68 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); | 68 ibus_engine_service_.reset(); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 void InputMethodEngineIBus::Initialize( | 72 void InputMethodEngineIBus::Initialize( |
73 InputMethodEngine::Observer* observer, | 73 InputMethodEngine::Observer* observer, |
74 const char* engine_name, | 74 const char* engine_name, |
75 const char* extension_id, | 75 const char* extension_id, |
76 const char* engine_id, | 76 const char* engine_id, |
77 const char* description, | 77 const char* description, |
78 const std::vector<std::string>& languages, | 78 const std::vector<std::string>& languages, |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 void InputMethodEngineIBus::SetSurroundingText(const std::string& text, | 520 void InputMethodEngineIBus::SetSurroundingText(const std::string& text, |
521 uint32 cursor_pos, | 521 uint32 cursor_pos, |
522 uint32 anchor_pos) { | 522 uint32 anchor_pos) { |
523 observer_->OnSurroundingTextChanged(engine_id_, | 523 observer_->OnSurroundingTextChanged(engine_id_, |
524 text, | 524 text, |
525 static_cast<int>(cursor_pos), | 525 static_cast<int>(cursor_pos), |
526 static_cast<int>(anchor_pos)); | 526 static_cast<int>(anchor_pos)); |
527 } | 527 } |
528 | 528 |
529 IBusEngineService* InputMethodEngineIBus::GetCurrentService() { | 529 IBusEngineService* InputMethodEngineIBus::GetCurrentService() { |
530 return DBusThreadManager::Get()->GetIBusEngineService(object_path_); | 530 if (!ibus_engine_service_) |
| 531 ibus_engine_service_.reset(IBusEngineService::Create()); |
| 532 return ibus_engine_service_.get(); |
531 } | 533 } |
532 | 534 |
533 void InputMethodEngineIBus::MenuItemToProperty( | 535 void InputMethodEngineIBus::MenuItemToProperty( |
534 const MenuItem& item, | 536 const MenuItem& item, |
535 input_method::InputMethodProperty* property) { | 537 input_method::InputMethodProperty* property) { |
536 property->key = item.id; | 538 property->key = item.id; |
537 | 539 |
538 if (item.modified & MENU_ITEM_MODIFIED_LABEL) { | 540 if (item.modified & MENU_ITEM_MODIFIED_LABEL) { |
539 property->label = item.label; | 541 property->label = item.label; |
540 } | 542 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 IBusClient* client = DBusThreadManager::Get()->GetIBusClient(); | 588 IBusClient* client = DBusThreadManager::Get()->GetIBusClient(); |
587 client->RegisterComponent( | 589 client->RegisterComponent( |
588 *component_.get(), | 590 *component_.get(), |
589 base::Bind(&InputMethodEngineIBus::OnComponentRegistered, | 591 base::Bind(&InputMethodEngineIBus::OnComponentRegistered, |
590 weak_ptr_factory_.GetWeakPtr()), | 592 weak_ptr_factory_.GetWeakPtr()), |
591 base::Bind(&InputMethodEngineIBus::OnComponentRegistrationFailed, | 593 base::Bind(&InputMethodEngineIBus::OnComponentRegistrationFailed, |
592 weak_ptr_factory_.GetWeakPtr())); | 594 weak_ptr_factory_.GetWeakPtr())); |
593 } | 595 } |
594 | 596 |
595 void InputMethodEngineIBus::OnComponentRegistered() { | 597 void InputMethodEngineIBus::OnComponentRegistered() { |
596 DBusThreadManager::Get()->GetIBusEngineFactoryService()-> | 598 ibus_engine_factory_service_->SetCreateEngineHandler( |
597 SetCreateEngineHandler(ibus_id_, | 599 ibus_id_, |
598 base::Bind( | 600 base::Bind(&InputMethodEngineIBus::CreateEngineHandler, |
599 &InputMethodEngineIBus::CreateEngineHandler, | 601 weak_ptr_factory_.GetWeakPtr())); |
600 weak_ptr_factory_.GetWeakPtr())); | |
601 } | 602 } |
602 | 603 |
603 void InputMethodEngineIBus::OnComponentRegistrationFailed() { | 604 void InputMethodEngineIBus::OnComponentRegistrationFailed() { |
604 DVLOG(1) << "Failed to register input method components."; | 605 DVLOG(1) << "Failed to register input method components."; |
605 // TODO(nona): Implement error handling. | 606 // TODO(nona): Implement error handling. |
606 } | 607 } |
607 | 608 |
608 void InputMethodEngineIBus::CreateEngineHandler( | 609 void InputMethodEngineIBus::CreateEngineHandler( |
609 const IBusEngineFactoryService::CreateEngineResponseSender& sender) { | 610 const IBusEngineFactoryService::CreateEngineResponseSender& sender) { |
610 GetCurrentService()->UnsetEngine(this); | 611 GetCurrentService()->UnsetEngine(this); |
611 DBusThreadManager::Get()->RemoveIBusEngineService(object_path_); | 612 ibus_engine_service_.reset(); |
612 | 613 object_path_ = ibus_engine_factory_service_->GenerateUniqueObjectPath(); |
613 object_path_ = DBusThreadManager::Get()->GetIBusEngineFactoryService()-> | |
614 GenerateUniqueObjectPath(); | |
615 | 614 |
616 GetCurrentService()->SetEngine(this); | 615 GetCurrentService()->SetEngine(this); |
617 sender.Run(object_path_); | 616 sender.Run(object_path_); |
618 } | 617 } |
619 | 618 |
620 } // namespace chromeos | 619 } // namespace chromeos |
OLD | NEW |