IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / renderer_host / input / web_input_event_builders_android.cc
blob43e9bb8657209d4433e18ebefa574b3de88753e5
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/web_input_event_util.h"
9 #include "content/browser/renderer_host/input/web_input_event_util_posix.h"
10 #include "ui/events/keycodes/keyboard_code_conversion_android.h"
11 #include "ui/events/keycodes/keyboard_codes_posix.h"
13 namespace content {
15 using blink::WebInputEvent;
16 using blink::WebKeyboardEvent;
17 using blink::WebGestureEvent;
18 using blink::WebMouseEvent;
19 using blink::WebMouseWheelEvent;
21 WebKeyboardEvent WebKeyboardEventBuilder::Build(WebInputEvent::Type type,
22 int modifiers,
23 double time_sec,
24 int keycode,
25 int unicode_character,
26 bool is_system_key) {
27 DCHECK(WebInputEvent::isKeyboardEventType(type));
28 WebKeyboardEvent result;
30 result.type = type;
31 result.modifiers = modifiers;
32 result.timeStampSeconds = time_sec;
33 ui::KeyboardCode windows_key_code =
34 ui::KeyboardCodeFromAndroidKeyCode(keycode);
35 UpdateWindowsKeyCodeAndKeyIdentifier(&result, windows_key_code);
36 result.modifiers |= GetLocationModifiersFromWindowsKeyCode(windows_key_code);
37 result.nativeKeyCode = keycode;
38 result.unmodifiedText[0] = unicode_character;
39 if (result.windowsKeyCode == ui::VKEY_RETURN) {
40 // This is the same behavior as GTK:
41 // We need to treat the enter key as a key press of character \r. This
42 // is apparently just how webkit handles it and what it expects.
43 result.unmodifiedText[0] = '\r';
45 result.text[0] = result.unmodifiedText[0];
46 result.isSystemKey = is_system_key;
48 return result;
51 WebMouseEvent WebMouseEventBuilder::Build(blink::WebInputEvent::Type type,
52 WebMouseEvent::Button button,
53 double time_sec,
54 int window_x,
55 int window_y,
56 int modifiers,
57 int click_count) {
58 DCHECK(WebInputEvent::isMouseEventType(type));
59 WebMouseEvent result;
61 result.type = type;
62 result.x = window_x;
63 result.y = window_y;
64 result.windowX = window_x;
65 result.windowY = window_y;
66 result.timeStampSeconds = time_sec;
67 result.clickCount = click_count;
68 result.modifiers = modifiers;
70 if (type == WebInputEvent::MouseDown || type == WebInputEvent::MouseUp)
71 result.button = button;
72 else
73 result.button = WebMouseEvent::ButtonNone;
75 return result;
78 WebMouseWheelEvent WebMouseWheelEventBuilder::Build(Direction direction,
79 double time_sec,
80 int window_x,
81 int window_y) {
82 WebMouseWheelEvent result;
84 result.type = WebInputEvent::MouseWheel;
85 result.x = window_x;
86 result.y = window_y;
87 result.windowX = window_x;
88 result.windowY = window_y;
89 result.timeStampSeconds = time_sec;
90 result.button = WebMouseEvent::ButtonNone;
92 // The below choices are matched from GTK.
93 const float scrollbar_pixels_per_tick = 160.0f / 3.0f;
95 switch (direction) {
96 case DIRECTION_UP:
97 result.deltaY = scrollbar_pixels_per_tick;
98 result.wheelTicksY = 1;
99 break;
100 case DIRECTION_DOWN:
101 result.deltaY = -scrollbar_pixels_per_tick;
102 result.wheelTicksY = -1;
103 break;
104 case DIRECTION_LEFT:
105 result.deltaX = scrollbar_pixels_per_tick;
106 result.wheelTicksX = 1;
107 break;
108 case DIRECTION_RIGHT:
109 result.deltaX = -scrollbar_pixels_per_tick;
110 result.wheelTicksX = -1;
111 break;
114 return result;
117 WebGestureEvent WebGestureEventBuilder::Build(WebInputEvent::Type type,
118 double time_sec,
119 int x,
120 int y) {
121 DCHECK(WebInputEvent::isGestureEventType(type));
122 WebGestureEvent result;
124 result.type = type;
125 result.x = x;
126 result.y = y;
127 result.timeStampSeconds = time_sec;
128 result.sourceDevice = WebGestureEvent::Touchscreen;
130 return result;
133 } // namespace content