Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / base / ime / chromeos / input_method_descriptor.cc
blobeda8aa6b9a66d625b75c9e46ee70ed16685792b4
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.
5 #include "ui/base/ime/chromeos/input_method_descriptor.h"
7 #include <sstream>
9 #include "base/logging.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "ui/base/ime/chromeos/extension_ime_util.h"
13 #include "url/gurl.h"
15 namespace chromeos {
16 namespace input_method {
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) {
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];
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 base::ToUpperASCII(GetPreferredKeyboardLayout().substr(0, 2));
50 DCHECK(language_codes_.size() > 0);
51 return base::ToUpperASCII(language_codes_[0].substr(0, 2));
53 return indicator_;
56 InputMethodDescriptor::InputMethodDescriptor() {
59 InputMethodDescriptor::~InputMethodDescriptor() {
62 } // namespace input_method
63 } // namespace chromeos