sandbox/linux/bpf_dsl: eliminate implicit dependency on C++ compiler behavior
[chromium-blink-merge.git] / content / browser / renderer_host / native_web_keyboard_event_aura.cc
blobd8536ad900d645273d5d9831cfbd0f2f32739a6f
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"
12 namespace {
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) {
23 return
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);
30 } // namespace
32 using blink::WebKeyboardEvent;
34 namespace content {
36 NativeWebKeyboardEvent::NativeWebKeyboardEvent()
37 : os_event(NULL),
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,
63 bool is_char,
64 wchar_t character,
65 int state,
66 double time_stamp_seconds)
67 : os_event(NULL),
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;
74 break;
75 case ui::ET_KEY_RELEASED:
76 type = blink::WebInputEvent::KeyUp;
77 break;
78 default:
79 NOTREACHED();
82 modifiers = EventFlagsToWebInputEventModifiers(state);
83 timeStampSeconds = time_stamp_seconds;
84 windowsKeyCode = character;
85 nativeKeyCode = character;
86 text[0] = character;
87 unmodifiedText[0] = character;
88 isSystemKey =
89 ui::IsSystemKeyModifier(state) && (state & ui::EF_ALTGR_DOWN) == 0;
90 setKeyIdentifierFromWindowsKeyCode();
93 NativeWebKeyboardEvent& NativeWebKeyboardEvent::operator=(
94 const NativeWebKeyboardEvent& other) {
95 WebKeyboardEvent::operator=(other);
96 delete os_event;
97 os_event = CopyEvent(other.os_event);
98 skip_in_browser = other.skip_in_browser;
99 match_edit_command = other.match_edit_command;
100 return *this;
103 NativeWebKeyboardEvent::~NativeWebKeyboardEvent() {
104 delete os_event;
107 } // namespace content