Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(864)

Side by Side Diff: ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h

Issue 817983002: ozone: xkb: Load keymaps on worker thread & cache them (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 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"
12 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/task_runner.h"
13 #include "ui/events/ozone/layout/events_ozone_layout_export.h" 17 #include "ui/events/ozone/layout/events_ozone_layout_export.h"
14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 18 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
15 #include "ui/events/ozone/layout/xkb/scoped_xkb.h" 19 #include "ui/events/ozone/layout/xkb/scoped_xkb.h"
16 #include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h" 20 #include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h"
17 21
18 namespace ui { 22 namespace ui {
19 23
20 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyboardLayoutEngine 24 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyboardLayoutEngine
21 : public KeyboardLayoutEngine { 25 : public KeyboardLayoutEngine {
22 public: 26 public:
23 XkbKeyboardLayoutEngine(const XkbKeyCodeConverter& converter); 27 XkbKeyboardLayoutEngine(const XkbKeyCodeConverter& converter);
24 virtual ~XkbKeyboardLayoutEngine(); 28 virtual ~XkbKeyboardLayoutEngine();
25 29
26 // KeyboardLayoutEngine: 30 // KeyboardLayoutEngine:
27 virtual bool CanSetCurrentLayout() const override; 31 virtual bool CanSetCurrentLayout() const override;
28 virtual bool SetCurrentLayoutByName(const std::string& layout_name) override; 32 virtual bool SetCurrentLayoutByName(const std::string& layout_name) override;
29 33
30 virtual bool UsesISOLevel5Shift() const override; 34 virtual bool UsesISOLevel5Shift() const override;
31 virtual bool UsesAltGr() const override; 35 virtual bool UsesAltGr() const override;
32 36
33 virtual bool Lookup(DomCode dom_code, 37 virtual bool Lookup(DomCode dom_code,
34 int flags, 38 int flags,
35 DomKey* dom_key, 39 DomKey* dom_key,
36 base::char16* character, 40 base::char16* character,
37 KeyboardCode* key_code, 41 KeyboardCode* key_code,
38 uint32* platform_keycode) const override; 42 uint32* platform_keycode) const override;
39 43
44 // Gets the names of the RMLO rule for libxkbcommon.
45 // Makes it protected for testing.
46 scoped_ptr<xkb_rule_names> GetXkbRuleNames(const std::string& layout_name);
47
40 protected: 48 protected:
41 // Table for EventFlagsToXkbFlags(). 49 // Table for EventFlagsToXkbFlags().
42 struct XkbFlagMapEntry { 50 struct XkbFlagMapEntry {
43 int ui_flag; 51 int ui_flag;
44 xkb_mod_mask_t xkb_flag; 52 xkb_mod_mask_t xkb_flag;
45 }; 53 };
46 std::vector<XkbFlagMapEntry> xkb_flag_map_; 54 std::vector<XkbFlagMapEntry> xkb_flag_map_;
47 55
48 // Determines the Windows-based KeyboardCode (VKEY) for a character key, 56 // Determines the Windows-based KeyboardCode (VKEY) for a character key,
49 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the 57 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the
50 // caller should use |DomCodeToNonLocatedKeyboardCode()| as a last resort. 58 // caller should use |DomCodeToNonLocatedKeyboardCode()| as a last resort.
51 KeyboardCode DifficultKeyboardCode(DomCode dom_code, 59 KeyboardCode DifficultKeyboardCode(DomCode dom_code,
52 int ui_flags, 60 int ui_flags,
53 xkb_keycode_t xkb_keycode, 61 xkb_keycode_t xkb_keycode,
54 xkb_mod_mask_t xkb_flags, 62 xkb_mod_mask_t xkb_flags,
55 xkb_keysym_t xkb_keysym, 63 xkb_keysym_t xkb_keysym,
56 DomKey dom_key, 64 DomKey dom_key,
57 base::char16 character) const; 65 base::char16 character) const;
58 66
59 // Maps DomCode to xkb_keycode_t. 67 // Maps DomCode to xkb_keycode_t.
60 const XkbKeyCodeConverter& key_code_converter_; 68 const XkbKeyCodeConverter& key_code_converter_;
61 69
62 private: 70 private:
71 struct XkbKeymapEntry {
72 std::string layout_name;
73 xkb_keymap* keymap;
74 };
75 std::vector<XkbKeymapEntry> xkb_keymaps_;
63 // Sets a new XKB keymap. This updates xkb_state_ (which takes ownership 76 // 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. 77 // of the keymap), and updates xkb_flag_map_ for the new keymap.
65 void SetKeymap(xkb_keymap* keymap); 78 void SetKeymap(xkb_keymap* keymap);
66 79
67 // Returns the XKB modifiers flags corresponding to the given EventFlags. 80 // Returns the XKB modifiers flags corresponding to the given EventFlags.
68 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; 81 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const;
69 82
70 // Determines the XKB KeySym and character associated with a key. 83 // Determines the XKB KeySym and character associated with a key.
71 // Returns true on success. This is virtual for testing. 84 // Returns true on success. This is virtual for testing.
72 virtual bool XkbLookup(xkb_keycode_t xkb_keycode, 85 virtual bool XkbLookup(xkb_keycode_t xkb_keycode,
73 xkb_mod_mask_t xkb_flags, 86 xkb_mod_mask_t xkb_flags,
74 xkb_keysym_t* xkb_keysym, 87 xkb_keysym_t* xkb_keysym,
75 base::char16* character) const; 88 base::char16* character) const;
76 89
77 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|, 90 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|,
78 // returns |base_character|; otherwise returns the XKB character for 91 // returns |base_character|; otherwise returns the XKB character for
79 // the keycode and mapped |ui_flags|. 92 // the keycode and mapped |ui_flags|.
80 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode, 93 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode,
81 xkb_mod_mask_t base_flags, 94 xkb_mod_mask_t base_flags,
82 base::char16 base_character, 95 base::char16 base_character,
83 int ui_flags) const; 96 int ui_flags) const;
84 97
98 // Callback when keymap file is loaded complete.
99 void OnKeymapLoaded(const std::string& layout_name,
100 scoped_ptr<xkb_keymap, XkbKeymapDeleter> keymap);
101
85 // libxkbcommon uses explicit reference counting for its structures, 102 // libxkbcommon uses explicit reference counting for its structures,
86 // so we need to trigger its cleanup. 103 // so we need to trigger its cleanup.
87 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; 104 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_;
88 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_; 105 scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_;
106
107 std::string current_layout_name_;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698