| 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_engine_ibus.h" |   14 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" | 
|   15 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |   15 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 
|   16 #include "chrome/browser/chromeos/language_preferences.h" |   16 #include "chrome/browser/chromeos/language_preferences.h" | 
|   17 #include "chromeos/dbus/dbus_thread_manager.h" |   17 #include "chromeos/dbus/dbus_thread_manager.h" | 
|   18 #include "chromeos/dbus/ibus/ibus_input_context_client.h" |   18 #include "chromeos/dbus/ibus/ibus_input_context_client.h" | 
 |   19 #include "chromeos/ime/extension_ime_util.h" | 
|   19 #include "chromeos/ime/input_method_delegate.h" |   20 #include "chromeos/ime/input_method_delegate.h" | 
|   20 #include "third_party/icu/public/common/unicode/uloc.h" |   21 #include "third_party/icu/public/common/unicode/uloc.h" | 
|   21 #include "ui/base/accelerators/accelerator.h" |   22 #include "ui/base/accelerators/accelerator.h" | 
|   22  |   23  | 
|   23 namespace chromeos { |   24 namespace chromeos { | 
|   24 namespace input_method { |   25 namespace input_method { | 
|   25  |   26  | 
|   26 namespace { |   27 namespace { | 
|   27  |   28  | 
|   28 bool Contains(const std::vector<std::string>& container, |   29 bool Contains(const std::vector<std::string>& container, | 
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  189  |  190  | 
|  190   if (new_active_input_method_ids_filtered.empty()) { |  191   if (new_active_input_method_ids_filtered.empty()) { | 
|  191     DVLOG(1) << "EnableInputMethods: No valid input method ID"; |  192     DVLOG(1) << "EnableInputMethods: No valid input method ID"; | 
|  192     return false; |  193     return false; | 
|  193   } |  194   } | 
|  194  |  195  | 
|  195   // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to |  196   // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to | 
|  196   // keep relative order of the extension input method IDs. |  197   // keep relative order of the extension input method IDs. | 
|  197   for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |  198   for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | 
|  198     const std::string& input_method_id = active_input_method_ids_[i]; |  199     const std::string& input_method_id = active_input_method_ids_[i]; | 
|  199     if (InputMethodUtil::IsExtensionInputMethod(input_method_id)) |  200     if (extension_ime_util::IsExtensionIME(input_method_id)) | 
|  200       new_active_input_method_ids_filtered.push_back(input_method_id); |  201       new_active_input_method_ids_filtered.push_back(input_method_id); | 
|  201   } |  202   } | 
|  202   active_input_method_ids_.swap(new_active_input_method_ids_filtered); |  203   active_input_method_ids_.swap(new_active_input_method_ids_filtered); | 
|  203  |  204  | 
|  204   if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { |  205   if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { | 
|  205     // Do NOT call ibus_controller_->Stop(); here to work around a crash issue |  206     // Do NOT call ibus_controller_->Stop(); here to work around a crash issue | 
|  206     // at crosbug.com/27051. |  207     // at crosbug.com/27051. | 
|  207     // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 |  208     // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 | 
|  208     // is implemented. |  209     // is implemented. | 
|  209   } else { |  210   } else { | 
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  276     if (input_context) |  277     if (input_context) | 
|  277       input_context->SetIsXKBLayout(true); |  278       input_context->SetIsXKBLayout(true); | 
|  278   } else { |  279   } else { | 
|  279     ibus_controller_->ChangeInputMethod(input_method_id_to_switch); |  280     ibus_controller_->ChangeInputMethod(input_method_id_to_switch); | 
|  280     if (input_context) |  281     if (input_context) | 
|  281       input_context->SetIsXKBLayout(false); |  282       input_context->SetIsXKBLayout(false); | 
|  282   } |  283   } | 
|  283  |  284  | 
|  284   if (current_input_method_.id() != input_method_id_to_switch) { |  285   if (current_input_method_.id() != input_method_id_to_switch) { | 
|  285     const InputMethodDescriptor* descriptor = NULL; |  286     const InputMethodDescriptor* descriptor = NULL; | 
|  286     if (!InputMethodUtil::IsExtensionInputMethod(input_method_id_to_switch)) { |  287     if (!extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { | 
|  287       descriptor = |  288       descriptor = | 
|  288           util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); |  289           util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); | 
|  289     } else { |  290     } else { | 
|  290       std::map<std::string, InputMethodDescriptor>::const_iterator i = |  291       std::map<std::string, InputMethodDescriptor>::const_iterator i = | 
|  291           extra_input_methods_.find(input_method_id_to_switch); |  292           extra_input_methods_.find(input_method_id_to_switch); | 
|  292       DCHECK(i != extra_input_methods_.end()); |  293       DCHECK(i != extra_input_methods_.end()); | 
|  293       descriptor = &(i->second); |  294       descriptor = &(i->second); | 
|  294     } |  295     } | 
|  295     DCHECK(descriptor); |  296     DCHECK(descriptor); | 
|  296  |  297  | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  319  |  320  | 
|  320 void InputMethodManagerImpl::AddInputMethodExtension( |  321 void InputMethodManagerImpl::AddInputMethodExtension( | 
|  321     const std::string& id, |  322     const std::string& id, | 
|  322     const std::string& name, |  323     const std::string& name, | 
|  323     const std::vector<std::string>& layouts, |  324     const std::vector<std::string>& layouts, | 
|  324     const std::string& language, |  325     const std::string& language, | 
|  325     InputMethodEngine* engine) { |  326     InputMethodEngine* engine) { | 
|  326   if (state_ == STATE_TERMINATING) |  327   if (state_ == STATE_TERMINATING) | 
|  327     return; |  328     return; | 
|  328  |  329  | 
|  329   if (!InputMethodUtil::IsExtensionInputMethod(id)) { |  330   if (!extension_ime_util::IsExtensionIME(id)) { | 
|  330     DVLOG(1) << id << " is not a valid extension input method ID."; |  331     DVLOG(1) << id << " is not a valid extension input method ID."; | 
|  331     return; |  332     return; | 
|  332   } |  333   } | 
|  333  |  334  | 
|  334   const std::string layout = layouts.empty() ? "" : layouts[0]; |  335   const std::string layout = layouts.empty() ? "" : layouts[0]; | 
|  335   extra_input_methods_[id] = |  336   extra_input_methods_[id] = | 
|  336       InputMethodDescriptor(id, name, layout, language, true); |  337       InputMethodDescriptor(id, name, layout, language, true); | 
|  337   if (!Contains(filtered_extension_imes_, id)) { |  338   if (!Contains(filtered_extension_imes_, id)) { | 
|  338     if (!Contains(active_input_method_ids_, id)) { |  339     if (!Contains(active_input_method_ids_, id)) { | 
|  339       active_input_method_ids_.push_back(id); |  340       active_input_method_ids_.push_back(id); | 
|  340     } else { |  341     } else { | 
|  341       DVLOG(1) << "AddInputMethodExtension: alread added: " |  342       DVLOG(1) << "AddInputMethodExtension: alread added: " | 
|  342                << id << ", " << name; |  343                << id << ", " << name; | 
|  343       // Call Start() anyway, just in case. |  344       // Call Start() anyway, just in case. | 
|  344     } |  345     } | 
|  345  |  346  | 
|  346     // Ensure that the input method daemon is running. |  347     // Ensure that the input method daemon is running. | 
|  347     MaybeInitializeCandidateWindowController(); |  348     MaybeInitializeCandidateWindowController(); | 
|  348     IBusDaemonController::GetInstance()->Start(); |  349     IBusDaemonController::GetInstance()->Start(); | 
|  349   } |  350   } | 
|  350  |  351  | 
|  351   extra_input_method_instances_[id] = |  352   extra_input_method_instances_[id] = | 
|  352       static_cast<InputMethodEngineIBus*>(engine); |  353       static_cast<InputMethodEngineIBus*>(engine); | 
|  353 } |  354 } | 
|  354  |  355  | 
|  355 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { |  356 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { | 
|  356   if (!InputMethodUtil::IsExtensionInputMethod(id)) |  357   if (!extension_ime_util::IsExtensionIME(id)) | 
|  357     DVLOG(1) << id << " is not a valid extension input method ID."; |  358     DVLOG(1) << id << " is not a valid extension input method ID."; | 
|  358  |  359  | 
|  359   std::vector<std::string>::iterator i = std::find( |  360   std::vector<std::string>::iterator i = std::find( | 
|  360       active_input_method_ids_.begin(), active_input_method_ids_.end(), id); |  361       active_input_method_ids_.begin(), active_input_method_ids_.end(), id); | 
|  361   if (i != active_input_method_ids_.end()) |  362   if (i != active_input_method_ids_.end()) | 
|  362     active_input_method_ids_.erase(i); |  363     active_input_method_ids_.erase(i); | 
|  363   extra_input_methods_.erase(id); |  364   extra_input_methods_.erase(id); | 
|  364  |  365  | 
|  365   if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { |  366   if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { | 
|  366     // Do NOT call ibus_controller_->Stop(); here to work around a crash issue |  367     // Do NOT call ibus_controller_->Stop(); here to work around a crash issue | 
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  694   candidate_window_controller_.reset( |  695   candidate_window_controller_.reset( | 
|  695       CandidateWindowController::CreateCandidateWindowController()); |  696       CandidateWindowController::CreateCandidateWindowController()); | 
|  696   if (candidate_window_controller_->Init(ibus_controller_.get())) |  697   if (candidate_window_controller_->Init(ibus_controller_.get())) | 
|  697     candidate_window_controller_->AddObserver(this); |  698     candidate_window_controller_->AddObserver(this); | 
|  698   else |  699   else | 
|  699     DVLOG(1) << "Failed to initialize the candidate window controller"; |  700     DVLOG(1) << "Failed to initialize the candidate window controller"; | 
|  700 } |  701 } | 
|  701  |  702  | 
|  702 }  // namespace input_method |  703 }  // namespace input_method | 
|  703 }  // namespace chromeos |  704 }  // namespace chromeos | 
| OLD | NEW |