Add ICU message format support
[chromium-blink-merge.git] / content / browser / renderer_host / input / web_input_event_builders_android.cc
blob37dd16af7280d7c349738c9640ae8c52404f078d
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;
22 namespace content {
24 WebKeyboardEvent WebKeyboardEventBuilder::Build(WebInputEvent::Type type,
25 int modifiers,
26 double time_sec,
27 int keycode,
28 int unicode_character,
29 bool is_system_key) {
30 DCHECK(WebInputEvent::isKeyboardEventType(type));
31 WebKeyboardEvent result;
33 result.type = type;
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;
51 return result;
54 WebMouseEvent WebMouseEventBuilder::Build(blink::WebInputEvent::Type type,
55 WebMouseEvent::Button button,
56 double time_sec,
57 int window_x,
58 int window_y,
59 int modifiers,
60 int click_count) {
61 DCHECK(WebInputEvent::isMouseEventType(type));
62 WebMouseEvent result;
64 result.type = type;
65 result.x = window_x;
66 result.y = window_y;
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;
75 else
76 result.button = WebMouseEvent::ButtonNone;
78 return result;
81 WebMouseWheelEvent WebMouseWheelEventBuilder::Build(float ticks_x,
82 float ticks_y,
83 float tick_multiplier,
84 double time_sec,
85 int window_x,
86 int window_y) {
87 WebMouseWheelEvent result;
89 result.type = WebInputEvent::MouseWheel;
90 result.x = window_x;
91 result.y = window_y;
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;
102 return result;
105 WebGestureEvent WebGestureEventBuilder::Build(WebInputEvent::Type type,
106 double time_sec,
107 int x,
108 int y) {
109 DCHECK(WebInputEvent::isGestureEventType(type));
110 WebGestureEvent result;
112 result.type = type;
113 result.x = x;
114 result.y = y;
115 result.timeStampSeconds = time_sec;
116 result.sourceDevice = blink::WebGestureDeviceTouchscreen;
118 return result;
121 } // namespace content