| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/input/touch_event_queue.h" | 5 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 WebInputEvent::TouchCancel, | 39 WebInputEvent::TouchCancel, |
| 40 // TODO(rbyers): Shouldn't we use a fresh timestamp? | 40 // TODO(rbyers): Shouldn't we use a fresh timestamp? |
| 41 event.event.timeStampSeconds, | 41 event.event.timeStampSeconds, |
| 42 &event.event); | 42 &event.event); |
| 43 return event; | 43 return event; |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool ShouldTouchTriggerTimeout(const WebTouchEvent& event) { | 46 bool ShouldTouchTriggerTimeout(const WebTouchEvent& event) { |
| 47 return (event.type == WebInputEvent::TouchStart || | 47 return (event.type == WebInputEvent::TouchStart || |
| 48 event.type == WebInputEvent::TouchMove) && | 48 event.type == WebInputEvent::TouchMove) && |
| 49 WebInputEventTraits::ShouldBlockEventStream(event) && event.cancelable; | 49 event.dispatchType == WebInputEvent::Blocking; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Compare all properties of touch points to determine the state. | 52 // Compare all properties of touch points to determine the state. |
| 53 bool HasPointChanged(const WebTouchPoint& point_1, | 53 bool HasPointChanged(const WebTouchPoint& point_1, |
| 54 const WebTouchPoint& point_2) { | 54 const WebTouchPoint& point_2) { |
| 55 DCHECK_EQ(point_1.id, point_2.id); | 55 DCHECK_EQ(point_1.id, point_2.id); |
| 56 if (point_1.screenPosition != point_2.screenPosition || | 56 if (point_1.screenPosition != point_2.screenPosition || |
| 57 point_1.position != point_2.position || | 57 point_1.position != point_2.position || |
| 58 point_1.radiusX != point_2.radiusX || | 58 point_1.radiusX != point_2.radiusX || |
| 59 point_1.radiusY != point_2.radiusY || | 59 point_1.radiusY != point_2.radiusY || |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 } | 596 } |
| 597 | 597 |
| 598 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; | 598 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; |
| 599 | 599 |
| 600 // Flush any pending async touch move. If it can be combined with the current | 600 // Flush any pending async touch move. If it can be combined with the current |
| 601 // (touchmove) event, great, otherwise send it immediately but separately. Its | 601 // (touchmove) event, great, otherwise send it immediately but separately. Its |
| 602 // ack will trigger forwarding of the original |touch| event. | 602 // ack will trigger forwarding of the original |touch| event. |
| 603 if (pending_async_touchmove_) { | 603 if (pending_async_touchmove_) { |
| 604 if (pending_async_touchmove_->CanCoalesceWith(touch)) { | 604 if (pending_async_touchmove_->CanCoalesceWith(touch)) { |
| 605 pending_async_touchmove_->CoalesceWith(touch); | 605 pending_async_touchmove_->CoalesceWith(touch); |
| 606 pending_async_touchmove_->event.cancelable = !send_touch_events_async_; | 606 pending_async_touchmove_->event.dispatchType = |
| 607 send_touch_events_async_ ? WebInputEvent::NonBlocking |
| 608 : WebInputEvent::Blocking; |
| 607 touch = *pending_async_touchmove_; | 609 touch = *pending_async_touchmove_; |
| 608 pending_async_touchmove_.reset(); | 610 pending_async_touchmove_.reset(); |
| 609 } else { | 611 } else { |
| 610 FlushPendingAsyncTouchmove(); | 612 FlushPendingAsyncTouchmove(); |
| 611 return; | 613 return; |
| 612 } | 614 } |
| 613 } | 615 } |
| 614 | 616 |
| 615 // Note: Touchstart events are marked cancelable to allow transitions between | 617 // Note: Touchstart events are marked cancelable to allow transitions between |
| 616 // platform scrolling and JS pinching. Touchend events, however, remain | 618 // platform scrolling and JS pinching. Touchend events, however, remain |
| 617 // uncancelable, mitigating the risk of jank when transitioning to a fling. | 619 // uncancelable, mitigating the risk of jank when transitioning to a fling. |
| 618 if (send_touch_events_async_ && touch.event.type != WebInputEvent::TouchStart) | 620 if (send_touch_events_async_ && touch.event.type != WebInputEvent::TouchStart) |
| 619 touch.event.cancelable = false; | 621 touch.event.dispatchType = WebInputEvent::NonBlocking; |
| 620 | 622 |
| 621 SendTouchEventImmediately(&touch); | 623 SendTouchEventImmediately(&touch); |
| 622 } | 624 } |
| 623 | 625 |
| 624 void TouchEventQueue::FlushPendingAsyncTouchmove() { | 626 void TouchEventQueue::FlushPendingAsyncTouchmove() { |
| 625 DCHECK(!dispatching_touch_); | 627 DCHECK(!dispatching_touch_); |
| 626 std::unique_ptr<TouchEventWithLatencyInfo> touch = | 628 std::unique_ptr<TouchEventWithLatencyInfo> touch = |
| 627 std::move(pending_async_touchmove_); | 629 std::move(pending_async_touchmove_); |
| 628 touch->event.cancelable = false; | 630 touch->event.dispatchType = WebInputEvent::NonBlocking; |
| 629 touch_queue_.push_front(new CoalescedWebTouchEvent(*touch, true)); | 631 touch_queue_.push_front(new CoalescedWebTouchEvent(*touch, true)); |
| 630 SendTouchEventImmediately(touch.get()); | 632 SendTouchEventImmediately(touch.get()); |
| 631 } | 633 } |
| 632 | 634 |
| 633 void TouchEventQueue::OnGestureScrollEvent( | 635 void TouchEventQueue::OnGestureScrollEvent( |
| 634 const GestureEventWithLatencyInfo& gesture_event) { | 636 const GestureEventWithLatencyInfo& gesture_event) { |
| 635 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { | 637 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { |
| 636 if (has_handler_for_current_sequence_ && | 638 if (has_handler_for_current_sequence_ && |
| 637 !drop_remaining_touches_in_sequence_) { | 639 !drop_remaining_touches_in_sequence_) { |
| 638 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) | 640 DCHECK(!touchmove_slop_suppressor_->suppressing_touchmoves()) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); | 780 last_sent_touchevent_.reset(new WebTouchEvent(touch->event)); |
| 779 | 781 |
| 780 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); | 782 base::AutoReset<bool> dispatching_touch(&dispatching_touch_, true); |
| 781 | 783 |
| 782 client_->SendTouchEventImmediately(*touch); | 784 client_->SendTouchEventImmediately(*touch); |
| 783 | 785 |
| 784 // A synchronous ack will reset |dispatching_touch_|, in which case the touch | 786 // A synchronous ack will reset |dispatching_touch_|, in which case the touch |
| 785 // timeout should not be started and the count also should not be increased. | 787 // timeout should not be started and the count also should not be increased. |
| 786 if (dispatching_touch_) { | 788 if (dispatching_touch_) { |
| 787 if (touch->event.type == WebInputEvent::TouchMove && | 789 if (touch->event.type == WebInputEvent::TouchMove && |
| 788 !touch->event.cancelable) { | 790 touch->event.dispatchType != WebInputEvent::Blocking) { |
| 789 // When we send out a uncancelable touch move, we increase the count and | 791 // When we send out a uncancelable touch move, we increase the count and |
| 790 // we do not process input event ack any more, we will just ack to client | 792 // we do not process input event ack any more, we will just ack to client |
| 791 // and wait for the ack from render. Also we will remove it from the front | 793 // and wait for the ack from render. Also we will remove it from the front |
| 792 // of the queue. | 794 // of the queue. |
| 793 ack_pending_async_touchmove_ids_.push_back( | 795 ack_pending_async_touchmove_ids_.push_back( |
| 794 touch->event.uniqueTouchEventId); | 796 touch->event.uniqueTouchEventId); |
| 795 dispatching_touch_ = false; | 797 dispatching_touch_ = false; |
| 796 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED); | 798 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_IGNORED); |
| 797 TryForwardNextEventToRenderer(); | 799 TryForwardNextEventToRenderer(); |
| 798 return; | 800 return; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 882 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 881 send_touch_events_async_ = false; | 883 send_touch_events_async_ = false; |
| 882 has_handler_for_current_sequence_ |= | 884 has_handler_for_current_sequence_ |= |
| 883 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 885 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
| 884 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { | 886 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { |
| 885 has_handler_for_current_sequence_ = false; | 887 has_handler_for_current_sequence_ = false; |
| 886 } | 888 } |
| 887 } | 889 } |
| 888 | 890 |
| 889 } // namespace content | 891 } // namespace content |
| OLD | NEW |