| 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/ui_events_helper.h" | 5 #include "content/browser/renderer_host/ui_events_helper.h" |
| 6 | 6 |
| 7 #include "content/common/input/web_touch_event_traits.h" | 7 #include "content/common/input/web_touch_event_traits.h" |
| 8 #include "third_party/WebKit/public/web/WebInputEvent.h" | 8 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return ui::ET_TOUCH_MOVED; | 49 return ui::ET_TOUCH_MOVED; |
| 50 | 50 |
| 51 case blink::WebTouchPoint::StateCancelled: | 51 case blink::WebTouchPoint::StateCancelled: |
| 52 return ui::ET_TOUCH_CANCELLED; | 52 return ui::ET_TOUCH_CANCELLED; |
| 53 | 53 |
| 54 default: | 54 default: |
| 55 return ui::ET_UNKNOWN; | 55 return ui::ET_UNKNOWN; |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 blink::WebTouchPoint::State TouchPointStateFromEvent( | |
| 60 const ui::TouchEvent& event) { | |
| 61 switch (event.type()) { | |
| 62 case ui::ET_TOUCH_PRESSED: | |
| 63 return blink::WebTouchPoint::StatePressed; | |
| 64 case ui::ET_TOUCH_RELEASED: | |
| 65 return blink::WebTouchPoint::StateReleased; | |
| 66 case ui::ET_TOUCH_MOVED: | |
| 67 return blink::WebTouchPoint::StateMoved; | |
| 68 case ui::ET_TOUCH_CANCELLED: | |
| 69 return blink::WebTouchPoint::StateCancelled; | |
| 70 default: | |
| 71 return blink::WebTouchPoint::StateUndefined; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 blink::WebInputEvent::Type TouchEventTypeFromEvent( | |
| 76 const ui::TouchEvent& event) { | |
| 77 switch (event.type()) { | |
| 78 case ui::ET_TOUCH_PRESSED: | |
| 79 return blink::WebInputEvent::TouchStart; | |
| 80 case ui::ET_TOUCH_RELEASED: | |
| 81 return blink::WebInputEvent::TouchEnd; | |
| 82 case ui::ET_TOUCH_MOVED: | |
| 83 return blink::WebInputEvent::TouchMove; | |
| 84 case ui::ET_TOUCH_CANCELLED: | |
| 85 return blink::WebInputEvent::TouchCancel; | |
| 86 default: | |
| 87 return blink::WebInputEvent::Undefined; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 } // namespace | 59 } // namespace |
| 92 | 60 |
| 93 namespace content { | 61 namespace content { |
| 94 | 62 |
| 95 bool MakeUITouchEventsFromWebTouchEvents( | 63 bool MakeUITouchEventsFromWebTouchEvents( |
| 96 const TouchEventWithLatencyInfo& touch_with_latency, | 64 const TouchEventWithLatencyInfo& touch_with_latency, |
| 97 ScopedVector<ui::TouchEvent>* list, | 65 ScopedVector<ui::TouchEvent>* list, |
| 98 TouchEventCoordinateSystem coordinate_system) { | 66 TouchEventCoordinateSystem coordinate_system) { |
| 99 const blink::WebTouchEvent& touch = touch_with_latency.event; | 67 const blink::WebTouchEvent& touch = touch_with_latency.event; |
| 100 ui::EventType type = ui::ET_UNKNOWN; | 68 ui::EventType type = ui::ET_UNKNOWN; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 modifiers |= blink::WebInputEvent::MiddleButtonDown; | 228 modifiers |= blink::WebInputEvent::MiddleButtonDown; |
| 261 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) | 229 if (flags & ui::EF_RIGHT_MOUSE_BUTTON) |
| 262 modifiers |= blink::WebInputEvent::RightButtonDown; | 230 modifiers |= blink::WebInputEvent::RightButtonDown; |
| 263 if (flags & ui::EF_CAPS_LOCK_DOWN) | 231 if (flags & ui::EF_CAPS_LOCK_DOWN) |
| 264 modifiers |= blink::WebInputEvent::CapsLockOn; | 232 modifiers |= blink::WebInputEvent::CapsLockOn; |
| 265 if (flags & ui::EF_IS_REPEAT) | 233 if (flags & ui::EF_IS_REPEAT) |
| 266 modifiers |= blink::WebInputEvent::IsAutoRepeat; | 234 modifiers |= blink::WebInputEvent::IsAutoRepeat; |
| 267 return modifiers; | 235 return modifiers; |
| 268 } | 236 } |
| 269 | 237 |
| 270 blink::WebTouchPoint* UpdateWebTouchEventFromUIEvent( | |
| 271 const ui::TouchEvent& event, | |
| 272 blink::WebTouchEvent* web_event) { | |
| 273 blink::WebTouchPoint* point = NULL; | |
| 274 switch (event.type()) { | |
| 275 case ui::ET_TOUCH_PRESSED: | |
| 276 // Add a new touch point. | |
| 277 if (web_event->touchesLength < blink::WebTouchEvent::touchesLengthCap) { | |
| 278 point = &web_event->touches[web_event->touchesLength++]; | |
| 279 point->id = event.touch_id(); | |
| 280 } | |
| 281 break; | |
| 282 case ui::ET_TOUCH_RELEASED: | |
| 283 case ui::ET_TOUCH_CANCELLED: | |
| 284 case ui::ET_TOUCH_MOVED: { | |
| 285 // The touch point should have been added to the event from an earlier | |
| 286 // _PRESSED event. So find that. | |
| 287 // At the moment, only a maximum of 4 touch-points are allowed. So a | |
| 288 // simple loop should be sufficient. | |
| 289 for (unsigned i = 0; i < web_event->touchesLength; ++i) { | |
| 290 point = web_event->touches + i; | |
| 291 if (point->id == event.touch_id()) | |
| 292 break; | |
| 293 point = NULL; | |
| 294 } | |
| 295 break; | |
| 296 } | |
| 297 default: | |
| 298 DLOG(WARNING) << "Unknown touch event " << event.type(); | |
| 299 break; | |
| 300 } | |
| 301 | |
| 302 if (!point) | |
| 303 return NULL; | |
| 304 | |
| 305 // The spec requires the radii values to be positive (and 1 when unknown). | |
| 306 point->radiusX = std::max(1.f, event.radius_x()); | |
| 307 point->radiusY = std::max(1.f, event.radius_y()); | |
| 308 point->rotationAngle = event.rotation_angle(); | |
| 309 point->force = event.force(); | |
| 310 | |
| 311 // Update the location and state of the point. | |
| 312 point->state = TouchPointStateFromEvent(event); | |
| 313 point->position.x = event.x(); | |
| 314 point->position.y = event.y(); | |
| 315 | |
| 316 const gfx::PointF& root_point = event.root_location_f(); | |
| 317 point->screenPosition.x = root_point.x(); | |
| 318 point->screenPosition.y = root_point.y(); | |
| 319 | |
| 320 // Mark the rest of the points as stationary. | |
| 321 for (unsigned i = 0; i < web_event->touchesLength; ++i) { | |
| 322 blink::WebTouchPoint* iter = web_event->touches + i; | |
| 323 if (iter != point) | |
| 324 iter->state = blink::WebTouchPoint::StateStationary; | |
| 325 } | |
| 326 | |
| 327 // Update the type of the touch event. | |
| 328 WebTouchEventTraits::ResetType(TouchEventTypeFromEvent(event), | |
| 329 event.time_stamp().InSecondsF(), | |
| 330 web_event); | |
| 331 web_event->modifiers = EventFlagsToWebEventModifiers(event.flags()); | |
| 332 | |
| 333 return point; | |
| 334 } | |
| 335 | |
| 336 } // namespace content | 238 } // namespace content |
| OLD | NEW |