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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 #include "content/browser/renderer_host/web_input_event_aura.h" | 38 #include "content/browser/renderer_host/web_input_event_aura.h" |
39 | 39 |
40 #include <X11/keysym.h> | 40 #include <X11/keysym.h> |
41 #include <X11/Xlib.h> | 41 #include <X11/Xlib.h> |
42 #include <X11/Xutil.h> | 42 #include <X11/Xutil.h> |
43 #include <cstdlib> | 43 #include <cstdlib> |
44 | 44 |
45 #include "base/event_types.h" | 45 #include "base/event_types.h" |
46 #include "base/logging.h" | 46 #include "base/logging.h" |
| 47 #include "content/browser/renderer_host/ui_events_helper.h" |
47 #include "ui/base/events/event.h" | 48 #include "ui/base/events/event.h" |
48 #include "ui/base/events/event_constants.h" | 49 #include "ui/base/events/event_constants.h" |
49 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 50 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
50 #include "ui/base/keycodes/keyboard_codes.h" | 51 #include "ui/base/keycodes/keyboard_codes.h" |
51 | 52 |
52 namespace content { | 53 namespace content { |
53 | 54 |
54 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have | 55 // chromium WebKit does not provide a WebInputEventFactory for X11, so we have |
55 // to do the work here ourselves. | 56 // to do the work here ourselves. |
56 | 57 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 case ui::VKEY_RETURN: | 129 case ui::VKEY_RETURN: |
129 return 0x0A; | 130 return 0x0A; |
130 // Returns 0 for all other keys to avoid inputting unexpected chars. | 131 // Returns 0 for all other keys to avoid inputting unexpected chars. |
131 default: | 132 default: |
132 break; | 133 break; |
133 } | 134 } |
134 } | 135 } |
135 return 0; | 136 return 0; |
136 } | 137 } |
137 | 138 |
138 WebKit::WebTouchPoint::State TouchPointStateFromEvent( | |
139 const ui::TouchEvent* event) { | |
140 switch (event->type()) { | |
141 case ui::ET_TOUCH_PRESSED: | |
142 return WebKit::WebTouchPoint::StatePressed; | |
143 case ui::ET_TOUCH_RELEASED: | |
144 return WebKit::WebTouchPoint::StateReleased; | |
145 case ui::ET_TOUCH_MOVED: | |
146 return WebKit::WebTouchPoint::StateMoved; | |
147 case ui::ET_TOUCH_CANCELLED: | |
148 return WebKit::WebTouchPoint::StateCancelled; | |
149 default: | |
150 return WebKit::WebTouchPoint::StateUndefined; | |
151 } | |
152 } | |
153 | |
154 WebKit::WebInputEvent::Type TouchEventTypeFromEvent( | |
155 const ui::TouchEvent* event) { | |
156 switch (event->type()) { | |
157 case ui::ET_TOUCH_PRESSED: | |
158 return WebKit::WebInputEvent::TouchStart; | |
159 case ui::ET_TOUCH_RELEASED: | |
160 return WebKit::WebInputEvent::TouchEnd; | |
161 case ui::ET_TOUCH_MOVED: | |
162 return WebKit::WebInputEvent::TouchMove; | |
163 case ui::ET_TOUCH_CANCELLED: | |
164 return WebKit::WebInputEvent::TouchCancel; | |
165 default: | |
166 return WebKit::WebInputEvent::Undefined; | |
167 } | |
168 } | |
169 | |
170 } // namespace | 139 } // namespace |
171 | 140 |
172 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( | 141 WebKit::WebMouseWheelEvent MakeWebMouseWheelEventFromAuraEvent( |
173 ui::MouseWheelEvent* event) { | 142 ui::MouseWheelEvent* event) { |
174 WebKit::WebMouseWheelEvent webkit_event; | 143 WebKit::WebMouseWheelEvent webkit_event; |
175 | 144 |
176 webkit_event.type = WebKit::WebInputEvent::MouseWheel; | 145 webkit_event.type = WebKit::WebInputEvent::MouseWheel; |
177 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; | 146 webkit_event.button = WebKit::WebMouseEvent::ButtonNone; |
178 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); | 147 webkit_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); |
179 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); | 148 webkit_event.timeStampSeconds = event->time_stamp().InSecondsF(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 default: | 331 default: |
363 NOTREACHED() << "Unknown gesture type: " << event->type(); | 332 NOTREACHED() << "Unknown gesture type: " << event->type(); |
364 } | 333 } |
365 | 334 |
366 gesture_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); | 335 gesture_event.modifiers = EventFlagsToWebEventModifiers(event->flags()); |
367 gesture_event.timeStampSeconds = event->time_stamp().InSecondsF(); | 336 gesture_event.timeStampSeconds = event->time_stamp().InSecondsF(); |
368 | 337 |
369 return gesture_event; | 338 return gesture_event; |
370 } | 339 } |
371 | 340 |
372 WebKit::WebTouchPoint* UpdateWebTouchEventFromAuraEvent( | |
373 ui::TouchEvent* event, WebKit::WebTouchEvent* web_event) { | |
374 WebKit::WebTouchPoint* point = NULL; | |
375 switch (event->type()) { | |
376 case ui::ET_TOUCH_PRESSED: | |
377 // Add a new touch point. | |
378 if (web_event->touchesLength < WebKit::WebTouchEvent::touchesLengthCap) { | |
379 point = &web_event->touches[web_event->touchesLength++]; | |
380 point->id = event->touch_id(); | |
381 } | |
382 break; | |
383 case ui::ET_TOUCH_RELEASED: | |
384 case ui::ET_TOUCH_CANCELLED: | |
385 case ui::ET_TOUCH_MOVED: { | |
386 // The touch point should have been added to the event from an earlier | |
387 // _PRESSED event. So find that. | |
388 // At the moment, only a maximum of 4 touch-points are allowed. So a | |
389 // simple loop should be sufficient. | |
390 for (unsigned i = 0; i < web_event->touchesLength; ++i) { | |
391 point = web_event->touches + i; | |
392 if (point->id == event->touch_id()) | |
393 break; | |
394 point = NULL; | |
395 } | |
396 break; | |
397 } | |
398 default: | |
399 DLOG(WARNING) << "Unknown touch event " << event->type(); | |
400 break; | |
401 } | |
402 | |
403 if (!point) | |
404 return NULL; | |
405 | |
406 // The spec requires the radii values to be positive (and 1 when unknown). | |
407 point->radiusX = std::max(1.f, event->radius_x()); | |
408 point->radiusY = std::max(1.f, event->radius_y()); | |
409 point->rotationAngle = event->rotation_angle(); | |
410 point->force = event->force(); | |
411 | |
412 // Update the location and state of the point. | |
413 point->state = TouchPointStateFromEvent(event); | |
414 if (point->state == WebKit::WebTouchPoint::StateMoved) { | |
415 // It is possible for badly written touch drivers to emit Move events even | |
416 // when the touch location hasn't changed. In such cases, consume the event | |
417 // and pretend nothing happened. | |
418 if (point->position.x == event->x() && point->position.y == event->y()) | |
419 return NULL; | |
420 } | |
421 point->position.x = event->x(); | |
422 point->position.y = event->y(); | |
423 | |
424 const gfx::Point root_point = event->root_location(); | |
425 point->screenPosition.x = root_point.x(); | |
426 point->screenPosition.y = root_point.y(); | |
427 | |
428 // Mark the rest of the points as stationary. | |
429 for (unsigned i = 0; i < web_event->touchesLength; ++i) { | |
430 WebKit::WebTouchPoint* iter = web_event->touches + i; | |
431 if (iter != point) | |
432 iter->state = WebKit::WebTouchPoint::StateStationary; | |
433 } | |
434 | |
435 // Update the type of the touch event. | |
436 web_event->type = TouchEventTypeFromEvent(event); | |
437 web_event->timeStampSeconds = event->time_stamp().InSecondsF(); | |
438 web_event->modifiers = EventFlagsToWebEventModifiers(event->flags()); | |
439 | |
440 return point; | |
441 } | |
442 | |
443 } // namespace content | 341 } // namespace content |
OLD | NEW |