OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/public/browser/native_web_keyboard_event.h" | 5 #include "content/public/browser/native_web_keyboard_event.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "content/browser/renderer_host/web_input_event_aura.h" | 7 #include "content/browser/renderer_host/web_input_event_aura.h" |
9 #include "ui/base/events.h" | |
10 | 8 |
11 using WebKit::WebKeyboardEvent; | 9 using WebKit::WebKeyboardEvent; |
12 | 10 |
13 namespace { | |
14 | |
15 int EventFlagsToWebInputEventModifiers(int flags) { | |
16 return | |
17 (flags & ui::EF_SHIFT_DOWN ? WebKit::WebInputEvent::ShiftKey : 0) | | |
18 (flags & ui::EF_CONTROL_DOWN ? WebKit::WebInputEvent::ControlKey : 0) | | |
19 (flags & ui::EF_CAPS_LOCK_DOWN ? WebKit::WebInputEvent::CapsLockOn : 0) | | |
20 (flags & ui::EF_ALT_DOWN ? WebKit::WebInputEvent::AltKey : 0); | |
21 } | |
22 | |
23 } // namespace | |
24 | |
25 NativeWebKeyboardEvent::NativeWebKeyboardEvent() | 11 NativeWebKeyboardEvent::NativeWebKeyboardEvent() |
26 : os_event(NULL), | 12 : os_event(NULL), |
27 skip_in_browser(false) { | 13 skip_in_browser(false) { |
28 } | 14 } |
29 | 15 |
30 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) | 16 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) |
31 : WebKeyboardEvent(content::MakeWebKeyboardEvent( | 17 : WebKeyboardEvent(content::MakeWebKeyboardEvent( |
32 reinterpret_cast<aura::KeyEvent*>(native_event))), | 18 reinterpret_cast<aura::KeyEvent*>(native_event))), |
33 os_event(native_event), | 19 os_event(native_event), |
34 skip_in_browser(false) { | 20 skip_in_browser(false) { |
35 } | 21 } |
36 | 22 |
37 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 23 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
38 const NativeWebKeyboardEvent& other) | 24 const NativeWebKeyboardEvent& other) |
39 : WebKeyboardEvent(other), | 25 : WebKeyboardEvent(other), |
40 os_event(other.os_event), | 26 os_event(other.os_event), |
41 skip_in_browser(other.skip_in_browser) { | 27 skip_in_browser(other.skip_in_browser) { |
42 } | 28 } |
43 | 29 |
44 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | |
45 ui::EventType key_event_type, | |
46 bool is_char, | |
47 wchar_t character, | |
48 int state, | |
49 double time_stamp_seconds) | |
50 : os_event(NULL), | |
51 skip_in_browser(true /* already handled by the input method */) { | |
52 switch (key_event_type) { | |
53 case ui::ET_KEY_PRESSED: | |
54 type = is_char ? WebKit::WebInputEvent::Char : | |
55 WebKit::WebInputEvent::RawKeyDown; | |
56 break; | |
57 case ui::ET_KEY_RELEASED: | |
58 type = WebKit::WebInputEvent::KeyUp; | |
59 break; | |
60 default: | |
61 NOTREACHED(); | |
62 } | |
63 | |
64 modifiers = EventFlagsToWebInputEventModifiers(state); | |
65 timeStampSeconds = time_stamp_seconds; | |
66 windowsKeyCode = character; | |
67 nativeKeyCode = character; | |
68 text[0] = character; | |
69 unmodifiedText[0] = character; | |
70 isSystemKey = (state & ui::EF_ALT_DOWN) != 0; | |
71 } | |
72 | |
73 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( | 30 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( |
74 const NativeWebKeyboardEvent& other) { | 31 const NativeWebKeyboardEvent& other) { |
75 WebKeyboardEvent::operator=(other); | 32 WebKeyboardEvent::operator=(other); |
76 | 33 |
77 os_event = other.os_event; | 34 os_event = other.os_event; |
78 skip_in_browser = other.skip_in_browser; | 35 skip_in_browser = other.skip_in_browser; |
79 | 36 |
80 return *this; | 37 return *this; |
81 } | 38 } |
82 | 39 |
83 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { | 40 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { |
84 } | 41 } |
OLD | NEW |