1 // Copyright 2013 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 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES
8 #include "content/browser/renderer_host/input/web_input_event_util.h"
12 #include "base/strings/string_util.h"
13 #include "content/common/input/web_touch_event_traits.h"
14 #include "ui/events/blink/blink_event_util.h"
15 #include "ui/events/event_constants.h"
16 #include "ui/events/gesture_detection/gesture_event_data.h"
17 #include "ui/events/gesture_detection/motion_event.h"
18 #include "ui/gfx/geometry/safe_integer_conversions.h"
20 using blink::WebGestureEvent
;
21 using blink::WebInputEvent
;
22 using blink::WebTouchEvent
;
23 using blink::WebTouchPoint
;
24 using ui::MotionEvent
;
28 const char* GetKeyIdentifier(ui::KeyboardCode key_code
) {
32 case ui::VKEY_CONTROL
:
36 case ui::VKEY_CAPITAL
:
49 case ui::VKEY_EXECUTE
:
103 case ui::VKEY_INSERT
:
113 case ui::VKEY_SNAPSHOT
:
114 return "PrintScreen";
117 case ui::VKEY_SCROLL
:
119 case ui::VKEY_SELECT
:
123 case ui::VKEY_DELETE
:
124 return "U+007F"; // Standard says that DEL becomes U+007F.
125 case ui::VKEY_MEDIA_NEXT_TRACK
:
126 return "MediaNextTrack";
127 case ui::VKEY_MEDIA_PREV_TRACK
:
128 return "MediaPreviousTrack";
129 case ui::VKEY_MEDIA_STOP
:
131 case ui::VKEY_MEDIA_PLAY_PAUSE
:
132 return "MediaPlayPause";
133 case ui::VKEY_VOLUME_MUTE
:
135 case ui::VKEY_VOLUME_DOWN
:
137 case ui::VKEY_VOLUME_UP
:
148 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent
* event
,
149 ui::KeyboardCode windows_key_code
) {
150 event
->windowsKeyCode
= windows_key_code
;
152 const char* id
= GetKeyIdentifier(windows_key_code
);
154 base::strlcpy(event
->keyIdentifier
, id
, sizeof(event
->keyIdentifier
) - 1);
157 event
->keyIdentifier
,
158 sizeof(event
->keyIdentifier
),
160 base::ToUpperASCII(static_cast<base::char16
>(windows_key_code
)));
164 int WebEventModifiersToEventFlags(int modifiers
) {
167 if (modifiers
& blink::WebInputEvent::ShiftKey
)
168 flags
|= ui::EF_SHIFT_DOWN
;
169 if (modifiers
& blink::WebInputEvent::ControlKey
)
170 flags
|= ui::EF_CONTROL_DOWN
;
171 if (modifiers
& blink::WebInputEvent::AltKey
)
172 flags
|= ui::EF_ALT_DOWN
;
173 if (modifiers
& blink::WebInputEvent::MetaKey
)
174 flags
|= ui::EF_COMMAND_DOWN
;
176 if (modifiers
& blink::WebInputEvent::LeftButtonDown
)
177 flags
|= ui::EF_LEFT_MOUSE_BUTTON
;
178 if (modifiers
& blink::WebInputEvent::MiddleButtonDown
)
179 flags
|= ui::EF_MIDDLE_MOUSE_BUTTON
;
180 if (modifiers
& blink::WebInputEvent::RightButtonDown
)
181 flags
|= ui::EF_RIGHT_MOUSE_BUTTON
;
182 if (modifiers
& blink::WebInputEvent::CapsLockOn
)
183 flags
|= ui::EF_CAPS_LOCK_DOWN
;
184 if (modifiers
& blink::WebInputEvent::IsAutoRepeat
)
185 flags
|= ui::EF_IS_REPEAT
;
190 } // namespace content