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 #include "ui/aura/window.h" | |
8 | 9 |
9 namespace content { | 10 namespace content { |
10 | 11 |
11 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
12 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent( | 13 WebKit::WebMouseEvent MakeUntranslatedWebMouseEventFromNativeEvent( |
13 base::NativeEvent native_event); | 14 base::NativeEvent native_event); |
14 WebKit::WebMouseWheelEvent MakeUntranslatedWebMouseWheelEventFromNativeEvent( | 15 WebKit::WebMouseWheelEvent MakeUntranslatedWebMouseWheelEventFromNativeEvent( |
15 base::NativeEvent native_event); | 16 base::NativeEvent native_event); |
16 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent( | 17 WebKit::WebKeyboardEvent MakeWebKeyboardEventFromNativeEvent( |
17 base::NativeEvent native_event); | 18 base::NativeEvent native_event); |
(...skipping 25 matching lines...) Expand all Loading... | |
43 // aura::Event's base::NativeEvent, and then replace the coordinate fields with | 44 // aura::Event's base::NativeEvent, and then replace the coordinate fields with |
44 // the translated values from the aura::Event. | 45 // the translated values from the aura::Event. |
45 // | 46 // |
46 // The exception is mouse events on linux. The aura::MouseEvent contains enough | 47 // The exception is mouse events on linux. The aura::MouseEvent contains enough |
47 // necessary information to construct a WebMouseEvent. So instead of extracting | 48 // necessary information to construct a WebMouseEvent. So instead of extracting |
48 // the information from the XEvent, which can be tricky when supporting both | 49 // the information from the XEvent, which can be tricky when supporting both |
49 // XInput2 and XInput, the WebMouseEvent is constructed from the | 50 // XInput2 and XInput, the WebMouseEvent is constructed from the |
50 // aura::MouseEvent. This will not be necessary once only XInput2 is supported. | 51 // aura::MouseEvent. This will not be necessary once only XInput2 is supported. |
51 // | 52 // |
52 | 53 |
53 WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event) { | 54 WebKit::WebMouseEvent MakeWebMouseEvent(aura::MouseEvent* event, |
55 aura::Window* window) { | |
54 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
55 // Construct an untranslated event from the platform event data. | 57 // Construct an untranslated event from the platform event data. |
56 WebKit::WebMouseEvent webkit_event = | 58 WebKit::WebMouseEvent webkit_event = |
57 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); | 59 MakeUntranslatedWebMouseEventFromNativeEvent(event->native_event()); |
58 #else | 60 #else |
59 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event); | 61 WebKit::WebMouseEvent webkit_event = MakeWebMouseEventFromAuraEvent(event); |
60 #endif | 62 #endif |
61 | 63 |
62 // Replace the event's coordinate fields with translated position data from | 64 // Replace the event's coordinate fields with translated position data from |
63 // |event|. | 65 // |event|. |
64 webkit_event.windowX = webkit_event.x = event->x(); | 66 webkit_event.windowX = webkit_event.x = event->x(); |
65 webkit_event.windowY = webkit_event.y = event->y(); | 67 webkit_event.windowY = webkit_event.y = event->y(); |
66 | 68 |
67 // TODO(beng): map these to screen coordinates. | 69 const gfx::Point screen_point = |
sadrul
2011/10/27 22:47:20
For the screen-location, it would be nice if we ca
Ben Goodger (Google)
2011/10/27 22:56:11
We can assume "screen" to mean "client position wi
Daniel Erat
2011/10/28 00:53:13
Done.
| |
68 webkit_event.globalX = event->x(); | 70 window->GetPointInScreenCoordinates(event->location()); |
69 webkit_event.globalY = event->y(); | 71 webkit_event.globalX = screen_point.x(); |
72 webkit_event.globalY = screen_point.y(); | |
70 | 73 |
71 return webkit_event; | 74 return webkit_event; |
72 } | 75 } |
73 | 76 |
74 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::MouseEvent* event) { | 77 WebKit::WebMouseWheelEvent MakeWebMouseWheelEvent(aura::MouseEvent* event, |
78 aura::Window* window) { | |
75 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
76 // Construct an untranslated event from the platform event data. | 80 // Construct an untranslated event from the platform event data. |
77 WebKit::WebMouseWheelEvent webkit_event = | 81 WebKit::WebMouseWheelEvent webkit_event = |
78 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event()); | 82 MakeUntranslatedWebMouseWheelEventFromNativeEvent(event->native_event()); |
79 #else | 83 #else |
80 WebKit::WebMouseWheelEvent webkit_event = | 84 WebKit::WebMouseWheelEvent webkit_event = |
81 MakeWebMouseWheelEventFromAuraEvent(event); | 85 MakeWebMouseWheelEventFromAuraEvent(event); |
82 #endif | 86 #endif |
83 | 87 |
84 // Replace the event's coordinate fields with translated position data from | 88 // Replace the event's coordinate fields with translated position data from |
85 // |event|. | 89 // |event|. |
86 webkit_event.windowX = webkit_event.x = event->x(); | 90 webkit_event.windowX = webkit_event.x = event->x(); |
87 webkit_event.windowY = webkit_event.y = event->y(); | 91 webkit_event.windowY = webkit_event.y = event->y(); |
88 | 92 |
89 // TODO(beng): map these to screen coordinates. | 93 const gfx::Point screen_point = |
90 webkit_event.globalX = event->x(); | 94 window->GetPointInScreenCoordinates(event->location()); |
91 webkit_event.globalY = event->y(); | 95 webkit_event.globalX = screen_point.x(); |
96 webkit_event.globalY = screen_point.y(); | |
92 | 97 |
93 return webkit_event; | 98 return webkit_event; |
94 } | 99 } |
95 | 100 |
96 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event) { | 101 WebKit::WebKeyboardEvent MakeWebKeyboardEvent(aura::KeyEvent* event) { |
97 // Windows can figure out whether or not to construct a RawKeyDown or a Char | 102 // Windows can figure out whether or not to construct a RawKeyDown or a Char |
98 // WebInputEvent based on the type of message carried in | 103 // WebInputEvent based on the type of message carried in |
99 // event->native_event(). X11 is not so fortunate, there is no separate | 104 // event->native_event(). X11 is not so fortunate, there is no separate |
100 // translated event type, so DesktopHostLinux sends an extra KeyEvent with | 105 // translated event type, so DesktopHostLinux sends an extra KeyEvent with |
101 // is_char() == true. We need to pass the aura::KeyEvent to the X11 function | 106 // is_char() == true. We need to pass the aura::KeyEvent to the X11 function |
102 // to detect this case so the right event type can be constructed. | 107 // to detect this case so the right event type can be constructed. |
103 #if defined(OS_WIN) | 108 #if defined(OS_WIN) |
104 // Key events require no translation by the aura system. | 109 // Key events require no translation by the aura system. |
105 return MakeWebKeyboardEventFromNativeEvent(event->native_event()); | 110 return MakeWebKeyboardEventFromNativeEvent(event->native_event()); |
106 #else | 111 #else |
107 return MakeWebKeyboardEventFromAuraEvent(event); | 112 return MakeWebKeyboardEventFromAuraEvent(event); |
108 #endif | 113 #endif |
109 } | 114 } |
110 | 115 |
111 WebKit::WebTouchPoint* UpdateWebTouchEvent(aura::TouchEvent* event, | 116 WebKit::WebTouchPoint* UpdateWebTouchEvent(aura::TouchEvent* event, |
112 WebKit::WebTouchEvent* web_event) { | 117 WebKit::WebTouchEvent* web_event) { |
113 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
114 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event); | 119 return UpdateWebTouchEventFromNativeEvent(event->native_event(), web_event); |
115 #else | 120 #else |
116 return UpdateWebTouchEventFromAuraEvent(event, web_event); | 121 return UpdateWebTouchEventFromAuraEvent(event, web_event); |
117 #endif | 122 #endif |
118 } | 123 } |
119 | 124 |
120 } // namespace content | 125 } // namespace content |
OLD | NEW |