2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found
|
|
|
|
// in the LICENSE file.
|
|
|
|
|
2024-07-02 20:16:55 +02:00
|
|
|
#include "cef/libcef/browser/browser_event_util.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-06-14 19:01:45 +02:00
|
|
|
#include "components/input/native_web_keyboard_event.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-06-14 19:01:45 +02:00
|
|
|
bool GetCefKeyEvent(const input::NativeWebKeyboardEvent& event,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefKeyEvent& cef_event) {
|
2017-04-20 21:28:17 +02:00
|
|
|
switch (event.GetType()) {
|
2020-06-09 19:48:00 +02:00
|
|
|
case blink::WebKeyboardEvent::Type::kRawKeyDown:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_RAWKEYDOWN;
|
|
|
|
break;
|
2020-06-09 19:48:00 +02:00
|
|
|
case blink::WebKeyboardEvent::Type::kKeyDown:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_KEYDOWN;
|
|
|
|
break;
|
2020-06-09 19:48:00 +02:00
|
|
|
case blink::WebKeyboardEvent::Type::kKeyUp:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_KEYUP;
|
|
|
|
break;
|
2020-06-09 19:48:00 +02:00
|
|
|
case blink::WebKeyboardEvent::Type::kChar:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_CHAR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cef_event.modifiers = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kShiftKey) {
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_SHIFT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kControlKey) {
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_CONTROL_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltKey) {
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_ALT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kMetaKey) {
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_COMMAND_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsKeyPad) {
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_KEY_PAD;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsLeft) {
|
2021-07-19 17:52:36 +02:00
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_LEFT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsRight) {
|
2021-07-19 17:52:36 +02:00
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_RIGHT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltGrKey) {
|
2021-07-19 17:52:36 +02:00
|
|
|
cef_event.modifiers |= EVENTFLAG_ALTGR_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsAutoRepeat) {
|
2021-07-19 17:52:36 +02:00
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_REPEAT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
cef_event.windows_key_code = event.windows_key_code;
|
|
|
|
cef_event.native_key_code = event.native_key_code;
|
|
|
|
cef_event.is_system_key = event.is_system_key;
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.character = event.text[0];
|
2017-04-20 21:28:17 +02:00
|
|
|
cef_event.unmodified_character = event.unmodified_text[0];
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool GetCefKeyEvent(const ui::KeyEvent& event, CefKeyEvent& cef_event) {
|
2024-06-14 19:01:45 +02:00
|
|
|
input::NativeWebKeyboardEvent native_event(event);
|
2016-01-19 21:09:01 +01:00
|
|
|
return GetCefKeyEvent(native_event, cef_event);
|
|
|
|
}
|