• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be found
3 // in the LICENSE file.
4 
5 #include "libcef/browser/browser_util.h"
6 
7 #include "content/public/browser/native_web_keyboard_event.h"
8 
9 namespace browser_util {
10 
GetCefKeyEvent(const content::NativeWebKeyboardEvent & event,CefKeyEvent & cef_event)11 bool GetCefKeyEvent(const content::NativeWebKeyboardEvent& event,
12                     CefKeyEvent& cef_event) {
13   switch (event.GetType()) {
14     case blink::WebKeyboardEvent::Type::kRawKeyDown:
15       cef_event.type = KEYEVENT_RAWKEYDOWN;
16       break;
17     case blink::WebKeyboardEvent::Type::kKeyDown:
18       cef_event.type = KEYEVENT_KEYDOWN;
19       break;
20     case blink::WebKeyboardEvent::Type::kKeyUp:
21       cef_event.type = KEYEVENT_KEYUP;
22       break;
23     case blink::WebKeyboardEvent::Type::kChar:
24       cef_event.type = KEYEVENT_CHAR;
25       break;
26     default:
27       return false;
28   }
29 
30   cef_event.modifiers = 0;
31   if (event.GetModifiers() & blink::WebKeyboardEvent::kShiftKey)
32     cef_event.modifiers |= EVENTFLAG_SHIFT_DOWN;
33   if (event.GetModifiers() & blink::WebKeyboardEvent::kControlKey)
34     cef_event.modifiers |= EVENTFLAG_CONTROL_DOWN;
35   if (event.GetModifiers() & blink::WebKeyboardEvent::kAltKey)
36     cef_event.modifiers |= EVENTFLAG_ALT_DOWN;
37   if (event.GetModifiers() & blink::WebKeyboardEvent::kMetaKey)
38     cef_event.modifiers |= EVENTFLAG_COMMAND_DOWN;
39   if (event.GetModifiers() & blink::WebKeyboardEvent::kIsKeyPad)
40     cef_event.modifiers |= EVENTFLAG_IS_KEY_PAD;
41   if (event.GetModifiers() & blink::WebKeyboardEvent::kIsLeft)
42     cef_event.modifiers |= EVENTFLAG_IS_LEFT;
43   if (event.GetModifiers() & blink::WebKeyboardEvent::kIsRight)
44     cef_event.modifiers |= EVENTFLAG_IS_RIGHT;
45   if (event.GetModifiers() & blink::WebKeyboardEvent::kAltGrKey)
46     cef_event.modifiers |= EVENTFLAG_ALTGR_DOWN;
47   if (event.GetModifiers() & blink::WebKeyboardEvent::kIsAutoRepeat)
48     cef_event.modifiers |= EVENTFLAG_IS_REPEAT;
49 
50   cef_event.windows_key_code = event.windows_key_code;
51   cef_event.native_key_code = event.native_key_code;
52   cef_event.is_system_key = event.is_system_key;
53   cef_event.character = event.text[0];
54   cef_event.unmodified_character = event.unmodified_text[0];
55 
56   return true;
57 }
58 
GetCefKeyEvent(const ui::KeyEvent & event,CefKeyEvent & cef_event)59 bool GetCefKeyEvent(const ui::KeyEvent& event, CefKeyEvent& cef_event) {
60   content::NativeWebKeyboardEvent native_event(event);
61   return GetCefKeyEvent(native_event, cef_event);
62 }
63 
64 }  // namespace browser_util
65