| 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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/browser/renderer_host/input/timeout_monitor.h" | 10 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, | 365 TouchEventQueue::TouchEventQueue(TouchEventQueueClient* client, |
| 366 const Config& config) | 366 const Config& config) |
| 367 : client_(client), | 367 : client_(client), |
| 368 dispatching_touch_ack_(false), | 368 dispatching_touch_ack_(false), |
| 369 dispatching_touch_(false), | 369 dispatching_touch_(false), |
| 370 has_handlers_(true), | 370 has_handlers_(true), |
| 371 has_handler_for_current_sequence_(false), | 371 has_handler_for_current_sequence_(false), |
| 372 drop_remaining_touches_in_sequence_(false), | 372 drop_remaining_touches_in_sequence_(false), |
| 373 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor), | 373 touchmove_slop_suppressor_(new TouchMoveSlopSuppressor), |
| 374 send_touch_events_async_(false), | 374 send_touch_events_async_(false), |
| 375 last_sent_touch_timestamp_sec_(0) { | 375 last_sent_touch_timestamp_sec_(0), |
| 376 receiving_async_touch_move_ack_(false) { |
| 376 DCHECK(client); | 377 DCHECK(client); |
| 377 if (config.touch_ack_timeout_supported) { | 378 if (config.touch_ack_timeout_supported) { |
| 378 timeout_handler_.reset( | 379 timeout_handler_.reset( |
| 379 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); | 380 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); |
| 380 } | 381 } |
| 381 } | 382 } |
| 382 | 383 |
| 383 TouchEventQueue::~TouchEventQueue() { | 384 TouchEventQueue::~TouchEventQueue() { |
| 384 if (!touch_queue_.empty()) | 385 if (!touch_queue_.empty()) |
| 385 STLDeleteElements(&touch_queue_); | 386 STLDeleteElements(&touch_queue_); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 dispatching_touch_ = false; | 428 dispatching_touch_ = false; |
| 428 | 429 |
| 429 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) | 430 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) |
| 430 return; | 431 return; |
| 431 | 432 |
| 432 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); | 433 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); |
| 433 | 434 |
| 434 if (touch_queue_.empty()) | 435 if (touch_queue_.empty()) |
| 435 return; | 436 return; |
| 436 | 437 |
| 437 PopTouchEventToClient(ack_result, latency_info); | 438 // If we receive the ACK from render for async touch moves, we do not call |
| 439 // this function again, because it has already been called by the fake ACK. |
| 440 if(!receiving_async_touch_move_ack_) |
| 441 PopTouchEventToClient(ack_result, latency_info); |
| 442 |
| 438 TryForwardNextEventToRenderer(); | 443 TryForwardNextEventToRenderer(); |
| 439 } | 444 } |
| 440 | 445 |
| 441 void TouchEventQueue::TryForwardNextEventToRenderer() { | 446 void TouchEventQueue::TryForwardNextEventToRenderer() { |
| 442 DCHECK(!dispatching_touch_ack_); | 447 DCHECK(!dispatching_touch_ack_); |
| 443 // If there are queued touch events, then try to forward them to the renderer | 448 // If there are queued touch events, then try to forward them to the renderer |
| 444 // immediately, or ACK the events back to the client if appropriate. | 449 // immediately, or ACK the events back to the client if appropriate. |
| 445 while (!touch_queue_.empty()) { | 450 while (!touch_queue_.empty()) { |
| 446 PreFilterResult filter_result = | 451 PreFilterResult filter_result = |
| 447 FilterBeforeForwarding(touch_queue_.front()->coalesced_event().event); | 452 FilterBeforeForwarding(touch_queue_.front()->coalesced_event().event); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 473 // application be sent touches at key points in the gesture stream, | 478 // application be sent touches at key points in the gesture stream, |
| 474 // e.g., when the application slop region is exceeded or touchmove | 479 // e.g., when the application slop region is exceeded or touchmove |
| 475 // coalescing fails because of different modifiers. | 480 // coalescing fails because of different modifiers. |
| 476 bool send_touchmove_now = size() > 1; | 481 bool send_touchmove_now = size() > 1; |
| 477 send_touchmove_now |= pending_async_touchmove_ && | 482 send_touchmove_now |= pending_async_touchmove_ && |
| 478 !pending_async_touchmove_->CanCoalesceWith(touch); | 483 !pending_async_touchmove_->CanCoalesceWith(touch); |
| 479 send_touchmove_now |= | 484 send_touchmove_now |= |
| 480 touch.event.timeStampSeconds >= | 485 touch.event.timeStampSeconds >= |
| 481 last_sent_touch_timestamp_sec_ + kAsyncTouchMoveIntervalSec; | 486 last_sent_touch_timestamp_sec_ + kAsyncTouchMoveIntervalSec; |
| 482 | 487 |
| 483 if (!send_touchmove_now) { | 488 // We send the next async touchmove after an interval of |
| 489 // kAsyncTouchMoveIntervalSec and receive the ACK back from render. |
| 490 if (!send_touchmove_now || !receiving_async_touch_move_ack_) { |
| 484 if (!pending_async_touchmove_) { | 491 if (!pending_async_touchmove_) { |
| 485 pending_async_touchmove_.reset(new TouchEventWithLatencyInfo(touch)); | 492 pending_async_touchmove_.reset(new TouchEventWithLatencyInfo(touch)); |
| 486 } else { | 493 } else { |
| 487 DCHECK(pending_async_touchmove_->CanCoalesceWith(touch)); | 494 DCHECK(pending_async_touchmove_->CanCoalesceWith(touch)); |
| 488 pending_async_touchmove_->CoalesceWith(touch); | 495 pending_async_touchmove_->CoalesceWith(touch); |
| 489 } | 496 } |
| 490 DCHECK_EQ(1U, size()); | 497 DCHECK_EQ(1U, size()); |
| 491 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 498 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 492 // It's possible (though unlikely) that ack'ing the current touch will | 499 // It's possible (though unlikely) that ack'ing the current touch will |
| 493 // trigger the queueing of another touch event (e.g., a touchcancel). As | 500 // trigger the queueing of another touch event (e.g., a touchcancel). As |
| 494 // forwarding of the queued event will be deferred while the ack is being | 501 // forwarding of the queued event will be deferred while the ack is being |
| 495 // dispatched (see |OnTouchEvent()|), try forwarding it now. | 502 // dispatched (see |OnTouchEvent()|), try forwarding it now. |
| 496 TryForwardNextEventToRenderer(); | 503 TryForwardNextEventToRenderer(); |
| 497 return; | 504 return; |
| 498 } | 505 } |
| 506 |
| 507 receiving_async_touch_move_ack_ = false; |
| 499 } | 508 } |
| 500 | 509 |
| 501 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; | 510 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; |
| 502 | 511 |
| 503 // Flush any pending async touch move. If it can be combined with the current | 512 // Flush any pending async touch move. If it can be combined with the current |
| 504 // (touchmove) event, great, otherwise send it immediately but separately. Its | 513 // (touchmove) event, great, otherwise send it immediately but separately. Its |
| 505 // ack will trigger forwarding of the original |touch| event. | 514 // ack will trigger forwarding of the original |touch| event. |
| 506 if (pending_async_touchmove_) { | 515 if (pending_async_touchmove_) { |
| 507 if (pending_async_touchmove_->CanCoalesceWith(touch)) { | 516 if (pending_async_touchmove_->CanCoalesceWith(touch)) { |
| 508 pending_async_touchmove_->CoalesceWith(touch); | 517 pending_async_touchmove_->CoalesceWith(touch); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 759 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 751 send_touch_events_async_ = false; | 760 send_touch_events_async_ = false; |
| 752 has_handler_for_current_sequence_ |= | 761 has_handler_for_current_sequence_ |= |
| 753 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 762 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
| 754 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { | 763 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { |
| 755 has_handler_for_current_sequence_ = false; | 764 has_handler_for_current_sequence_ = false; |
| 756 } | 765 } |
| 757 } | 766 } |
| 758 | 767 |
| 759 } // namespace content | 768 } // namespace content |
| OLD | NEW |