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