OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/common/native_web_keyboard_event_views.h" | |
6 | |
7 #if defined(TOOLKIT_USES_GTK) | |
8 #include <gdk/gdk.h> | |
9 #endif | |
10 | |
11 #include "base/logging.h" | |
12 #include "ui/views/events/event.h" | |
13 | |
14 namespace { | |
15 | |
16 int ViewsFlagsToWebInputEventModifiers(int flags) { | |
17 return | |
18 (flags & ui::EF_SHIFT_DOWN ? WebKit::WebInputEvent::ShiftKey : 0) | | |
19 (flags & ui::EF_CONTROL_DOWN ? WebKit::WebInputEvent::ControlKey : 0) | | |
20 (flags & ui::EF_CAPS_LOCK_DOWN ? WebKit::WebInputEvent::CapsLockOn : 0) | | |
21 (flags & ui::EF_ALT_DOWN ? WebKit::WebInputEvent::AltKey : 0); | |
22 } | |
23 | |
24 } // namespace | |
25 | |
26 NativeWebKeyboardEventViews::NativeWebKeyboardEventViews( | |
27 const views::KeyEvent& event) { | |
28 skip_in_browser = false; | |
29 DCHECK(event.type() == ui::ET_KEY_PRESSED || | |
30 event.type() == ui::ET_KEY_RELEASED); | |
31 | |
32 if (event.type() == ui::ET_KEY_PRESSED) | |
33 type = WebKit::WebInputEvent::RawKeyDown; | |
34 else | |
35 type = WebKit::WebInputEvent::KeyUp; | |
36 | |
37 modifiers = ViewsFlagsToWebInputEventModifiers(event.flags()); | |
38 timeStampSeconds = event.time_stamp().ToDoubleT(); | |
39 windowsKeyCode = event.key_code(); | |
40 nativeKeyCode = windowsKeyCode; | |
41 text[0] = event.GetCharacter(); | |
42 unmodifiedText[0] = event.GetUnmodifiedCharacter(); | |
43 setKeyIdentifierFromWindowsKeyCode(); | |
44 | |
45 #if defined(USE_AURA) | |
46 // TODO(beng): | |
47 NOTIMPLEMENTED(); | |
48 #elif defined(OS_WIN) | |
49 // |os_event| is a MSG struct, so we can copy it directly. | |
50 os_event = event.native_event(); | |
51 #elif defined(TOOLKIT_USES_GTK) | |
52 if (event.gdk_event()) { | |
53 os_event = gdk_event_copy(event.gdk_event()); | |
54 nativeKeyCode = os_event->key.keyval; | |
55 } else { | |
56 os_event = NULL; | |
57 } | |
58 #endif | |
59 | |
60 #if defined(TOOLKIT_USES_GTK) | |
61 match_edit_command = false; | |
62 #endif | |
63 } | |
64 | |
65 NativeWebKeyboardEventViews::NativeWebKeyboardEventViews( | |
66 uint16 character, | |
67 int flags, | |
68 double time_stamp_seconds, | |
69 FromViewsEvent) { | |
70 skip_in_browser = true; | |
71 | |
72 type = WebKit::WebInputEvent::Char; | |
73 modifiers = ViewsFlagsToWebInputEventModifiers(flags); | |
74 timeStampSeconds = time_stamp_seconds; | |
75 windowsKeyCode = character; | |
76 nativeKeyCode = character; | |
77 text[0] = character; | |
78 unmodifiedText[0] = character; | |
79 isSystemKey = (flags & ui::EF_ALT_DOWN) != 0; | |
80 | |
81 #if defined(OS_WIN) | |
82 memset(&os_event, 0, sizeof(os_event)); | |
83 #elif defined(TOOLKIT_USES_GTK) | |
84 os_event = NULL; | |
85 #endif | |
86 | |
87 #if defined(TOOLKIT_USES_GTK) | |
88 match_edit_command = false; | |
89 #endif | |
90 } | |
91 | |
92 NativeWebKeyboardEventViews::~NativeWebKeyboardEventViews() { | |
93 } | |
OLD | NEW |