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

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

Issue 18856014: We should switch the keyboard layout to the layout the user set according to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Diff versus master. Created 7 years, 5 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } kMigrationHangulKeyboardToInputMethodID[] = { 103 } kMigrationHangulKeyboardToInputMethodID[] = {
104 { "2", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_2set" }, 104 { "2", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_2set" },
105 { "3f", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setfinal" }, 105 { "3f", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setfinal" },
106 { "39", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3set390" }, 106 { "39", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3set390" },
107 { "3s", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setnoshift" }, 107 { "3s", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_3setnoshift" },
108 { "ro", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja" }, 108 { "ro", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja" },
109 }; 109 };
110 110
111 } // namespace 111 } // namespace
112 112
113 bool InputMethodManagerImpl::IsFullLatinKeyboard(
114 const std::string& layout) const {
115 const std::string& lang = util_.GetLanguageCodeFromInputMethodId(layout);
116 return full_latin_keyboard_checker.IsFullLatinKeyboard(layout, lang);
117 }
118
113 InputMethodManagerImpl::InputMethodManagerImpl( 119 InputMethodManagerImpl::InputMethodManagerImpl(
114 scoped_ptr<InputMethodDelegate> delegate) 120 scoped_ptr<InputMethodDelegate> delegate)
115 : delegate_(delegate.Pass()), 121 : delegate_(delegate.Pass()),
116 state_(STATE_LOGIN_SCREEN), 122 state_(STATE_LOGIN_SCREEN),
117 util_(delegate_.get(), GetSupportedInputMethods()), 123 util_(delegate_.get(), GetSupportedInputMethods()),
118 component_extension_ime_manager_(new ComponentExtensionIMEManager()), 124 component_extension_ime_manager_(new ComponentExtensionIMEManager()),
119 weak_ptr_factory_(this) { 125 weak_ptr_factory_(this) {
120 IBusDaemonController::GetInstance()->AddObserver(this); 126 IBusDaemonController::GetInstance()->AddObserver(this);
121 } 127 }
122 128
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 206 }
201 if (result->empty()) { 207 if (result->empty()) {
202 // Initially |active_input_method_ids_| is empty. browser_tests might take 208 // Initially |active_input_method_ids_| is empty. browser_tests might take
203 // this path. 209 // this path.
204 result->push_back( 210 result->push_back(
205 InputMethodUtil::GetFallbackInputMethodDescriptor()); 211 InputMethodUtil::GetFallbackInputMethodDescriptor());
206 } 212 }
207 return result.Pass(); 213 return result.Pass();
208 } 214 }
209 215
216 const std::vector<std::string>&
217 InputMethodManagerImpl::GetActiveInputMethodIds() const {
218 return active_input_method_ids_;
219 }
220
210 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { 221 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const {
211 return active_input_method_ids_.size(); 222 return active_input_method_ids_.size();
212 } 223 }
213 224
214 void InputMethodManagerImpl::EnableLayouts(const std::string& language_code, 225 void InputMethodManagerImpl::EnableLayouts(const std::string& language_code,
215 const std::string& initial_layout) { 226 const std::string& initial_layout) {
216 if (state_ == STATE_TERMINATING) 227 if (state_ == STATE_TERMINATING)
217 return; 228 return;
218 229
219 std::vector<std::string> candidates; 230 std::vector<std::string> candidates;
(...skipping 23 matching lines...) Expand all
243 // Not efficient, but should be fine, as the two vectors are very 254 // Not efficient, but should be fine, as the two vectors are very
244 // short (2-5 items). 255 // short (2-5 items).
245 if (!Contains(layouts, candidate)) 256 if (!Contains(layouts, candidate))
246 layouts.push_back(candidate); 257 layouts.push_back(candidate);
247 } 258 }
248 259
249 active_input_method_ids_.swap(layouts); 260 active_input_method_ids_.swap(layouts);
250 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. 261 ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|.
251 } 262 }
252 263
264 // Adds new input method to given list.
265 bool InputMethodManagerImpl::EnableInputMethodImpl(
266 const std::string& input_method_id,
267 std::vector<std::string>& new_active_input_method_ids) const {
268 if (!util_.IsValidInputMethodId(input_method_id)) {
269 DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id;
270 return false;
271 }
272
273 if (!Contains(new_active_input_method_ids, input_method_id))
274 new_active_input_method_ids.push_back(input_method_id);
275
276 return true;
277 }
278
279 // Starts or stops the system input method framework as needed.
280 void InputMethodManagerImpl::ReconfigureIMFramework() {
281 if (component_extension_ime_manager_->IsInitialized())
282 LoadNecessaryComponentExtensions();
283
284 if (ContainsOnlyKeyboardLayout(active_input_method_ids_)) {
285 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue
286 // at crbug.com/27051.
287 // TODO(yusukes): We can safely call Stop(); here once crbug.com/26443
288 // is implemented.
289 } else {
290 MaybeInitializeCandidateWindowController();
291 IBusDaemonController::GetInstance()->Start();
292 }
293 }
294
295 bool InputMethodManagerImpl::EnableInputMethod(
296 const std::string& input_method_id) {
297 if (!EnableInputMethodImpl(input_method_id, active_input_method_ids_))
298 return false;
299
300 ReconfigureIMFramework();
301 return true;
302 }
303
253 bool InputMethodManagerImpl::EnableInputMethods( 304 bool InputMethodManagerImpl::EnableInputMethods(
254 const std::vector<std::string>& new_active_input_method_ids) { 305 const std::vector<std::string>& new_active_input_method_ids) {
255 if (state_ == STATE_TERMINATING) 306 if (state_ == STATE_TERMINATING)
256 return false; 307 return false;
257 308
258 // Filter unknown or obsolete IDs. 309 // Filter unknown or obsolete IDs.
259 std::vector<std::string> new_active_input_method_ids_filtered; 310 std::vector<std::string> new_active_input_method_ids_filtered;
260 311
261 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) { 312 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i)
262 const std::string& input_method_id = new_active_input_method_ids[i]; 313 EnableInputMethodImpl(new_active_input_method_ids[i],
263 if (util_.IsValidInputMethodId(input_method_id)) 314 new_active_input_method_ids_filtered);
264 new_active_input_method_ids_filtered.push_back(input_method_id);
265 else
266 DVLOG(1) << "EnableInputMethods: Invalid ID: " << input_method_id;
267 }
268 315
269 if (new_active_input_method_ids_filtered.empty()) { 316 if (new_active_input_method_ids_filtered.empty()) {
270 DVLOG(1) << "EnableInputMethods: No valid input method ID"; 317 DVLOG(1) << "EnableInputMethods: No valid input method ID";
271 return false; 318 return false;
272 } 319 }
273 320
274 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to 321 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to
275 // keep relative order of the extension input method IDs. 322 // keep relative order of the extension input method IDs.
276 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 323 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
277 const std::string& input_method_id = active_input_method_ids_[i]; 324 const std::string& input_method_id = active_input_method_ids_[i];
278 if (extension_ime_util::IsExtensionIME(input_method_id)) 325 if (extension_ime_util::IsExtensionIME(input_method_id))
279 new_active_input_method_ids_filtered.push_back(input_method_id); 326 new_active_input_method_ids_filtered.push_back(input_method_id);
280 } 327 }
281 active_input_method_ids_.swap(new_active_input_method_ids_filtered); 328 active_input_method_ids_.swap(new_active_input_method_ids_filtered);
282 329
283 if (component_extension_ime_manager_->IsInitialized()) 330 ReconfigureIMFramework();
284 LoadNecessaryComponentExtensions();
285
286 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) {
287 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue
288 // at crosbug.com/27051.
289 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443
290 // is implemented.
291 } else {
292 MaybeInitializeCandidateWindowController();
293 IBusDaemonController::GetInstance()->Start();
294 }
295 331
296 // If |current_input_method| is no longer in |active_input_method_ids_|, 332 // If |current_input_method| is no longer in |active_input_method_ids_|,
297 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. 333 // ChangeInputMethod() picks the first one in |active_input_method_ids_|.
298 ChangeInputMethod(current_input_method_.id()); 334 ChangeInputMethod(current_input_method_.id());
299 return true; 335 return true;
300 } 336 }
301 337
302 bool InputMethodManagerImpl::MigrateOldInputMethods( 338 bool InputMethodManagerImpl::MigrateOldInputMethods(
303 std::vector<std::string>* input_method_ids) { 339 std::vector<std::string>* input_method_ids) {
304 bool rewritten = false; 340 bool rewritten = false;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { 593 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) {
558 if (!extension_ime_util::IsExtensionIME(id)) 594 if (!extension_ime_util::IsExtensionIME(id))
559 DVLOG(1) << id << " is not a valid extension input method ID."; 595 DVLOG(1) << id << " is not a valid extension input method ID.";
560 596
561 std::vector<std::string>::iterator i = std::find( 597 std::vector<std::string>::iterator i = std::find(
562 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); 598 active_input_method_ids_.begin(), active_input_method_ids_.end(), id);
563 if (i != active_input_method_ids_.end()) 599 if (i != active_input_method_ids_.end())
564 active_input_method_ids_.erase(i); 600 active_input_method_ids_.erase(i);
565 extra_input_methods_.erase(id); 601 extra_input_methods_.erase(id);
566 602
567 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { 603 if (ContainsOnlyKeyboardLayout(active_input_method_ids_)) {
568 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue 604 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue
569 // at crosbug.com/27051. 605 // at crosbug.com/27051.
570 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 606 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443
571 // is implemented. 607 // is implemented.
572 } 608 }
573 609
574 // If |current_input_method| is no longer in |active_input_method_ids_|, 610 // If |current_input_method| is no longer in |active_input_method_ids_|,
575 // switch to the first one in |active_input_method_ids_|. 611 // switch to the first one in |active_input_method_ids_|.
576 ChangeInputMethod(current_input_method_.id()); 612 ChangeInputMethod(current_input_method_.id());
577 613
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 active_input_method_ids_ = saved_active_input_method_ids_; 947 active_input_method_ids_ = saved_active_input_method_ids_;
912 948
913 ChangeInputMethod(current_input_method_.id()); 949 ChangeInputMethod(current_input_method_.id());
914 } 950 }
915 951
916 bool InputMethodManagerImpl::InputMethodIsActivated( 952 bool InputMethodManagerImpl::InputMethodIsActivated(
917 const std::string& input_method_id) { 953 const std::string& input_method_id) {
918 return Contains(active_input_method_ids_, input_method_id); 954 return Contains(active_input_method_ids_, input_method_id);
919 } 955 }
920 956
921 bool InputMethodManagerImpl::ContainOnlyKeyboardLayout( 957 bool InputMethodManagerImpl::ContainsOnlyKeyboardLayout(
922 const std::vector<std::string>& value) { 958 const std::vector<std::string>& value) {
923 for (size_t i = 0; i < value.size(); ++i) { 959 for (size_t i = 0; i < value.size(); ++i) {
924 if (!InputMethodUtil::IsKeyboardLayout(value[i])) 960 if (!InputMethodUtil::IsKeyboardLayout(value[i]))
925 return false; 961 return false;
926 } 962 }
927 return true; 963 return true;
928 } 964 }
929 965
930 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 966 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
931 if (candidate_window_controller_.get()) 967 if (candidate_window_controller_.get())
932 return; 968 return;
933 969
934 candidate_window_controller_.reset( 970 candidate_window_controller_.reset(
935 CandidateWindowController::CreateCandidateWindowController()); 971 CandidateWindowController::CreateCandidateWindowController());
936 if (candidate_window_controller_->Init()) 972 if (candidate_window_controller_->Init())
937 candidate_window_controller_->AddObserver(this); 973 candidate_window_controller_->AddObserver(this);
938 else 974 else
939 DVLOG(1) << "Failed to initialize the candidate window controller"; 975 DVLOG(1) << "Failed to initialize the candidate window controller";
940 } 976 }
941 977
942 bool InputMethodManagerImpl::IsIBusConnectionAlive() { 978 bool InputMethodManagerImpl::IsIBusConnectionAlive() {
943 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient(); 979 return DBusThreadManager::Get() && DBusThreadManager::Get()->GetIBusClient();
944 } 980 }
945 981
946 } // namespace input_method 982 } // namespace input_method
947 } // namespace chromeos 983 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698