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"
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"
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
)
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 StringToUpperASCII(GetPreferredKeyboardLayout().substr(0, 2));
49 DCHECK(language_codes_
.size() > 0);
50 return StringToUpperASCII(language_codes_
[0].substr(0, 2));
55 InputMethodDescriptor::InputMethodDescriptor() {
58 InputMethodDescriptor::~InputMethodDescriptor() {
61 } // namespace input_method
62 } // namespace chromeos