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 // Portions based heavily on: | 5 // Portions based heavily on: |
6 // third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.cpp | 6 // third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFactory.cpp |
7 // | 7 // |
8 /* | 8 /* |
9 * Copyright (C) 2006-2011 Google Inc. All rights reserved. | 9 * Copyright (C) 2006-2011 Google Inc. All rights reserved. |
10 * | 10 * |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 namespace content { | 52 namespace content { |
53 | 53 |
54 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have | 54 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have |
55 // to do the work here ourselves. | 55 // to do the work here ourselves. |
56 | 56 |
57 namespace { | 57 namespace { |
58 | 58 |
59 // This matches Firefox behavior. | 59 // This matches Firefox behavior. |
60 const int kPixelsPerTick = 53; | 60 const int kPixelsPerTick = 53; |
61 | 61 |
62 int EventFlagsToWebEventModifiers(int flags) { | |
63 int modifiers = 0; | |
64 if (flags & ui::EF_SHIFT_DOWN) | |
65 modifiers |= WebKit::WebInputEvent::ShiftKey; | |
66 if (flags & ui::EF_CONTROL_DOWN) | |
67 modifiers |= WebKit::WebInputEvent::ControlKey; | |
68 if (flags & ui::EF_ALT_DOWN) | |
69 modifiers |= WebKit::WebInputEvent::AltKey; | |
70 // TODO(beng): MetaKey/META_MASK | |
71 if (flags & ui::EF_LEFT_MOUSE_BUTTON) | |
72 modifiers |= WebKit::WebInputEvent::LeftButtonDown; | |
73 if (flags & ui::EF_MIDDLE_MOUSE_BUTTON) | |
74 modifiers |= WebKit::WebInputEvent::MiddleButtonDown; | |
75 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) | |
76 modifiers |= WebKit::WebInputEvent::RightButtonDown; | |
77 if (flags & ui::EF_CAPS_LOCK_DOWN) | |
78 modifiers |= WebKit::WebInputEvent::CapsLockOn; | |
79 return modifiers; | |
80 } | |
81 | |
82 int XKeyEventToWindowsKeyCode(XKeyEvent* event) { | 62 int XKeyEventToWindowsKeyCode(XKeyEvent* event) { |
83 int windows_key_code = | 63 int windows_key_code = |
84 ui::KeyboardCodeFromXKeyEvent(reinterpret_cast<XEvent*>(event)); | 64 ui::KeyboardCodeFromXKeyEvent(reinterpret_cast<XEvent*>(event)); |
85 if (windows_key_code == ui::VKEY_SHIFT || | 65 if (windows_key_code == ui::VKEY_SHIFT || |
86 windows_key_code == ui::VKEY_CONTROL || | 66 windows_key_code == ui::VKEY_CONTROL || |
87 windows_key_code == ui::VKEY_MENU) { | 67 windows_key_code == ui::VKEY_MENU) { |
88 // To support DOM3 'location' attribute, we need to lookup an X KeySym and | 68 // To support DOM3 'location' attribute, we need to lookup an X KeySym and |
89 // set ui::VKEY_[LR]XXX instead of ui::VKEY_XXX. | 69 // set ui::VKEY_[LR]XXX instead of ui::VKEY_XXX. |
90 KeySym keysym = XK_VoidSymbol; | 70 KeySym keysym = XK_VoidSymbol; |
91 XLookupString(event, NULL, 0, &keysym, NULL); | 71 XLookupString(event, NULL, 0, &keysym, NULL); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return WebKit::WebInputEvent::TouchMove; | 162 return WebKit::WebInputEvent::TouchMove; |
183 case ui::ET_TOUCH_CANCELLED: | 163 case ui::ET_TOUCH_CANCELLED: |
184 return WebKit::WebInputEvent::TouchCancel; | 164 return WebKit::WebInputEvent::TouchCancel; |
185 default: | 165 default: |
186 return WebKit::WebInputEvent::Undefined; | 166 return WebKit::WebInputEvent::Undefined; |
187 } | 167 } |
188 } | 168 } |
189 | 169 |
190 } // namespace | 170 } // namespace |
191 | 171 |
192 WebKit::WebMouseEvent MakeWebMouseEventFromAuraEvent(ui::MouseEvent* event) { | |
193 WebKit::WebMouseEvent webkit_event; | |
194 | |
195 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); | |
196 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); | |
197 | |
198 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; | |
199 if (event->flags() & ui::EF_LEFT_MOUSE_BUTTON) | |
200 webkit_event.button = WebKit::WebMouseEvent::ButtonLeft; | |
201 if (event->flags() & ui::EF_MIDDLE_MOUSE_BUTTON) | |
202 webkit_event.button = WebKit::WebMouseEvent::ButtonMiddle; | |
203 if (event->flags() & ui::EF_RIGHT_MOUSE_BUTTON) | |
204 webkit_event.button = WebKit::WebMouseEvent::ButtonRight; | |
205 | |
206 switch (event->type()) { | |
207 case ui::ET_MOUSE_PRESSED: | |
208 webkit_event.type = WebKit::WebInputEvent::MouseDown; | |
209 webkit_event.clickCount = event->GetClickCount(); | |
210 break; | |
211 case ui::ET_MOUSE_RELEASED: | |
212 webkit_event.type = WebKit::WebInputEvent::MouseUp; | |
213 break; | |
214 case ui::ET_MOUSE_ENTERED: | |
215 case ui::ET_MOUSE_EXITED: | |
216 case ui::ET_MOUSE_MOVED: | |
217 case ui::ET_MOUSE_DRAGGED: | |
218 webkit_event.type = WebKit::WebInputEvent::MouseMove; | |
219 break; | |
220 default: | |
221 NOTIMPLEMENTED() << "Received unexpected event: " << event->type(); | |
222 break; | |
223 } | |
224 | |
225 return webkit_event; | |
226 } | |
227 | |
228 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( | 172 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( |
229 ui::MouseWheelEvent* event) { | 173 ui::MouseWheelEvent* event) { |
230 WebKit::WebMouseWheelEvent webkit_event; | 174 WebKit::WebMouseWheelEvent webkit_event; |
231 | 175 |
232 webkit_event.type = WebKit::WebInputEvent::MouseWheel; | 176 webkit_event.type = WebKit::WebInputEvent::MouseWheel; |
233 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; | 177 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; |
234 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); | 178 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); |
235 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); | 179 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); |
236 webkit_event.deltaY = event->offset(); | 180 webkit_event.deltaY = event->offset(); |
237 webkit_event.wheelTicksY = webkit_event.deltaY / kPixelsPerTick; | 181 webkit_event.wheelTicksY = webkit_event.deltaY / kPixelsPerTick; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 | 430 |
487 // Update the type of the touch event. | 431 // Update the type of the touch event. |
488 web_event->type = TouchEventTypeFromEvent(event); | 432 web_event->type = TouchEventTypeFromEvent(event); |
489 web_event->timeStampSeconds = event->time_stamp().InSecondsF(); | 433 web_event->timeStampSeconds = event->time_stamp().InSecondsF(); |
490 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags()); | 434 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags()); |
491 | 435 |
492 return point; | 436 return point; |
493 } | 437 } |
494 | 438 |
495 } // namespace content | 439 } // namespace content |
OLD | NEW |