Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui/chromeos/login/l10n_util.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/l10n_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 } | 275 } |
| 276 | 276 |
| 277 const LanguagePair& pair = language_map[out_display_names[i]]; | 277 const LanguagePair& pair = language_map[out_display_names[i]]; |
| 278 language_list->Append( | 278 language_list->Append( |
| 279 CreateLanguageEntry(pair.first, out_display_names[i], pair.second)); | 279 CreateLanguageEntry(pair.first, out_display_names[i], pair.second)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 return language_list; | 282 return language_list; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Note: this method updates |selected_locale| only if it is empty. | |
| 286 void GetAndMergeKeyboardLayoutsForLocale(input_method::InputMethodUtil* util, | |
| 287 const std::string& locale, | |
| 288 std::string* selected_locale, | |
| 289 std::vector<std::string>* layouts) { | |
|
Shu Chen
2016/06/29 13:10:37
Please remove potential duplicates in |layouts|.
Alexander Alekseev
2016/06/29 23:00:46
Duplicates are removed on lines 318-327 below. We
| |
| 290 std::vector<std::string> layouts_from_locale; | |
| 291 util->GetInputMethodIdsFromLanguageCode( | |
| 292 locale, input_method::kKeyboardLayoutsOnly, &layouts_from_locale); | |
| 293 layouts->insert(layouts->end(), layouts_from_locale.begin(), | |
| 294 layouts_from_locale.end()); | |
| 295 if (selected_locale->empty() && !layouts_from_locale.empty()) { | |
| 296 *selected_locale = | |
| 297 util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); | |
| 298 } | |
| 299 } | |
| 300 | |
| 285 // Invokes |callback| with a list of keyboard layouts that can be used for | 301 // Invokes |callback| with a list of keyboard layouts that can be used for |
| 286 // |resolved_locale|. | 302 // |resolved_locale|. |
| 287 void GetKeyboardLayoutsForResolvedLocale( | 303 void GetKeyboardLayoutsForResolvedLocale( |
| 304 const std::string& requested_locale, | |
| 288 const GetKeyboardLayoutsForLocaleCallback& callback, | 305 const GetKeyboardLayoutsForLocaleCallback& callback, |
| 289 const std::string& resolved_locale) { | 306 const std::string& resolved_locale) { |
| 290 input_method::InputMethodUtil* util = | 307 input_method::InputMethodUtil* util = |
| 291 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 308 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| 292 std::vector<std::string> layouts = util->GetHardwareInputMethodIds(); | 309 std::vector<std::string> layouts = util->GetHardwareInputMethodIds(); |
| 293 std::vector<std::string> layouts_from_locale; | |
| 294 util->GetInputMethodIdsFromLanguageCode( | |
| 295 resolved_locale, | |
| 296 input_method::kKeyboardLayoutsOnly, | |
| 297 &layouts_from_locale); | |
| 298 layouts.insert(layouts.end(), layouts_from_locale.begin(), | |
| 299 layouts_from_locale.end()); | |
| 300 | 310 |
| 311 // "Selected" will be set from the fist non-empty list. | |
| 301 std::string selected; | 312 std::string selected; |
|
Shu Chen
2016/06/29 13:10:37
|selected| is unused?
Alexander Alekseev
2016/06/29 23:00:46
See line 327 below.
| |
| 302 if (!layouts_from_locale.empty()) { | 313 GetAndMergeKeyboardLayoutsForLocale(util, requested_locale, &selected, |
| 303 selected = | 314 &layouts); |
| 304 util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); | 315 GetAndMergeKeyboardLayoutsForLocale(util, resolved_locale, &selected, |
| 305 } | 316 &layouts); |
| 306 | 317 |
| 307 std::unique_ptr<base::ListValue> input_methods_list(new base::ListValue); | 318 std::unique_ptr<base::ListValue> input_methods_list(new base::ListValue); |
| 308 std::set<std::string> input_methods_added; | 319 std::set<std::string> input_methods_added; |
| 309 for (std::vector<std::string>::const_iterator it = layouts.begin(); | 320 for (std::vector<std::string>::const_iterator it = layouts.begin(); |
| 310 it != layouts.end(); ++it) { | 321 it != layouts.end(); ++it) { |
| 311 const input_method::InputMethodDescriptor* ime = | 322 const input_method::InputMethodDescriptor* ime = |
| 312 util->GetInputMethodDescriptorFromId(*it); | 323 util->GetInputMethodDescriptorFromId(*it); |
| 313 if (!InsertString(ime->id(), &input_methods_added)) | 324 if (!InsertString(ime->id(), &input_methods_added)) |
| 314 continue; | 325 continue; |
| 315 input_methods_list->Append( | 326 input_methods_list->Append( |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 572 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 583 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 573 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 584 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 574 worker_pool->GetNamedSequenceToken(kSequenceToken), | 585 worker_pool->GetNamedSequenceToken(kSequenceToken), |
| 575 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 586 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 576 | 587 |
| 577 // Resolve |locale| on a background thread, then continue on the current | 588 // Resolve |locale| on a background thread, then continue on the current |
| 578 // thread. | 589 // thread. |
| 579 std::string (*get_application_locale)(const std::string&, bool) = | 590 std::string (*get_application_locale)(const std::string&, bool) = |
| 580 &l10n_util::GetApplicationLocale; | 591 &l10n_util::GetApplicationLocale; |
| 581 base::PostTaskAndReplyWithResult( | 592 base::PostTaskAndReplyWithResult( |
| 582 background_task_runner.get(), | 593 background_task_runner.get(), FROM_HERE, |
| 583 FROM_HERE, | |
| 584 base::Bind(get_application_locale, locale, false /* set_icu_locale */), | 594 base::Bind(get_application_locale, locale, false /* set_icu_locale */), |
| 585 base::Bind(&GetKeyboardLayoutsForResolvedLocale, callback)); | 595 base::Bind(&GetKeyboardLayoutsForResolvedLocale, locale, callback)); |
| 586 } | 596 } |
| 587 | 597 |
| 588 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { | 598 std::unique_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { |
| 589 const input_method::InputMethodDescriptor current_input_method = | 599 const input_method::InputMethodDescriptor current_input_method = |
| 590 input_method::InputMethodManager::Get() | 600 input_method::InputMethodManager::Get() |
| 591 ->GetActiveIMEState() | 601 ->GetActiveIMEState() |
| 592 ->GetCurrentInputMethod(); | 602 ->GetCurrentInputMethod(); |
| 593 return CreateInputMethodsEntry(current_input_method, | 603 return CreateInputMethodsEntry(current_input_method, |
| 594 current_input_method.id()); | 604 current_input_method.id()); |
| 595 } | 605 } |
| 596 | 606 |
| 597 } // namespace chromeos | 607 } // namespace chromeos |
| OLD | NEW |