Index: ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h |
diff --git a/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..177be0093f2713b9c44f1a171a53916a07d1c056 |
--- /dev/null |
+++ b/ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h |
@@ -0,0 +1,98 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
+#define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |
+ |
+#include "base/containers/hash_tables.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/strings/string16.h" |
+#include "ui/events/ozone/layout/events_ozone_layout_export.h" |
+#include "ui/events/ozone/layout/keyboard_layout_engine.h" |
+#include "ui/events/ozone/layout/xkb/xkb.h" |
+ |
+namespace ui { |
+ |
+#if defined(USE_X11) |
+using XkbKeyCode = decltype(XKeyEvent.keycode); |
spang
2014/12/08 22:47:28
remove dead code
kpschoedel
2014/12/08 23:15:26
Done.
|
+using XkbFlags = decltype(XKeyEvent.state); |
+#else |
+using XkbKeyCode = xkb_keycode_t; |
+using XkbFlags = xkb_mod_mask_t; |
+using XkbKeySym = xkb_keysym_t; |
+#endif |
+ |
+class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyCodeConverter { |
+ public: |
+ XkbKeyCodeConverter(); |
+ virtual ~XkbKeyCodeConverter(); |
+ XkbKeyCode InvalidXkbKeyCode() const { return invalid_xkb_keycode_; } |
+ virtual XkbKeyCode DomCodeToXkbKeyCode(DomCode dom_code) const = 0; |
+ |
+ protected: |
+ XkbKeyCode invalid_xkb_keycode_; |
+}; |
+ |
+class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyboardLayoutEngine |
+ : public KeyboardLayoutEngine { |
+ public: |
+ XkbKeyboardLayoutEngine(const XkbKeyCodeConverter& converter); |
+ virtual ~XkbKeyboardLayoutEngine(); |
+ |
+ // KeyboardLayoutEngine: |
+ virtual bool CanSetCurrentLayout() const override; |
+ virtual bool SetCurrentLayoutByName(const std::string& layout_name) override; |
+ |
+ virtual bool UsesISOLevel5Shift() const override; |
+ virtual bool UsesAltGr() const override; |
+ |
+ virtual bool Lookup(DomCode dom_code, |
+ int flags, |
+ DomKey* dom_key, |
+ base::char16* character, |
+ KeyboardCode* key_code) const override; |
+ |
+ private: |
+#if !defined(USE_X11) |
+ // Sets a new XKB keymap, updating object fields. |
+ void SetKeymap(xkb_keymap* keymap); |
+#endif |
+ |
+ // Returns the XKB modifiers flags corresponding to the given EventFlags. |
+ XkbFlags EventFlagsToXkbFlags(int ui_flags) const; |
+ |
+ // Determines the XKB KeySym and character associated with a key. |
+ // Returns true on success. |
+ bool XkbLookup(XkbKeyCode xkb_keycode, |
+ XkbFlags xkb_flags, |
+ XkbKeySym* xkb_keysym, |
+ base::char16* character) const; |
+ |
+ // Maps DomCode to XkbKeyCode. |
+ const XkbKeyCodeConverter& key_code_converter_; |
+ |
+#if !defined(USE_X11) |
+ // libxkbcommon uses explicit reference counting for its structures, |
+ // so we need XXX |
+ struct XkbContextDeleter { |
+ void operator()(xkb_context* context) { xkb_context_unref(context); } |
+ }; |
+ scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_; |
+ struct XkbstateDeleter { |
+ void operator()(xkb_state* state) { xkb_state_unref(state); } |
+ }; |
+ scoped_ptr<xkb_state, XkbstateDeleter> xkb_state_; |
+#endif |
+ |
+ // Table for EventFlagsToXkbFlags(). |
+ struct XkbFlagMapEntry { |
+ int ui_flag; |
+ XkbFlags xkb_flag; |
+ }; |
+ std::vector<XkbFlagMapEntry> xkb_flag_map_; |
+}; |
+ |
+} // namespace ui |
+ |
+#endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_ |