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 "chrome/browser/chromeos/input_method/input_method_manager_impl_ll.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include <limits> | |
10 | |
11 namespace chromeos { | |
12 namespace input_method { | |
13 | |
14 struct KBDList { | |
15 const char* const* layouts; | |
16 size_t size; | |
17 }; | |
18 | |
19 namespace { | |
20 | |
21 // A language may have some special layout that allows full latin input. | |
22 static const char* const kJPFullLatinKeyboardLayouts[] = { | |
23 "xkb:jp::jpn" | |
24 }; | |
25 | |
26 static const KBDList kJPFullLatinKeyboards = { | |
27 kJPFullLatinKeyboardLayouts, arraysize(kJPFullLatinKeyboardLayouts) | |
28 }; | |
29 | |
30 // A list of languages and their layouts having full 26 latin letter set on | |
31 // keyboard. | |
32 | |
33 // If permitted_layouts is NULL, then all keyboard layouts for the | |
34 // language are "Full Latin Input" and can be used to input passwords on | |
35 // login screen. | |
36 | |
37 // If permitted_layouts is not NULL, it must contain all layouts for the | |
38 // language, that can be used at login screen. | |
39 // | |
40 static const struct SomeLatinKeyboardLanguageList { | |
41 const char* lang; | |
42 const KBDList* permitted_layouts; | |
43 } kHasLatinKeyboardLanguageList[] = { | |
44 {"ca" /* Catalan */, NULL}, | |
45 {"cs" /* Czech */, NULL}, | |
46 {"da" /* Danish */, NULL}, | |
47 {"de" /* German */, NULL}, | |
48 {"en" /* English */, NULL}, | |
49 {"es" /* Spanish */, NULL}, | |
50 {"et" /* Estonian */, NULL}, | |
51 {"fi" /* Finnish */, NULL}, | |
52 {"fr" /* French */, NULL}, | |
53 {"ja" /* Japanese */, &kJPFullLatinKeyboards}, | |
54 {"hr" /* Croatian */, NULL}, | |
55 {"hu" /* Hungarian */, NULL}, | |
56 {"is" /* Icelandic */, NULL}, | |
57 {"it" /* Italian */, NULL}, | |
58 {"lt" /* Lithuanian */, NULL}, | |
59 {"lv" /* Latvian */, NULL}, | |
60 {"nb" /* Norwegian (Bokmal) */, NULL}, | |
61 {"nl" /* Dutch */, NULL}, | |
62 {"pl" /* Polish */, NULL}, | |
63 {"pt" /* Portuguese */, NULL}, | |
64 {"ro" /* Romanian */, NULL}, | |
65 {"sk" /* Slovak */, NULL}, | |
66 {"sl" /* Slovenian */, NULL}, | |
67 {"sv" /* Swedish */, NULL}, | |
68 {"tr" /* Turkish */, NULL}, | |
69 }; | |
70 | |
71 } // namespace | |
72 | |
73 bool FullLatinKeyboardLayoutChecker::IsFullLatinKeyboard( | |
74 const std::string& layout, | |
75 const std::string& lang) const { | |
76 if (lang.size() < 2) { | |
77 return false; | |
78 } | |
79 | |
80 const TwoLetterLanguageCode ll(lang.c_str()); | |
81 const std::vector<TwoLetterLanguageCode2KBDList>::const_iterator pos = | |
82 std::lower_bound(full_latin_keyboard_languages_.begin(), | |
83 full_latin_keyboard_languages_.end(), | |
84 ll); | |
85 | |
86 if (pos == full_latin_keyboard_languages_.end()) | |
87 return false; | |
88 | |
89 if (pos->lang != ll) | |
90 return false; | |
91 | |
92 const KBDList* kbdlist = | |
93 kHasLatinKeyboardLanguageList[pos->index].permitted_layouts; | |
94 | |
95 if (kbdlist == NULL) | |
96 return true; | |
97 | |
98 for (size_t i = 0; i < kbdlist->size; ++i) | |
99 if (strcmp(layout.c_str(), kbdlist->layouts[i]) == 0) | |
100 return true; | |
101 | |
102 return false; | |
103 } | |
104 | |
105 FullLatinKeyboardLayoutChecker::FullLatinKeyboardLayoutChecker() { | |
106 DCHECK(arraysize(kHasLatinKeyboardLanguageList) < | |
107 std::numeric_limits<uint16_t>::max()); | |
108 | |
109 full_latin_keyboard_languages_.reserve( | |
110 arraysize(kHasLatinKeyboardLanguageList)); | |
111 | |
112 for (size_t i = 0; i < arraysize(kHasLatinKeyboardLanguageList); ++i) | |
113 full_latin_keyboard_languages_.push_back(TwoLetterLanguageCode2KBDList( | |
114 kHasLatinKeyboardLanguageList[i].lang, i)); | |
115 | |
116 std::sort(full_latin_keyboard_languages_.begin(), | |
117 full_latin_keyboard_languages_.end()); | |
118 } | |
119 | |
120 FullLatinKeyboardLayoutChecker::~FullLatinKeyboardLayoutChecker() { | |
121 } | |
122 | |
123 } // namespace input_method | |
124 } // namespace chromeos | |
OLD | NEW |