OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 "chromeos/ime/input_method_descriptor.h" |
| 6 |
| 7 #include <sstream> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_split.h" |
| 11 #include "base/strings/string_util.h" |
| 12 #include "chromeos/ime/extension_ime_util.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace chromeos { |
| 16 namespace input_method { |
| 17 |
| 18 InputMethodDescriptor::InputMethodDescriptor( |
| 19 const std::string& id, |
| 20 const std::string& name, |
| 21 const std::string& indicator, |
| 22 const std::vector<std::string>& keyboard_layouts, |
| 23 const std::vector<std::string>& language_codes, |
| 24 bool is_login_keyboard, |
| 25 const GURL& options_page_url, |
| 26 const GURL& input_view_url) |
| 27 : id_(id), |
| 28 name_(name), |
| 29 keyboard_layouts_(keyboard_layouts), |
| 30 language_codes_(language_codes), |
| 31 indicator_(indicator), |
| 32 is_login_keyboard_(is_login_keyboard), |
| 33 options_page_url_(options_page_url), |
| 34 input_view_url_(input_view_url) { |
| 35 } |
| 36 |
| 37 std::string InputMethodDescriptor::GetPreferredKeyboardLayout() const { |
| 38 // TODO(nona): Investigate better way to guess the preferred layout |
| 39 // http://crbug.com/170601. |
| 40 return keyboard_layouts_.empty() ? "us" : keyboard_layouts_[0]; |
| 41 } |
| 42 |
| 43 std::string InputMethodDescriptor::GetIndicator() const { |
| 44 // If indicator is empty, use the first two character in its preferred |
| 45 // keyboard layout or language code. |
| 46 if (indicator_.empty()) { |
| 47 if (extension_ime_util::IsKeyboardLayoutExtension(id_)) |
| 48 return StringToUpperASCII(GetPreferredKeyboardLayout().substr(0, 2)); |
| 49 DCHECK(language_codes_.size() > 0); |
| 50 return StringToUpperASCII(language_codes_[0].substr(0, 2)); |
| 51 } |
| 52 return indicator_; |
| 53 } |
| 54 |
| 55 InputMethodDescriptor::InputMethodDescriptor() { |
| 56 } |
| 57 |
| 58 InputMethodDescriptor::~InputMethodDescriptor() { |
| 59 } |
| 60 |
| 61 } // namespace input_method |
| 62 } // namespace chromeos |
OLD | NEW |