| Index: ui/base/x/x11_util.cc
|
| diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
|
| index 690a9c770f26545d32e2c93712126c3d6d3693ac..e63c56a84a2bc916ea2be7879a2aeae298952da1 100644
|
| --- a/ui/base/x/x11_util.cc
|
| +++ b/ui/base/x/x11_util.cc
|
| @@ -24,6 +24,7 @@
|
| #include "base/string_util.h"
|
| #include "base/stringprintf.h"
|
| #include "base/threading/thread.h"
|
| +#include "ui/base/keycodes/keyboard_code_conversion_x.h"
|
| #include "ui/base/x/x11_util_internal.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/size.h"
|
| @@ -103,6 +104,38 @@ bool GetProperty(XID window, const std::string& property_name, long max_length,
|
| property);
|
| }
|
|
|
| +// Converts ui::EventType to XKeyEvent state.
|
| +unsigned int XKeyEventState(int flags) {
|
| + return
|
| + ((flags & ui::EF_SHIFT_DOWN) ? ShiftMask : 0) |
|
| + ((flags & ui::EF_CONTROL_DOWN) ? ControlMask : 0) |
|
| + ((flags & ui::EF_CAPS_LOCK_DOWN) ? LockMask : 0);
|
| +}
|
| +
|
| +// Converts EventType to XKeyEvent type.
|
| +int XKeyEventType(ui::EventType type) {
|
| + switch (type) {
|
| + case ui::ET_KEY_PRESSED:
|
| + return KeyPress;
|
| + case ui::ET_KEY_RELEASED:
|
| + return KeyRelease;
|
| + default:
|
| + return 0;
|
| + }
|
| +}
|
| +
|
| +// Converts KeyboardCode to XKeyEvent keycode.
|
| +unsigned int XKeyEventKeyCode(ui::KeyboardCode key_code,
|
| + int flags,
|
| + Display* display) {
|
| + const int keysym = XKeysymForWindowsKeyCode(key_code,
|
| + flags & ui::EF_SHIFT_DOWN);
|
| + // Tests assume the keycode for XK_less is equal to the one of XK_comma,
|
| + // but XKeysymToKeycode returns 94 for XK_less while it returns 59 for
|
| + // XK_comma. Here we convert the value for XK_less to the value for XK_comma.
|
| + return (keysym == XK_less) ? 59 : XKeysymToKeycode(display, keysym);
|
| +}
|
| +
|
| // A process wide singleton that manages the usage of X cursors.
|
| class XCursorCache {
|
| public:
|
| @@ -872,6 +905,33 @@ void UpdateButtonMap() {
|
| XButtonMap::GetInstance()->UpdateMapping();
|
| }
|
|
|
| +void InitXKeyEventForTesting(EventType type,
|
| + KeyboardCode key_code,
|
| + int flags,
|
| + XEvent* event) {
|
| + CHECK(event);
|
| + Display* display = GetXDisplay();
|
| + XKeyEvent key_event;
|
| + key_event.type = XKeyEventType(type);
|
| + CHECK_NE(0, key_event.type);
|
| + key_event.serial = 0;
|
| + key_event.send_event = 0;
|
| + key_event.display = display;
|
| + key_event.time = 0;
|
| + key_event.window = 0;
|
| + key_event.root = 0;
|
| + key_event.subwindow = 0;
|
| + key_event.x = 0;
|
| + key_event.y = 0;
|
| + key_event.x_root = 0;
|
| + key_event.y_root = 0;
|
| + key_event.state = XKeyEventState(flags);
|
| + key_event.keycode = XKeyEventKeyCode(key_code, flags, display);
|
| + key_event.same_screen = 1;
|
| + event->type = key_event.type;
|
| + event->xkey = key_event;
|
| +}
|
| +
|
| // ----------------------------------------------------------------------------
|
| // These functions are declared in x11_util_internal.h because they require
|
| // XLib.h to be included, and it conflicts with many other headers.
|
|
|