Chromium Code Reviews| 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/renderer/pepper/event_conversion.h" | 5 #include "content/renderer/pepper/event_conversion.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 InputEventData result = GetEventWithCommonFieldsAndType(event); | 208 InputEventData result = GetEventWithCommonFieldsAndType(event); |
| 209 result.event_modifiers = mouse_wheel_event.modifiers; | 209 result.event_modifiers = mouse_wheel_event.modifiers; |
| 210 result.wheel_delta.x = mouse_wheel_event.deltaX; | 210 result.wheel_delta.x = mouse_wheel_event.deltaX; |
| 211 result.wheel_delta.y = mouse_wheel_event.deltaY; | 211 result.wheel_delta.y = mouse_wheel_event.deltaY; |
| 212 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; | 212 result.wheel_ticks.x = mouse_wheel_event.wheelTicksX; |
| 213 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; | 213 result.wheel_ticks.y = mouse_wheel_event.wheelTicksY; |
| 214 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; | 214 result.wheel_scroll_by_page = !!mouse_wheel_event.scrollByPage; |
| 215 result_events->push_back(result); | 215 result_events->push_back(result); |
| 216 } | 216 } |
| 217 | 217 |
| 218 enum IncludedTouchPointTypes { | |
| 219 ACTIVE, // Only pointers that are currently down. | |
| 220 CHANGED // Only pointers that have changed since the previous event. | |
| 221 }; | |
| 218 void SetPPTouchPoints(const WebTouchPoint* touches, | 222 void SetPPTouchPoints(const WebTouchPoint* touches, |
| 219 uint32_t touches_length, | 223 uint32_t touches_length, |
| 224 IncludedTouchPointTypes included_types, | |
| 220 std::vector<PP_TouchPoint>* result) { | 225 std::vector<PP_TouchPoint>* result) { |
| 221 for (uint32_t i = 0; i < touches_length; i++) { | 226 for (uint32_t i = 0; i < touches_length; i++) { |
| 222 const WebTouchPoint& touch_point = touches[i]; | 227 const WebTouchPoint& touch_point = touches[i]; |
| 228 if (included_types == ACTIVE && | |
| 229 (touch_point.state == WebTouchPoint::StateReleased || | |
| 230 touch_point.state == WebTouchPoint::StateCancelled)) { | |
| 231 continue; | |
| 232 } | |
| 233 if (included_types == CHANGED && | |
| 234 (touch_point.state == WebTouchPoint::StateUndefined || | |
| 235 touch_point.state == WebTouchPoint::StateStationary)) { | |
| 236 continue; | |
| 237 } | |
| 223 PP_TouchPoint pp_pt; | 238 PP_TouchPoint pp_pt; |
| 224 pp_pt.id = touch_point.id; | 239 pp_pt.id = touch_point.id; |
| 225 pp_pt.position.x = touch_point.position.x; | 240 pp_pt.position.x = touch_point.position.x; |
| 226 pp_pt.position.y = touch_point.position.y; | 241 pp_pt.position.y = touch_point.position.y; |
| 227 pp_pt.radius.x = touch_point.radiusX; | 242 pp_pt.radius.x = touch_point.radiusX; |
| 228 pp_pt.radius.y = touch_point.radiusY; | 243 pp_pt.radius.y = touch_point.radiusY; |
| 229 pp_pt.rotation_angle = touch_point.rotationAngle; | 244 pp_pt.rotation_angle = touch_point.rotationAngle; |
| 230 pp_pt.pressure = touch_point.force; | 245 pp_pt.pressure = touch_point.force; |
| 231 result->push_back(pp_pt); | 246 result->push_back(pp_pt); |
| 232 } | 247 } |
| 233 } | 248 } |
| 234 | 249 |
| 235 void AppendTouchEvent(const WebInputEvent& event, | 250 void AppendTouchEvent(const WebInputEvent& event, |
| 236 std::vector<InputEventData>* result_events) { | 251 std::vector<InputEventData>* result_events) { |
| 237 const WebTouchEvent& touch_event = | 252 const WebTouchEvent& touch_event = |
| 238 reinterpret_cast<const WebTouchEvent&>(event); | 253 reinterpret_cast<const WebTouchEvent&>(event); |
| 239 | 254 |
| 240 InputEventData result = GetEventWithCommonFieldsAndType(event); | 255 InputEventData result = GetEventWithCommonFieldsAndType(event); |
| 241 SetPPTouchPoints( | 256 SetPPTouchPoints( |
| 242 touch_event.touches, touch_event.touchesLength, &result.touches); | 257 touch_event.touches, touch_event.touchesLength, ACTIVE, &result.touches); |
| 243 SetPPTouchPoints(touch_event.changedTouches, | 258 SetPPTouchPoints(touch_event.touches, |
| 244 touch_event.changedTouchesLength, | 259 touch_event.touchesLength, |
| 260 CHANGED, | |
| 245 &result.changed_touches); | 261 &result.changed_touches); |
| 246 SetPPTouchPoints(touch_event.targetTouches, | |
| 247 touch_event.targetTouchesLength, | |
| 248 &result.target_touches); | |
| 249 | 262 |
| 250 result_events->push_back(result); | 263 result_events->push_back(result); |
| 251 } | 264 } |
| 252 | 265 |
| 253 // Structure used to map touch point id's to touch states. Since the pepper | 266 // Structure used to map touch point id's to touch states. Since the pepper |
| 254 // touch event structure does not have states for individual touch points and | 267 // touch event structure does not have states for individual touch points and |
| 255 // instead relies on the event type in combination with the set of touch lists, | 268 // instead relies on the event type in combination with the set of touch lists, |
| 256 // we have to set the state for the changed touches to be the same as the event | 269 // we have to set the state for the changed touches to be the same as the event |
| 257 // type and all others to be 'stationary.' | 270 // type and all others to be 'stationary.' |
| 258 typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap; | 271 typedef std::map<uint32_t, WebTouchPoint::State> TouchStateMap; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 default: | 325 default: |
| 313 NOTREACHED(); | 326 NOTREACHED(); |
| 314 } | 327 } |
| 315 WebTouchEventTraits::ResetType( | 328 WebTouchEventTraits::ResetType( |
| 316 type, PPTimeTicksToEventTime(event.event_time_stamp), web_event); | 329 type, PPTimeTicksToEventTime(event.event_time_stamp), web_event); |
| 317 | 330 |
| 318 TouchStateMap states_map; | 331 TouchStateMap states_map; |
| 319 for (uint32_t i = 0; i < event.changed_touches.size(); i++) | 332 for (uint32_t i = 0; i < event.changed_touches.size(); i++) |
| 320 states_map[event.changed_touches[i].id] = state; | 333 states_map[event.changed_touches[i].id] = state; |
| 321 | 334 |
| 322 SetWebTouchPoints(event.changed_touches, | |
| 323 states_map, | |
| 324 web_event->changedTouches, | |
| 325 &web_event->changedTouchesLength); | |
| 326 | |
| 327 SetWebTouchPoints( | 335 SetWebTouchPoints( |
| 328 event.touches, states_map, web_event->touches, &web_event->touchesLength); | 336 event.touches, states_map, web_event->touches, &web_event->touchesLength); |
|
bokan
2014/09/09 20:17:38
Where do the InputEventData events come from? Will
jdduke (slow)
2014/09/09 20:52:24
We're not sure, so we have the branch below. I thi
| |
| 329 | 337 |
| 330 SetWebTouchPoints(event.target_touches, | |
| 331 states_map, | |
| 332 web_event->targetTouches, | |
| 333 &web_event->targetTouchesLength); | |
| 334 | |
| 335 if (web_event->type == WebInputEvent::TouchEnd || | 338 if (web_event->type == WebInputEvent::TouchEnd || |
| 336 web_event->type == WebInputEvent::TouchCancel) { | 339 web_event->type == WebInputEvent::TouchCancel) { |
| 337 SetWebTouchPoints(event.changed_touches, | 340 SetWebTouchPoints(event.changed_touches, |
|
bokan
2014/09/09 20:17:38
Same question again, are we sure ToucheEnd/Cancel
jdduke (slow)
2014/09/09 20:52:24
Ah, you're right, I thought SetWebTouchPoints chec
| |
| 338 states_map, | 341 states_map, |
| 339 web_event->touches, | 342 web_event->touches, |
| 340 &web_event->touchesLength); | 343 &web_event->touchesLength); |
| 341 SetWebTouchPoints(event.changed_touches, | |
| 342 states_map, | |
| 343 web_event->targetTouches, | |
| 344 &web_event->targetTouchesLength); | |
| 345 } | 344 } |
| 346 | 345 |
| 347 return web_event; | 346 return web_event; |
| 348 } | 347 } |
| 349 | 348 |
| 350 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { | 349 WebKeyboardEvent* BuildKeyEvent(const InputEventData& event) { |
| 351 WebKeyboardEvent* key_event = new WebKeyboardEvent(); | 350 WebKeyboardEvent* key_event = new WebKeyboardEvent(); |
| 352 switch (event.event_type) { | 351 switch (event.event_type) { |
| 353 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: | 352 case PP_INPUTEVENT_TYPE_RAWKEYDOWN: |
| 354 key_event->type = WebInputEvent::RawKeyDown; | 353 key_event->type = WebInputEvent::RawKeyDown; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 case WebInputEvent::TouchStart: | 729 case WebInputEvent::TouchStart: |
| 731 return PP_INPUTEVENT_CLASS_TOUCH; | 730 return PP_INPUTEVENT_CLASS_TOUCH; |
| 732 case WebInputEvent::Undefined: | 731 case WebInputEvent::Undefined: |
| 733 default: | 732 default: |
| 734 CHECK(WebInputEvent::isGestureEventType(type)); | 733 CHECK(WebInputEvent::isGestureEventType(type)); |
| 735 return PP_InputEvent_Class(0); | 734 return PP_InputEvent_Class(0); |
| 736 } | 735 } |
| 737 } | 736 } |
| 738 | 737 |
| 739 } // namespace content | 738 } // namespace content |
| OLD | NEW |