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..d4c3f91d65c35c4eeef924982f713e33da3a6933 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,34 +174,40 @@ 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; |
| - std::vector<std::string> candidates; |
| + // First, hardware keyboard layout should be shown. |
| + std::vector<std::string> candidates = |
| + util_.GetHardwareLoginInputMethodIds(); |
| + |
| + // Seocnd, locale based input method should be shown. |
| // Add input methods associated with the language. |
| + std::vector<std::string> layouts_from_locale; |
| util_.GetInputMethodIdsFromLanguageCode(language_code, |
| kKeyboardLayoutsOnly, |
| - &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()); |
| + &layouts_from_locale); |
| + candidates.insert(candidates.end(), layouts_from_locale.begin(), |
| + layouts_from_locale.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])) { |
|
Hiro Komatsu
2014/02/14 07:16:51
Let's remove '!' and swap if and else blocks.
Seigo Nonaka
2014/02/14 08:13:22
Done.
|
| + 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 +227,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. |
| @@ -539,7 +561,7 @@ void InputMethodManagerImpl::SetEnabledExtensionImes( |
| } |
| } |
| -void InputMethodManagerImpl::SetInputMethodDefault() { |
| +void InputMethodManagerImpl::SetInputMethodLoginDefault() { |
| // Set up keyboards. For example, when |locale| is "en-US", enable US qwerty |
| // and US dvorak keyboard layouts. |
| if (g_browser_process && g_browser_process->local_state()) { |
| @@ -548,12 +570,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(); |
| + input_methods_to_be_enabled = util_.GetHardwareLoginInputMethodIds(); |
| + } 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 +806,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; |
| + const std::vector<std::string>& hardware_keyboard_ids = |
| + util_.GetHardwareLoginInputMethodIds(); |
| active_input_method_ids_.clear(); |
| for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| @@ -796,11 +817,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_); |
|
Hiro Komatsu
2014/02/14 07:16:51
How about checking the existence when you add entr
Seigo Nonaka
2014/02/14 08:13:22
Done.
|
| ChangeInputMethod(current_input_method_.id()); |
| } |