| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 type == WebInputEvent::TouchMove; | 40 type == WebInputEvent::TouchMove; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 | 45 |
| 46 // Cancels a touch sequence if a touchstart or touchmove ack response is | 46 // Cancels a touch sequence if a touchstart or touchmove ack response is |
| 47 // sufficiently delayed. | 47 // sufficiently delayed. |
| 48 class TouchEventQueue::TouchTimeoutHandler { | 48 class TouchEventQueue::TouchTimeoutHandler { |
| 49 public: | 49 public: |
| 50 TouchTimeoutHandler(TouchEventQueue* touch_queue, size_t timeout_delay_ms) | 50 TouchTimeoutHandler(TouchEventQueue* touch_queue, |
| 51 base::TimeDelta timeout_delay) |
| 51 : touch_queue_(touch_queue), | 52 : touch_queue_(touch_queue), |
| 52 timeout_delay_(base::TimeDelta::FromMilliseconds(timeout_delay_ms)), | 53 timeout_delay_(timeout_delay), |
| 53 pending_ack_state_(PENDING_ACK_NONE), | 54 pending_ack_state_(PENDING_ACK_NONE), |
| 54 timeout_monitor_(base::Bind(&TouchTimeoutHandler::OnTimeOut, | 55 timeout_monitor_(base::Bind(&TouchTimeoutHandler::OnTimeOut, |
| 55 base::Unretained(this))) {} | 56 base::Unretained(this))) {} |
| 56 | 57 |
| 57 ~TouchTimeoutHandler() {} | 58 ~TouchTimeoutHandler() {} |
| 58 | 59 |
| 59 void Start(const TouchEventWithLatencyInfo& event) { | 60 void Start(const TouchEventWithLatencyInfo& event) { |
| 60 DCHECK_EQ(pending_ack_state_, PENDING_ACK_NONE); | 61 DCHECK_EQ(pending_ack_state_, PENDING_ACK_NONE); |
| 61 DCHECK(ShouldTouchTypeTriggerTimeout(event.event.type)); | 62 DCHECK(ShouldTouchTypeTriggerTimeout(event.event.type)); |
| 62 timeout_event_ = event; | 63 timeout_event_ = event; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 | 93 |
| 93 bool IsTimeoutTimerRunning() const { | 94 bool IsTimeoutTimerRunning() const { |
| 94 return timeout_monitor_.IsRunning(); | 95 return timeout_monitor_.IsRunning(); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void Reset() { | 98 void Reset() { |
| 98 pending_ack_state_ = PENDING_ACK_NONE; | 99 pending_ack_state_ = PENDING_ACK_NONE; |
| 99 timeout_monitor_.Stop(); | 100 timeout_monitor_.Stop(); |
| 100 } | 101 } |
| 101 | 102 |
| 103 void set_timeout_delay(base::TimeDelta timeout_delay) { |
| 104 timeout_delay_ = timeout_delay; |
| 105 } |
| 106 |
| 102 private: | 107 private: |
| 103 enum PendingAckState { | 108 enum PendingAckState { |
| 104 PENDING_ACK_NONE, | 109 PENDING_ACK_NONE, |
| 105 PENDING_ACK_ORIGINAL_EVENT, | 110 PENDING_ACK_ORIGINAL_EVENT, |
| 106 PENDING_ACK_CANCEL_EVENT, | 111 PENDING_ACK_CANCEL_EVENT, |
| 107 }; | 112 }; |
| 108 | 113 |
| 109 void OnTimeOut() { | 114 void OnTimeOut() { |
| 110 TRACE_EVENT1("input", "TouchEventQueue::TouchTimedOut", | 115 TRACE_EVENT1("input", "TouchEventQueue::TouchTimedOut", |
| 111 "type", WebInputEventTraits::GetName(timeout_event_.event.type)
); | 116 "type", WebInputEventTraits::GetName(timeout_event_.event.type)
); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 DCHECK(!dispatching_touch_ack_); | 504 DCHECK(!dispatching_touch_ack_); |
| 500 if (touch_queue_.empty()) | 505 if (touch_queue_.empty()) |
| 501 return false; | 506 return false; |
| 502 | 507 |
| 503 const blink::WebTouchEvent& event = | 508 const blink::WebTouchEvent& event = |
| 504 touch_queue_.front()->coalesced_event().event; | 509 touch_queue_.front()->coalesced_event().event; |
| 505 return (event.type == WebInputEvent::TouchStart); | 510 return (event.type == WebInputEvent::TouchStart); |
| 506 } | 511 } |
| 507 | 512 |
| 508 void TouchEventQueue::SetAckTimeoutEnabled(bool enabled, | 513 void TouchEventQueue::SetAckTimeoutEnabled(bool enabled, |
| 509 size_t ack_timeout_delay_ms) { | 514 base::TimeDelta ack_timeout_delay) { |
| 510 if (!enabled) { | 515 if (!enabled) { |
| 511 // Avoid resetting |timeout_handler_|, as an outstanding timeout may | |
| 512 // be active and must be completed for ack handling consistency. | |
| 513 ack_timeout_enabled_ = false; | 516 ack_timeout_enabled_ = false; |
| 517 if (touch_filtering_state_ == FORWARD_TOUCHES_UNTIL_TIMEOUT) |
| 518 touch_filtering_state_ = FORWARD_ALL_TOUCHES; |
| 519 // Only reset the |timeout_handler_| if the timer is running and has not yet |
| 520 // timed out. This ensures that an already timed out sequence is properly |
| 521 // flushed by the handler. |
| 522 if (timeout_handler_ && timeout_handler_->IsTimeoutTimerRunning()) |
| 523 timeout_handler_->Reset(); |
| 514 return; | 524 return; |
| 515 } | 525 } |
| 516 | 526 |
| 517 ack_timeout_enabled_ = true; | 527 ack_timeout_enabled_ = true; |
| 518 if (!timeout_handler_) | 528 if (!timeout_handler_) |
| 519 timeout_handler_.reset(new TouchTimeoutHandler(this, ack_timeout_delay_ms)); | 529 timeout_handler_.reset(new TouchTimeoutHandler(this, ack_timeout_delay)); |
| 530 else |
| 531 timeout_handler_->set_timeout_delay(ack_timeout_delay); |
| 520 } | 532 } |
| 521 | 533 |
| 522 bool TouchEventQueue::IsTimeoutRunningForTesting() const { | 534 bool TouchEventQueue::IsTimeoutRunningForTesting() const { |
| 523 return timeout_handler_ && timeout_handler_->IsTimeoutTimerRunning(); | 535 return timeout_handler_ && timeout_handler_->IsTimeoutTimerRunning(); |
| 524 } | 536 } |
| 525 | 537 |
| 526 const TouchEventWithLatencyInfo& | 538 const TouchEventWithLatencyInfo& |
| 527 TouchEventQueue::GetLatestEventForTesting() const { | 539 TouchEventQueue::GetLatestEventForTesting() const { |
| 528 return touch_queue_.back()->coalesced_event(); | 540 return touch_queue_.back()->coalesced_event(); |
| 529 } | 541 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 } else if (event.type == WebInputEvent::TouchStart) { | 636 } else if (event.type == WebInputEvent::TouchStart) { |
| 625 for (unsigned i = 0; i < event.touchesLength; ++i) { | 637 for (unsigned i = 0; i < event.touchesLength; ++i) { |
| 626 const WebTouchPoint& point = event.touches[i]; | 638 const WebTouchPoint& point = event.touches[i]; |
| 627 if (point.state == WebTouchPoint::StatePressed) | 639 if (point.state == WebTouchPoint::StatePressed) |
| 628 touch_ack_states_[point.id] = ack_result; | 640 touch_ack_states_[point.id] = ack_result; |
| 629 } | 641 } |
| 630 } | 642 } |
| 631 } | 643 } |
| 632 | 644 |
| 633 } // namespace content | 645 } // namespace content |
| OLD | NEW |