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

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

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

Powered by Google App Engine
This is Rietveld 408576698