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

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
« no previous file with comments | « chromeos/ime/extension_ime_util.h ('k') | chromeos/ime/input_method_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8712451ee4b4d6ba32a59b2f6265a3d7b07be3d7 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 "";
}
+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,27 @@ bool IsKeyboardLayoutExtension(const std::string& input_method_id) {
return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true);
}
+bool UseWrappedExtensionKeyboardLayouts() {
+ return g_use_wrapped_extension_keyboard_layouts;
+}
+
+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;
+}
+
+ScopedUseExtensionKeyboardFlagForTesting::
+ ScopedUseExtensionKeyboardFlagForTesting(bool new_flag)
+ : auto_reset_(&g_use_wrapped_extension_keyboard_layouts, new_flag) {
+}
+
+ScopedUseExtensionKeyboardFlagForTesting::
+ ~ScopedUseExtensionKeyboardFlagForTesting() {
+}
+
} // namespace extension_ime_util
} // namespace chromeos
« no previous file with comments | « chromeos/ime/extension_ime_util.h ('k') | chromeos/ime/input_method_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698