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 #ifndef UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ | 5 #ifndef UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
6 #define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ | 6 #define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
7 | 7 |
8 #include <xkbcommon/xkbcommon.h> | 8 #include <xkbcommon/xkbcommon.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 // KeyboardLayoutEngine: | 30 // KeyboardLayoutEngine: |
31 bool CanSetCurrentLayout() const override; | 31 bool CanSetCurrentLayout() const override; |
32 bool SetCurrentLayoutByName(const std::string& layout_name) override; | 32 bool SetCurrentLayoutByName(const std::string& layout_name) override; |
33 | 33 |
34 bool UsesISOLevel5Shift() const override; | 34 bool UsesISOLevel5Shift() const override; |
35 bool UsesAltGr() const override; | 35 bool UsesAltGr() const override; |
36 | 36 |
37 bool Lookup(DomCode dom_code, | 37 bool Lookup(DomCode dom_code, |
38 int flags, | 38 int flags, |
39 DomKey* dom_key, | 39 DomKey* dom_key, |
40 base::char16* character, | |
41 KeyboardCode* key_code, | 40 KeyboardCode* key_code, |
42 uint32* platform_keycode) const override; | 41 uint32* platform_keycode) const override; |
43 | 42 |
44 static void ParseLayoutName(const std::string& layout_name, | 43 static void ParseLayoutName(const std::string& layout_name, |
45 std::string* layout_id, | 44 std::string* layout_id, |
46 std::string* layout_variant); | 45 std::string* layout_variant); |
47 | 46 |
48 protected: | 47 protected: |
49 // Table for EventFlagsToXkbFlags(). | 48 // Table for EventFlagsToXkbFlags(). |
50 struct XkbFlagMapEntry { | 49 struct XkbFlagMapEntry { |
51 int ui_flag; | 50 int ui_flag; |
52 xkb_mod_mask_t xkb_flag; | 51 xkb_mod_mask_t xkb_flag; |
53 }; | 52 }; |
54 std::vector<XkbFlagMapEntry> xkb_flag_map_; | 53 std::vector<XkbFlagMapEntry> xkb_flag_map_; |
55 | 54 |
56 // Flag mask for num lock, which is always considered enabled. | 55 // Flag mask for num lock, which is always considered enabled. |
57 xkb_mod_mask_t num_lock_mod_mask_ = 0; | 56 xkb_mod_mask_t num_lock_mod_mask_ = 0; |
58 | 57 |
59 // Determines the Windows-based KeyboardCode (VKEY) for a character key, | 58 // Determines the Windows-based KeyboardCode (VKEY) for a character key, |
60 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the | 59 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the |
61 // caller should, as a last resort, obtain a KeyboardCode using | 60 // caller should, as a last resort, obtain a KeyboardCode using |
62 // |DomCodeToUsLayoutMeaning()|. | 61 // |DomCodeToUsLayoutDomKey()|. |
63 KeyboardCode DifficultKeyboardCode(DomCode dom_code, | 62 KeyboardCode DifficultKeyboardCode(DomCode dom_code, |
64 int ui_flags, | 63 int ui_flags, |
65 xkb_keycode_t xkb_keycode, | 64 xkb_keycode_t xkb_keycode, |
66 xkb_mod_mask_t xkb_flags, | 65 xkb_mod_mask_t xkb_flags, |
67 xkb_keysym_t xkb_keysym, | 66 xkb_keysym_t xkb_keysym, |
68 DomKey dom_key, | |
69 base::char16 character) const; | 67 base::char16 character) const; |
70 | 68 |
71 // Maps DomCode to xkb_keycode_t. | 69 // Maps DomCode to xkb_keycode_t. |
72 const XkbKeyCodeConverter& key_code_converter_; | 70 const XkbKeyCodeConverter& key_code_converter_; |
73 | 71 |
74 private: | 72 private: |
75 struct XkbKeymapEntry { | 73 struct XkbKeymapEntry { |
76 std::string layout_name; | 74 std::string layout_name; |
77 xkb_keymap* keymap; | 75 xkb_keymap* keymap; |
78 }; | 76 }; |
79 std::vector<XkbKeymapEntry> xkb_keymaps_; | 77 std::vector<XkbKeymapEntry> xkb_keymaps_; |
80 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership | 78 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership |
81 // of the keymap), and updates xkb_flag_map_ for the new keymap. | 79 // of the keymap), and updates xkb_flag_map_ for the new keymap. |
82 void SetKeymap(xkb_keymap* keymap); | 80 void SetKeymap(xkb_keymap* keymap); |
83 | 81 |
84 // Returns the XKB modifiers flags corresponding to the given EventFlags. | 82 // Returns the XKB modifiers flags corresponding to the given EventFlags. |
85 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; | 83 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; |
86 | 84 |
87 // Determines the XKB KeySym and character associated with a key. | 85 // Determines the XKB KeySym and character associated with a key. |
88 // Returns true on success. This is virtual for testing. | 86 // Returns true on success. This is virtual for testing. |
89 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, | 87 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, |
90 xkb_mod_mask_t xkb_flags, | 88 xkb_mod_mask_t xkb_flags, |
91 xkb_keysym_t* xkb_keysym, | 89 xkb_keysym_t* xkb_keysym, |
92 base::char16* character) const; | 90 uint32_t* character) const; |
93 | 91 |
94 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, | 92 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, |
95 // returns |base_character|; otherwise returns the XKB character for | 93 // returns |base_character|; otherwise returns the XKB character for |
96 // the keycode and mapped |ui_flags|. | 94 // the keycode and mapped |ui_flags|. |
97 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, | 95 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, |
98 xkb_mod_mask_t base_flags, | 96 xkb_mod_mask_t base_flags, |
99 base::char16 base_character, | 97 base::char16 base_character, |
100 int ui_flags) const; | 98 int ui_flags) const; |
101 | 99 |
102 // Callback when keymap file is loaded complete. | 100 // Callback when keymap file is loaded complete. |
103 void OnKeymapLoaded(const std::string& layout_name, | 101 void OnKeymapLoaded(const std::string& layout_name, |
104 scoped_ptr<char, base::FreeDeleter> keymap_str); | 102 scoped_ptr<char, base::FreeDeleter> keymap_str); |
105 | 103 |
106 // libxkbcommon uses explicit reference counting for its structures, | 104 // libxkbcommon uses explicit reference counting for its structures, |
107 // so we need to trigger its cleanup. | 105 // so we need to trigger its cleanup. |
108 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; | 106 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; |
109 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_; | 107 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_; |
110 | 108 |
111 std::string current_layout_name_; | 109 std::string current_layout_name_; |
112 | 110 |
113 // Support weak pointers for attach & detach callbacks. | 111 // Support weak pointers for attach & detach callbacks. |
114 base::WeakPtrFactory<XkbKeyboardLayoutEngine> weak_ptr_factory_; | 112 base::WeakPtrFactory<XkbKeyboardLayoutEngine> weak_ptr_factory_; |
115 }; | 113 }; |
116 | 114 |
117 } // namespace ui | 115 } // namespace ui |
118 | 116 |
119 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ | 117 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
OLD | NEW |