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

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: Removed bool login_layouts_only option from EnableLayouts(); EnableLayouts => EnableLoginLayouts. Created 6 years, 11 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 137
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::EnableLoginLayouts(
150 const std::string& initial_layout) { 148 const std::string& language_code,
149 const std::string& initial_layout) {
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 (!IsLoginKeyboard(initial_layout)) {
169 layouts.push_back(initial_layout); 168 DVLOG(1)
169 << "EnableLoginLayouts: ignoring non-login initial keyboard layout:"
170 << initial_layout;
171 } else {
172 layouts.push_back(initial_layout);
173 }
170 } else if (!initial_layout.empty()) { 174 } else if (!initial_layout.empty()) {
171 DVLOG(1) << "EnableLayouts: ignoring non-keyboard or invalid ID: " 175 DVLOG(1) << "EnableLoginLayouts: ignoring non-keyboard or invalid ID: "
172 << initial_layout; 176 << initial_layout;
173 } 177 }
174 178
175 // Add candidates to layouts, while skipping duplicates. 179 // Add candidates to layouts, while skipping duplicates.
176 for (size_t i = 0; i < candidates.size(); ++i) { 180 for (size_t i = 0; i < candidates.size(); ++i) {
177 const std::string& candidate = candidates[i]; 181 const std::string& candidate = candidates[i];
178 // Not efficient, but should be fine, as the two vectors are very 182 // Not efficient, but should be fine, as the two vectors are very
179 // short (2-5 items). 183 // short (2-5 items).
180 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) 184 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate))
181 layouts.push_back(candidate); 185 layouts.push_back(candidate);
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 EnableLoginLayouts(locale, initial_input_method_id);
541 } 545 }
542 } 546 }
543 547
544 bool InputMethodManagerImpl::SwitchToNextInputMethod() { 548 bool InputMethodManagerImpl::SwitchToNextInputMethod() {
545 // Sanity checks. 549 // Sanity checks.
546 if (active_input_method_ids_.empty()) { 550 if (active_input_method_ids_.empty()) {
547 DVLOG(1) << "active input method is empty"; 551 DVLOG(1) << "active input method is empty";
548 return false; 552 return false;
549 } 553 }
550 554
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 if (candidate_window_controller_.get()) 819 if (candidate_window_controller_.get())
816 return; 820 return;
817 821
818 candidate_window_controller_.reset( 822 candidate_window_controller_.reset(
819 CandidateWindowController::CreateCandidateWindowController()); 823 CandidateWindowController::CreateCandidateWindowController());
820 candidate_window_controller_->AddObserver(this); 824 candidate_window_controller_->AddObserver(this);
821 } 825 }
822 826
823 } // namespace input_method 827 } // namespace input_method
824 } // namespace chromeos 828 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698