| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 input_method::InputMethodManager::Get()->GetInputMethodUtil(); | 46 input_method::InputMethodManager::Get()->GetInputMethodUtil(); |
| 47 const std::string& ime_id = method.id(); | 47 const std::string& ime_id = method.id(); |
| 48 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); | 48 scoped_ptr<base::DictionaryValue> input_method(new base::DictionaryValue); |
| 49 input_method->SetString("value", ime_id); | 49 input_method->SetString("value", ime_id); |
| 50 input_method->SetString("title", util->GetInputMethodLongName(method)); | 50 input_method->SetString("title", util->GetInputMethodLongName(method)); |
| 51 input_method->SetBoolean("selected", ime_id == selected); | 51 input_method->SetBoolean("selected", ime_id == selected); |
| 52 return input_method.Pass(); | 52 return input_method.Pass(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 // Returns true if element was inserted. | 55 // Returns true if element was inserted. |
| 56 bool InsertString(const std::string& str, std::set<std::string>& to) { | 56 bool InsertString(const std::string& str, std::set<std::string>* to) { |
| 57 const std::pair<std::set<std::string>::iterator, bool> result = | 57 const std::pair<std::set<std::string>::iterator, bool> result = |
| 58 to.insert(str); | 58 to->insert(str); |
| 59 return result.second; | 59 return result.second; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { | 62 void AddOptgroupOtherLayouts(base::ListValue* input_methods_list) { |
| 63 scoped_ptr<base::DictionaryValue> optgroup(new base::DictionaryValue); | 63 scoped_ptr<base::DictionaryValue> optgroup(new base::DictionaryValue); |
| 64 optgroup->SetString( | 64 optgroup->SetString( |
| 65 "optionGroupName", | 65 "optionGroupName", |
| 66 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); | 66 l10n_util::GetStringUTF16(IDS_OOBE_OTHER_KEYBOARD_LAYOUTS)); |
| 67 input_methods_list->Append(optgroup.release()); | 67 input_methods_list->Append(optgroup.release()); |
| 68 } | 68 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 selected = | 302 selected = |
| 303 util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); | 303 util->GetInputMethodDescriptorFromId(layouts_from_locale[0])->id(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 scoped_ptr<base::ListValue> input_methods_list(new base::ListValue); | 306 scoped_ptr<base::ListValue> input_methods_list(new base::ListValue); |
| 307 std::set<std::string> input_methods_added; | 307 std::set<std::string> input_methods_added; |
| 308 for (std::vector<std::string>::const_iterator it = layouts.begin(); | 308 for (std::vector<std::string>::const_iterator it = layouts.begin(); |
| 309 it != layouts.end(); ++it) { | 309 it != layouts.end(); ++it) { |
| 310 const input_method::InputMethodDescriptor* ime = | 310 const input_method::InputMethodDescriptor* ime = |
| 311 util->GetInputMethodDescriptorFromId(*it); | 311 util->GetInputMethodDescriptorFromId(*it); |
| 312 if (!InsertString(ime->id(), input_methods_added)) | 312 if (!InsertString(ime->id(), &input_methods_added)) |
| 313 continue; | 313 continue; |
| 314 input_methods_list->Append( | 314 input_methods_list->Append( |
| 315 CreateInputMethodsEntry(*ime, selected).release()); | 315 CreateInputMethodsEntry(*ime, selected).release()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 callback.Run(input_methods_list.Pass()); | 318 callback.Run(input_methods_list.Pass()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace | 321 } // namespace |
| 322 | 322 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 CreateInputMethodsEntry(*ime, selected).release()); | 439 CreateInputMethodsEntry(*ime, selected).release()); |
| 440 } else { | 440 } else { |
| 441 NOTREACHED(); | 441 NOTREACHED(); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 bool optgroup_added = false; | 445 bool optgroup_added = false; |
| 446 for (size_t i = 0; i < input_methods->size(); ++i) { | 446 for (size_t i = 0; i < input_methods->size(); ++i) { |
| 447 // Makes sure the id is in legacy xkb id format. | 447 // Makes sure the id is in legacy xkb id format. |
| 448 const std::string& ime_id = (*input_methods)[i].id(); | 448 const std::string& ime_id = (*input_methods)[i].id(); |
| 449 if (!InsertString(ime_id, input_methods_added)) | 449 if (!InsertString(ime_id, &input_methods_added)) |
| 450 continue; | 450 continue; |
| 451 if (!optgroup_added) { | 451 if (!optgroup_added) { |
| 452 optgroup_added = true; | 452 optgroup_added = true; |
| 453 AddOptgroupOtherLayouts(input_methods_list.get()); | 453 AddOptgroupOtherLayouts(input_methods_list.get()); |
| 454 } | 454 } |
| 455 input_methods_list->Append(CreateInputMethodsEntry((*input_methods)[i], | 455 input_methods_list->Append(CreateInputMethodsEntry((*input_methods)[i], |
| 456 selected).release()); | 456 selected).release()); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // "xkb:us::eng" should always be in the list of available layouts. | 459 // "xkb:us::eng" should always be in the list of available layouts. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { | 497 scoped_ptr<base::DictionaryValue> GetCurrentKeyboardLayout() { |
| 498 const input_method::InputMethodDescriptor current_input_method = | 498 const input_method::InputMethodDescriptor current_input_method = |
| 499 input_method::InputMethodManager::Get() | 499 input_method::InputMethodManager::Get() |
| 500 ->GetActiveIMEState() | 500 ->GetActiveIMEState() |
| 501 ->GetCurrentInputMethod(); | 501 ->GetCurrentInputMethod(); |
| 502 return CreateInputMethodsEntry(current_input_method, | 502 return CreateInputMethodsEntry(current_input_method, |
| 503 current_input_method.id()); | 503 current_input_method.id()); |
| 504 } | 504 } |
| 505 | 505 |
| 506 } // namespace chromeos | 506 } // namespace chromeos |
| OLD | NEW |