| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 #include <xkbcommon/xkbcommon.h> | 9 #include <xkbcommon/xkbcommon.h> |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the | 65 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the |
| 66 // caller should, as a last resort, obtain a KeyboardCode using | 66 // caller should, as a last resort, obtain a KeyboardCode using |
| 67 // |DomCodeToUsLayoutDomKey()|. | 67 // |DomCodeToUsLayoutDomKey()|. |
| 68 KeyboardCode DifficultKeyboardCode(DomCode dom_code, | 68 KeyboardCode DifficultKeyboardCode(DomCode dom_code, |
| 69 int ui_flags, | 69 int ui_flags, |
| 70 xkb_keycode_t xkb_keycode, | 70 xkb_keycode_t xkb_keycode, |
| 71 xkb_mod_mask_t xkb_flags, | 71 xkb_mod_mask_t xkb_flags, |
| 72 xkb_keysym_t xkb_keysym, | 72 xkb_keysym_t xkb_keysym, |
| 73 base::char16 character) const; | 73 base::char16 character) const; |
| 74 | 74 |
| 75 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership |
| 76 // of the keymap), and updates xkb_flag_map_ for the new keymap. |
| 77 virtual void SetKeymap(xkb_keymap* keymap); |
| 78 |
| 75 // Maps DomCode to xkb_keycode_t. | 79 // Maps DomCode to xkb_keycode_t. |
| 76 const XkbKeyCodeConverter& key_code_converter_; | 80 const XkbKeyCodeConverter& key_code_converter_; |
| 77 | 81 |
| 82 // libxkbcommon uses explicit reference counting for its structures, |
| 83 // so we need to trigger its cleanup. |
| 84 std::unique_ptr<xkb_state, XkbStateDeleter> xkb_state_; |
| 85 |
| 78 private: | 86 private: |
| 79 struct XkbKeymapEntry { | 87 struct XkbKeymapEntry { |
| 80 std::string layout_name; | 88 std::string layout_name; |
| 81 xkb_keymap* keymap; | 89 xkb_keymap* keymap; |
| 82 }; | 90 }; |
| 83 std::vector<XkbKeymapEntry> xkb_keymaps_; | 91 std::vector<XkbKeymapEntry> xkb_keymaps_; |
| 84 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership | |
| 85 // of the keymap), and updates xkb_flag_map_ for the new keymap. | |
| 86 void SetKeymap(xkb_keymap* keymap); | |
| 87 | 92 |
| 88 // Returns the XKB modifiers flags corresponding to the given EventFlags. | 93 // Returns the XKB modifiers flags corresponding to the given EventFlags. |
| 89 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; | 94 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; |
| 90 | 95 |
| 91 // Determines the XKB KeySym and character associated with a key. | 96 // Determines the XKB KeySym and character associated with a key. |
| 92 // Returns true on success. This is virtual for testing. | 97 // Returns true on success. This is virtual for testing. |
| 93 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, | 98 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, |
| 94 xkb_mod_mask_t xkb_flags, | 99 xkb_mod_mask_t xkb_flags, |
| 95 xkb_keysym_t* xkb_keysym, | 100 xkb_keysym_t* xkb_keysym, |
| 96 uint32_t* character) const; | 101 uint32_t* character) const; |
| 97 | 102 |
| 98 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, | 103 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, |
| 99 // returns |base_character|; otherwise returns the XKB character for | 104 // returns |base_character|; otherwise returns the XKB character for |
| 100 // the keycode and mapped |ui_flags|. | 105 // the keycode and mapped |ui_flags|. |
| 101 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, | 106 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, |
| 102 xkb_mod_mask_t base_flags, | 107 xkb_mod_mask_t base_flags, |
| 103 base::char16 base_character, | 108 base::char16 base_character, |
| 104 int ui_flags) const; | 109 int ui_flags) const; |
| 105 | 110 |
| 106 // Callback when keymap file is loaded complete. | 111 // Callback when keymap file is loaded complete. |
| 107 void OnKeymapLoaded(const std::string& layout_name, | 112 void OnKeymapLoaded(const std::string& layout_name, |
| 108 std::unique_ptr<char, base::FreeDeleter> keymap_str); | 113 std::unique_ptr<char, base::FreeDeleter> keymap_str); |
| 109 | 114 |
| 110 // libxkbcommon uses explicit reference counting for its structures, | |
| 111 // so we need to trigger its cleanup. | |
| 112 std::unique_ptr<xkb_context, XkbContextDeleter> xkb_context_; | 115 std::unique_ptr<xkb_context, XkbContextDeleter> xkb_context_; |
| 113 std::unique_ptr<xkb_state, XkbStateDeleter> xkb_state_; | |
| 114 | 116 |
| 115 std::string current_layout_name_; | 117 std::string current_layout_name_; |
| 116 | 118 |
| 117 // Support weak pointers for attach & detach callbacks. | 119 // Support weak pointers for attach & detach callbacks. |
| 118 base::WeakPtrFactory<XkbKeyboardLayoutEngine> weak_ptr_factory_; | 120 base::WeakPtrFactory<XkbKeyboardLayoutEngine> weak_ptr_factory_; |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 } // namespace ui | 123 } // namespace ui |
| 122 | 124 |
| 123 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ | 125 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
| OLD | NEW |