| 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for | 355 // Returning |kDefaultLanguageCode| here is not for Chrome OS but for |
| 356 // Ubuntu where the ibus-xkb-layouts engine could be missing. | 356 // Ubuntu where the ibus-xkb-layouts engine could be missing. |
| 357 kDefaultLanguageCode : iter->second; | 357 kDefaultLanguageCode : iter->second; |
| 358 } | 358 } |
| 359 | 359 |
| 360 std::string InputMethodUtil::GetKeyboardLayoutName( | 360 std::string InputMethodUtil::GetKeyboardLayoutName( |
| 361 const std::string& input_method_id) const { | 361 const std::string& input_method_id) const { |
| 362 InputMethodIdToDescriptorMap::const_iterator iter | 362 InputMethodIdToDescriptorMap::const_iterator iter |
| 363 = id_to_descriptor_.find(input_method_id); | 363 = id_to_descriptor_.find(input_method_id); |
| 364 return (iter == id_to_descriptor_.end()) ? | 364 return (iter == id_to_descriptor_.end()) ? |
| 365 "" : iter->second.keyboard_layout(); | 365 "" : iter->second.GetPreferredKeyboardLayout(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( | 368 std::string InputMethodUtil::GetInputMethodDisplayNameFromId( |
| 369 const std::string& input_method_id) const { | 369 const std::string& input_method_id) const { |
| 370 string16 display_name; | 370 string16 display_name; |
| 371 if (!extension_ime_util::IsExtensionIME(input_method_id) && | 371 if (!extension_ime_util::IsExtensionIME(input_method_id) && |
| 372 TranslateStringInternal(input_method_id, &display_name)) { | 372 TranslateStringInternal(input_method_id, &display_name)) { |
| 373 return UTF16ToUTF8(display_name); | 373 return UTF16ToUTF8(display_name); |
| 374 } | 374 } |
| 375 // Return an empty string if the display name is not found. | 375 // Return an empty string if the display name is not found. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 550 |
| 551 // Check if there is one that matches the current keyboard layout, but | 551 // Check if there is one that matches the current keyboard layout, but |
| 552 // not the current keyboard itself. This is useful if there are | 552 // not the current keyboard itself. This is useful if there are |
| 553 // multiple keyboard layout choices for one input method. For | 553 // multiple keyboard layout choices for one input method. For |
| 554 // instance, Mozc provides three choices: mozc (US keyboard), mozc-jp | 554 // instance, Mozc provides three choices: mozc (US keyboard), mozc-jp |
| 555 // (JP keyboard), mozc-dv (Dvorak). | 555 // (JP keyboard), mozc-dv (Dvorak). |
| 556 const InputMethodDescriptor* descriptor = | 556 const InputMethodDescriptor* descriptor = |
| 557 GetInputMethodDescriptorFromId(input_method_id); | 557 GetInputMethodDescriptorFromId(input_method_id); |
| 558 if (descriptor && | 558 if (descriptor && |
| 559 descriptor->id() != current_input_method.id() && | 559 descriptor->id() != current_input_method.id() && |
| 560 descriptor->keyboard_layout() == | 560 descriptor->GetPreferredKeyboardLayout() == |
| 561 current_input_method.keyboard_layout()) { | 561 current_input_method.GetPreferredKeyboardLayout()) { |
| 562 most_popular_id = input_method_id; | 562 most_popular_id = input_method_id; |
| 563 break; | 563 break; |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 // Add the most popular input method ID, if it's different from the | 566 // Add the most popular input method ID, if it's different from the |
| 567 // current input method. | 567 // current input method. |
| 568 if (most_popular_id != current_input_method.id() && | 568 if (most_popular_id != current_input_method.id() && |
| 569 // TODO(yusukes): Remove this hack when we remove the "english-m" IME. | 569 // TODO(yusukes): Remove this hack when we remove the "english-m" IME. |
| 570 most_popular_id != "english-m") { | 570 most_popular_id != "english-m") { |
| 571 out_input_method_ids->push_back(most_popular_id); | 571 out_input_method_ids->push_back(most_popular_id); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 const InputMethodDescriptor& input_method = imes.at(i); | 613 const InputMethodDescriptor& input_method = imes.at(i); |
| 614 const std::string language_code = input_method.language_code(); | 614 const std::string language_code = input_method.language_code(); |
| 615 id_to_language_code_.insert( | 615 id_to_language_code_.insert( |
| 616 std::make_pair(input_method.id(), language_code)); | 616 std::make_pair(input_method.id(), language_code)); |
| 617 id_to_descriptor_.insert( | 617 id_to_descriptor_.insert( |
| 618 std::make_pair(input_method.id(), input_method)); | 618 std::make_pair(input_method.id(), input_method)); |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 | 621 |
| 622 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { | 622 InputMethodDescriptor InputMethodUtil::GetFallbackInputMethodDescriptor() { |
| 623 std::vector<std::string> layouts; |
| 624 layouts.push_back("us"); |
| 623 return InputMethodDescriptor("xkb:us::eng", | 625 return InputMethodDescriptor("xkb:us::eng", |
| 624 "", | 626 "", |
| 625 "us", | 627 layouts, |
| 626 "en-US", | 628 "en-US", |
| 627 ""); // options page, not available. | 629 ""); // options page, not available. |
| 628 } | 630 } |
| 629 | 631 |
| 630 void InputMethodUtil::ReloadInternalMaps() { | 632 void InputMethodUtil::ReloadInternalMaps() { |
| 631 if (supported_input_methods_->size() <= 1) { | 633 if (supported_input_methods_->size() <= 1) { |
| 632 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; | 634 DVLOG(1) << "GetSupportedInputMethods returned a fallback ID"; |
| 633 // TODO(yusukes): Handle this error in nicer way. | 635 // TODO(yusukes): Handle this error in nicer way. |
| 634 } | 636 } |
| 635 | 637 |
| 636 // Clear the existing maps. | 638 // Clear the existing maps. |
| 637 language_code_to_ids_.clear(); | 639 language_code_to_ids_.clear(); |
| 638 id_to_language_code_.clear(); | 640 id_to_language_code_.clear(); |
| 639 id_to_descriptor_.clear(); | 641 id_to_descriptor_.clear(); |
| 640 xkb_id_to_descriptor_.clear(); | 642 xkb_id_to_descriptor_.clear(); |
| 641 | 643 |
| 642 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { | 644 for (size_t i = 0; i < supported_input_methods_->size(); ++i) { |
| 643 const InputMethodDescriptor& input_method = | 645 const InputMethodDescriptor& input_method = |
| 644 supported_input_methods_->at(i); | 646 supported_input_methods_->at(i); |
| 645 const std::string language_code = input_method.language_code(); | 647 const std::string language_code = input_method.language_code(); |
| 646 language_code_to_ids_.insert( | 648 language_code_to_ids_.insert( |
| 647 std::make_pair(language_code, input_method.id())); | 649 std::make_pair(language_code, input_method.id())); |
| 648 // Remember the pairs. | 650 // Remember the pairs. |
| 649 id_to_language_code_.insert( | 651 id_to_language_code_.insert( |
| 650 std::make_pair(input_method.id(), language_code)); | 652 std::make_pair(input_method.id(), language_code)); |
| 651 id_to_descriptor_.insert( | 653 id_to_descriptor_.insert( |
| 652 std::make_pair(input_method.id(), input_method)); | 654 std::make_pair(input_method.id(), input_method)); |
| 653 if (IsKeyboardLayout(input_method.id())) { | 655 if (IsKeyboardLayout(input_method.id())) { |
| 654 xkb_id_to_descriptor_.insert( | 656 xkb_id_to_descriptor_.insert( |
| 655 std::make_pair(input_method.keyboard_layout(), input_method)); | 657 std::make_pair(input_method.GetPreferredKeyboardLayout(), |
| 658 input_method)); |
| 656 } | 659 } |
| 657 } | 660 } |
| 658 | 661 |
| 659 // Go through the languages listed in kExtraLanguages. | 662 // Go through the languages listed in kExtraLanguages. |
| 660 for (size_t i = 0; i < kExtraLanguagesLength; ++i) { | 663 for (size_t i = 0; i < kExtraLanguagesLength; ++i) { |
| 661 const char* language_code = kExtraLanguages[i].language_code; | 664 const char* language_code = kExtraLanguages[i].language_code; |
| 662 const char* input_method_id = kExtraLanguages[i].input_method_id; | 665 const char* input_method_id = kExtraLanguages[i].input_method_id; |
| 663 InputMethodIdToDescriptorMap::const_iterator iter = | 666 InputMethodIdToDescriptorMap::const_iterator iter = |
| 664 id_to_descriptor_.find(input_method_id); | 667 id_to_descriptor_.find(input_method_id); |
| 665 // If the associated input method descriptor is found, add the language | 668 // If the associated input method descriptor is found, add the language |
| 666 // code and the input method. | 669 // code and the input method. |
| 667 if (iter != id_to_descriptor_.end()) { | 670 if (iter != id_to_descriptor_.end()) { |
| 668 const InputMethodDescriptor& input_method = iter->second; | 671 const InputMethodDescriptor& input_method = iter->second; |
| 669 language_code_to_ids_.insert( | 672 language_code_to_ids_.insert( |
| 670 std::make_pair(language_code, input_method.id())); | 673 std::make_pair(language_code, input_method.id())); |
| 671 } | 674 } |
| 672 } | 675 } |
| 673 } | 676 } |
| 674 | 677 |
| 675 } // namespace input_method | 678 } // namespace input_method |
| 676 } // namespace chromeos | 679 } // namespace chromeos |
| OLD | NEW |