| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/input_method/input_method_descriptor.h" |
| 6 |
| 7 #include <sstream> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/string_split.h" |
| 11 #include "chrome/browser/chromeos/input_method/input_method_whitelist.h" |
| 12 |
| 13 namespace chromeos { |
| 14 namespace input_method { |
| 15 |
| 16 namespace { |
| 17 const char kFallbackLayout[] = "us"; |
| 18 } // namespace |
| 19 |
| 20 InputMethodDescriptor::InputMethodDescriptor( |
| 21 const InputMethodWhitelist& whitelist, |
| 22 const std::string& id, |
| 23 const std::string& name, |
| 24 const std::string& raw_layout, |
| 25 const std::string& language_code) |
| 26 : id_(id), |
| 27 name_(name), |
| 28 language_code_(language_code) { |
| 29 keyboard_layout_ = kFallbackLayout; |
| 30 base::SplitString(raw_layout, ',', &virtual_keyboard_layouts_); |
| 31 |
| 32 // Find a valid XKB layout name from the comma-separated list, |raw_layout|. |
| 33 // Only the first acceptable XKB layout name in the list is used as the |
| 34 // |keyboard_layout| value of the InputMethodDescriptor object to be created |
| 35 for (size_t i = 0; i < virtual_keyboard_layouts_.size(); ++i) { |
| 36 if (whitelist.XkbLayoutIsSupported(virtual_keyboard_layouts_[i])) { |
| 37 keyboard_layout_ = virtual_keyboard_layouts_[i]; |
| 38 DCHECK(keyboard_layout_.find(",") == std::string::npos); |
| 39 break; |
| 40 } |
| 41 } |
| 42 } |
| 43 |
| 44 InputMethodDescriptor::InputMethodDescriptor() { |
| 45 } |
| 46 |
| 47 InputMethodDescriptor::~InputMethodDescriptor() { |
| 48 } |
| 49 |
| 50 InputMethodDescriptor::InputMethodDescriptor( |
| 51 const std::string& in_id, |
| 52 const std::string& in_name, |
| 53 const std::string& in_keyboard_layout, |
| 54 const std::string& in_virtual_keyboard_layouts, |
| 55 const std::string& in_language_code) |
| 56 : id_(in_id), |
| 57 name_(in_name), |
| 58 keyboard_layout_(in_keyboard_layout), |
| 59 language_code_(in_language_code) { |
| 60 DCHECK(keyboard_layout_.find(",") == std::string::npos); |
| 61 base::SplitString( |
| 62 in_virtual_keyboard_layouts, ',', &virtual_keyboard_layouts_); |
| 63 } |
| 64 |
| 65 // static |
| 66 InputMethodDescriptor |
| 67 InputMethodDescriptor::GetFallbackInputMethodDescriptor() { |
| 68 return InputMethodDescriptor("xkb:us::eng", |
| 69 "", |
| 70 kFallbackLayout, |
| 71 kFallbackLayout, |
| 72 "en-US"); |
| 73 } |
| 74 |
| 75 std::string InputMethodDescriptor::ToString() const { |
| 76 std::stringstream stream; |
| 77 stream << "id=" << id() |
| 78 << ", name=" << name() |
| 79 << ", keyboard_layout=" << keyboard_layout() |
| 80 << ", virtual_keyboard_layouts=" << virtual_keyboard_layouts_.size() |
| 81 << ", language_code=" << language_code(); |
| 82 return stream.str(); |
| 83 } |
| 84 |
| 85 } // namespace input_method |
| 86 } // namespace chromeos |
| OLD | NEW |