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 "ui/events/keycodes/dom/dom_code.h"
11 #include "ui/events/keycodes/dom/keycode_converter.h"
12 #include "ui/events/keycodes/keyboard_code_conversion.h"
13 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
14 #include "ui/events/keycodes/keyboard_codes_posix.h"
16 using blink::WebInputEvent
;
17 using blink::WebKeyboardEvent
;
18 using blink::WebGestureEvent
;
19 using blink::WebMouseEvent
;
20 using blink::WebMouseWheelEvent
;
21 using blink::WebTouchEvent
;
22 using blink::WebTouchPoint
;
26 WebKeyboardEvent
WebKeyboardEventBuilder::Build(WebInputEvent::Type type
,
31 int unicode_character
,
33 DCHECK(WebInputEvent::isKeyboardEventType(type
));
34 WebKeyboardEvent result
;
36 ui::DomCode dom_code
= ui::DomCode::NONE
;
38 dom_code
= ui::KeycodeConverter::NativeKeycodeToDomCode(scancode
);
40 result
.modifiers
= modifiers
;
41 result
.timeStampSeconds
= time_sec
;
42 result
.windowsKeyCode
= ui::LocatedToNonLocatedKeyboardCode(
43 ui::KeyboardCodeFromAndroidKeyCode(keycode
));
44 result
.modifiers
|= DomCodeToWebInputEventModifiers(dom_code
);
45 result
.nativeKeyCode
= keycode
;
46 result
.domCode
= static_cast<int>(dom_code
);
47 result
.unmodifiedText
[0] = unicode_character
;
48 if (result
.windowsKeyCode
== ui::VKEY_RETURN
) {
49 // This is the same behavior as GTK:
50 // We need to treat the enter key as a key press of character \r. This
51 // is apparently just how webkit handles it and what it expects.
52 result
.unmodifiedText
[0] = '\r';
54 result
.text
[0] = result
.unmodifiedText
[0];
55 result
.isSystemKey
= is_system_key
;
56 result
.setKeyIdentifierFromWindowsKeyCode();
61 WebMouseEvent
WebMouseEventBuilder::Build(blink::WebInputEvent::Type type
,
62 WebMouseEvent::Button button
,
68 DCHECK(WebInputEvent::isMouseEventType(type
));
74 result
.windowX
= window_x
;
75 result
.windowY
= window_y
;
76 result
.timeStampSeconds
= time_sec
;
77 result
.clickCount
= click_count
;
78 result
.modifiers
= modifiers
;
80 if (type
== WebInputEvent::MouseDown
|| type
== WebInputEvent::MouseUp
)
81 result
.button
= button
;
83 result
.button
= WebMouseEvent::ButtonNone
;
88 WebMouseWheelEvent
WebMouseWheelEventBuilder::Build(float ticks_x
,
90 float tick_multiplier
,
94 WebMouseWheelEvent result
;
96 result
.type
= WebInputEvent::MouseWheel
;
99 result
.windowX
= window_x
;
100 result
.windowY
= window_y
;
101 result
.timeStampSeconds
= time_sec
;
102 result
.button
= WebMouseEvent::ButtonNone
;
103 result
.hasPreciseScrollingDeltas
= true;
104 result
.deltaX
= ticks_x
* tick_multiplier
;
105 result
.deltaY
= ticks_y
* tick_multiplier
;
106 result
.wheelTicksX
= ticks_x
;
107 result
.wheelTicksY
= ticks_y
;
112 WebGestureEvent
WebGestureEventBuilder::Build(WebInputEvent::Type type
,
116 DCHECK(WebInputEvent::isGestureEventType(type
));
117 WebGestureEvent result
;
122 result
.timeStampSeconds
= time_sec
;
123 result
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
128 } // namespace content