Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / input / web_input_event_builders_android.cc
blob6ec1614c81df2df87573b85ba2f0022dbbbe9615
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;
24 namespace content {
26 WebKeyboardEvent WebKeyboardEventBuilder::Build(WebInputEvent::Type type,
27 int modifiers,
28 double time_sec,
29 int keycode,
30 int scancode,
31 int unicode_character,
32 bool is_system_key) {
33 DCHECK(WebInputEvent::isKeyboardEventType(type));
34 WebKeyboardEvent result;
36 ui::DomCode dom_code = ui::DomCode::NONE;
37 if (scancode != 0)
38 dom_code = ui::KeycodeConverter::NativeKeycodeToDomCode(scancode);
39 result.type = type;
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();
58 return result;
61 WebMouseEvent WebMouseEventBuilder::Build(blink::WebInputEvent::Type type,
62 WebMouseEvent::Button button,
63 double time_sec,
64 int window_x,
65 int window_y,
66 int modifiers,
67 int click_count) {
68 DCHECK(WebInputEvent::isMouseEventType(type));
69 WebMouseEvent result;
71 result.type = type;
72 result.x = window_x;
73 result.y = window_y;
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;
82 else
83 result.button = WebMouseEvent::ButtonNone;
85 return result;
88 WebMouseWheelEvent WebMouseWheelEventBuilder::Build(float ticks_x,
89 float ticks_y,
90 float tick_multiplier,
91 double time_sec,
92 int window_x,
93 int window_y) {
94 WebMouseWheelEvent result;
96 result.type = WebInputEvent::MouseWheel;
97 result.x = window_x;
98 result.y = window_y;
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;
109 return result;
112 WebGestureEvent WebGestureEventBuilder::Build(WebInputEvent::Type type,
113 double time_sec,
114 int x,
115 int y) {
116 DCHECK(WebInputEvent::isGestureEventType(type));
117 WebGestureEvent result;
119 result.type = type;
120 result.x = x;
121 result.y = y;
122 result.timeStampSeconds = time_sec;
123 result.sourceDevice = blink::WebGestureDeviceTouchscreen;
125 return result;
128 } // namespace content