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.
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_util.h"
|
|
|
|
|
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
|
|
|
|
|
|
|
namespace browser_util {
|
|
|
|
|
|
|
|
bool GetCefKeyEvent(const content::NativeWebKeyboardEvent& event,
|
|
|
|
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;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kShiftKey)
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_SHIFT_DOWN;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kControlKey)
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_CONTROL_DOWN;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltKey)
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_ALT_DOWN;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kMetaKey)
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_COMMAND_DOWN;
|
2017-04-20 21:28:17 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsKeyPad)
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_KEY_PAD;
|
2021-07-19 17:52:36 +02:00
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsLeft)
|
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_LEFT;
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsRight)
|
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_RIGHT;
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kAltGrKey)
|
|
|
|
cef_event.modifiers |= EVENTFLAG_ALTGR_DOWN;
|
|
|
|
if (event.GetModifiers() & blink::WebKeyboardEvent::kIsAutoRepeat)
|
|
|
|
cef_event.modifiers |= EVENTFLAG_IS_REPEAT;
|
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) {
|
2016-01-19 21:09:01 +01:00
|
|
|
content::NativeWebKeyboardEvent native_event(event);
|
|
|
|
return GetCefKeyEvent(native_event, cef_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace browser_util
|