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(float ticks_x
,
83 float tick_multiplier
,
87 WebMouseWheelEvent result
;
89 result
.type
= WebInputEvent::MouseWheel
;
92 result
.windowX
= window_x
;
93 result
.windowY
= window_y
;
94 result
.timeStampSeconds
= time_sec
;
95 result
.button
= WebMouseEvent::ButtonNone
;
96 result
.hasPreciseScrollingDeltas
= true;
97 result
.deltaX
= ticks_x
* tick_multiplier
;
98 result
.deltaY
= ticks_y
* tick_multiplier
;
99 result
.wheelTicksX
= ticks_x
;
100 result
.wheelTicksY
= ticks_y
;
105 WebGestureEvent
WebGestureEventBuilder::Build(WebInputEvent::Type type
,
109 DCHECK(WebInputEvent::isGestureEventType(type
));
110 WebGestureEvent result
;
115 result
.timeStampSeconds
= time_sec
;
116 result
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
121 } // namespace content