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 <map> |
8 #include <xkbcommon/xkbcommon.h> | 9 #include <xkbcommon/xkbcommon.h> |
9 | 10 |
10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/task_runner.h" |
13 #include "ui/events/ozone/layout/events_ozone_layout_export.h" | 18 #include "ui/events/ozone/layout/events_ozone_layout_export.h" |
14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 19 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
15 #include "ui/events/ozone/layout/xkb/scoped_xkb.h" | 20 #include "ui/events/ozone/layout/xkb/scoped_xkb.h" |
16 #include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h" | 21 #include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h" |
17 | 22 |
18 namespace ui { | 23 namespace ui { |
19 | 24 |
20 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyboardLayoutEngine | 25 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyboardLayoutEngine |
21 : public KeyboardLayoutEngine { | 26 : public KeyboardLayoutEngine { |
22 public: | 27 public: |
23 XkbKeyboardLayoutEngine(const XkbKeyCodeConverter& converter); | 28 XkbKeyboardLayoutEngine(const XkbKeyCodeConverter& converter); |
24 virtual ~XkbKeyboardLayoutEngine(); | 29 virtual ~XkbKeyboardLayoutEngine(); |
25 | 30 |
26 // KeyboardLayoutEngine: | 31 // KeyboardLayoutEngine: |
27 virtual bool CanSetCurrentLayout() const override; | 32 virtual bool CanSetCurrentLayout() const override; |
28 virtual bool SetCurrentLayoutByName(const std::string& layout_name) override; | 33 virtual bool SetCurrentLayoutByName(const std::string& layout_name) override; |
29 | 34 |
30 virtual bool UsesISOLevel5Shift() const override; | 35 virtual bool UsesISOLevel5Shift() const override; |
31 virtual bool UsesAltGr() const override; | 36 virtual bool UsesAltGr() const override; |
32 | 37 |
33 virtual bool Lookup(DomCode dom_code, | 38 virtual bool Lookup(DomCode dom_code, |
34 int flags, | 39 int flags, |
35 DomKey* dom_key, | 40 DomKey* dom_key, |
36 base::char16* character, | 41 base::char16* character, |
37 KeyboardCode* key_code, | 42 KeyboardCode* key_code, |
38 uint32* platform_keycode) const override; | 43 uint32* platform_keycode) const override; |
39 | 44 |
| 45 // Gets the names of the RMLO rule for libxkbcommon. |
| 46 // Makes it protected for testing. |
| 47 scoped_ptr<xkb_rule_names> GetXkbRuleNames(const std::string& layout_name); |
| 48 |
40 protected: | 49 protected: |
41 // Table for EventFlagsToXkbFlags(). | 50 // Table for EventFlagsToXkbFlags(). |
42 struct XkbFlagMapEntry { | 51 struct XkbFlagMapEntry { |
43 int ui_flag; | 52 int ui_flag; |
44 xkb_mod_mask_t xkb_flag; | 53 xkb_mod_mask_t xkb_flag; |
45 }; | 54 }; |
46 std::vector<XkbFlagMapEntry> xkb_flag_map_; | 55 std::vector<XkbFlagMapEntry> xkb_flag_map_; |
47 | 56 |
48 // Determines the Windows-based KeyboardCode (VKEY) for a character key, | 57 // Determines the Windows-based KeyboardCode (VKEY) for a character key, |
49 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the | 58 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the |
50 // caller should use |DomCodeToNonLocatedKeyboardCode()| as a last resort. | 59 // caller should use |DomCodeToNonLocatedKeyboardCode()| as a last resort. |
51 KeyboardCode DifficultKeyboardCode(DomCode dom_code, | 60 KeyboardCode DifficultKeyboardCode(DomCode dom_code, |
52 int ui_flags, | 61 int ui_flags, |
53 xkb_keycode_t xkb_keycode, | 62 xkb_keycode_t xkb_keycode, |
54 xkb_mod_mask_t xkb_flags, | 63 xkb_mod_mask_t xkb_flags, |
55 xkb_keysym_t xkb_keysym, | 64 xkb_keysym_t xkb_keysym, |
56 DomKey dom_key, | 65 DomKey dom_key, |
57 base::char16 character) const; | 66 base::char16 character) const; |
58 | 67 |
59 // Maps DomCode to xkb_keycode_t. | 68 // Maps DomCode to xkb_keycode_t. |
60 const XkbKeyCodeConverter& key_code_converter_; | 69 const XkbKeyCodeConverter& key_code_converter_; |
61 | 70 |
62 private: | 71 private: |
| 72 |
63 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership | 73 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership |
64 // of the keymap), and updates xkb_flag_map_ for the new keymap. | 74 // of the keymap), and updates xkb_flag_map_ for the new keymap. |
65 void SetKeymap(xkb_keymap* keymap); | 75 void SetKeymap(xkb_keymap* keymap); |
66 | 76 |
67 // Returns the XKB modifiers flags corresponding to the given EventFlags. | 77 // Returns the XKB modifiers flags corresponding to the given EventFlags. |
68 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; | 78 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; |
69 | 79 |
70 // Determines the XKB KeySym and character associated with a key. | 80 // Determines the XKB KeySym and character associated with a key. |
71 // Returns true on success. This is virtual for testing. | 81 // Returns true on success. This is virtual for testing. |
72 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, | 82 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, |
73 xkb_mod_mask_t xkb_flags, | 83 xkb_mod_mask_t xkb_flags, |
74 xkb_keysym_t* xkb_keysym, | 84 xkb_keysym_t* xkb_keysym, |
75 base::char16* character) const; | 85 base::char16* character) const; |
76 | 86 |
77 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, | 87 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, |
78 // returns |base_character|; otherwise returns the XKB character for | 88 // returns |base_character|; otherwise returns the XKB character for |
79 // the keycode and mapped |ui_flags|. | 89 // the keycode and mapped |ui_flags|. |
80 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, | 90 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, |
81 xkb_mod_mask_t base_flags, | 91 xkb_mod_mask_t base_flags, |
82 base::char16 base_character, | 92 base::char16 base_character, |
83 int ui_flags) const; | 93 int ui_flags) const; |
84 | 94 |
| 95 // Callback when keymap file is loaded complete. |
| 96 void OnKeymapLoaded(const std::string& layout_name, xkb_keymap* keymap); |
| 97 |
85 // libxkbcommon uses explicit reference counting for its structures, | 98 // libxkbcommon uses explicit reference counting for its structures, |
86 // so we need to trigger its cleanup. | 99 // so we need to trigger its cleanup. |
87 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; | 100 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; |
88 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_; | 101 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_; |
| 102 std::map<std::string, xkb_keymap*> xkb_keymaps_; |
| 103 |
| 104 std::string current_layout_name_; |
| 105 |
| 106 // Task runner for event dispatch. |
| 107 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 108 |
| 109 // Support weak pointers for attach & detach callbacks. |
| 110 base::WeakPtrFactory<XkbKeyboardLayoutEngine> weak_ptr_factory_; |
89 }; | 111 }; |
90 | 112 |
91 } // namespace ui | 113 } // namespace ui |
92 | 114 |
93 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ | 115 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
OLD | NEW |