| 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_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 13 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
| 14 #include "chrome/browser/chromeos/input_method/input_method_delegate.h" | 14 #include "chrome/browser/chromeos/input_method/input_method_delegate.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" | 15 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" |
| 16 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 16 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 17 #include "chrome/browser/chromeos/language_preferences.h" | 17 #include "chrome/browser/chromeos/language_preferences.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/dbus/ibus/ibus_input_context_client.h" |
| 18 #include "third_party/icu/public/common/unicode/uloc.h" | 20 #include "third_party/icu/public/common/unicode/uloc.h" |
| 19 #include "ui/base/accelerators/accelerator.h" | 21 #include "ui/base/accelerators/accelerator.h" |
| 20 | 22 |
| 21 namespace chromeos { | 23 namespace chromeos { |
| 22 namespace input_method { | 24 namespace input_method { |
| 23 | 25 |
| 24 namespace { | 26 namespace { |
| 25 | 27 |
| 26 bool Contains(const std::vector<std::string>& container, | 28 bool Contains(const std::vector<std::string>& container, |
| 27 const std::string& value) { | 29 const std::string& value) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); | 246 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); |
| 245 DCHECK(!input_methods->empty()); | 247 DCHECK(!input_methods->empty()); |
| 246 input_method_id_to_switch = input_methods->at(0).id(); | 248 input_method_id_to_switch = input_methods->at(0).id(); |
| 247 if (!input_method_id.empty()) { | 249 if (!input_method_id.empty()) { |
| 248 DVLOG(1) << "Can't change the current input method to " | 250 DVLOG(1) << "Can't change the current input method to " |
| 249 << input_method_id << " since the engine is not enabled. " | 251 << input_method_id << " since the engine is not enabled. " |
| 250 << "Switch to " << input_method_id_to_switch << " instead."; | 252 << "Switch to " << input_method_id_to_switch << " instead."; |
| 251 } | 253 } |
| 252 } | 254 } |
| 253 | 255 |
| 256 IBusInputContextClient* input_context = |
| 257 chromeos::DBusThreadManager::Get()->GetIBusInputContextClient(); |
| 254 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | 258 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { |
| 255 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 259 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| 256 observers_, | 260 observers_, |
| 257 InputMethodPropertyChanged(this)); | 261 InputMethodPropertyChanged(this)); |
| 258 // Hack for fixing http://crosbug.com/p/12798 | 262 // Hack for fixing http://crosbug.com/p/12798 |
| 259 // We should notify IME switching to ibus-daemon, otherwise | 263 // We should notify IME switching to ibus-daemon, otherwise |
| 260 // IBusPreeditFocusMode does not work. To achieve it, change engine to | 264 // IBusPreeditFocusMode does not work. To achieve it, change engine to |
| 261 // itself if the next engine is XKB layout. | 265 // itself if the next engine is XKB layout. |
| 262 const std::string current_input_method_id = current_input_method_.id(); | 266 const std::string current_input_method_id = current_input_method_.id(); |
| 263 if (current_input_method_id.empty() || | 267 if (current_input_method_id.empty() || |
| 264 InputMethodUtil::IsKeyboardLayout(current_input_method_id)) { | 268 InputMethodUtil::IsKeyboardLayout(current_input_method_id)) { |
| 265 ibus_controller_->Reset(); | 269 ibus_controller_->Reset(); |
| 266 } else { | 270 } else { |
| 267 ibus_controller_->ChangeInputMethod(current_input_method_id); | 271 ibus_controller_->ChangeInputMethod(current_input_method_id); |
| 268 } | 272 } |
| 273 if (input_context) |
| 274 input_context->SetIsXKBLayout(true); |
| 269 } else { | 275 } else { |
| 270 ibus_controller_->ChangeInputMethod(input_method_id_to_switch); | 276 ibus_controller_->ChangeInputMethod(input_method_id_to_switch); |
| 277 if (input_context) |
| 278 input_context->SetIsXKBLayout(false); |
| 271 } | 279 } |
| 272 | 280 |
| 273 if (current_input_method_.id() != input_method_id_to_switch) { | 281 if (current_input_method_.id() != input_method_id_to_switch) { |
| 274 const InputMethodDescriptor* descriptor = NULL; | 282 const InputMethodDescriptor* descriptor = NULL; |
| 275 if (!InputMethodUtil::IsExtensionInputMethod(input_method_id_to_switch)) { | 283 if (!InputMethodUtil::IsExtensionInputMethod(input_method_id_to_switch)) { |
| 276 descriptor = | 284 descriptor = |
| 277 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 285 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |
| 278 } else { | 286 } else { |
| 279 std::map<std::string, InputMethodDescriptor>::const_iterator i = | 287 std::map<std::string, InputMethodDescriptor>::const_iterator i = |
| 280 extra_input_methods_.find(input_method_id_to_switch); | 288 extra_input_methods_.find(input_method_id_to_switch); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 } | 565 } |
| 558 | 566 |
| 559 void InputMethodManagerImpl::OnConnected() { | 567 void InputMethodManagerImpl::OnConnected() { |
| 560 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = | 568 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 561 extra_input_method_instances_.begin(); | 569 extra_input_method_instances_.begin(); |
| 562 ite != extra_input_method_instances_.end(); | 570 ite != extra_input_method_instances_.end(); |
| 563 ite++) { | 571 ite++) { |
| 564 if (!Contains(filtered_extension_imes_, ite->first)) | 572 if (!Contains(filtered_extension_imes_, ite->first)) |
| 565 ite->second->OnConnected(); | 573 ite->second->OnConnected(); |
| 566 } | 574 } |
| 575 |
| 576 const bool is_xkb_layout = |
| 577 InputMethodUtil::IsKeyboardLayout(current_input_method_.id()); |
| 578 IBusInputContextClient* input_context = |
| 579 chromeos::DBusThreadManager::Get()->GetIBusInputContextClient(); |
| 580 DCHECK(input_context); |
| 581 input_context->SetIsXKBLayout(is_xkb_layout); |
| 567 } | 582 } |
| 568 | 583 |
| 569 void InputMethodManagerImpl::OnDisconnected() { | 584 void InputMethodManagerImpl::OnDisconnected() { |
| 570 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = | 585 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 571 extra_input_method_instances_.begin(); | 586 extra_input_method_instances_.begin(); |
| 572 ite != extra_input_method_instances_.end(); | 587 ite != extra_input_method_instances_.end(); |
| 573 ite++) { | 588 ite++) { |
| 574 if (!Contains(filtered_extension_imes_, ite->first)) | 589 if (!Contains(filtered_extension_imes_, ite->first)) |
| 575 ite->second->OnDisconnected(); | 590 ite->second->OnDisconnected(); |
| 576 } | 591 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 candidate_window_controller_.reset( | 691 candidate_window_controller_.reset( |
| 677 CandidateWindowController::CreateCandidateWindowController()); | 692 CandidateWindowController::CreateCandidateWindowController()); |
| 678 if (candidate_window_controller_->Init(ibus_controller_.get())) | 693 if (candidate_window_controller_->Init(ibus_controller_.get())) |
| 679 candidate_window_controller_->AddObserver(this); | 694 candidate_window_controller_->AddObserver(this); |
| 680 else | 695 else |
| 681 DVLOG(1) << "Failed to initialize the candidate window controller"; | 696 DVLOG(1) << "Failed to initialize the candidate window controller"; |
| 682 } | 697 } |
| 683 | 698 |
| 684 } // namespace input_method | 699 } // namespace input_method |
| 685 } // namespace chromeos | 700 } // namespace chromeos |
| OLD | NEW |