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" |
8 #include "ui/aura/event.h" | 9 #include "ui/aura/event.h" |
9 | 10 |
10 namespace { | 11 namespace { |
11 | 12 |
12 // We need to copy |os_event| in NativeWebKeyboardEvent because it is | 13 // We need to copy |os_event| in NativeWebKeyboardEvent because it is |
13 // queued in RenderWidgetHost and may be passed and used | 14 // queued in RenderWidgetHost and may be passed and used |
14 // RenderViewHostDelegate::HandledKeybardEvent after the original aura | 15 // RenderViewHostDelegate::HandledKeybardEvent after the original aura |
15 // event is destroyed. | 16 // event is destroyed. |
16 aura::Event* CopyEvent(aura::Event* event) { | 17 aura::Event* CopyEvent(aura::Event* event) { |
17 return event ? static_cast<aura::KeyEvent*>(event)->Copy() : NULL; | 18 return event ? static_cast<aura::KeyEvent*>(event)->Copy() : NULL; |
18 } | 19 } |
19 | 20 |
| 21 int EventFlagsToWebInputEventModifiers(int flags) { |
| 22 return |
| 23 (flags & ui::EF_SHIFT_DOWN ? WebKit::WebInputEvent::ShiftKey : 0) | |
| 24 (flags & ui::EF_CONTROL_DOWN ? WebKit::WebInputEvent::ControlKey : 0) | |
| 25 (flags & ui::EF_CAPS_LOCK_DOWN ? WebKit::WebInputEvent::CapsLockOn : 0) | |
| 26 (flags & ui::EF_ALT_DOWN ? WebKit::WebInputEvent::AltKey : 0); |
20 } | 27 } |
21 | 28 |
| 29 } // namespace |
| 30 |
22 using WebKit::WebKeyboardEvent; | 31 using WebKit::WebKeyboardEvent; |
23 | 32 |
24 NativeWebKeyboardEvent::NativeWebKeyboardEvent() | 33 NativeWebKeyboardEvent::NativeWebKeyboardEvent() |
25 : os_event(NULL), | 34 : os_event(NULL), |
26 skip_in_browser(false) { | 35 skip_in_browser(false) { |
27 } | 36 } |
28 | 37 |
29 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) | 38 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event) |
30 : WebKeyboardEvent(content::MakeWebKeyboardEvent( | 39 : WebKeyboardEvent(content::MakeWebKeyboardEvent( |
31 static_cast<aura::KeyEvent*>(native_event))), | 40 static_cast<aura::KeyEvent*>(native_event))), |
32 os_event(CopyEvent(native_event)), | 41 os_event(CopyEvent(native_event)), |
33 skip_in_browser(false) { | 42 skip_in_browser(false) { |
34 } | 43 } |
35 | 44 |
36 NativeWebKeyboardEvent::NativeWebKeyboardEvent( | 45 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
37 const NativeWebKeyboardEvent& other) | 46 const NativeWebKeyboardEvent& other) |
38 : WebKeyboardEvent(other), | 47 : WebKeyboardEvent(other), |
39 os_event(CopyEvent(other.os_event)), | 48 os_event(CopyEvent(other.os_event)), |
40 skip_in_browser(other.skip_in_browser) { | 49 skip_in_browser(other.skip_in_browser) { |
41 } | 50 } |
42 | 51 |
| 52 NativeWebKeyboardEvent::NativeWebKeyboardEvent( |
| 53 ui::EventType key_event_type, |
| 54 bool is_char, |
| 55 wchar_t character, |
| 56 int state, |
| 57 double time_stamp_seconds) |
| 58 : os_event(NULL), |
| 59 skip_in_browser(true /* already handled by the input method */) { |
| 60 switch (key_event_type) { |
| 61 case ui::ET_KEY_PRESSED: |
| 62 type = is_char ? WebKit::WebInputEvent::Char : |
| 63 WebKit::WebInputEvent::RawKeyDown; |
| 64 break; |
| 65 case ui::ET_KEY_RELEASED: |
| 66 type = WebKit::WebInputEvent::KeyUp; |
| 67 break; |
| 68 default: |
| 69 NOTREACHED(); |
| 70 } |
| 71 |
| 72 modifiers = EventFlagsToWebInputEventModifiers(state); |
| 73 timeStampSeconds = time_stamp_seconds; |
| 74 windowsKeyCode = character; |
| 75 nativeKeyCode = character; |
| 76 text[0] = character; |
| 77 unmodifiedText[0] = character; |
| 78 isSystemKey = (state & ui::EF_ALT_DOWN) != 0; |
| 79 } |
| 80 |
43 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( | 81 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=( |
44 const NativeWebKeyboardEvent& other) { | 82 const NativeWebKeyboardEvent& other) { |
45 WebKeyboardEvent::operator=(other); | 83 WebKeyboardEvent::operator=(other); |
46 delete os_event; | 84 delete os_event; |
47 os_event = CopyEvent(other.os_event); | 85 os_event = CopyEvent(other.os_event); |
48 skip_in_browser = other.skip_in_browser; | 86 skip_in_browser = other.skip_in_browser; |
49 | 87 |
50 return *this; | 88 return *this; |
51 } | 89 } |
52 | 90 |
53 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { | 91 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() { |
54 delete os_event; | 92 delete os_event; |
55 } | 93 } |
OLD | NEW |