| 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/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" | 17 #include "chrome/browser/chromeos/input_method/candidate_window_controller.h" |
| 18 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" | 18 #include "chrome/browser/chromeos/input_method/component_extension_ime_manager_i
mpl.h" |
| 19 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" | 19 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" |
| 20 #include "chrome/browser/chromeos/language_preferences.h" | 20 #include "chrome/browser/chromeos/language_preferences.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/dbus/ibus/ibus_client.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/input_method_delegate.h" | 24 #include "chromeos/ime/input_method_delegate.h" |
| 26 #include "chromeos/ime/xkeyboard.h" | 25 #include "chromeos/ime/xkeyboard.h" |
| 27 #include "third_party/icu/source/common/unicode/uloc.h" | 26 #include "third_party/icu/source/common/unicode/uloc.h" |
| 28 #include "ui/base/accelerators/accelerator.h" | 27 #include "ui/base/accelerators/accelerator.h" |
| 29 | 28 |
| 30 namespace chromeos { | 29 namespace chromeos { |
| 31 namespace input_method { | 30 namespace input_method { |
| 32 | 31 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); | 288 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); |
| 290 DCHECK(!input_methods->empty()); | 289 DCHECK(!input_methods->empty()); |
| 291 input_method_id_to_switch = input_methods->at(0).id(); | 290 input_method_id_to_switch = input_methods->at(0).id(); |
| 292 if (!input_method_id.empty()) { | 291 if (!input_method_id.empty()) { |
| 293 DVLOG(1) << "Can't change the current input method to " | 292 DVLOG(1) << "Can't change the current input method to " |
| 294 << input_method_id << " since the engine is not enabled. " | 293 << input_method_id << " since the engine is not enabled. " |
| 295 << "Switch to " << input_method_id_to_switch << " instead."; | 294 << "Switch to " << input_method_id_to_switch << " instead."; |
| 296 } | 295 } |
| 297 } | 296 } |
| 298 | 297 |
| 299 if (!component_extension_ime_manager_->IsInitialized() || | 298 if (!component_extension_ime_manager_->IsInitialized()) { |
| 300 (!InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch) && | 299 // We can't change input method before the initialization of |
| 301 !IsIBusConnectionAlive())) { | 300 // component extension ime manager. ChangeInputMethod will be |
| 302 // We can't change input method before the initialization of component | 301 // called with |pending_input_method_| when the initialization is |
| 303 // extension ime manager or before connection to ibus-daemon is not | 302 // done. |
| 304 // established. ChangeInputMethod will be called with | |
| 305 // |pending_input_method_| when the both initialization is done. | |
| 306 pending_input_method_ = input_method_id_to_switch; | 303 pending_input_method_ = input_method_id_to_switch; |
| 307 return false; | 304 return false; |
| 308 } | 305 } |
| 309 | 306 |
| 310 pending_input_method_.clear(); | 307 pending_input_method_.clear(); |
| 311 IBusEngineHandlerInterface* engine = IBusBridge::Get()->GetEngineHandler(); | 308 IBusEngineHandlerInterface* engine = IBusBridge::Get()->GetEngineHandler(); |
| 312 const std::string current_input_method_id = current_input_method_.id(); | 309 const std::string current_input_method_id = current_input_method_.id(); |
| 313 IBusClient* client = DBusThreadManager::Get()->GetIBusClient(); | |
| 314 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { | 310 if (InputMethodUtil::IsKeyboardLayout(input_method_id_to_switch)) { |
| 315 FOR_EACH_OBSERVER(InputMethodManager::Observer, | 311 FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| 316 observers_, | 312 observers_, |
| 317 InputMethodPropertyChanged(this)); | 313 InputMethodPropertyChanged(this)); |
| 318 if (engine) { | 314 if (engine) { |
| 319 engine->Disable(); | 315 engine->Disable(); |
| 320 IBusBridge::Get()->SetEngineHandler(NULL); | 316 IBusBridge::Get()->SetEngineHandler(NULL); |
| 321 } | 317 } |
| 322 } else { | 318 } else { |
| 323 DCHECK(client); | 319 // Disable the current engine and enable the next engine. |
| 324 client->SetGlobalEngine(input_method_id_to_switch, | 320 if (engine) |
| 325 base::Bind(&base::DoNothing)); | 321 engine->Disable(); |
| 322 IBusBridge::Get()->CreateEngine(input_method_id_to_switch); |
| 323 IBusEngineHandlerInterface* next_engine = |
| 324 IBusBridge::Get()->GetEngineHandler(); |
| 325 IBusBridge::Get()->SetEngineHandler(next_engine); |
| 326 if (next_engine) |
| 327 next_engine->Enable(); |
| 326 } | 328 } |
| 327 | 329 |
| 328 if (current_input_method_id != input_method_id_to_switch) { | 330 if (current_input_method_id != input_method_id_to_switch) { |
| 329 // Clear input method properties unconditionally if | 331 // Clear input method properties unconditionally if |
| 330 // |input_method_id_to_switch| is not equal to |current_input_method_id|. | 332 // |input_method_id_to_switch| is not equal to |current_input_method_id|. |
| 331 // | 333 // |
| 332 // When switching to another input method and no text area is focused, | 334 // When switching to another input method and no text area is focused, |
| 333 // RegisterProperties signal for the new input method will NOT be sent | 335 // RegisterProperties signal for the new input method will NOT be sent |
| 334 // until a text area is focused. Therefore, we have to clear the old input | 336 // until a text area is focused. Therefore, we have to clear the old input |
| 335 // method properties here to keep the input method switcher status | 337 // method properties here to keep the input method switcher status |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 return; | 861 return; |
| 860 | 862 |
| 861 candidate_window_controller_.reset( | 863 candidate_window_controller_.reset( |
| 862 CandidateWindowController::CreateCandidateWindowController()); | 864 CandidateWindowController::CreateCandidateWindowController()); |
| 863 if (candidate_window_controller_->Init()) | 865 if (candidate_window_controller_->Init()) |
| 864 candidate_window_controller_->AddObserver(this); | 866 candidate_window_controller_->AddObserver(this); |
| 865 else | 867 else |
| 866 DVLOG(1) << "Failed to initialize the candidate window controller"; | 868 DVLOG(1) << "Failed to initialize the candidate window controller"; |
| 867 } | 869 } |
| 868 | 870 |
| 869 bool InputMethodManagerImpl::IsIBusConnectionAlive() { | |
| 870 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); | |
| 871 } | |
| 872 | |
| 873 } // namespace input_method | 871 } // namespace input_method |
| 874 } // namespace chromeos | 872 } // namespace chromeos |
| OLD | NEW |