Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1006)

Unified Diff: chrome/browser/chromeos/input_method/input_method_manager_impl_ll.cc

Issue 18856014: We should switch the keyboard layout to the layout the user set according to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Diff versus master. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/input_method/input_method_manager_impl_ll.cc
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl_ll.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl_ll.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2eb586c182d76160fd8989931a7499d6c8d4c7b
--- /dev/null
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl_ll.cc
@@ -0,0 +1,124 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/input_method/input_method_manager_impl_ll.h"
+
+#include <string.h>
+
+#include <limits>
+
+namespace chromeos {
+namespace input_method {
+
+struct KBDList {
+ const char* const* layouts;
+ size_t size;
+};
+
+namespace {
+
+// A language may have some special layout that allows full latin input.
+static const char* const kJPFullLatinKeyboardLayouts[] = {
+ "xkb:jp::jpn"
+};
+
+static const KBDList kJPFullLatinKeyboards = {
+ kJPFullLatinKeyboardLayouts, arraysize(kJPFullLatinKeyboardLayouts)
+};
+
+// A list of languages and their layouts having full 26 latin letter set on
+// keyboard.
+
+// If permitted_layouts is NULL, then all keyboard layouts for the
+// language are "Full Latin Input" and can be used to input passwords on
+// login screen.
+
+// If permitted_layouts is not NULL, it must contain all layouts for the
+// language, that can be used at login screen.
+//
+static const struct SomeLatinKeyboardLanguageList {
+ const char* lang;
+ const KBDList* permitted_layouts;
+} kHasLatinKeyboardLanguageList[] = {
+ {"ca" /* Catalan */, NULL},
+ {"cs" /* Czech */, NULL},
+ {"da" /* Danish */, NULL},
+ {"de" /* German */, NULL},
+ {"en" /* English */, NULL},
+ {"es" /* Spanish */, NULL},
+ {"et" /* Estonian */, NULL},
+ {"fi" /* Finnish */, NULL},
+ {"fr" /* French */, NULL},
+ {"ja" /* Japanese */, &kJPFullLatinKeyboards},
+ {"hr" /* Croatian */, NULL},
+ {"hu" /* Hungarian */, NULL},
+ {"is" /* Icelandic */, NULL},
+ {"it" /* Italian */, NULL},
+ {"lt" /* Lithuanian */, NULL},
+ {"lv" /* Latvian */, NULL},
+ {"nb" /* Norwegian (Bokmal) */, NULL},
+ {"nl" /* Dutch */, NULL},
+ {"pl" /* Polish */, NULL},
+ {"pt" /* Portuguese */, NULL},
+ {"ro" /* Romanian */, NULL},
+ {"sk" /* Slovak */, NULL},
+ {"sl" /* Slovenian */, NULL},
+ {"sv" /* Swedish */, NULL},
+ {"tr" /* Turkish */, NULL},
+};
+
+} // namespace
+
+bool FullLatinKeyboardLayoutChecker::IsFullLatinKeyboard(
+ const std::string& layout,
+ const std::string& lang) const {
+ if (lang.size() < 2) {
+ return false;
+ }
+
+ const TwoLetterLanguageCode ll(lang.c_str());
+ const std::vector<TwoLetterLanguageCode2KBDList>::const_iterator pos =
+ std::lower_bound(full_latin_keyboard_languages_.begin(),
+ full_latin_keyboard_languages_.end(),
+ ll);
+
+ if (pos == full_latin_keyboard_languages_.end())
+ return false;
+
+ if (pos->lang != ll)
+ return false;
+
+ const KBDList* kbdlist =
+ kHasLatinKeyboardLanguageList[pos->index].permitted_layouts;
+
+ if (kbdlist == NULL)
+ return true;
+
+ for (size_t i = 0; i < kbdlist->size; ++i)
+ if (strcmp(layout.c_str(), kbdlist->layouts[i]) == 0)
+ return true;
+
+ return false;
+}
+
+FullLatinKeyboardLayoutChecker::FullLatinKeyboardLayoutChecker() {
+ DCHECK(arraysize(kHasLatinKeyboardLanguageList) <
+ std::numeric_limits<uint16_t>::max());
+
+ full_latin_keyboard_languages_.reserve(
+ arraysize(kHasLatinKeyboardLanguageList));
+
+ for (size_t i = 0; i < arraysize(kHasLatinKeyboardLanguageList); ++i)
+ full_latin_keyboard_languages_.push_back(TwoLetterLanguageCode2KBDList(
+ kHasLatinKeyboardLanguageList[i].lang, i));
+
+ std::sort(full_latin_keyboard_languages_.begin(),
+ full_latin_keyboard_languages_.end());
+}
+
+FullLatinKeyboardLayoutChecker::~FullLatinKeyboardLayoutChecker() {
+}
+
+} // namespace input_method
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698