OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | 5 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
6 | 6 |
7 #include <xkbcommon/xkbcommon-names.h> | 7 #include <xkbcommon/xkbcommon-names.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 {0x0163, VKEY_OEM_7}, // t cedilla | 618 {0x0163, VKEY_OEM_7}, // t cedilla |
619 {0x0165, VKEY_5}, // t caron | 619 {0x0165, VKEY_5}, // t caron |
620 {0x016F, VKEY_OEM_1}, // u ring above | 620 {0x016F, VKEY_OEM_1}, // u ring above |
621 {0x0171, VKEY_OEM_5}, // u double acute | 621 {0x0171, VKEY_OEM_5}, // u double acute |
622 {0x01A1, VKEY_OEM_6}, // o horn | 622 {0x01A1, VKEY_OEM_6}, // o horn |
623 {0x01B0, VKEY_OEM_4}, // u horn | 623 {0x01B0, VKEY_OEM_4}, // u horn |
624 {0x01B6, VKEY_OEM_6}, // z stroke | 624 {0x01B6, VKEY_OEM_6}, // z stroke |
625 {0x0259, VKEY_OEM_3}, // schwa | 625 {0x0259, VKEY_OEM_3}, // schwa |
626 }; | 626 }; |
627 | 627 |
628 void ParseLayoutName(const std::string& layout_name, | |
629 std::string* layout_id, | |
630 std::string* layout_variant) { | |
631 size_t dash_index = layout_name.find('-'); | |
632 size_t parentheses_index = layout_name.find('('); | |
633 *layout_id = layout_name; | |
634 *layout_variant = ""; | |
635 if (parentheses_index != std::string::npos) { | |
636 *layout_id = layout_name.substr(0, parentheses_index); | |
637 size_t close_index = layout_name.find(')', parentheses_index); | |
638 if (close_index == std::string::npos) | |
639 close_index = layout_name.size(); | |
640 *layout_variant = layout_name.substr(parentheses_index + 1, | |
641 close_index - parentheses_index - 1); | |
642 } else if (dash_index != std::string::npos) { | |
643 *layout_id = layout_name.substr(0, dash_index); | |
644 *layout_variant = layout_name.substr(dash_index + 1); | |
645 } | |
646 } | |
647 | |
648 void LoadKeymap(const std::string& layout_name, | 628 void LoadKeymap(const std::string& layout_name, |
649 scoped_refptr<base::SingleThreadTaskRunner> reply_runner, | 629 scoped_refptr<base::SingleThreadTaskRunner> reply_runner, |
650 const LoadKeymapCallback& reply_callback) { | 630 const LoadKeymapCallback& reply_callback) { |
651 std::string layout_id; | 631 std::string layout_id; |
652 std::string layout_variant; | 632 std::string layout_variant; |
653 ParseLayoutName(layout_name, &layout_id, &layout_variant); | 633 XkbKeyboardLayoutEngine::ParseLayoutName(layout_name, &layout_id, |
| 634 &layout_variant); |
654 xkb_rule_names names = {.rules = NULL, | 635 xkb_rule_names names = {.rules = NULL, |
655 .model = "pc101", | 636 .model = "pc101", |
656 .layout = layout_id.c_str(), | 637 .layout = layout_id.c_str(), |
657 .variant = layout_variant.c_str(), | 638 .variant = layout_variant.c_str(), |
658 .options = ""}; | 639 .options = ""}; |
659 scoped_ptr<xkb_context, XkbContextDeleter> context; | 640 scoped_ptr<xkb_context, XkbContextDeleter> context; |
660 context.reset(xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES)); | 641 context.reset(xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES)); |
661 xkb_context_include_path_append(context.get(), "/usr/share/X11/xkb"); | 642 xkb_context_include_path_append(context.get(), "/usr/share/X11/xkb"); |
662 scoped_ptr<xkb_keymap, XkbKeymapDeleter> keymap; | 643 scoped_ptr<xkb_keymap, XkbKeymapDeleter> keymap; |
663 keymap.reset(xkb_keymap_new_from_names(context.get(), &names, | 644 keymap.reset(xkb_keymap_new_from_names(context.get(), &names, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 xkb_mod_mask_t flags = EventFlagsToXkbFlags(ui_flags); | 925 xkb_mod_mask_t flags = EventFlagsToXkbFlags(ui_flags); |
945 if (flags == base_flags) | 926 if (flags == base_flags) |
946 return base_character; | 927 return base_character; |
947 xkb_keysym_t keysym; | 928 xkb_keysym_t keysym; |
948 base::char16 character = 0; | 929 base::char16 character = 0; |
949 if (!XkbLookup(xkb_keycode, flags, &keysym, &character)) | 930 if (!XkbLookup(xkb_keycode, flags, &keysym, &character)) |
950 character = kNone; | 931 character = kNone; |
951 return character; | 932 return character; |
952 } | 933 } |
953 | 934 |
| 935 void XkbKeyboardLayoutEngine::ParseLayoutName(const std::string& layout_name, |
| 936 std::string* layout_id, |
| 937 std::string* layout_variant) { |
| 938 size_t dash_index = layout_name.find('-'); |
| 939 size_t parentheses_index = layout_name.find('('); |
| 940 *layout_id = layout_name; |
| 941 *layout_variant = ""; |
| 942 if (parentheses_index != std::string::npos) { |
| 943 *layout_id = layout_name.substr(0, parentheses_index); |
| 944 size_t close_index = layout_name.find(')', parentheses_index); |
| 945 if (close_index == std::string::npos) |
| 946 close_index = layout_name.size(); |
| 947 *layout_variant = layout_name.substr(parentheses_index + 1, |
| 948 close_index - parentheses_index - 1); |
| 949 } else if (dash_index != std::string::npos) { |
| 950 *layout_id = layout_name.substr(0, dash_index); |
| 951 *layout_variant = layout_name.substr(dash_index + 1); |
| 952 } |
| 953 } |
954 } // namespace ui | 954 } // namespace ui |
OLD | NEW |