This source file includes following definitions.
- XKeyEventToWindowsKeyCode
- MakeWebKeyboardEventFromAuraEvent
#include "content/browser/renderer_host/web_input_event_aura.h"
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <cstdlib>
#include "base/event_types.h"
#include "base/logging.h"
#include "content/browser/renderer_host/ui_events_helper.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace content {
namespace {
int XKeyEventToWindowsKeyCode(XKeyEvent* event) {
int windows_key_code =
ui::KeyboardCodeFromXKeyEvent(reinterpret_cast<XEvent*>(event));
if (windows_key_code == ui::VKEY_SHIFT ||
windows_key_code == ui::VKEY_CONTROL ||
windows_key_code == ui::VKEY_MENU) {
KeySym keysym = XK_VoidSymbol;
XLookupString(event, NULL, 0, &keysym, NULL);
switch (keysym) {
case XK_Shift_L:
return ui::VKEY_LSHIFT;
case XK_Shift_R:
return ui::VKEY_RSHIFT;
case XK_Control_L:
return ui::VKEY_LCONTROL;
case XK_Control_R:
return ui::VKEY_RCONTROL;
case XK_Meta_L:
case XK_Alt_L:
return ui::VKEY_LMENU;
case XK_Meta_R:
case XK_Alt_R:
return ui::VKEY_RMENU;
}
}
return windows_key_code;
}
}
blink::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
ui::KeyEvent* event) {
const base::NativeEvent& native_event = event->native_event();
blink::WebKeyboardEvent webkit_event;
XKeyEvent* native_key_event = &native_event->xkey;
webkit_event.timeStampSeconds = event->time_stamp().InSecondsF();
webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags());
switch (native_event->type) {
case KeyPress:
webkit_event.type = event->is_char() ? blink::WebInputEvent::Char :
blink::WebInputEvent::RawKeyDown;
break;
case KeyRelease:
webkit_event.type = blink::WebInputEvent::KeyUp;
break;
default:
NOTREACHED();
}
if (webkit_event.modifiers & blink::WebInputEvent::AltKey)
webkit_event.isSystemKey = true;
webkit_event.windowsKeyCode = XKeyEventToWindowsKeyCode(native_key_event);
webkit_event.nativeKeyCode = native_key_event->keycode;
if (webkit_event.windowsKeyCode == ui::VKEY_RETURN)
webkit_event.unmodifiedText[0] = '\r';
else
webkit_event.unmodifiedText[0] = ui::GetCharacterFromXEvent(native_event);
if (webkit_event.modifiers & blink::WebInputEvent::ControlKey) {
webkit_event.text[0] =
GetControlCharacter(
webkit_event.windowsKeyCode,
webkit_event.modifiers & blink::WebInputEvent::ShiftKey);
} else {
webkit_event.text[0] = webkit_event.unmodifiedText[0];
}
webkit_event.setKeyIdentifierFromWindowsKeyCode();
return webkit_event;
}
}