Chromium Code Reviews| 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 "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "content/browser/renderer_host/input/timeout_monitor.h" | 10 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 696 } | 696 } |
| 697 | 697 |
| 698 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { | 698 scoped_ptr<CoalescedWebTouchEvent> TouchEventQueue::PopTouchEvent() { |
| 699 DCHECK(!touch_queue_.empty()); | 699 DCHECK(!touch_queue_.empty()); |
| 700 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); | 700 scoped_ptr<CoalescedWebTouchEvent> event(touch_queue_.front()); |
| 701 touch_queue_.pop_front(); | 701 touch_queue_.pop_front(); |
| 702 return event.Pass(); | 702 return event.Pass(); |
| 703 } | 703 } |
| 704 | 704 |
| 705 void TouchEventQueue::SendTouchEventImmediately( | 705 void TouchEventQueue::SendTouchEventImmediately( |
| 706 const TouchEventWithLatencyInfo& touch) { | 706 TouchEventWithLatencyInfo& touch) { |
|
jdduke (slow)
2014/12/15 16:51:08
Nit: Either pass by const ref, or by pointer (the
USE s.singapati at gmail.com
2014/12/17 11:28:43
Done.
| |
| 707 if (needs_async_touchmove_for_outer_slop_region_) { | 707 if (needs_async_touchmove_for_outer_slop_region_) { |
| 708 // Any event other than a touchmove (e.g., touchcancel or secondary | 708 // Any event other than a touchmove (e.g., touchcancel or secondary |
| 709 // touchstart) after a scroll has started will interrupt the need to send a | 709 // touchstart) after a scroll has started will interrupt the need to send a |
| 710 // an outer slop-region exceeding touchmove. | 710 // an outer slop-region exceeding touchmove. |
| 711 if (touch.event.type != WebInputEvent::TouchMove || | 711 if (touch.event.type != WebInputEvent::TouchMove || |
| 712 OutsideApplicationSlopRegion(touch.event, | 712 OutsideApplicationSlopRegion(touch.event, |
| 713 touch_sequence_start_position_)) | 713 touch_sequence_start_position_)) |
| 714 needs_async_touchmove_for_outer_slop_region_ = false; | 714 needs_async_touchmove_for_outer_slop_region_ = false; |
| 715 } | 715 } |
| 716 | 716 |
| 717 // For touchmove events, compare touch points position from current event | |
| 718 // to last sent event and update touch points state. | |
| 719 if (touch.event.type == WebInputEvent::TouchMove) { | |
| 720 if (last_sent_touchmove_) { | |
| 721 for (unsigned int i = 0; i < last_sent_touchmove_->touchesLength; ++i) { | |
| 722 const WebTouchPoint& last_touchmove_point = | |
| 723 last_sent_touchmove_->touches[i]; | |
| 724 | |
| 725 // touches with same id may not have same index in touches array | |
| 726 for (unsigned int j = 0; j < touch.event.touchesLength; ++j) { | |
| 727 WebTouchPoint& current_touchmove_point = touch.event.touches[j]; | |
| 728 if (last_touchmove_point.id == current_touchmove_point.id) { | |
| 729 if (fabs(current_touchmove_point.position.x - | |
|
jdduke (slow)
2014/12/15 16:51:08
Can we avoid using the epsilon? If the touch reall
USE s.singapati at gmail.com
2014/12/17 11:28:43
Done. Did more testing and no problems found.
| |
| 730 last_touchmove_point.position.x) < 0.000001 | |
| 731 && fabs(current_touchmove_point.position.y - | |
| 732 last_touchmove_point.position.y) < 0.000001) | |
| 733 current_touchmove_point.state = WebTouchPoint::StateStationary; | |
| 734 | |
| 735 break; | |
| 736 } | |
| 737 } | |
| 738 } | |
| 739 *last_sent_touchmove_ = touch.event; | |
| 740 } else { | |
| 741 last_sent_touchmove_.reset(new WebTouchEvent(touch.event)); | |
| 742 } | |
| 743 } else { | |
| 744 if (last_sent_touchmove_) | |
|
jdduke (slow)
2014/12/15 16:51:08
Nit: No need for the if, you can just unconditiona
USE s.singapati at gmail.com
2014/12/17 11:28:42
Done.
| |
| 745 last_sent_touchmove_.reset(); | |
| 746 } | |
| 747 | |
| 717 client_->SendTouchEventImmediately(touch); | 748 client_->SendTouchEventImmediately(touch); |
| 718 } | 749 } |
| 719 | 750 |
| 720 TouchEventQueue::PreFilterResult | 751 TouchEventQueue::PreFilterResult |
| 721 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { | 752 TouchEventQueue::FilterBeforeForwarding(const WebTouchEvent& event) { |
| 722 if (timeout_handler_ && timeout_handler_->FilterEvent(event)) | 753 if (timeout_handler_ && timeout_handler_->FilterEvent(event)) |
| 723 return ACK_WITH_NO_CONSUMER_EXISTS; | 754 return ACK_WITH_NO_CONSUMER_EXISTS; |
| 724 | 755 |
| 725 if (touchmove_slop_suppressor_->FilterEvent(event)) | 756 if (touchmove_slop_suppressor_->FilterEvent(event)) |
| 726 return ACK_WITH_NOT_CONSUMED; | 757 return ACK_WITH_NOT_CONSUMED; |
| 727 | 758 |
| 728 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { | 759 if (WebTouchEventTraits::IsTouchSequenceStart(event)) { |
| 729 touch_consumer_states_.clear(); | 760 touch_consumer_states_.clear(); |
| 730 send_touch_events_async_ = false; | 761 send_touch_events_async_ = false; |
| 731 pending_async_touchmove_.reset(); | 762 pending_async_touchmove_.reset(); |
| 763 last_sent_touchmove_.reset(); | |
| 764 | |
| 732 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); | 765 touch_sequence_start_position_ = gfx::PointF(event.touches[0].position); |
| 733 drop_remaining_touches_in_sequence_ = false; | 766 drop_remaining_touches_in_sequence_ = false; |
| 734 if (!has_handlers_) { | 767 if (!has_handlers_) { |
| 735 drop_remaining_touches_in_sequence_ = true; | 768 drop_remaining_touches_in_sequence_ = true; |
| 736 return ACK_WITH_NO_CONSUMER_EXISTS; | 769 return ACK_WITH_NO_CONSUMER_EXISTS; |
| 737 } | 770 } |
| 738 } | 771 } |
| 739 | 772 |
| 740 if (drop_remaining_touches_in_sequence_ && | 773 if (drop_remaining_touches_in_sequence_ && |
| 741 event.type != WebInputEvent::TouchCancel) { | 774 event.type != WebInputEvent::TouchCancel) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 if (ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) | 810 if (ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS) |
| 778 touch_consumer_states_.mark_bit(point.id); | 811 touch_consumer_states_.mark_bit(point.id); |
| 779 else | 812 else |
| 780 touch_consumer_states_.clear_bit(point.id); | 813 touch_consumer_states_.clear_bit(point.id); |
| 781 } | 814 } |
| 782 } | 815 } |
| 783 } | 816 } |
| 784 } | 817 } |
| 785 | 818 |
| 786 } // namespace content | 819 } // namespace content |
| OLD | NEW |