OLD | NEW |
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/window.h" | 7 #include "ui/aura/window.h" |
8 #include "ui/base/events/event.h" | 8 #include "ui/base/events/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(ui::MouseEvent* event); | |
25 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( | 24 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( |
26 ui::MouseWheelEvent* event); | 25 ui::MouseWheelEvent* event); |
27 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( | 26 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( |
28 ui::ScrollEvent* event); | 27 ui::ScrollEvent* event); |
29 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( | 28 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromAuraEvent( |
30 ui::KeyEvent* event); | 29 ui::KeyEvent* event); |
31 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( | 30 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( |
32 ui::GestureEvent* event); | 31 ui::GestureEvent* event); |
33 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( | 32 WebKit::WebGestureEvent MakeWebGestureEventFromAuraEvent( |
34 ui::ScrollEvent* event); | 33 ui::ScrollEvent* event); |
35 WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent( | 34 WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent( |
36 ui::TouchEvent* event, WebKit::WebTouchEvent* web_event); | 35 ui::TouchEvent* event, WebKit::WebTouchEvent* web_event); |
37 #endif | 36 #endif |
38 | 37 |
| 38 int EventFlagsToWebEventModifiers(int flags); |
| 39 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event); |
| 40 |
39 // General approach: | 41 // General approach: |
40 // | 42 // |
41 // ui::Event only carries a subset of possible event data provided to Aura by | 43 // 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 | 44 // the host platform. WebKit utilizes a larger subset of that information than |
43 // Aura itself. WebKit includes some built in cracking functionality that we | 45 // Aura itself. WebKit includes some built in cracking functionality that we |
44 // rely on to obtain this information cleanly and consistently. | 46 // rely on to obtain this information cleanly and consistently. |
45 // | 47 // |
46 // The only place where an ui::Event's data differs from what the underlying | 48 // 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 | 49 // base::NativeEvent would provide is position data, since we would like to |
48 // provide coordinates relative to the aura::Window that is hosting the | 50 // provide coordinates relative to the aura::Window that is hosting the |
49 // renderer, not the top level platform window. | 51 // renderer, not the top level platform window. |
50 // | 52 // |
51 // The approach is to fully construct a WebKit::WebInputEvent from the | 53 // The approach is to fully construct a WebKit::WebInputEvent from the |
52 // ui::Event's base::NativeEvent, and then replace the coordinate fields with | 54 // ui::Event's base::NativeEvent, and then replace the coordinate fields with |
53 // the translated values from the ui::Event. | 55 // the translated values from the ui::Event. |
54 // | 56 // |
55 // The exception is mouse events on linux. The ui::MouseEvent contains enough | 57 // The exception is mouse events on linux. The ui::MouseEvent contains enough |
56 // necessary information to construct a WebMouseEvent. So instead of extracting | 58 // necessary information to construct a WebMouseEvent. So instead of extracting |
57 // the information from the XEvent, which can be tricky when supporting both | 59 // the information from the XEvent, which can be tricky when supporting both |
58 // XInput2 and XInput, the WebMouseEvent is constructed from the | 60 // XInput2 and XInput, the WebMouseEvent is constructed from the |
59 // ui::MouseEvent. This will not be necessary once only XInput2 is supported. | 61 // ui::MouseEvent. This will not be necessary once only XInput2 is supported. |
60 // | 62 // |
61 | 63 |
62 WebKit::WebMouseEvent MakeWebMouseEvent(ui::MouseEvent* event) { | 64 WebKit::WebMouseEvent MakeWebMouseEvent(ui::MouseEvent* event) { |
63 #if defined(OS_WIN) | |
64 // Construct an untranslated event from the platform event data. | 65 // Construct an untranslated event from the platform event data. |
65 WebKit::WebMouseEvent webkit_event = | 66 WebKit::WebMouseEvent webkit_event = |
66 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); | 67 #if defined(OS_WIN) |
| 68 // On Windows we have WM_ events comming from desktop and pure aura |
| 69 // events comming from metro mode. |
| 70 event->native_event().message ? |
| 71 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()) : |
| 72 MakeWebMouseEventFromAuraEvent(event); |
67 #else | 73 #else |
68 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event); | 74 MakeWebMouseEventFromAuraEvent(event); |
69 #endif | 75 #endif |
70 | |
71 // Replace the event's coordinate fields with translated position data from | 76 // Replace the event's coordinate fields with translated position data from |
72 // |event|. | 77 // |event|. |
73 webkit_event.windowX = webkit_event.x = event->x(); | 78 webkit_event.windowX = webkit_event.x = event->x(); |
74 webkit_event.windowY = webkit_event.y = event->y(); | 79 webkit_event.windowY = webkit_event.y = event->y(); |
75 | 80 |
76 const gfx::Point root_point = event->root_location(); | 81 const gfx::Point root_point = event->root_location(); |
77 webkit_event.globalX = root_point.x(); | 82 webkit_event.globalX = root_point.x(); |
78 webkit_event.globalY = root_point.y(); | 83 webkit_event.globalY = root_point.y(); |
79 | 84 |
80 return webkit_event; | 85 return webkit_event; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 191 |
187 WebKit::WebTouchPoint* UpdateWebTouchEvent(ui::TouchEvent* event, | 192 WebKit::WebTouchPoint* UpdateWebTouchEvent(ui::TouchEvent* event, |
188 WebKit::WebTouchEvent* web_event) { | 193 WebKit::WebTouchEvent* web_event) { |
189 #if defined(OS_WIN) | 194 #if defined(OS_WIN) |
190 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event); | 195 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event); |
191 #else | 196 #else |
192 return UpdateWebTouchEventFromAuraEvent(event, web_event); | 197 return UpdateWebTouchEventFromAuraEvent(event, web_event); |
193 #endif | 198 #endif |
194 } | 199 } |
195 | 200 |
| 201 int EventFlagsToWebEventModifiers(int flags) { |
| 202 int modifiers = 0; |
| 203 if (flags & ui::EF_SHIFT_DOWN) |
| 204 modifiers |= WebKit::WebInputEvent::ShiftKey; |
| 205 if (flags & ui::EF_CONTROL_DOWN) |
| 206 modifiers |= WebKit::WebInputEvent::ControlKey; |
| 207 if (flags & ui::EF_ALT_DOWN) |
| 208 modifiers |= WebKit::WebInputEvent::AltKey; |
| 209 // TODO(beng): MetaKey/META_MASK |
| 210 if (flags & ui::EF_LEFT_MOUSE_BUTTON) |
| 211 modifiers |= WebKit::WebInputEvent::LeftButtonDown; |
| 212 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) |
| 213 modifiers |= WebKit::WebInputEvent::MiddleButtonDown; |
| 214 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) |
| 215 modifiers |= WebKit::WebInputEvent::RightButtonDown; |
| 216 if (flags & ui::EF_CAPS_LOCK_DOWN) |
| 217 modifiers |= WebKit::WebInputEvent::CapsLockOn; |
| 218 return modifiers; |
| 219 } |
| 220 |
| 221 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event) { |
| 222 WebKit::WebMouseEvent webkit_event; |
| 223 |
| 224 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); |
| 225 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); |
| 226 |
| 227 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; |
| 228 if (event->flags() & ui::EF_LEFT_MOUSE_BUTTON) |
| 229 webkit_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 230 if (event->flags() & ui::EF_MIDDLE_MOUSE_BUTTON) |
| 231 webkit_event.button = WebKit::WebMouseEvent::ButtonMiddle; |
| 232 if (event->flags() & ui::EF_RIGHT_MOUSE_BUTTON) |
| 233 webkit_event.button = WebKit::WebMouseEvent::ButtonRight; |
| 234 |
| 235 switch (event->type()) { |
| 236 case ui::ET_MOUSE_PRESSED: |
| 237 webkit_event.type = WebKit::WebInputEvent::MouseDown; |
| 238 webkit_event.clickCount = event->GetClickCount(); |
| 239 break; |
| 240 case ui::ET_MOUSE_RELEASED: |
| 241 webkit_event.type = WebKit::WebInputEvent::MouseUp; |
| 242 break; |
| 243 case ui::ET_MOUSE_ENTERED: |
| 244 case ui::ET_MOUSE_EXITED: |
| 245 case ui::ET_MOUSE_MOVED: |
| 246 case ui::ET_MOUSE_DRAGGED: |
| 247 webkit_event.type = WebKit::WebInputEvent::MouseMove; |
| 248 break; |
| 249 default: |
| 250 NOTIMPLEMENTED() << "Received unexpected event: " << event->type(); |
| 251 break; |
| 252 } |
| 253 |
| 254 return webkit_event; |
| 255 } |
| 256 |
196 } // namespace content | 257 } // namespace content |
OLD | NEW |