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> |
| 8 |
7 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
12 #include "content/browser/renderer_host/input/timeout_monitor.h" | 14 #include "content/browser/renderer_host/input/timeout_monitor.h" |
13 #include "content/common/input/web_touch_event_traits.h" | 15 #include "content/common/input/web_touch_event_traits.h" |
14 #include "ui/gfx/geometry/point_f.h" | 16 #include "ui/gfx/geometry/point_f.h" |
15 | 17 |
16 using blink::WebInputEvent; | 18 using blink::WebInputEvent; |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 // platform scrolling and JS pinching. Touchend events, however, remain | 614 // platform scrolling and JS pinching. Touchend events, however, remain |
613 // uncancelable, mitigating the risk of jank when transitioning to a fling. | 615 // uncancelable, mitigating the risk of jank when transitioning to a fling. |
614 if (send_touch_events_async_ && touch.event.type != WebInputEvent::TouchStart) | 616 if (send_touch_events_async_ && touch.event.type != WebInputEvent::TouchStart) |
615 touch.event.cancelable = false; | 617 touch.event.cancelable = false; |
616 | 618 |
617 SendTouchEventImmediately(&touch); | 619 SendTouchEventImmediately(&touch); |
618 } | 620 } |
619 | 621 |
620 void TouchEventQueue::FlushPendingAsyncTouchmove() { | 622 void TouchEventQueue::FlushPendingAsyncTouchmove() { |
621 DCHECK(!dispatching_touch_); | 623 DCHECK(!dispatching_touch_); |
622 scoped_ptr<TouchEventWithLatencyInfo> touch = pending_async_touchmove_.Pass(); | 624 scoped_ptr<TouchEventWithLatencyInfo> touch = |
| 625 std::move(pending_async_touchmove_); |
623 touch->event.cancelable = false; | 626 touch->event.cancelable = false; |
624 touch_queue_.push_front(new CoalescedWebTouchEvent(*touch, true)); | 627 touch_queue_.push_front(new CoalescedWebTouchEvent(*touch, true)); |
625 SendTouchEventImmediately(touch.get()); | 628 SendTouchEventImmediately(touch.get()); |
626 } | 629 } |
627 | 630 |
628 void TouchEventQueue::OnGestureScrollEvent( | 631 void TouchEventQueue::OnGestureScrollEvent( |
629 const GestureEventWithLatencyInfo& gesture_event) { | 632 const GestureEventWithLatencyInfo& gesture_event) { |
630 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { | 633 if (gesture_event.event.type == blink::WebInputEvent::GestureScrollBegin) { |
631 if (has_handler_for_current_sequence_ && | 634 if (has_handler_for_current_sequence_ && |
632 !drop_remaining_touches_in_sequence_) { | 635 !drop_remaining_touches_in_sequence_) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // Note that acking the touch-event may result in multiple gestures being sent | 737 // Note that acking the touch-event may result in multiple gestures being sent |
735 // to the renderer, or touch-events being queued. | 738 // to the renderer, or touch-events being queued. |
736 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); | 739 base::AutoReset<bool> dispatching_touch_ack(&dispatching_touch_ack_, true); |
737 acked_event->DispatchAckToClient(ack_result, optional_latency_info, client_); | 740 acked_event->DispatchAckToClient(ack_result, optional_latency_info, client_); |
738 } | 741 } |
739 | 742 |
740 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { | 743 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { |
741 DCHECK(!touch_queue_.empty()); | 744 DCHECK(!touch_queue_.empty()); |
742 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); | 745 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); |
743 touch_queue_.pop_front(); | 746 touch_queue_.pop_front(); |
744 return event.Pass(); | 747 return event; |
745 } | 748 } |
746 | 749 |
747 void TouchEventQueue::SendTouchEventImmediately( | 750 void TouchEventQueue::SendTouchEventImmediately( |
748 TouchEventWithLatencyInfo* touch) { | 751 TouchEventWithLatencyInfo* touch) { |
749 // For touchmove events, compare touch points position from current event | 752 // For touchmove events, compare touch points position from current event |
750 // to last sent event and update touch points state. | 753 // to last sent event and update touch points state. |
751 if (touch->event.type == WebInputEvent::TouchMove) { | 754 if (touch->event.type == WebInputEvent::TouchMove) { |
752 CHECK(last_sent_touchevent_); | 755 CHECK(last_sent_touchevent_); |
753 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { | 756 for (unsigned int i = 0; i < last_sent_touchevent_->touchesLength; ++i) { |
754 const WebTouchPoint& last_touch_point = | 757 const WebTouchPoint& last_touch_point = |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
875 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 878 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
876 send_touch_events_async_ = false; | 879 send_touch_events_async_ = false; |
877 has_handler_for_current_sequence_ |= | 880 has_handler_for_current_sequence_ |= |
878 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 881 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
879 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { | 882 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { |
880 has_handler_for_current_sequence_ = false; | 883 has_handler_for_current_sequence_ = false; |
881 } | 884 } |
882 } | 885 } |
883 | 886 |
884 } // namespace content | 887 } // namespace content |
OLD | NEW |