Chromium Code Reviews| 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" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 | 32 |
| 33 const char nacl_mozc_jp_id[] = | 33 const char nacl_mozc_jp_id[] = |
| 34 "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp"; | 34 "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp"; |
| 35 | 35 |
| 36 bool Contains(const std::vector<std::string>& container, | 36 bool Contains(const std::vector<std::string>& container, |
| 37 const std::string& value) { | 37 const std::string& value) { |
| 38 return std::find(container.begin(), container.end(), value) != | 38 return std::find(container.begin(), container.end(), value) != |
| 39 container.end(); | 39 container.end(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void UniquifyVectorWithKeepingOrder(std::vector<std::string>* v) { | |
| 43 DCHECK(v); | |
| 44 std::set<std::string> added_value; | |
| 45 size_t output_pos = 0; | |
| 46 for (size_t i = 0; i < v->size(); ++i) { | |
| 47 if ((*v)[i].empty()) | |
| 48 continue; | |
| 49 if (added_value.find((*v)[i]) == added_value.end()) { | |
| 50 (*v)[output_pos++] = (*v)[i]; | |
| 51 added_value.insert((*v)[i]); | |
| 52 } | |
| 53 } | |
| 54 v->resize(output_pos); | |
| 55 } | |
| 56 | |
| 42 } // namespace | 57 } // namespace |
| 43 | 58 |
| 44 bool InputMethodManagerImpl::IsLoginKeyboard( | 59 bool InputMethodManagerImpl::IsLoginKeyboard( |
| 45 const std::string& layout) const { | 60 const std::string& layout) const { |
| 46 return util_.IsLoginKeyboard(layout); | 61 return util_.IsLoginKeyboard(layout); |
| 47 } | 62 } |
| 48 | 63 |
| 49 InputMethodManagerImpl::InputMethodManagerImpl( | 64 InputMethodManagerImpl::InputMethodManagerImpl( |
| 50 scoped_ptr<InputMethodDelegate> delegate) | 65 scoped_ptr<InputMethodDelegate> delegate) |
| 51 : delegate_(delegate.Pass()), | 66 : delegate_(delegate.Pass()), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 std::map<std::string, InputMethodDescriptor>::const_iterator ix = | 167 std::map<std::string, InputMethodDescriptor>::const_iterator ix = |
| 153 extra_input_methods_.find(input_method_id); | 168 extra_input_methods_.find(input_method_id); |
| 154 if (ix != extra_input_methods_.end()) | 169 if (ix != extra_input_methods_.end()) |
| 155 ime = &ix->second; | 170 ime = &ix->second; |
| 156 } | 171 } |
| 157 return ime; | 172 return ime; |
| 158 } | 173 } |
| 159 | 174 |
| 160 void InputMethodManagerImpl::EnableLoginLayouts( | 175 void InputMethodManagerImpl::EnableLoginLayouts( |
| 161 const std::string& language_code, | 176 const std::string& language_code, |
| 162 const std::string& initial_layout) { | 177 const std::vector<std::string>& initial_layouts) { |
| 163 if (state_ == STATE_TERMINATING) | 178 if (state_ == STATE_TERMINATING) |
| 164 return; | 179 return; |
| 165 | 180 |
| 166 std::vector<std::string> candidates; | 181 std::vector<std::string> candidates; |
| 167 // Add input methods associated with the language. | 182 // Add input methods associated with the language. |
| 168 util_.GetInputMethodIdsFromLanguageCode(language_code, | 183 util_.GetInputMethodIdsFromLanguageCode(language_code, |
| 169 kKeyboardLayoutsOnly, | 184 kKeyboardLayoutsOnly, |
| 170 &candidates); | 185 &candidates); |
| 171 // Add the hardware keyboard as well. We should always add this so users | 186 // Add the hardware keyboard as well. We should always add this so users |
| 172 // can use the hardware keyboard on the login screen and the screen locker. | 187 // can use the hardware keyboard on the login screen and the screen locker. |
| 173 candidates.push_back(util_.GetHardwareLoginInputMethodId()); | 188 std::vector<std::string> hardware_layouts; |
| 189 util_.GetHardwareLoginInputMethodId(&hardware_layouts); | |
| 190 candidates.insert(candidates.end(), hardware_layouts.begin(), | |
| 191 hardware_layouts.end()); | |
| 174 | 192 |
| 175 std::vector<std::string> layouts; | 193 std::vector<std::string> layouts; |
| 176 // First, add the initial input method ID, if it's requested, to | 194 // First, add the initial input method ID, if it's requested, to |
| 177 // layouts, so it appears first on the list of active input | 195 // layouts, so it appears first on the list of active input |
| 178 // methods at the input language status menu. | 196 // methods at the input language status menu. |
| 179 if (util_.IsValidInputMethodId(initial_layout)) { | 197 for (size_t i = 0; i < initial_layouts.size(); ++i) { |
| 180 if (!IsLoginKeyboard(initial_layout)) { | 198 if (util_.IsValidInputMethodId(initial_layouts[i])) { |
| 181 DVLOG(1) | 199 if (!IsLoginKeyboard(initial_layouts[i])) { |
| 182 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:" | 200 DVLOG(1) |
| 183 << initial_layout; | 201 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:" |
| 184 } else { | 202 << initial_layouts[i]; |
| 185 layouts.push_back(initial_layout); | 203 } else { |
| 204 layouts.push_back(initial_layouts[i]); | |
| 205 } | |
| 206 } else if (!initial_layouts[i].empty()) { | |
| 207 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: " | |
| 208 << initial_layouts[i]; | |
| 186 } | 209 } |
| 187 } else if (!initial_layout.empty()) { | |
| 188 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: " | |
| 189 << initial_layout; | |
| 190 } | 210 } |
| 191 | 211 |
| 192 // Add candidates to layouts, while skipping duplicates. | 212 // Add candidates to layouts, while skipping duplicates. |
| 193 for (size_t i = 0; i < candidates.size(); ++i) { | 213 for (size_t i = 0; i < candidates.size(); ++i) { |
| 194 const std::string& candidate = candidates[i]; | 214 const std::string& candidate = candidates[i]; |
| 195 // Not efficient, but should be fine, as the two vectors are very | 215 // Not efficient, but should be fine, as the two vectors are very |
| 196 // short (2-5 items). | 216 // short (2-5 items). |
| 197 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) | 217 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) |
| 198 layouts.push_back(candidate); | 218 layouts.push_back(candidate); |
| 199 } | 219 } |
| 200 | 220 |
| 201 active_input_method_ids_.swap(layouts); | 221 active_input_method_ids_.swap(layouts); |
| 202 | 222 |
| 203 // Initialize candidate window controller and widgets such as | 223 // Initialize candidate window controller and widgets such as |
| 204 // candidate window, infolist and mode indicator. Note, mode | 224 // candidate window, infolist and mode indicator. Note, mode |
| 205 // indicator is used by only keyboard layout input methods. | 225 // indicator is used by only keyboard layout input methods. |
| 206 if (active_input_method_ids_.size() > 1) | 226 if (active_input_method_ids_.size() > 1) |
| 207 MaybeInitializeCandidateWindowController(); | 227 MaybeInitializeCandidateWindowController(); |
| 208 | 228 |
| 209 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. | 229 // you can pass empty |initial_layout|. |
| 230 ChangeInputMethod(initial_layouts.empty() ? "" : initial_layouts[0]); | |
| 210 } | 231 } |
| 211 | 232 |
| 212 // Adds new input method to given list. | 233 // Adds new input method to given list. |
| 213 bool InputMethodManagerImpl::EnableInputMethodImpl( | 234 bool InputMethodManagerImpl::EnableInputMethodImpl( |
| 214 const std::string& input_method_id, | 235 const std::string& input_method_id, |
| 215 std::vector<std::string>* new_active_input_method_ids) const { | 236 std::vector<std::string>* new_active_input_method_ids) const { |
| 216 DCHECK(new_active_input_method_ids); | 237 DCHECK(new_active_input_method_ids); |
| 217 if (!util_.IsValidInputMethodId(input_method_id)) { | 238 if (!util_.IsValidInputMethodId(input_method_id)) { |
| 218 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; | 239 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; |
| 219 return false; | 240 return false; |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 | 562 |
| 542 void InputMethodManagerImpl::SetInputMethodDefault() { | 563 void InputMethodManagerImpl::SetInputMethodDefault() { |
| 543 // Set up keyboards. For example, when |locale| is "en-US", enable US qwerty | 564 // Set up keyboards. For example, when |locale| is "en-US", enable US qwerty |
| 544 // and US dvorak keyboard layouts. | 565 // and US dvorak keyboard layouts. |
| 545 if (g_browser_process && g_browser_process->local_state()) { | 566 if (g_browser_process && g_browser_process->local_state()) { |
| 546 const std::string locale = g_browser_process->GetApplicationLocale(); | 567 const std::string locale = g_browser_process->GetApplicationLocale(); |
| 547 // If the preferred keyboard for the login screen has been saved, use it. | 568 // If the preferred keyboard for the login screen has been saved, use it. |
| 548 PrefService* prefs = g_browser_process->local_state(); | 569 PrefService* prefs = g_browser_process->local_state(); |
| 549 std::string initial_input_method_id = | 570 std::string initial_input_method_id = |
| 550 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); | 571 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); |
| 572 std::vector<std::string> input_methods_to_be_enabled; | |
| 551 if (initial_input_method_id.empty()) { | 573 if (initial_input_method_id.empty()) { |
| 552 // If kPreferredKeyboardLayout is not specified, use the hardware layout. | 574 // If kPreferredKeyboardLayout is not specified, use the hardware layout. |
| 553 initial_input_method_id = | 575 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.
| |
| 554 GetInputMethodUtil()->GetHardwareInputMethodId(); | 576 } else { |
| 577 input_methods_to_be_enabled.push_back(initial_input_method_id); | |
| 555 } | 578 } |
| 556 EnableLoginLayouts(locale, initial_input_method_id); | 579 EnableLoginLayouts(locale, input_methods_to_be_enabled); |
| 557 } | 580 } |
| 558 } | 581 } |
| 559 | 582 |
| 560 bool InputMethodManagerImpl::SwitchToNextInputMethod() { | 583 bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
| 561 // Sanity checks. | 584 // Sanity checks. |
| 562 if (active_input_method_ids_.empty()) { | 585 if (active_input_method_ids_.empty()) { |
| 563 DVLOG(1) << "active input method is empty"; | 586 DVLOG(1) << "active input method is empty"; |
| 564 return false; | 587 return false; |
| 565 } | 588 } |
| 566 | 589 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, | 798 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, |
| 776 candidate_window_observers_, | 799 candidate_window_observers_, |
| 777 CandidateWindowClosed(this)); | 800 CandidateWindowClosed(this)); |
| 778 } | 801 } |
| 779 | 802 |
| 780 void InputMethodManagerImpl::OnScreenLocked() { | 803 void InputMethodManagerImpl::OnScreenLocked() { |
| 781 saved_previous_input_method_ = previous_input_method_; | 804 saved_previous_input_method_ = previous_input_method_; |
| 782 saved_current_input_method_ = current_input_method_; | 805 saved_current_input_method_ = current_input_method_; |
| 783 saved_active_input_method_ids_ = active_input_method_ids_; | 806 saved_active_input_method_ids_ = active_input_method_ids_; |
| 784 | 807 |
| 785 const std::string hardware_keyboard_id = util_.GetHardwareInputMethodId(); | 808 std::vector<std::string> hardware_keyboard_ids; |
| 786 // We'll add the hardware keyboard if it's not included in | 809 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.
| |
| 787 // |active_input_method_list| so that the user can always use the hardware | |
| 788 // keyboard on the screen locker. | |
| 789 bool should_add_hardware_keyboard = true; | |
| 790 | 810 |
| 791 active_input_method_ids_.clear(); | 811 active_input_method_ids_.clear(); |
| 792 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { | 812 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| 793 const std::string& input_method_id = saved_active_input_method_ids_[i]; | 813 const std::string& input_method_id = saved_active_input_method_ids_[i]; |
| 794 // Skip if it's not a keyboard layout. Drop input methods including | 814 // Skip if it's not a keyboard layout. Drop input methods including |
| 795 // extension ones. | 815 // extension ones. |
| 796 if (!IsLoginKeyboard(input_method_id)) | 816 if (!IsLoginKeyboard(input_method_id)) |
| 797 continue; | 817 continue; |
| 798 active_input_method_ids_.push_back(input_method_id); | 818 active_input_method_ids_.push_back(input_method_id); |
| 799 if (input_method_id == hardware_keyboard_id) | |
| 800 should_add_hardware_keyboard = false; | |
| 801 } | 819 } |
| 802 if (should_add_hardware_keyboard) | 820 |
| 803 active_input_method_ids_.push_back(hardware_keyboard_id); | 821 // We'll add the hardware keyboard if it's not included in |
| 822 // |active_input_method_ids_| so that the user can always use the hardware | |
| 823 // keyboard on the screen locker. | |
| 824 active_input_method_ids_.insert(active_input_method_ids_.end(), | |
| 825 hardware_keyboard_ids.begin(), | |
| 826 hardware_keyboard_ids.end()); | |
| 827 | |
| 828 UniquifyVectorWithKeepingOrder(&active_input_method_ids_); | |
| 804 | 829 |
| 805 ChangeInputMethod(current_input_method_.id()); | 830 ChangeInputMethod(current_input_method_.id()); |
| 806 } | 831 } |
| 807 | 832 |
| 808 void InputMethodManagerImpl::OnScreenUnlocked() { | 833 void InputMethodManagerImpl::OnScreenUnlocked() { |
| 809 previous_input_method_ = saved_previous_input_method_; | 834 previous_input_method_ = saved_previous_input_method_; |
| 810 current_input_method_ = saved_current_input_method_; | 835 current_input_method_ = saved_current_input_method_; |
| 811 active_input_method_ids_ = saved_active_input_method_ids_; | 836 active_input_method_ids_ = saved_active_input_method_ids_; |
| 812 | 837 |
| 813 ChangeInputMethod(current_input_method_.id()); | 838 ChangeInputMethod(current_input_method_.id()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 831 if (candidate_window_controller_.get()) | 856 if (candidate_window_controller_.get()) |
| 832 return; | 857 return; |
| 833 | 858 |
| 834 candidate_window_controller_.reset( | 859 candidate_window_controller_.reset( |
| 835 CandidateWindowController::CreateCandidateWindowController()); | 860 CandidateWindowController::CreateCandidateWindowController()); |
| 836 candidate_window_controller_->AddObserver(this); | 861 candidate_window_controller_->AddObserver(this); |
| 837 } | 862 } |
| 838 | 863 |
| 839 } // namespace input_method | 864 } // namespace input_method |
| 840 } // namespace chromeos | 865 } // namespace chromeos |
| OLD | NEW |