Commit 80093bd0 authored by kpschoedel's avatar kpschoedel Committed by Commit bot

Partial XKB implementation of Ozone key layout.

No layout switching; uses a hard-coded US layout.

BUG=430194

Review URL: https://codereview.chromium.org/778503002

Cr-Commit-Position: refs/heads/master@{#308447}
parent 95ade62c
......@@ -133,6 +133,8 @@ component("events_ozone_layout") {
"layout/keyboard_layout_engine.h",
"layout/keyboard_layout_engine_manager.cc",
"layout/keyboard_layout_engine_manager.h",
"layout/layout_util.cc",
"layout/layout_util.h",
"layout/no/no_keyboard_layout_engine.cc",
"layout/no/no_keyboard_layout_engine.h",
"layout/stub/stub_keyboard_layout_engine.cc",
......@@ -144,4 +146,19 @@ component("events_ozone_layout") {
deps = [
"//base",
]
if (use_xkbcommon) {
sources += [
"layout/xkb/xkb.h",
"layout/xkb/xkb_evdev_codes.cc",
"layout/xkb/xkb_evdev_codes.h",
"layout/xkb/xkb_key_code_converter.h",
"layout/xkb/xkb_keyboard_code_conversion.cc",
"layout/xkb/xkb_keyboard_code_conversion.h",
"layout/xkb/xkb_keyboard_layout_engine.cc",
"layout/xkb/xkb_keyboard_layout_engine.h",
"layout/xkb/xkb_keysym.h",
"layout/xkb/scoped_xkb.h",
]
}
}
......@@ -36,14 +36,6 @@
['exclude', '_udev\\.(h|cc)$'],
],
}],
['use_xkbcommon==1', {
'dependencies': [
'../../../build/linux/system.gyp:xkbcommon',
],
'defines': [
'USE_XKBCOMMON',
],
}],
['use_ozone_evdev==1 and use_udev==1', {
'dependencies': [
'<(DEPTH)/device/udev_linux/udev.gyp:udev_linux',
......@@ -144,10 +136,34 @@
'layout/keyboard_layout_engine.h',
'layout/keyboard_layout_engine_manager.cc',
'layout/keyboard_layout_engine_manager.h',
'layout/layout_util.cc',
'layout/layout_util.h',
'layout/no/no_keyboard_layout_engine.cc',
'layout/no/no_keyboard_layout_engine.h',
'layout/stub/stub_keyboard_layout_engine.cc',
'layout/stub/stub_keyboard_layout_engine.h',
],
'conditions': [
['use_xkbcommon==1', {
'dependencies': [
'../../../build/linux/system.gyp:xkbcommon',
],
'defines': [
'USE_XKBCOMMON',
],
'sources': [
'layout/xkb/xkb.h',
'layout/xkb/xkb_evdev_codes.cc',
'layout/xkb/xkb_evdev_codes.h',
'layout/xkb/xkb_key_code_converter.h',
'layout/xkb/xkb_keyboard_code_conversion.cc',
'layout/xkb/xkb_keyboard_code_conversion.h',
'layout/xkb/xkb_keyboard_layout_engine.cc',
'layout/xkb/xkb_keyboard_layout_engine.h',
'layout/xkb/xkb_keysym.h',
'layout/xkb/scoped_xkb.h',
],
}],
],
}]
}
This diff is collapsed.
// 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_LAYOUT_UTIL_H_
#define UI_EVENTS_OZONE_LAYOUT_LAYOUT_UTIL_H_
// TODO(kpschoedel): consider moving this out of Ozone.
#include "base/strings/string16.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ui {
enum class DomCode;
enum class DomKey;
// Returns the Windows-based VKEY value corresponding to a DOM Level 3 |code|.
// The returned VKEY is located (e.g. VKEY_LSHIFT).
KeyboardCode DomCodeToKeyboardCode(DomCode dom_code);
// Returns a Windows-based VKEY for a non-printable DOM Level 3 |key|.
// The returned VKEY is non-located (e.g. VKEY_SHIFT).
KeyboardCode NonPrintableDomKeyToKeyboardCode(DomKey dom_key);
// Determine the non-located VKEY corresponding to a located VKEY.
KeyboardCode DeLocateKeyboardCode(KeyboardCode key_code);
// Returns true control character corresponding to a physical key.
// In some contexts this is used instead of the key layout.
bool LookupControlCharacter(DomCode dom_code,
int flags,
DomKey* dom_key,
base::char16* character,
KeyboardCode* key_code);
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_LAYOUT_UTIL_H_
// 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_SCOPED_XKB_H_
#define UI_EVENTS_OZONE_LAYOUT_XKB_SCOPED_XKB_H_
#include <xkbcommon/xkbcommon.h>
namespace ui {
// libxkbcommon uses explicit reference counting for its structures,
// so we need to trigger its cleanup.
struct XkbContextDeleter {
void operator()(xkb_context* context) { xkb_context_unref(context); }
};
struct XkbStateDeleter {
void operator()(xkb_state* state) { xkb_state_unref(state); }
};
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_XKB_SCOPED_XKB_H_
// 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.
#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
#include "ui/events/keycodes/dom4/keycode_converter.h"
namespace ui {
XkbEvdevCodes::XkbEvdevCodes() {
invalid_xkb_keycode_ =
static_cast<xkb_keycode_t>(KeycodeConverter::InvalidNativeKeycode());
}
XkbEvdevCodes::~XkbEvdevCodes() {
}
xkb_keycode_t XkbEvdevCodes::DomCodeToXkbKeyCode(DomCode dom_code) const {
// This assumes KeycodeConverter has been built with evdev/xkb codes.
return static_cast<xkb_keycode_t>(
KeycodeConverter::DomCodeToNativeKeycode(dom_code));
}
} // namespace ui
// 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_EVDEV_CODES_H_
#define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_EVDEV_CODES_H_
#include "ui/events/ozone/layout/events_ozone_layout_export.h"
#include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h"
namespace ui {
class EVENTS_OZONE_LAYOUT_EXPORT XkbEvdevCodes : public XkbKeyCodeConverter {
public:
XkbEvdevCodes();
virtual ~XkbEvdevCodes();
virtual xkb_keycode_t DomCodeToXkbKeyCode(DomCode dom_code) const override;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_EVDEV_CODES_H_
// 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_KEY_CODE_CONVERTER_H_
#define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEY_CODE_CONVERTER_H_
#include <xkbcommon/xkbcommon.h>
namespace ui {
enum class DomCode;
class EVENTS_OZONE_LAYOUT_EXPORT XkbKeyCodeConverter {
public:
XkbKeyCodeConverter();
virtual ~XkbKeyCodeConverter();
xkb_keycode_t InvalidXkbKeyCode() const { return invalid_xkb_keycode_; }
virtual xkb_keycode_t DomCodeToXkbKeyCode(DomCode dom_code) const = 0;
protected:
xkb_keycode_t invalid_xkb_keycode_;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEY_CODE_CONVERTER_H_
This diff is collapsed.
// 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_CODE_CONVERSION_H_
#define UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_CODE_CONVERSION_H_
// TODO(kpschoedel): move this file out of Ozone so that it can be used to
// determine DomKey for desktop X11, OR switch desktop X11 to use the Ozone
// keyboard layout interface.
#include <xkbcommon/xkbcommon.h>
#include "base/strings/string16.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace ui {
enum class DomKey;
// Returns the DomKey associated with a non-character xkb_keysym_t.
// Returns DomKey::NONE for unrecognized keysyms, which includes
// all printable characters.
DomKey XkbKeySymToDomKey(xkb_keysym_t keysym);
// Returns the dead key combining character associated with an xkb_keysym_t,
// or 0 if the keysym is not recognized.
base::char16 XkbKeySymDeadKey(xkb_keysym_t keysym);
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_CODE_CONVERSION_H_
This diff is collapsed.
// 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 <xkbcommon/xkbcommon.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/scoped_xkb.h"
#include "ui/events/ozone/layout/xkb/xkb_key_code_converter.h"
namespace ui {
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:
// Sets a new XKB keymap, updating object fields.
void SetKeymap(xkb_keymap* keymap);
// Returns the XKB modifiers flags corresponding to the given EventFlags.
xkb_mod_mask_t EventFlagsToXkbFlags(int ui_flags) const;
// Determines the XKB KeySym and character associated with a key.
// Returns true on success.
bool XkbLookup(xkb_keycode_t xkb_keycode,
xkb_mod_mask_t xkb_flags,
xkb_keysym_t* xkb_keysym,
base::char16* character) const;
// Maps DomCode to xkb_keycode_t.
const XkbKeyCodeConverter& key_code_converter_;
// libxkbcommon uses explicit reference counting for its structures,
// so we need to trigger its cleanup.
scoped_ptr<xkb_context, XkbContextDeleter> xkb_context_;
scoped_ptr<xkb_state, XkbStateDeleter> xkb_state_;
// Table for EventFlagsToXkbFlags().
struct XkbFlagMapEntry {
int ui_flag;
xkb_mod_mask_t xkb_flag;
};
std::vector<XkbFlagMapEntry> xkb_flag_map_;
};
} // namespace ui
#endif // UI_EVENTS_OZONE_LAYOUT_XKB_XKB_KEYBOARD_LAYOUT_ENGINE_H_
......@@ -10,7 +10,6 @@
#include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/ozone/platform/dri/display_manager.h"
#include "ui/ozone/platform/dri/dri_buffer.h"
#include "ui/ozone/platform/dri/dri_cursor.h"
......@@ -28,6 +27,13 @@
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ui_thread_gpu.h"
#if defined(USE_XKBCOMMON)
#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
#else
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#endif
namespace ui {
namespace {
......@@ -99,8 +105,13 @@ class OzonePlatformDri : public OzonePlatform {
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
window_manager_.reset(
new DriWindowManager(gpu_platform_support_host_.get()));
#if defined(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_)));
#else
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
make_scoped_ptr(new StubKeyboardLayoutEngine()));
#endif
event_factory_ozone_.reset(new EventFactoryEvdev(
window_manager_->cursor(), device_manager_.get(),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
......@@ -131,6 +142,10 @@ class OzonePlatformDri : public OzonePlatform {
UiThreadGpu ui_thread_gpu_;
#if defined(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_;
#endif
DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri);
};
......
......@@ -15,7 +15,6 @@
#include "ui/events/ozone/device/device_manager.h"
#include "ui/events/ozone/evdev/event_factory_evdev.h"
#include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#include "ui/ozone/platform/dri/display_manager.h"
#include "ui/ozone/platform/dri/dri_cursor.h"
#include "ui/ozone/platform/dri/dri_gpu_platform_support.h"
......@@ -37,6 +36,13 @@
#include "ui/ozone/public/ozone_platform.h"
#include "ui/ozone/public/ozone_switches.h"
#if defined(USE_XKBCOMMON)
#include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
#include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
#else
#include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
#endif
namespace ui {
namespace {
......@@ -128,8 +134,13 @@ class OzonePlatformGbm : public OzonePlatform {
cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
window_manager_.reset(
new DriWindowManager(gpu_platform_support_host_.get()));
#if defined(USE_XKBCOMMON)
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_)));
#else
KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
make_scoped_ptr(new StubKeyboardLayoutEngine()));
#endif
event_factory_ozone_.reset(new EventFactoryEvdev(
window_manager_->cursor(), device_manager_.get(),
KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
......@@ -175,6 +186,10 @@ class OzonePlatformGbm : public OzonePlatform {
scoped_ptr<DriWindowManager> window_manager_;
scoped_ptr<DisplayManager> display_manager_;
#if defined(USE_XKBCOMMON)
XkbEvdevCodes xkb_evdev_code_converter_;
#endif
DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment