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

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

Issue 786813004: Generate correct KeyboardCode (VKEY). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@x430194-xkb
Patch Set: Created 6 years 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 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "ui/events/ozone/layout/events_ozone_layout_export.h" 13 #include "ui/events/ozone/layout/events_ozone_layout_export.h"
14 #include "ui/events/ozone/layout/keyboard_layout_engine.h" 14 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
15 15
16 namespace ui { 16 namespace ui {
17 17
18 // XKB scan code values are platform-dependent; this provides the layout engine
19 // with the mapping from DomCode to xkb_keycode_t. (This mapping is in principle
20 // derivable from the XKB keyboard layout, but xkbcommon does not provide a
21 // practical interface to do so.)
18 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyCodeConverter { 22 class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyCodeConverter {
19 public: 23 public:
20 XkbKeyCodeConverter(); 24 XkbKeyCodeConverter();
21 virtual ~XkbKeyCodeConverter(); 25 virtual ~XkbKeyCodeConverter();
22 xkb_keycode_t InvalidXkbKeyCode() const { return invalid_xkb_keycode_; } 26 xkb_keycode_t InvalidXkbKeyCode() const { return invalid_xkb_keycode_; }
23 virtual xkb_keycode_t DomCodeToXkbKeyCode(DomCode dom_code) const = 0; 27 virtual xkb_keycode_t DomCodeToXkbKeyCode(DomCode dom_code) const = 0;
24 28
25 protected: 29 protected:
26 xkb_keycode_t invalid_xkb_keycode_; 30 xkb_keycode_t invalid_xkb_keycode_;
27 }; 31 };
(...skipping 10 matching lines...) Expand all
38 42
39 virtual bool UsesISOLevel5Shift() const override; 43 virtual bool UsesISOLevel5Shift() const override;
40 virtual bool UsesAltGr() const override; 44 virtual bool UsesAltGr() const override;
41 45
42 virtual bool Lookup(DomCode dom_code, 46 virtual bool Lookup(DomCode dom_code,
43 int flags, 47 int flags,
44 DomKey* dom_key, 48 DomKey* dom_key,
45 base::char16* character, 49 base::char16* character,
46 KeyboardCode* key_code) const override; 50 KeyboardCode* key_code) const override;
47 51
52 protected:
53 // Table for EventFlagsToXkbFlags().
54 struct XkbFlagMapEntry {
55 int ui_flag;
56 xkb_mod_mask_t xkb_flag;
57 };
58 std::vector<XkbFlagMapEntry> xkb_flag_map_;
59
60 // Determines the Windows-based KeyboardCode (VKEY) for a character key,
61 // accounting for non-US layouts. May return VKEY_UNKNOWN, in which case the
62 // caller should use |DomCodeToNonLocatedKeyboardCode()| as a last resort.
63 KeyboardCode DifficultKeyboardCode(DomCode dom_code,
64 int ui_flags,
65 xkb_keycode_t xkb_keycode,
66 xkb_mod_mask_t xkb_flags,
67 xkb_keysym_t xkb_keysym,
68 DomKey dom_key,
69 base::char16 character) const;
70
71 // Maps DomCode to xkb_keycode_t.
72 const XkbKeyCodeConverter& key_code_converter_;
73
48 private: 74 private:
49 // Sets a new XKB keymap, updating object fields. 75 // Sets a new XKB keymap, updating object fields.
50 void SetKeymap(xkb_keymap* keymap); 76 void SetKeymap(xkb_keymap* keymap);
51 77
52 // Returns the XKB modifiers flags corresponding to the given EventFlags. 78 // Returns the XKB modifiers flags corresponding to the given EventFlags.
53 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const; 79 xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const;
54 80
55 // Determines the XKB KeySym and character associated with a key. 81 // Determines the XKB KeySym and character associated with a key.
56 // Returns true on success. 82 // Returns true on success. This is virtual for testing.
57 bool XkbLookup(xkb_keycode_t xkb_keycode, 83 virtual bool XkbLookup(xkb_keycode_t xkb_keycode,
58 xkb_mod_mask_t xkb_flags, 84 xkb_mod_mask_t xkb_flags,
59 xkb_keysym_t* xkb_keysym, 85 xkb_keysym_t* xkb_keysym,
60 base::char16* character) const; 86 base::char16* character) const;
61 87
62 // Maps DomCode to xkb_keycode_t. 88 // Helper for difficult VKEY lookup. If |ui_flags| matches |base_flags|,
63 const XkbKeyCodeConverter& key_code_converter_; 89 // returns |base_character|; otherwise returns the XKB character for
90 // the keycode and mapped |ui_flags|.
91 base::char16 XkbSubCharacter(xkb_keycode_t xkb_keycode,
92 xkb_mod_mask_t base_flags,
93 base::char16 base_character,
94 int ui_flags) const;
64 95
65 // libxkbcommon uses explicit reference counting for its structures, 96 // libxkbcommon uses explicit reference counting for its structures,
66 // so we need to trigger its cleanup. 97 // so we need to trigger its cleanup.
67 struct XkbContextDeleter { 98 struct XkbContextDeleter {
68 void operator()(xkb_context* context) { xkb_context_unref(context); } 99 void operator()(xkb_context* context) { xkb_context_unref(context); }
69 }; 100 };
70 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; 101 scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_;
71 struct XkbstateDeleter { 102 struct XkbstateDeleter {
72 void operator()(xkb_state* state) { xkb_state_unref(state); } 103 void operator()(xkb_state* state) { xkb_state_unref(state); }
73 }; 104 };
74 scoped_ptr<xkb_state, XkbstateDeleter> xkb_state_; 105 scoped_ptr<xkb_state, XkbstateDeleter> xkb_state_;
75
76 // Table for EventFlagsToXkbFlags().
77 struct XkbFlagMapEntry {
78 int ui_flag;
79 xkb_mod_mask_t xkb_flag;
80 };
81 std::vector<XkbFlagMapEntry> xkb_flag_map_;
82 }; 106 };
83 107
84 } // namespace ui 108 } // namespace ui
85 109
86 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ 110 #endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698