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 #include "content/browser/renderer_host/input/web_input_event_builders_android.h"
7 #include "base/logging.h"
8 #include "content/browser/renderer_host/input/motion_event_android.h"
9 #include "content/browser/renderer_host/input/web_input_event_util.h"
10 #include "content/browser/renderer_host/input/web_input_event_util_posix.h"
11 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
12 #include "ui/events/keycodes/keyboard_codes_posix.h"
14 using blink::WebInputEvent
;
15 using blink::WebKeyboardEvent
;
16 using blink::WebGestureEvent
;
17 using blink::WebMouseEvent
;
18 using blink::WebMouseWheelEvent
;
19 using blink::WebTouchEvent
;
20 using blink::WebTouchPoint
;
24 WebKeyboardEvent
WebKeyboardEventBuilder::Build(WebInputEvent::Type type
,
28 int unicode_character
,
30 DCHECK(WebInputEvent::isKeyboardEventType(type
));
31 WebKeyboardEvent result
;
34 result
.modifiers
= modifiers
;
35 result
.timeStampSeconds
= time_sec
;
36 ui::KeyboardCode windows_key_code
=
37 ui::KeyboardCodeFromAndroidKeyCode(keycode
);
38 UpdateWindowsKeyCodeAndKeyIdentifier(&result
, windows_key_code
);
39 result
.modifiers
|= GetLocationModifiersFromWindowsKeyCode(windows_key_code
);
40 result
.nativeKeyCode
= keycode
;
41 result
.unmodifiedText
[0] = unicode_character
;
42 if (result
.windowsKeyCode
== ui::VKEY_RETURN
) {
43 // This is the same behavior as GTK:
44 // We need to treat the enter key as a key press of character \r. This
45 // is apparently just how webkit handles it and what it expects.
46 result
.unmodifiedText
[0] = '\r';
48 result
.text
[0] = result
.unmodifiedText
[0];
49 result
.isSystemKey
= is_system_key
;
54 WebMouseEvent
WebMouseEventBuilder::Build(blink::WebInputEvent::Type type
,
55 WebMouseEvent::Button button
,
61 DCHECK(WebInputEvent::isMouseEventType(type
));
67 result
.windowX
= window_x
;
68 result
.windowY
= window_y
;
69 result
.timeStampSeconds
= time_sec
;
70 result
.clickCount
= click_count
;
71 result
.modifiers
= modifiers
;
73 if (type
== WebInputEvent::MouseDown
|| type
== WebInputEvent::MouseUp
)
74 result
.button
= button
;
76 result
.button
= WebMouseEvent::ButtonNone
;
81 WebMouseWheelEvent
WebMouseWheelEventBuilder::Build(Direction direction
,
85 WebMouseWheelEvent result
;
87 result
.type
= WebInputEvent::MouseWheel
;
90 result
.windowX
= window_x
;
91 result
.windowY
= window_y
;
92 result
.timeStampSeconds
= time_sec
;
93 result
.button
= WebMouseEvent::ButtonNone
;
95 // The below choices are matched from GTK.
96 const float scrollbar_pixels_per_tick
= 160.0f
/ 3.0f
;
100 result
.deltaY
= scrollbar_pixels_per_tick
;
101 result
.wheelTicksY
= 1;
104 result
.deltaY
= -scrollbar_pixels_per_tick
;
105 result
.wheelTicksY
= -1;
108 result
.deltaX
= scrollbar_pixels_per_tick
;
109 result
.wheelTicksX
= 1;
111 case DIRECTION_RIGHT
:
112 result
.deltaX
= -scrollbar_pixels_per_tick
;
113 result
.wheelTicksX
= -1;
120 WebGestureEvent
WebGestureEventBuilder::Build(WebInputEvent::Type type
,
124 DCHECK(WebInputEvent::isGestureEventType(type
));
125 WebGestureEvent result
;
130 result
.timeStampSeconds
= time_sec
;
131 result
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
136 } // namespace content