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()) {
|
|
|
|
case blink::WebKeyboardEvent::kRawKeyDown:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_RAWKEYDOWN;
|
|
|
|
break;
|
2017-04-20 21:28:17 +02:00
|
|
|
case blink::WebKeyboardEvent::kKeyDown:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_KEYDOWN;
|
|
|
|
break;
|
2017-04-20 21:28:17 +02:00
|
|
|
case blink::WebKeyboardEvent::kKeyUp:
|
2016-01-19 21:09:01 +01:00
|
|
|
cef_event.type = KEYEVENT_KEYUP;
|
|
|
|
break;
|
2017-04-20 21:28:17 +02:00
|
|
|
case blink::WebKeyboardEvent::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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetCefKeyEvent(const ui::KeyEvent& event,
|
|
|
|
CefKeyEvent& cef_event) {
|
|
|
|
content::NativeWebKeyboardEvent native_event(event);
|
|
|
|
return GetCefKeyEvent(native_event, cef_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace browser_util
|