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.
5 #include "content/public/browser/native_web_keyboard_event.h"
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/web_input_event_aura.h"
9 #include "ui/events/base_event_utils.h"
10 #include "ui/events/event.h"
14 // We need to copy |os_event| in NativeWebKeyboardEvent because it is
15 // queued in RenderWidgetHost and may be passed and used
16 // RenderViewHostDelegate::HandledKeybardEvent after the original aura
17 // event is destroyed.
18 ui::Event
* CopyEvent(const ui::Event
* event
) {
19 return event
? ui::Event::Clone(*event
).release() : nullptr;
22 int EventFlagsToWebInputEventModifiers(int flags
) {
24 (flags
& ui::EF_SHIFT_DOWN
? blink::WebInputEvent::ShiftKey
: 0) |
25 (flags
& ui::EF_CONTROL_DOWN
? blink::WebInputEvent::ControlKey
: 0) |
26 (flags
& ui::EF_CAPS_LOCK_DOWN
? blink::WebInputEvent::CapsLockOn
: 0) |
27 (flags
& ui::EF_ALT_DOWN
? blink::WebInputEvent::AltKey
: 0);
32 using blink::WebKeyboardEvent
;
36 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
38 skip_in_browser(false),
39 match_edit_command(false) {
42 NativeWebKeyboardEvent::NativeWebKeyboardEvent(gfx::NativeEvent native_event
)
43 : NativeWebKeyboardEvent(static_cast<ui::KeyEvent
&>(*native_event
)) {
46 NativeWebKeyboardEvent::NativeWebKeyboardEvent(const ui::KeyEvent
& key_event
)
47 : WebKeyboardEvent(MakeWebKeyboardEvent(key_event
)),
48 os_event(CopyEvent(&key_event
)),
49 skip_in_browser(false),
50 match_edit_command(false) {
53 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
54 const NativeWebKeyboardEvent
& other
)
55 : WebKeyboardEvent(other
),
56 os_event(CopyEvent(other
.os_event
)),
57 skip_in_browser(other
.skip_in_browser
),
58 match_edit_command(false) {
61 NativeWebKeyboardEvent::NativeWebKeyboardEvent(
62 ui::EventType key_event_type
,
66 double time_stamp_seconds
)
68 skip_in_browser(false),
69 match_edit_command(false) {
70 switch (key_event_type
) {
71 case ui::ET_KEY_PRESSED
:
72 type
= is_char
? blink::WebInputEvent::Char
:
73 blink::WebInputEvent::RawKeyDown
;
75 case ui::ET_KEY_RELEASED
:
76 type
= blink::WebInputEvent::KeyUp
;
82 modifiers
= EventFlagsToWebInputEventModifiers(state
);
83 timeStampSeconds
= time_stamp_seconds
;
84 windowsKeyCode
= character
;
85 nativeKeyCode
= character
;
87 unmodifiedText
[0] = character
;
89 ui::IsSystemKeyModifier(state
) && (state
& ui::EF_ALTGR_DOWN
) == 0;
90 setKeyIdentifierFromWindowsKeyCode();
93 NativeWebKeyboardEvent
& NativeWebKeyboardEvent::operator=(
94 const NativeWebKeyboardEvent
& other
) {
95 WebKeyboardEvent::operator=(other
);
97 os_event
= CopyEvent(other
.os_event
);
98 skip_in_browser
= other
.skip_in_browser
;
99 match_edit_command
= other
.match_edit_command
;
103 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
107 } // namespace content