| OLD | NEW | 
|---|
| 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_util.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <functional> | 8 #include <functional> | 
| 9 #include <map> | 9 #include <map> | 
| 10 #include <utility> | 10 #include <utility> | 
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 596     DCHECK(!input_method->language_codes().empty()); | 596     DCHECK(!input_method->language_codes().empty()); | 
| 597     const std::string language_code = input_method->language_codes().at(0); | 597     const std::string language_code = input_method->language_codes().at(0); | 
| 598     // Add it if it's not already present. | 598     // Add it if it's not already present. | 
| 599     if (std::count(out_language_codes->begin(), out_language_codes->end(), | 599     if (std::count(out_language_codes->begin(), out_language_codes->end(), | 
| 600                    language_code) == 0) { | 600                    language_code) == 0) { | 
| 601       out_language_codes->push_back(language_code); | 601       out_language_codes->push_back(language_code); | 
| 602     } | 602     } | 
| 603   } | 603   } | 
| 604 } | 604 } | 
| 605 | 605 | 
|  | 606 std::string InputMethodUtil::GetLanguageDefaultInputMethodId( | 
|  | 607     const std::string& language_code) { | 
|  | 608   std::vector<std::string> candidates; | 
|  | 609   GetInputMethodIdsFromLanguageCode( | 
|  | 610       language_code, input_method::kKeyboardLayoutsOnly, &candidates); | 
|  | 611   if (candidates.size()) | 
|  | 612     return candidates.front(); | 
|  | 613 | 
|  | 614   return std::string(); | 
|  | 615 } | 
|  | 616 | 
| 606 std::string InputMethodUtil::GetHardwareInputMethodId() const { | 617 std::string InputMethodUtil::GetHardwareInputMethodId() const { | 
| 607   const std::string input_method_id = delegate_->GetHardwareKeyboardLayout(); | 618   const std::string input_method_id = delegate_->GetHardwareKeyboardLayout(); | 
| 608 | 619 | 
| 609   if (input_method_id.empty()) { | 620   if (input_method_id.empty()) { | 
| 610     // This is totally fine if it's empty. The hardware keyboard layout is | 621     // This is totally fine if it's empty. The hardware keyboard layout is | 
| 611     // not stored if startup_manifest.json (OEM customization data) is not | 622     // not stored if startup_manifest.json (OEM customization data) is not | 
| 612     // present (ex. Cr48 doen't have that file). | 623     // present (ex. Cr48 doen't have that file). | 
| 613     return GetFallbackInputMethodDescriptor().id(); | 624     return GetFallbackInputMethodDescriptor().id(); | 
| 614   } | 625   } | 
| 615   return input_method_id; | 626   return input_method_id; | 
| 616 } | 627 } | 
| 617 | 628 | 
|  | 629 std::string InputMethodUtil::GetHardwareLoginInputMethodId() const { | 
|  | 630   const std::string input_method_id = GetHardwareInputMethodId(); | 
|  | 631 | 
|  | 632   if (!IsLoginKeyboard(input_method_id)) | 
|  | 633     return GetFallbackInputMethodDescriptor().id(); | 
|  | 634 | 
|  | 635   return input_method_id; | 
|  | 636 } | 
|  | 637 | 
|  | 638 bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) | 
|  | 639     const { | 
|  | 640   const InputMethodDescriptor* ime = | 
|  | 641       GetInputMethodDescriptorFromId(input_method_id); | 
|  | 642   return ime ? ime->is_login_keyboard() : false; | 
|  | 643 } | 
|  | 644 | 
| 618 void InputMethodUtil::SetComponentExtensions( | 645 void InputMethodUtil::SetComponentExtensions( | 
| 619     const InputMethodDescriptors& imes) { | 646     const InputMethodDescriptors& imes) { | 
| 620   component_extension_ime_id_to_descriptor_.clear(); | 647   component_extension_ime_id_to_descriptor_.clear(); | 
| 621   for (size_t i = 0; i < imes.size(); ++i) { | 648   for (size_t i = 0; i < imes.size(); ++i) { | 
| 622     const InputMethodDescriptor& input_method = imes.at(i); | 649     const InputMethodDescriptor& input_method = imes.at(i); | 
| 623     DCHECK(!input_method.language_codes().empty()); | 650     DCHECK(!input_method.language_codes().empty()); | 
| 624     const std::string language_code = input_method.language_codes().at(0); | 651     const std::string language_code = input_method.language_codes().at(0); | 
| 625     id_to_language_code_.insert( | 652     id_to_language_code_.insert( | 
| 626         std::make_pair(input_method.id(), language_code)); | 653         std::make_pair(input_method.id(), language_code)); | 
| 627     id_to_descriptor_.insert( | 654     id_to_descriptor_.insert( | 
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 672     if (IsKeyboardLayout(input_method.id())) { | 699     if (IsKeyboardLayout(input_method.id())) { | 
| 673       xkb_id_to_descriptor_.insert( | 700       xkb_id_to_descriptor_.insert( | 
| 674           std::make_pair(input_method.GetPreferredKeyboardLayout(), | 701           std::make_pair(input_method.GetPreferredKeyboardLayout(), | 
| 675                          input_method)); | 702                          input_method)); | 
| 676     } | 703     } | 
| 677   } | 704   } | 
| 678 } | 705 } | 
| 679 | 706 | 
| 680 }  // namespace input_method | 707 }  // namespace input_method | 
| 681 }  // namespace chromeos | 708 }  // namespace chromeos | 
| OLD | NEW | 
|---|