Chromium Code Reviews| Index: chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| index 4070e7d31150e658352e60fcdda4560337f6b00f..8e7232c7cde034267e479db27140c72cf1a1c896 100644 |
| --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| @@ -39,6 +39,21 @@ bool Contains(const std::vector<std::string>& container, |
| container.end(); |
| } |
| +void UniquifyVectorWithKeepingOrder(std::vector<std::string>* v) { |
| + DCHECK(v); |
| + std::set<std::string> added_value; |
| + size_t output_pos = 0; |
| + for (size_t i = 0; i < v->size(); ++i) { |
| + if ((*v)[i].empty()) |
| + continue; |
| + if (added_value.find((*v)[i]) == added_value.end()) { |
| + (*v)[output_pos++] = (*v)[i]; |
| + added_value.insert((*v)[i]); |
| + } |
| + } |
| + v->resize(output_pos); |
| +} |
| + |
| } // namespace |
| bool InputMethodManagerImpl::IsLoginKeyboard( |
| @@ -159,7 +174,7 @@ const InputMethodDescriptor* InputMethodManagerImpl::GetInputMethodFromId( |
| void InputMethodManagerImpl::EnableLoginLayouts( |
| const std::string& language_code, |
| - const std::string& initial_layout) { |
| + const std::vector<std::string>& initial_layouts) { |
| if (state_ == STATE_TERMINATING) |
| return; |
| @@ -170,23 +185,28 @@ void InputMethodManagerImpl::EnableLoginLayouts( |
| &candidates); |
| // Add the hardware keyboard as well. We should always add this so users |
| // can use the hardware keyboard on the login screen and the screen locker. |
| - candidates.push_back(util_.GetHardwareLoginInputMethodId()); |
| + std::vector<std::string> hardware_layouts; |
| + util_.GetHardwareLoginInputMethodId(&hardware_layouts); |
| + candidates.insert(candidates.end(), hardware_layouts.begin(), |
| + hardware_layouts.end()); |
| std::vector<std::string> layouts; |
| // First, add the initial input method ID, if it's requested, to |
| // layouts, so it appears first on the list of active input |
| // methods at the input language status menu. |
| - if (util_.IsValidInputMethodId(initial_layout)) { |
| - if (!IsLoginKeyboard(initial_layout)) { |
| - DVLOG(1) |
| - << "EnableLoginLayouts: ignoring non-login initial keyboard layout:" |
| - << initial_layout; |
| - } else { |
| - layouts.push_back(initial_layout); |
| + for (size_t i = 0; i < initial_layouts.size(); ++i) { |
| + if (util_.IsValidInputMethodId(initial_layouts[i])) { |
| + if (!IsLoginKeyboard(initial_layouts[i])) { |
| + DVLOG(1) |
| + << "EnableLoginLayouts: ignoring non-login initial keyboard layout:" |
| + << initial_layouts[i]; |
| + } else { |
| + layouts.push_back(initial_layouts[i]); |
| + } |
| + } else if (!initial_layouts[i].empty()) { |
| + DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: " |
| + << initial_layouts[i]; |
| } |
| - } else if (!initial_layout.empty()) { |
| - DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: " |
| - << initial_layout; |
| } |
| // Add candidates to layouts, while skipping duplicates. |
| @@ -206,7 +226,8 @@ void InputMethodManagerImpl::EnableLoginLayouts( |
| if (active_input_method_ids_.size() > 1) |
| MaybeInitializeCandidateWindowController(); |
| - ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. |
| + // you can pass empty |initial_layout|. |
| + ChangeInputMethod(initial_layouts.empty() ? "" : initial_layouts[0]); |
| } |
| // Adds new input method to given list. |
| @@ -548,12 +569,14 @@ void InputMethodManagerImpl::SetInputMethodDefault() { |
| PrefService* prefs = g_browser_process->local_state(); |
| std::string initial_input_method_id = |
| prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); |
| + std::vector<std::string> input_methods_to_be_enabled; |
| if (initial_input_method_id.empty()) { |
| // If kPreferredKeyboardLayout is not specified, use the hardware layout. |
| - initial_input_method_id = |
| - GetInputMethodUtil()->GetHardwareInputMethodId(); |
| + util_.GetHardwareInputMethodIds(&input_methods_to_be_enabled); |
|
Alexander Alekseev
2014/02/11 13:36:02
SetInputMethodDefault() is called only from signin
Seigo Nonaka
2014/02/12 13:21:02
Done.
|
| + } else { |
| + input_methods_to_be_enabled.push_back(initial_input_method_id); |
| } |
| - EnableLoginLayouts(locale, initial_input_method_id); |
| + EnableLoginLayouts(locale, input_methods_to_be_enabled); |
| } |
| } |
| @@ -782,11 +805,8 @@ void InputMethodManagerImpl::OnScreenLocked() { |
| saved_current_input_method_ = current_input_method_; |
| saved_active_input_method_ids_ = active_input_method_ids_; |
| - const std::string hardware_keyboard_id = util_.GetHardwareInputMethodId(); |
| - // We'll add the hardware keyboard if it's not included in |
| - // |active_input_method_list| so that the user can always use the hardware |
| - // keyboard on the screen locker. |
| - bool should_add_hardware_keyboard = true; |
| + std::vector<std::string> hardware_keyboard_ids; |
| + util_.GetHardwareInputMethodIds(&hardware_keyboard_ids); |
|
Alexander Alekseev
2014/02/11 13:36:02
GetHardwareLoginInputMethodIds() (only login hardw
Seigo Nonaka
2014/02/12 13:21:02
Done.
|
| active_input_method_ids_.clear(); |
| for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| @@ -796,11 +816,16 @@ void InputMethodManagerImpl::OnScreenLocked() { |
| if (!IsLoginKeyboard(input_method_id)) |
| continue; |
| active_input_method_ids_.push_back(input_method_id); |
| - if (input_method_id == hardware_keyboard_id) |
| - should_add_hardware_keyboard = false; |
| } |
| - if (should_add_hardware_keyboard) |
| - active_input_method_ids_.push_back(hardware_keyboard_id); |
| + |
| + // We'll add the hardware keyboard if it's not included in |
| + // |active_input_method_ids_| so that the user can always use the hardware |
| + // keyboard on the screen locker. |
| + active_input_method_ids_.insert(active_input_method_ids_.end(), |
| + hardware_keyboard_ids.begin(), |
| + hardware_keyboard_ids.end()); |
| + |
| + UniquifyVectorWithKeepingOrder(&active_input_method_ids_); |
| ChangeInputMethod(current_input_method_.id()); |
| } |