Chromium Code Reviews| Index: chrome/browser/chromeos/input_method/input_method_util.cc |
| diff --git a/chrome/browser/chromeos/input_method/input_method_util.cc b/chrome/browser/chromeos/input_method/input_method_util.cc |
| index 6946a8b59bd787791343836784b99b25b4ca2264..153948fb8e4e73680ea978f81b61702a2b721975 100644 |
| --- a/chrome/browser/chromeos/input_method/input_method_util.cc |
| +++ b/chrome/browser/chromeos/input_method/input_method_util.cc |
| @@ -17,6 +17,8 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "chromeos/ime/component_extension_ime_manager.h" |
| #include "chromeos/ime/extension_ime_util.h" |
| +// For SetHardwareKeyboardLayoutForTesting. |
| +#include "chromeos/ime/fake_input_method_delegate.h" |
| #include "chromeos/ime/input_method_delegate.h" |
| // TODO(nona): move this header from this file. |
| #include "grit/generated_resources.h" |
| @@ -614,25 +616,54 @@ std::string InputMethodUtil::GetLanguageDefaultInputMethodId( |
| return std::string(); |
| } |
| -std::string InputMethodUtil::GetHardwareInputMethodId() const { |
| - const std::string input_method_id = delegate_->GetHardwareKeyboardLayout(); |
| +void InputMethodUtil::UpdateHardwareLayoutCache() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + hardware_layouts_.clear(); |
| + hardware_login_layouts_.clear(); |
| + Tokenize(delegate_->GetHardwareKeyboardLayouts(), ",", &hardware_layouts_); |
| - if (input_method_id.empty()) { |
| + for (size_t i = 0; i < hardware_layouts_.size(); ++i) { |
| + if (IsLoginKeyboard(hardware_layouts_[i])) |
| + hardware_login_layouts_.push_back(hardware_layouts_[i]); |
| + } |
| + if (hardware_layouts_.empty()) { |
| // This is totally fine if it's empty. The hardware keyboard layout is |
| // not stored if startup_manifest.json (OEM customization data) is not |
| // present (ex. Cr48 doen't have that file). |
| - return GetFallbackInputMethodDescriptor().id(); |
| + hardware_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
| } |
| - return input_method_id; |
| + |
| + if (hardware_login_layouts_.empty()) |
| + hardware_login_layouts_.push_back(GetFallbackInputMethodDescriptor().id()); |
| } |
| -std::string InputMethodUtil::GetHardwareLoginInputMethodId() const { |
| - const std::string input_method_id = GetHardwareInputMethodId(); |
| +void InputMethodUtil::SetHardwareKeyboardLayoutForTesting( |
| + const std::string& layout) { |
| + FakeInputMethodDelegate* fake_delegate = |
| + static_cast<FakeInputMethodDelegate*>(delegate_); |
| + CHECK(fake_delegate) |
| + << "To use SetHardwareKeyboardLayoutForTesting, " |
| + << "need to set FakeInputMethodDelegate to constructor."; |
| + fake_delegate->set_hardware_keyboard_layout(layout); |
|
Alexander Alekseev
2014/02/13 12:47:04
Probably it would be better to add
virtual InputM
Seigo Nonaka
2014/02/14 03:51:45
Added SetHardwareKeyboardLayoutForTesting.
On 201
|
| + UpdateHardwareLayoutCache(); |
| +} |
| - if (!IsLoginKeyboard(input_method_id)) |
| - return GetFallbackInputMethodDescriptor().id(); |
| +const std::vector<std::string>& |
| + InputMethodUtil::GetHardwareInputMethodIds() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + // Once the initialization is done, at least one input method should be set. |
| + if (hardware_layouts_.empty()) |
| + UpdateHardwareLayoutCache(); |
| + return hardware_layouts_; |
| +} |
| - return input_method_id; |
| +const std::vector<std::string>& |
| + InputMethodUtil::GetHardwareLoginInputMethodIds() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + // Once the initialization is done, at least one input method should be set. |
| + if (hardware_login_layouts_.empty()) |
| + UpdateHardwareLayoutCache(); |
| + return hardware_login_layouts_; |
| } |
| bool InputMethodUtil::IsLoginKeyboard(const std::string& input_method_id) |