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

Unified Diff: chromeos/ime/extension_ime_util.cc

Issue 178343005: [IME] migrate the xkb ID to extension based xkb ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 10 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: chromeos/ime/extension_ime_util.cc
diff --git a/chromeos/ime/extension_ime_util.cc b/chromeos/ime/extension_ime_util.cc
index 7955e52536caae6569ca3c4a917fb6f66e25ab55..ff1a0493bf777e3d1d2be0be5a6abe586de511a4 100644
--- a/chromeos/ime/extension_ime_util.cc
+++ b/chromeos/ime/extension_ime_util.cc
@@ -18,6 +18,9 @@ const int kComponentExtensionIMEPrefixLength =
sizeof(kComponentExtensionIMEPrefix) /
sizeof(kComponentExtensionIMEPrefix[0]) - 1;
const int kExtensionIdLength = 32;
+// Hard coded to true. If the wrapped extension keyboards misbehaves,
+// we can easily change this to false to switch back to legacy xkb keyboards.
+bool g_use_wrapped_extension_keyboard_layouts = true;
} // namespace
namespace extension_ime_util {
@@ -52,6 +55,19 @@ std::string GetExtensionIDFromInputMethodID(
return "";
}
+const std::string GetInputMethodIDByKeyboardLayout(
+ const std::string& keyboard_layout_id) {
+ bool migrate = UseWrappedExtensionKeyboardLayouts();
+ if (IsKeyboardLayoutExtension(keyboard_layout_id)) {
+ if (migrate)
+ return keyboard_layout_id;
+ return keyboard_layout_id.substr(arraysize(kExtensionXkbIdPrefix) - 1);
+ }
+ if (migrate && StartsWithASCII(keyboard_layout_id, "xkb:", true))
+ return kExtensionXkbIdPrefix + keyboard_layout_id;
+ return keyboard_layout_id;
+}
+
bool IsExtensionIME(const std::string& input_method_id) {
return StartsWithASCII(input_method_id,
kExtensionIMEPrefix,
@@ -75,5 +91,24 @@ bool IsKeyboardLayoutExtension(const std::string& input_method_id) {
return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true);
}
+bool UseWrappedExtensionKeyboardLayouts() {
+ return g_use_wrapped_extension_keyboard_layouts;
+}
+
+bool SetUseWrappedExtensionKeyboardLayoutsFlagForTesting(bool enabled) {
+ bool ret = g_use_wrapped_extension_keyboard_layouts;
+ g_use_wrapped_extension_keyboard_layouts = enabled;
+ return ret;
+}
+
+const std::string MaybeGetLegacyXkbId(const std::string& input_method_id) {
+ if (IsKeyboardLayoutExtension(input_method_id)) {
+ size_t pos = input_method_id.find("xkb:");
+ if (pos != std::string::npos)
+ return input_method_id.substr(pos);
+ }
+ return input_method_id;
+}
+
} // namespace extension_ime_util
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698