Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 133273032: Guest Mode: input method should default to the underlying latin keyboard layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Use EnableInputMethod instead of EnableInputMethods. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 input_method_id); 150 input_method_id);
153 if (!ime) { 151 if (!ime) {
154 std::map<std::string, InputMethodDescriptor>::const_iterator ix = 152 std::map<std::string, InputMethodDescriptor>::const_iterator ix =
155 extra_input_methods_.find(input_method_id); 153 extra_input_methods_.find(input_method_id);
156 if (ix != extra_input_methods_.end()) 154 if (ix != extra_input_methods_.end())
157 ime = &ix->second; 155 ime = &ix->second;
158 } 156 }
159 return ime; 157 return ime;
160 } 158 }
161 159
162 void InputMethodManagerImpl::EnableLayouts(const std::string& language_code, 160 void InputMethodManagerImpl::EnableLoginLayouts(
163 const std::string& initial_layout) { 161 const std::string& language_code,
162 const std::string& initial_layout) {
164 if (state_ == STATE_TERMINATING) 163 if (state_ == STATE_TERMINATING)
165 return; 164 return;
166 165
167 std::vector<std::string> candidates; 166 std::vector<std::string> candidates;
168 // Add input methods associated with the language. 167 // Add input methods associated with the language.
169 util_.GetInputMethodIdsFromLanguageCode(language_code, 168 util_.GetInputMethodIdsFromLanguageCode(language_code,
170 kKeyboardLayoutsOnly, 169 kKeyboardLayoutsOnly,
171 &candidates); 170 &candidates);
172 // Add the hardware keyboard as well. We should always add this so users 171 // Add the hardware keyboard as well. We should always add this so users
173 // can use the hardware keyboard on the login screen and the screen locker. 172 // can use the hardware keyboard on the login screen and the screen locker.
174 candidates.push_back(util_.GetHardwareInputMethodId()); 173 candidates.push_back(util_.GetHardwareLoginInputMethodId());
175 174
176 std::vector<std::string> layouts; 175 std::vector<std::string> layouts;
177 // First, add the initial input method ID, if it's requested, to 176 // First, add the initial input method ID, if it's requested, to
178 // layouts, so it appears first on the list of active input 177 // layouts, so it appears first on the list of active input
179 // methods at the input language status menu. 178 // methods at the input language status menu.
180 if (util_.IsValidInputMethodId(initial_layout) && 179 if (util_.IsValidInputMethodId(initial_layout)) {
181 IsLoginKeyboard(initial_layout)) { 180 if (!IsLoginKeyboard(initial_layout)) {
182 layouts.push_back(initial_layout); 181 DVLOG(1)
182 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:"
183 << initial_layout;
184 } else {
185 layouts.push_back(initial_layout);
186 }
183 } else if (!initial_layout.empty()) { 187 } else if (!initial_layout.empty()) {
184 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " 188 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: "
185 << initial_layout; 189 << initial_layout;
186 } 190 }
187 191
188 // Add candidates to layouts, while skipping duplicates. 192 // Add candidates to layouts, while skipping duplicates.
189 for (size_t i = 0; i < candidates.size(); ++i) { 193 for (size_t i = 0; i < candidates.size(); ++i) {
190 const std::string& candidate = candidates[i]; 194 const std::string& candidate = candidates[i];
191 // Not efficient, but should be fine, as the two vectors are very 195 // Not efficient, but should be fine, as the two vectors are very
192 // short (2-5 items). 196 // short (2-5 items).
193 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) 197 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate))
194 layouts.push_back(candidate); 198 layouts.push_back(candidate);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 const std::string locale = g_browser_process->GetApplicationLocale(); 547 const std::string locale = g_browser_process->GetApplicationLocale();
544 // If the preferred keyboard for the login screen has been saved, use it. 548 // If the preferred keyboard for the login screen has been saved, use it.
545 PrefService* prefs = g_browser_process->local_state(); 549 PrefService* prefs = g_browser_process->local_state();
546 std::string initial_input_method_id = 550 std::string initial_input_method_id =
547 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout); 551 prefs->GetString(chromeos::language_prefs::kPreferredKeyboardLayout);
548 if (initial_input_method_id.empty()) { 552 if (initial_input_method_id.empty()) {
549 // If kPreferredKeyboardLayout is not specified, use the hardware layout. 553 // If kPreferredKeyboardLayout is not specified, use the hardware layout.
550 initial_input_method_id = 554 initial_input_method_id =
551 GetInputMethodUtil()->GetHardwareInputMethodId(); 555 GetInputMethodUtil()->GetHardwareInputMethodId();
552 } 556 }
553 EnableLayouts(locale, initial_input_method_id); 557 EnableLoginLayouts(locale, initial_input_method_id);
554 } 558 }
555 } 559 }
556 560
557 bool InputMethodManagerImpl::SwitchToNextInputMethod() { 561 bool InputMethodManagerImpl::SwitchToNextInputMethod() {
558 // Sanity checks. 562 // Sanity checks.
559 if (active_input_method_ids_.empty()) { 563 if (active_input_method_ids_.empty()) {
560 DVLOG(1) << "active input method is empty"; 564 DVLOG(1) << "active input method is empty";
561 return false; 565 return false;
562 } 566 }
563 567
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 if (candidate_window_controller_.get()) 832 if (candidate_window_controller_.get())
829 return; 833 return;
830 834
831 candidate_window_controller_.reset( 835 candidate_window_controller_.reset(
832 CandidateWindowController::CreateCandidateWindowController()); 836 CandidateWindowController::CreateCandidateWindowController());
833 candidate_window_controller_->AddObserver(this); 837 candidate_window_controller_->AddObserver(this);
834 } 838 }
835 839
836 } // namespace input_method 840 } // namespace input_method
837 } // namespace chromeos 841 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698