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" |
7 #include "content/browser/renderer_host/web_input_event_aura.h" | 8 #include "content/browser/renderer_host/web_input_event_aura.h" |
| 9 #include "ui/base/events.h" |
8 | 10 |
9 using WebKit::WebKeyboardEvent; | 11 using WebKit::WebKeyboardEvent; |
10 | 12 |
| 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 |
11 NativeWebKeyboardEvent::NativeWebKeyboardEvent() | 25 NativeWebKeyboardEvent::NativeWebKeyboardEvent() |
12 : os_event(NULL), | 26 : os_event(NULL), |
13 skip_in_browser(false) { | 27 skip_in_browser(false) { |
14 } | 28 } |
15 | 29 |
16 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) | 30 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) |
17 : WebKeyboardEvent(content::MakeWebKeyboardEvent( | 31 : WebKeyboardEvent(content::MakeWebKeyboardEvent( |
18 reinterpret_cast<aura::KeyEvent*>(native_event))), | 32 reinterpret_cast<aura::KeyEvent*>(native_event))), |
19 os_event(native_event), | 33 os_event(native_event), |
20 skip_in_browser(false) { | 34 skip_in_browser(false) { |
21 } | 35 } |
22 | 36 |
23 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 37 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
24 const NativeWebKeyboardEvent& other) | 38 const NativeWebKeyboardEvent& other) |
25 : WebKeyboardEvent(other), | 39 : WebKeyboardEvent(other), |
26 os_event(other.os_event), | 40 os_event(other.os_event), |
27 skip_in_browser(other.skip_in_browser) { | 41 skip_in_browser(other.skip_in_browser) { |
28 } | 42 } |
29 | 43 |
| 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 |
30 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( | 73 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( |
31 const NativeWebKeyboardEvent& other) { | 74 const NativeWebKeyboardEvent& other) { |
32 WebKeyboardEvent::operator=(other); | 75 WebKeyboardEvent::operator=(other); |
33 | 76 |
34 os_event = other.os_event; | 77 os_event = other.os_event; |
35 skip_in_browser = other.skip_in_browser; | 78 skip_in_browser = other.skip_in_browser; |
36 | 79 |
37 return *this; | 80 return *this; |
38 } | 81 } |
39 | 82 |
40 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { | 83 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { |
41 } | 84 } |
OLD | NEW |