Index: content/renderer/browser_plugin/browser_plugin.cc |
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc |
index d7ba64b88e5514c9cb2d25e06f651a7e6968d74a..71dc8c2d70b378d2fa6c4925e6085752fb3671de 100644 |
--- a/content/renderer/browser_plugin/browser_plugin.cc |
+++ b/content/renderer/browser_plugin/browser_plugin.cc |
@@ -582,42 +582,48 @@ bool BrowserPlugin::handleInputEvent(const blink::WebInputEvent& event, |
if (blink::WebInputEvent::isTouchEventType(event.type)) { |
const blink::WebTouchEvent* orig_touch_event = |
static_cast<const blink::WebTouchEvent*>(&event); |
- |
- touch_event.reset(new blink::WebTouchEvent()); |
- memcpy(touch_event.get(), orig_touch_event, sizeof(blink::WebTouchEvent)); |
- |
- // TODO(bokan): Blink passes back a WebGestureEvent with a touches, |
- // changedTouches, and targetTouches lists; however, it doesn't set |
- // the state field on the touches which is what the RenderWidget uses |
- // to create a WebCore::TouchEvent. crbug.com/358132 tracks removing |
- // these multiple lists from WebTouchEvent since they lead to misuse |
- // like this and are functionally unused. In the mean time we'll setup |
- // the state field here manually to fix multi-touch BrowserPlugins. |
- for (size_t i = 0; i < touch_event->touchesLength; ++i) { |
- blink::WebTouchPoint& touch = touch_event->touches[i]; |
- touch.state = blink::WebTouchPoint::StateStationary; |
- for (size_t j = 0; j < touch_event->changedTouchesLength; ++j) { |
- blink::WebTouchPoint& changed_touch = touch_event->changedTouches[j]; |
- if (touch.id == changed_touch.id) { |
- touch.state = changed_touch.state; |
- break; |
+ // TODO(jdduke): Remove this branch when Blink starts forwarding |
+ // WebTouchEvents with a fully populated |touches| field. |
+ if (orig_touch_event->changedTouchesLength) { |
+ touch_event.reset(new blink::WebTouchEvent()); |
+ memcpy(touch_event.get(), orig_touch_event, sizeof(blink::WebTouchEvent)); |
+ |
+ if (touch_event->changedTouchesLength) |
bokan
2014/09/09 20:17:38
Nit: I should have done this when i was here...can
jdduke (slow)
2014/09/09 20:52:24
Done.
|
+ // TODO(bokan): Blink passes back a WebGestureEvent with touches and |
+ // changedTouches lists; however, it doesn't set the state field on the |
+ // touches which is what the RenderWidget uses to create a |
+ // WebCore::TouchEvent. crbug.com/358132 tracks removing these multiple |
+ // from WebTouchEvent since they lead to misuse like this and are |
+ // functionally unused. In the mean time we'll setup the state field |
+ // here manually to fix multi-touch BrowserPlugins. |
+ for (size_t i = 0; i < touch_event->touchesLength; ++i) { |
+ blink::WebTouchPoint& touch = touch_event->touches[i]; |
+ touch.state = blink::WebTouchPoint::StateStationary; |
+ for (size_t j = 0; j < touch_event->changedTouchesLength; ++j) { |
+ blink::WebTouchPoint& changed_touch = |
+ touch_event->changedTouches[j]; |
+ if (touch.id == changed_touch.id) { |
+ touch.state = changed_touch.state; |
+ break; |
+ } |
+ } |
} |
- } |
- } |
- // For End and Cancel, Blink gives BrowserPlugin a list of touches that |
- // are down, but the browser process expects a list of all touches. We |
- // modify these events here to match these expectations. |
- if (event.type == blink::WebInputEvent::TouchEnd || |
- event.type == blink::WebInputEvent::TouchCancel) { |
- if (touch_event->changedTouchesLength > 0) { |
- memcpy(&touch_event->touches[touch_event->touchesLength], |
- &touch_event->changedTouches, |
+ // For End and Cancel, Blink gives BrowserPlugin a list of touches that |
+ // are down, but the browser process expects a list of all touches. We |
+ // modify these events here to match these expectations. |
+ if (event.type == blink::WebInputEvent::TouchEnd || |
+ event.type == blink::WebInputEvent::TouchCancel) { |
+ if (touch_event->changedTouchesLength > 0) { |
+ memcpy( |
+ &touch_event->touches[touch_event->touchesLength], |
+ &touch_event->changedTouches, |
touch_event->changedTouchesLength * sizeof(blink::WebTouchPoint)); |
- touch_event->touchesLength += touch_event->changedTouchesLength; |
+ touch_event->touchesLength += touch_event->changedTouchesLength; |
+ } |
} |
+ modified_event = touch_event.get(); |
} |
- modified_event = touch_event.get(); |
} |
if (blink::WebInputEvent::isKeyboardEventType(event.type) && |