OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | 7 #include "ui/aura/event.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
11 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent( | 11 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent( |
12 base::NativeEvent native_event); | 12 base::NativeEvent native_event); |
13 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(aura::MouseEvent* event); | |
13 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent( | 14 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent( |
14 base::NativeEvent native_event); | 15 base::NativeEvent native_event); |
15 | 16 |
16 // General approach: | 17 // General approach: |
17 // | 18 // |
18 // aura::Event only carries a subset of possible event data provided to Aura by | 19 // aura::Event only carries a subset of possible event data provided to Aura by |
19 // the host platform. WebKit utilizes a larger subset of that information than | 20 // the host platform. WebKit utilizes a larger subset of that information than |
20 // Aura itself. WebKit includes some built in cracking functionality that we | 21 // Aura itself. WebKit includes some built in cracking functionality that we |
21 // rely on to obtain this information cleanly and consistently. | 22 // rely on to obtain this information cleanly and consistently. |
22 // | 23 // |
23 // The only place where an aura::Event's data differs from what the underlying | 24 // The only place where an aura::Event's data differs from what the underlying |
24 // base::NativeEvent would provide is position data, since we would like to | 25 // base::NativeEvent would provide is position data, since we would like to |
25 // provide coordinates relative to the aura::Window that is hosting the | 26 // provide coordinates relative to the aura::Window that is hosting the |
26 // renderer, not the top level platform window. | 27 // renderer, not the top level platform window. |
27 // | 28 // |
28 // The approach is to fully construct a WebKit::WebInputEvent from the | 29 // The approach is to fully construct a WebKit::WebInputEvent from the |
29 // aura::Event's base::NativeEvent, and then replace the coordinate fields with | 30 // aura::Event's base::NativeEvent, and then replace the coordinate fields with |
30 // the translated values from the aura::Event. | 31 // the translated values from the aura::Event. |
31 // | 32 // |
33 // The exception is mouse events on linux. The aura::MouseEvent contains enough | |
34 // necessary information to construct a WebMouseEvent. So instead of extracting | |
35 // the information from the XEvent, which can be tricky when supporting both | |
36 // XInput2 and XInput. | |
Ben Goodger (Google)
2011/10/19 16:14:20
Can you note that this can be resolved and we can
sadrul
2011/10/19 16:34:37
Done.
| |
37 // | |
32 | 38 |
33 WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event) { | 39 WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event) { |
40 #if defined(OS_WIN) | |
34 // Construct an untranslated event from the platform event data. | 41 // Construct an untranslated event from the platform event data. |
35 WebKit::WebMouseEvent webkit_event = | 42 WebKit::WebMouseEvent webkit_event = |
36 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); | 43 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); |
44 #else | |
45 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event); | |
46 #endif | |
37 | 47 |
38 // Replace the event's coordinate fields with translated position data from | 48 // Replace the event's coordinate fields with translated position data from |
39 // |event|. | 49 // |event|. |
40 webkit_event.windowX = webkit_event.x = event->x(); | 50 webkit_event.windowX = webkit_event.x = event->x(); |
41 webkit_event.windowY = webkit_event.y = event->y(); | 51 webkit_event.windowY = webkit_event.y = event->y(); |
42 | 52 |
43 // TODO(beng): map these to screen coordinates. | 53 // TODO(beng): map these to screen coordinates. |
44 webkit_event.globalX = event->x(); | 54 webkit_event.globalX = event->x(); |
45 webkit_event.globalY = event->y(); | 55 webkit_event.globalY = event->y(); |
46 | 56 |
47 return webkit_event; | 57 return webkit_event; |
48 } | 58 } |
49 | 59 |
50 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event) { | 60 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event) { |
51 // Key events require no translation by the aura system. | 61 // Key events require no translation by the aura system. |
52 return MakeWebKeyboardEventFromNativeEvent(event->native_event()); | 62 return MakeWebKeyboardEventFromNativeEvent(event->native_event()); |
53 } | 63 } |
54 | 64 |
55 } // namespace content | 65 } // namespace content |
OLD | NEW |