| 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 25 matching lines...) Expand all Loading... |
| 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 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 bool InputMethodManagerImpl::IsLoginKeyboard( | 44 bool InputMethodManagerImpl::IsLoginKeyboard( |
| 45 const std::string& layout) const { | 45 const std::string& layout) const { |
| 46 const InputMethodDescriptor* ime = | 46 return util_.IsLoginKeyboard(layout); |
| 47 util_.GetInputMethodDescriptorFromId(layout); | |
| 48 return ime ? ime->is_login_keyboard() : false; | |
| 49 } | 47 } |
| 50 | 48 |
| 51 InputMethodManagerImpl::InputMethodManagerImpl( | 49 InputMethodManagerImpl::InputMethodManagerImpl( |
| 52 scoped_ptr<InputMethodDelegate> delegate) | 50 scoped_ptr<InputMethodDelegate> delegate) |
| 53 : delegate_(delegate.Pass()), | 51 : delegate_(delegate.Pass()), |
| 54 state_(STATE_LOGIN_SCREEN), | 52 state_(STATE_LOGIN_SCREEN), |
| 55 util_(delegate_.get(), GetSupportedInputMethods()), | 53 util_(delegate_.get(), GetSupportedInputMethods()), |
| 56 component_extension_ime_manager_(new ComponentExtensionIMEManager()), | 54 component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
| 57 weak_ptr_factory_(this) { | 55 weak_ptr_factory_(this) { |
| 58 } | 56 } |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const std::vector<std::string>& | 138 const std::vector<std::string>& |
| 141 InputMethodManagerImpl::GetActiveInputMethodIds() const { | 139 InputMethodManagerImpl::GetActiveInputMethodIds() const { |
| 142 return active_input_method_ids_; | 140 return active_input_method_ids_; |
| 143 } | 141 } |
| 144 | 142 |
| 145 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { | 143 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { |
| 146 return active_input_method_ids_.size(); | 144 return active_input_method_ids_.size(); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void InputMethodManagerImpl::EnableLayouts(const std::string& language_code, | 147 void InputMethodManagerImpl::EnableLayouts(const std::string& language_code, |
| 150 const std::string& initial_layout) { | 148 const std::string& initial_layout, |
| 149 const bool login_layouts_only) { |
| 151 if (state_ == STATE_TERMINATING) | 150 if (state_ == STATE_TERMINATING) |
| 152 return; | 151 return; |
| 153 | 152 |
| 154 std::vector<std::string> candidates; | 153 std::vector<std::string> candidates; |
| 155 // Add input methods associated with the language. | 154 // Add input methods associated with the language. |
| 156 util_.GetInputMethodIdsFromLanguageCode(language_code, | 155 util_.GetInputMethodIdsFromLanguageCode(language_code, |
| 157 kKeyboardLayoutsOnly, | 156 kKeyboardLayoutsOnly, |
| 158 &candidates); | 157 &candidates); |
| 159 // Add the hardware keyboard as well. We should always add this so users | 158 // Add the hardware keyboard as well. We should always add this so users |
| 160 // can use the hardware keyboard on the login screen and the screen locker. | 159 // can use the hardware keyboard on the login screen and the screen locker. |
| 161 candidates.push_back(util_.GetHardwareInputMethodId()); | 160 candidates.push_back(util_.GetHardwareLoginInputMethodId()); |
| 162 | 161 |
| 163 std::vector<std::string> layouts; | 162 std::vector<std::string> layouts; |
| 164 // First, add the initial input method ID, if it's requested, to | 163 // First, add the initial input method ID, if it's requested, to |
| 165 // layouts, so it appears first on the list of active input | 164 // layouts, so it appears first on the list of active input |
| 166 // methods at the input language status menu. | 165 // methods at the input language status menu. |
| 167 if (util_.IsValidInputMethodId(initial_layout) && | 166 if (util_.IsValidInputMethodId(initial_layout)) { |
| 168 IsLoginKeyboard(initial_layout)) { | 167 if (login_layouts_only && !IsLoginKeyboard(initial_layout)) { |
| 169 layouts.push_back(initial_layout); | 168 DVLOG(1) << "EnableLayouts: ignoring non-login initial keyboard layout:" |
| 169 << initial_layout; |
| 170 } else { |
| 171 layouts.push_back(initial_layout); |
| 172 } |
| 170 } else if (!initial_layout.empty()) { | 173 } else if (!initial_layout.empty()) { |
| 171 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " | 174 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " |
| 172 << initial_layout; | 175 << initial_layout; |
| 173 } | 176 } |
| 174 | 177 |
| 175 // Add candidates to layouts, while skipping duplicates. | 178 // Add candidates to layouts, while skipping duplicates. |
| 176 for (size_t i = 0; i < candidates.size(); ++i) { | 179 for (size_t i = 0; i < candidates.size(); ++i) { |
| 177 const std::string& candidate = candidates[i]; | 180 const std::string& candidate = candidates[i]; |
| 178 // Not efficient, but should be fine, as the two vectors are very | 181 // Not efficient, but should be fine, as the two vectors are very |
| 179 // short (2-5 items). | 182 // short (2-5 items). |
| 180 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) | 183 if (!Contains(layouts, candidate) && |
| 184 (!login_layouts_only || IsLoginKeyboard(candidate))) |
| 181 layouts.push_back(candidate); | 185 layouts.push_back(candidate); |
| 182 } | 186 } |
| 183 | 187 |
| 184 active_input_method_ids_.swap(layouts); | 188 active_input_method_ids_.swap(layouts); |
| 185 | 189 |
| 186 // Initialize candidate window controller and widgets such as | 190 // Initialize candidate window controller and widgets such as |
| 187 // candidate window, infolist and mode indicator. Note, mode | 191 // candidate window, infolist and mode indicator. Note, mode |
| 188 // indicator is used by only keyboard layout input methods. | 192 // indicator is used by only keyboard layout input methods. |
| 189 if (active_input_method_ids_.size() > 1) | 193 if (active_input_method_ids_.size() > 1) |
| 190 MaybeInitializeCandidateWindowController(); | 194 MaybeInitializeCandidateWindowController(); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 const std::string locale = g_browser_process->GetApplicationLocale(); | 534 const std::string locale = g_browser_process->GetApplicationLocale(); |
| 531 // If the preferred keyboard for the login screen has been saved, use it. | 535 // If the preferred keyboard for the login screen has been saved, use it. |
| 532 PrefService* prefs = g_browser_process->local_state(); | 536 PrefService* prefs = g_browser_process->local_state(); |
| 533 std::string initial_input_method_id = | 537 std::string initial_input_method_id = |
| 534 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); | 538 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); |
| 535 if (initial_input_method_id.empty()) { | 539 if (initial_input_method_id.empty()) { |
| 536 // If kPreferredKeyboardLayout is not specified, use the hardware layout. | 540 // If kPreferredKeyboardLayout is not specified, use the hardware layout. |
| 537 initial_input_method_id = | 541 initial_input_method_id = |
| 538 GetInputMethodUtil()->GetHardwareInputMethodId(); | 542 GetInputMethodUtil()->GetHardwareInputMethodId(); |
| 539 } | 543 } |
| 540 EnableLayouts(locale, initial_input_method_id); | 544 EnableLayouts( |
| 545 locale, initial_input_method_id, true /* login_layouts_only */); |
| 541 } | 546 } |
| 542 } | 547 } |
| 543 | 548 |
| 544 bool InputMethodManagerImpl::SwitchToNextInputMethod() { | 549 bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
| 545 // Sanity checks. | 550 // Sanity checks. |
| 546 if (active_input_method_ids_.empty()) { | 551 if (active_input_method_ids_.empty()) { |
| 547 DVLOG(1) << "active input method is empty"; | 552 DVLOG(1) << "active input method is empty"; |
| 548 return false; | 553 return false; |
| 549 } | 554 } |
| 550 | 555 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 if (candidate_window_controller_.get()) | 820 if (candidate_window_controller_.get()) |
| 816 return; | 821 return; |
| 817 | 822 |
| 818 candidate_window_controller_.reset( | 823 candidate_window_controller_.reset( |
| 819 CandidateWindowController::CreateCandidateWindowController()); | 824 CandidateWindowController::CreateCandidateWindowController()); |
| 820 candidate_window_controller_->AddObserver(this); | 825 candidate_window_controller_->AddObserver(this); |
| 821 } | 826 } |
| 822 | 827 |
| 823 } // namespace input_method | 828 } // namespace input_method |
| 824 } // namespace chromeos | 829 } // namespace chromeos |
| OLD | NEW |