OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/ime/extension_ime_util.h" | 5 #include "chromeos/ime/extension_ime_util.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 | 8 |
9 namespace chromeos { | 9 namespace chromeos { |
10 namespace { | 10 namespace { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 if (IsComponentExtensionIME(input_method_id) && | 46 if (IsComponentExtensionIME(input_method_id) && |
47 input_method_id.size() >= kComponentExtensionIMEPrefixLength + | 47 input_method_id.size() >= kComponentExtensionIMEPrefixLength + |
48 kExtensionIdLength) { | 48 kExtensionIdLength) { |
49 return input_method_id.substr(kComponentExtensionIMEPrefixLength, | 49 return input_method_id.substr(kComponentExtensionIMEPrefixLength, |
50 kExtensionIdLength); | 50 kExtensionIdLength); |
51 } | 51 } |
52 return ""; | 52 return ""; |
53 } | 53 } |
54 | 54 |
| 55 std::string GetInputMethodIDByKeyboardLayout( |
| 56 const std::string& keyboard_layout_id) { |
| 57 bool migrate = UseWrappedExtensionKeyboardLayouts(); |
| 58 if (IsKeyboardLayoutExtension(keyboard_layout_id)) { |
| 59 if (migrate) |
| 60 return keyboard_layout_id; |
| 61 return keyboard_layout_id.substr(arraysize(kExtensionXkbIdPrefix) - 1); |
| 62 } |
| 63 if (migrate && StartsWithASCII(keyboard_layout_id, "xkb:", true)) |
| 64 return kExtensionXkbIdPrefix + keyboard_layout_id; |
| 65 return keyboard_layout_id; |
| 66 } |
| 67 |
55 bool IsExtensionIME(const std::string& input_method_id) { | 68 bool IsExtensionIME(const std::string& input_method_id) { |
56 return StartsWithASCII(input_method_id, | 69 return StartsWithASCII(input_method_id, |
57 kExtensionIMEPrefix, | 70 kExtensionIMEPrefix, |
58 true); // Case sensitive. | 71 true); // Case sensitive. |
59 } | 72 } |
60 | 73 |
61 bool IsComponentExtensionIME(const std::string& input_method_id) { | 74 bool IsComponentExtensionIME(const std::string& input_method_id) { |
62 return StartsWithASCII(input_method_id, | 75 return StartsWithASCII(input_method_id, |
63 kComponentExtensionIMEPrefix, | 76 kComponentExtensionIMEPrefix, |
64 true); // Case sensitive. | 77 true); // Case sensitive. |
65 } | 78 } |
66 | 79 |
67 bool IsMemberOfExtension(const std::string& input_method_id, | 80 bool IsMemberOfExtension(const std::string& input_method_id, |
68 const std::string& extension_id) { | 81 const std::string& extension_id) { |
69 return StartsWithASCII(input_method_id, | 82 return StartsWithASCII(input_method_id, |
70 kExtensionIMEPrefix + extension_id, | 83 kExtensionIMEPrefix + extension_id, |
71 true); // Case sensitive. | 84 true); // Case sensitive. |
72 } | 85 } |
73 | 86 |
74 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { | 87 bool IsKeyboardLayoutExtension(const std::string& input_method_id) { |
75 return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true); | 88 return StartsWithASCII(input_method_id, kExtensionXkbIdPrefix, true); |
76 } | 89 } |
77 | 90 |
| 91 bool UseWrappedExtensionKeyboardLayouts() { |
| 92 // Hard coded to true. If the wrapped extension keyboards misbehaves, |
| 93 // we can easily change this to false to switch back to legacy xkb keyboards. |
| 94 return true; |
| 95 } |
| 96 |
78 } // namespace extension_ime_util | 97 } // namespace extension_ime_util |
79 } // namespace chromeos | 98 } // namespace chromeos |
OLD | NEW |