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);
156 base::snprintf(event
->keyIdentifier
,
157 sizeof(event
->keyIdentifier
),
159 base::ToUpperASCII(static_cast<int>(windows_key_code
)));
163 int WebEventModifiersToEventFlags(int modifiers
) {
166 if (modifiers
& blink::WebInputEvent::ShiftKey
)
167 flags
|= ui::EF_SHIFT_DOWN
;
168 if (modifiers
& blink::WebInputEvent::ControlKey
)
169 flags
|= ui::EF_CONTROL_DOWN
;
170 if (modifiers
& blink::WebInputEvent::AltKey
)
171 flags
|= ui::EF_ALT_DOWN
;
172 if (modifiers
& blink::WebInputEvent::MetaKey
)
173 flags
|= ui::EF_COMMAND_DOWN
;
175 if (modifiers
& blink::WebInputEvent::LeftButtonDown
)
176 flags
|= ui::EF_LEFT_MOUSE_BUTTON
;
177 if (modifiers
& blink::WebInputEvent::MiddleButtonDown
)
178 flags
|= ui::EF_MIDDLE_MOUSE_BUTTON
;
179 if (modifiers
& blink::WebInputEvent::RightButtonDown
)
180 flags
|= ui::EF_RIGHT_MOUSE_BUTTON
;
181 if (modifiers
& blink::WebInputEvent::CapsLockOn
)
182 flags
|= ui::EF_CAPS_LOCK_DOWN
;
183 if (modifiers
& blink::WebInputEvent::IsAutoRepeat
)
184 flags
|= ui::EF_IS_REPEAT
;
185 if (modifiers
& blink::WebInputEvent::IsKeyPad
)
186 flags
|= ui::EF_NUMPAD_KEY
;
191 } // namespace content