Chromium Code Reviews| Index: content/browser/renderer_host/input/touch_emulator.cc |
| diff --git a/content/browser/renderer_host/input/touch_emulator.cc b/content/browser/renderer_host/input/touch_emulator.cc |
| index 6e4f26bc3acff17b82cb61d04fc83a0e800f893c..5fab626165817e6a87a1b1c4e71f36afef768274 100644 |
| --- a/content/browser/renderer_host/input/touch_emulator.cc |
| +++ b/content/browser/renderer_host/input/touch_emulator.cc |
| @@ -85,7 +85,8 @@ void TouchEmulator::ResetState() { |
| last_mouse_move_timestamp_ = 0; |
| mouse_pressed_ = false; |
| shift_pressed_ = false; |
| - touch_active_ = false; |
| + emulated_stream_active_ = false; |
| + native_stream_active_ = false; |
| suppress_next_fling_cancel_ = false; |
| pinch_scale_ = 1.f; |
| pinch_gesture_active_ = false; |
| @@ -155,7 +156,7 @@ bool TouchEmulator::HandleMouseEvent(const WebMouseEvent& mouse_event) { |
| if (FillTouchEventAndPoint(mouse_event) && |
| gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) { |
| - client_->ForwardTouchEvent(touch_event_); |
| + ForwardTouchEventToClient(); |
| } |
| // Do not pass mouse events to the renderer. |
| @@ -167,7 +168,7 @@ bool TouchEmulator::HandleMouseWheelEvent(const WebMouseWheelEvent& event) { |
| return false; |
| // Send mouse wheel for easy scrolling when there is no active touch. |
| - return touch_active_; |
| + return emulated_stream_active_; |
| } |
| bool TouchEmulator::HandleKeyboardEvent(const WebKeyboardEvent& event) { |
| @@ -193,13 +194,49 @@ bool TouchEmulator::HandleKeyboardEvent(const WebKeyboardEvent& event) { |
| return false; |
| } |
| -bool TouchEmulator::HandleTouchEventAck(InputEventAckState ack_result) { |
| - const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
| - gesture_provider_.OnTouchEventAck(event_consumed); |
| - // TODO(dgozman): Disable emulation when real touch events are available. |
| +bool TouchEmulator::HandleTouchEvent(const blink::WebTouchEvent& event) { |
| + // Block native event when emulated touch stream is active. |
| + // Do not allow middle-sequence event to pass through, if start was blocked. |
| + if (native_stream_active_ || |
|
jdduke (slow)
2014/07/15 19:43:03
Hmm, maybe split out the conditional?
if (!emula
dgozman
2014/07/16 09:05:03
This code have changed now.
|
| + (!emulated_stream_active_ && |
| + WebTouchEventTraits::IsTouchSequenceStart(event))) { |
| + native_stream_active_ = true; |
| + return false; |
| + } |
| return true; |
| } |
| +void TouchEmulator::ForwardTouchEventToClient() { |
| + // Block emulated event when native touch stream is active. |
| + // Do not allow middle-sequence event to pass through, if start was blocked. |
| + if (emulated_stream_active_ || |
| + (!native_stream_active_ && |
| + WebTouchEventTraits::IsTouchSequenceStart(touch_event_))) { |
| + emulated_stream_active_ = true; |
| + client_->ForwardEmulatedTouchEvent(touch_event_); |
| + } else { |
| + // Block emulated stream and ack immediately. |
| + gesture_provider_.OnTouchEventAck(true); |
|
jdduke (slow)
2014/07/15 19:43:03
Nit: For readability maybe add something like
con
dgozman
2014/07/16 09:05:03
Done.
|
| + } |
| +} |
| + |
| +bool TouchEmulator::HandleTouchEventAck( |
| + const blink::WebTouchEvent& event, InputEventAckState ack_result) { |
| + if (emulated_stream_active_) { |
| + if (WebTouchEventTraits::IsTouchSequenceEnd(event)) |
| + emulated_stream_active_ = false; |
| + |
| + const bool event_consumed = ack_result == INPUT_EVENT_ACK_STATE_CONSUMED; |
| + gesture_provider_.OnTouchEventAck(event_consumed); |
| + return true; |
| + } |
| + |
| + DCHECK(native_stream_active_); |
| + if (WebTouchEventTraits::IsTouchSequenceEnd(event)) |
| + native_stream_active_ = false; |
| + return false; |
| +} |
| + |
| void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { |
| WebGestureEvent gesture_event = |
| CreateWebGestureEventFromGestureEventData(gesture); |
| @@ -267,16 +304,15 @@ void TouchEmulator::OnGestureEvent(const ui::GestureEventData& gesture) { |
| } |
| void TouchEmulator::CancelTouch() { |
| - if (!touch_active_) |
| + if (!emulated_stream_active_) |
| return; |
| WebTouchEventTraits::ResetTypeAndTouchStates( |
| WebInputEvent::TouchCancel, |
| (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(), |
| &touch_event_); |
| - touch_active_ = false; |
| if (gesture_provider_.OnTouchEvent(MotionEventWeb(touch_event_))) |
| - client_->ForwardTouchEvent(touch_event_); |
| + ForwardTouchEventToClient(); |
| } |
| void TouchEmulator::UpdateCursor() { |
| @@ -352,14 +388,12 @@ bool TouchEmulator::FillTouchEventAndPoint(const WebMouseEvent& mouse_event) { |
| switch (mouse_event.type) { |
| case WebInputEvent::MouseDown: |
| eventType = WebInputEvent::TouchStart; |
| - touch_active_ = true; |
| break; |
| case WebInputEvent::MouseMove: |
| eventType = WebInputEvent::TouchMove; |
| break; |
| case WebInputEvent::MouseUp: |
| eventType = WebInputEvent::TouchEnd; |
| - touch_active_ = false; |
| break; |
| default: |
| eventType = WebInputEvent::Undefined; |