Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1024)

Side by Side Diff: content/browser/renderer_host/web_input_event_aura.cc

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/web_input_event_aura.h" 5 #include "content/browser/renderer_host/web_input_event_aura.h"
6 6
7 #include "ui/aura/event.h"
8 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/base/event.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent( 13 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent(
14 base::NativeEvent native_event); 14 base::NativeEvent native_event);
15 WebKit::WebMouseWheelEvent MakeUntranslatedWebMouseWheelEventFromNativeEvent( 15 WebKit::WebMouseWheelEvent MakeUntranslatedWebMouseWheelEventFromNativeEvent(
16 base::NativeEvent native_event); 16 base::NativeEvent native_event);
17 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent( 17 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent(
18 base::NativeEvent native_event); 18 base::NativeEvent native_event);
19 WebKit::WebGestureEvent MakeWebGestureEventFromNativeEvent( 19 WebKit::WebGestureEvent MakeWebGestureEventFromNativeEvent(
20 base::NativeEvent native_event); 20 base::NativeEvent native_event);
21 WebKit::WebTouchPoint* UpdateWebTouchEventFromNativeEvent( 21 WebKit::WebTouchPoint* UpdateWebTouchEventFromNativeEvent(
22 base::NativeEvent native_event, WebKit::WebTouchEvent* web_event); 22 base::NativeEvent native_event, WebKit::WebTouchEvent* web_event);
23 #else 23 #else
24 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(aura::MouseEvent* event); 24 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event);
25 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( 25 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
26 aura::MouseEvent* event); 26 ui::MouseEvent* event);
27 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( 27 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent(
28 aura::ScrollEvent* event); 28 ui::ScrollEvent* event);
29 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( 29 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent(
30 aura::KeyEvent* event); 30 ui::KeyEvent* event);
31 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( 31 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent(
32 aura::GestureEvent* event); 32 ui::GestureEventImpl* event);
33 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( 33 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent(
34 aura::ScrollEvent* event); 34 ui::ScrollEvent* event);
35 WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent( 35 WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent(
36 aura::TouchEvent* event, WebKit::WebTouchEvent* web_event); 36 ui::TouchEventImpl* event, WebKit::WebTouchEvent* web_event);
37 #endif 37 #endif
38 38
39 // General approach: 39 // General approach:
40 // 40 //
41 // aura::Event only carries a subset of possible event data provided to Aura by 41 // ui::Event only carries a subset of possible event data provided to Aura by
42 // the host platform. WebKit utilizes a larger subset of that information than 42 // the host platform. WebKit utilizes a larger subset of that information than
43 // Aura itself. WebKit includes some built in cracking functionality that we 43 // Aura itself. WebKit includes some built in cracking functionality that we
44 // rely on to obtain this information cleanly and consistently. 44 // rely on to obtain this information cleanly and consistently.
45 // 45 //
46 // The only place where an aura::Event's data differs from what the underlying 46 // The only place where an ui::Event's data differs from what the underlying
47 // base::NativeEvent would provide is position data, since we would like to 47 // base::NativeEvent would provide is position data, since we would like to
48 // provide coordinates relative to the aura::Window that is hosting the 48 // provide coordinates relative to the aura::Window that is hosting the
49 // renderer, not the top level platform window. 49 // renderer, not the top level platform window.
50 // 50 //
51 // The approach is to fully construct a WebKit::WebInputEvent from the 51 // The approach is to fully construct a WebKit::WebInputEvent from the
52 // aura::Event's base::NativeEvent, and then replace the coordinate fields with 52 // ui::Event's base::NativeEvent, and then replace the coordinate fields with
53 // the translated values from the aura::Event. 53 // the translated values from the ui::Event.
54 // 54 //
55 // The exception is mouse events on linux. The aura::MouseEvent contains enough 55 // The exception is mouse events on linux. The ui::MouseEvent contains enough
56 // necessary information to construct a WebMouseEvent. So instead of extracting 56 // necessary information to construct a WebMouseEvent. So instead of extracting
57 // the information from the XEvent, which can be tricky when supporting both 57 // the information from the XEvent, which can be tricky when supporting both
58 // XInput2 and XInput, the WebMouseEvent is constructed from the 58 // XInput2 and XInput, the WebMouseEvent is constructed from the
59 // aura::MouseEvent. This will not be necessary once only XInput2 is supported. 59 // ui::MouseEvent. This will not be necessary once only XInput2 is supported.
60 // 60 //
61 61
62 WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event) { 62 WebKit::WebMouseEvent MakeWebMouseEvent(ui::MouseEvent* event) {
63 #if defined(OS_WIN) 63 #if defined(OS_WIN)
64 // Construct an untranslated event from the platform event data. 64 // Construct an untranslated event from the platform event data.
65 WebKit::WebMouseEvent webkit_event = 65 WebKit::WebMouseEvent webkit_event =
66 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); 66 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event());
67 #else 67 #else
68 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event); 68 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event);
69 #endif 69 #endif
70 70
71 // Replace the event's coordinate fields with translated position data from 71 // Replace the event's coordinate fields with translated position data from
72 // |event|. 72 // |event|.
73 webkit_event.windowX = webkit_event.x = event->x(); 73 webkit_event.windowX = webkit_event.x = event->x();
74 webkit_event.windowY = webkit_event.y = event->y(); 74 webkit_event.windowY = webkit_event.y = event->y();
75 75
76 const gfx::Point root_point = event->root_location(); 76 const gfx::Point root_point = event->root_location();
77 webkit_event.globalX = root_point.x(); 77 webkit_event.globalX = root_point.x();
78 webkit_event.globalY = root_point.y(); 78 webkit_event.globalY = root_point.y();
79 79
80 return webkit_event; 80 return webkit_event;
81 } 81 }
82 82
83 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::MouseEvent* event) { 83 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(ui::MouseEvent* event) {
84 #if defined(OS_WIN) 84 #if defined(OS_WIN)
85 // Construct an untranslated event from the platform event data. 85 // Construct an untranslated event from the platform event data.
86 WebKit::WebMouseWheelEvent webkit_event = 86 WebKit::WebMouseWheelEvent webkit_event =
87 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event()); 87 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event());
88 #else 88 #else
89 WebKit::WebMouseWheelEvent webkit_event = 89 WebKit::WebMouseWheelEvent webkit_event =
90 MakeWebMouseWheelEventFromAuraEvent(event); 90 MakeWebMouseWheelEventFromAuraEvent(event);
91 #endif 91 #endif
92 92
93 // Replace the event's coordinate fields with translated position data from 93 // Replace the event's coordinate fields with translated position data from
94 // |event|. 94 // |event|.
95 webkit_event.windowX = webkit_event.x = event->x(); 95 webkit_event.windowX = webkit_event.x = event->x();
96 webkit_event.windowY = webkit_event.y = event->y(); 96 webkit_event.windowY = webkit_event.y = event->y();
97 97
98 const gfx::Point root_point = event->root_location(); 98 const gfx::Point root_point = event->root_location();
99 webkit_event.globalX = root_point.x(); 99 webkit_event.globalX = root_point.x();
100 webkit_event.globalY = root_point.y(); 100 webkit_event.globalY = root_point.y();
101 101
102 return webkit_event; 102 return webkit_event;
103 } 103 }
104 104
105 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::ScrollEvent* event) { 105 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(ui::ScrollEvent* event) {
106 #if defined(OS_WIN) 106 #if defined(OS_WIN)
107 // Construct an untranslated event from the platform event data. 107 // Construct an untranslated event from the platform event data.
108 WebKit::WebMouseWheelEvent webkit_event = 108 WebKit::WebMouseWheelEvent webkit_event =
109 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event()); 109 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event());
110 #else 110 #else
111 WebKit::WebMouseWheelEvent webkit_event = 111 WebKit::WebMouseWheelEvent webkit_event =
112 MakeWebMouseWheelEventFromAuraEvent(event); 112 MakeWebMouseWheelEventFromAuraEvent(event);
113 #endif 113 #endif
114 114
115 // Replace the event's coordinate fields with translated position data from 115 // Replace the event's coordinate fields with translated position data from
116 // |event|. 116 // |event|.
117 webkit_event.windowX = webkit_event.x = event->x(); 117 webkit_event.windowX = webkit_event.x = event->x();
118 webkit_event.windowY = webkit_event.y = event->y(); 118 webkit_event.windowY = webkit_event.y = event->y();
119 119
120 const gfx::Point root_point = event->root_location(); 120 const gfx::Point root_point = event->root_location();
121 webkit_event.globalX = root_point.x(); 121 webkit_event.globalX = root_point.x();
122 webkit_event.globalY = root_point.y(); 122 webkit_event.globalY = root_point.y();
123 123
124 return webkit_event; 124 return webkit_event;
125 } 125 }
126 126
127 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event) { 127 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(ui::KeyEvent* event) {
128 // Windows can figure out whether or not to construct a RawKeyDown or a Char 128 // Windows can figure out whether or not to construct a RawKeyDown or a Char
129 // WebInputEvent based on the type of message carried in 129 // WebInputEvent based on the type of message carried in
130 // event->native_event(). X11 is not so fortunate, there is no separate 130 // event->native_event(). X11 is not so fortunate, there is no separate
131 // translated event type, so DesktopHostLinux sends an extra KeyEvent with 131 // translated event type, so DesktopHostLinux sends an extra KeyEvent with
132 // is_char() == true. We need to pass the aura::KeyEvent to the X11 function 132 // is_char() == true. We need to pass the ui::KeyEvent to the X11 function
133 // to detect this case so the right event type can be constructed. 133 // to detect this case so the right event type can be constructed.
134 #if defined(OS_WIN) 134 #if defined(OS_WIN)
135 // Key events require no translation by the aura system. 135 // Key events require no translation by the aura system.
136 return MakeWebKeyboardEventFromNativeEvent(event->native_event()); 136 return MakeWebKeyboardEventFromNativeEvent(event->native_event());
137 #else 137 #else
138 return MakeWebKeyboardEventFromAuraEvent(event); 138 return MakeWebKeyboardEventFromAuraEvent(event);
139 #endif 139 #endif
140 } 140 }
141 141
142 WebKit::WebGestureEvent MakeWebGestureEvent(aura::GestureEvent* event) { 142 WebKit::WebGestureEvent MakeWebGestureEvent(ui::GestureEventImpl* event) {
143 WebKit::WebGestureEvent gesture_event; 143 WebKit::WebGestureEvent gesture_event;
144 #if defined(OS_WIN) 144 #if defined(OS_WIN)
145 gesture_event = MakeWebGestureEventFromNativeEvent(event->native_event()); 145 gesture_event = MakeWebGestureEventFromNativeEvent(event->native_event());
146 #else 146 #else
147 gesture_event = MakeWebGestureEventFromAuraEvent(event); 147 gesture_event = MakeWebGestureEventFromAuraEvent(event);
148 #endif 148 #endif
149 149
150 gesture_event.x = event->x(); 150 gesture_event.x = event->x();
151 gesture_event.y = event->y(); 151 gesture_event.y = event->y();
152 152
153 const gfx::Point root_point = event->root_location(); 153 const gfx::Point root_point = event->root_location();
154 gesture_event.globalX = root_point.x(); 154 gesture_event.globalX = root_point.x();
155 gesture_event.globalY = root_point.y(); 155 gesture_event.globalY = root_point.y();
156 156
157 return gesture_event; 157 return gesture_event;
158 } 158 }
159 159
160 WebKit::WebGestureEvent MakeWebGestureEvent(aura::ScrollEvent* event) { 160 WebKit::WebGestureEvent MakeWebGestureEvent(ui::ScrollEvent* event) {
161 WebKit::WebGestureEvent gesture_event; 161 WebKit::WebGestureEvent gesture_event;
162 162
163 #if defined(OS_WIN) 163 #if defined(OS_WIN)
164 gesture_event = MakeWebGestureEventFromNativeEvent(event->native_event()); 164 gesture_event = MakeWebGestureEventFromNativeEvent(event->native_event());
165 #else 165 #else
166 gesture_event = MakeWebGestureEventFromAuraEvent(event); 166 gesture_event = MakeWebGestureEventFromAuraEvent(event);
167 #endif 167 #endif
168 168
169 gesture_event.x = event->x(); 169 gesture_event.x = event->x();
170 gesture_event.y = event->y(); 170 gesture_event.y = event->y();
171 171
172 const gfx::Point root_point = event->root_location(); 172 const gfx::Point root_point = event->root_location();
173 gesture_event.globalX = root_point.x(); 173 gesture_event.globalX = root_point.x();
174 gesture_event.globalY = root_point.y(); 174 gesture_event.globalY = root_point.y();
175 175
176 return gesture_event; 176 return gesture_event;
177 } 177 }
178 178
179 WebKit::WebGestureEvent MakeWebGestureEventFlingCancel() { 179 WebKit::WebGestureEvent MakeWebGestureEventFlingCancel() {
180 WebKit::WebGestureEvent gesture_event; 180 WebKit::WebGestureEvent gesture_event;
181 181
182 // All other fields are ignored on a GestureFlingCancel event. 182 // All other fields are ignored on a GestureFlingCancel event.
183 gesture_event.type = WebKit::WebInputEvent::GestureFlingCancel; 183 gesture_event.type = WebKit::WebInputEvent::GestureFlingCancel;
184 return gesture_event; 184 return gesture_event;
185 } 185 }
186 186
187 WebKit::WebTouchPoint* UpdateWebTouchEvent(aura::TouchEvent* event, 187 WebKit::WebTouchPoint* UpdateWebTouchEvent(ui::TouchEventImpl* event,
188 WebKit::WebTouchEvent* web_event) { 188 WebKit::WebTouchEvent* web_event) {
189 #if defined(OS_WIN) 189 #if defined(OS_WIN)
190 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event); 190 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event);
191 #else 191 #else
192 return UpdateWebTouchEventFromAuraEvent(event, web_event); 192 return UpdateWebTouchEventFromAuraEvent(event, web_event);
193 #endif 193 #endif
194 } 194 }
195 195
196 } // namespace content 196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/web_input_event_aura.h ('k') | content/browser/renderer_host/web_input_event_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698