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 receive_async_touch_move_ack_(false), | |
376 ignore_ack_(0), | |
377 sent_async_touch_move_count_(0), | |
375 last_sent_touch_timestamp_sec_(0) { | 378 last_sent_touch_timestamp_sec_(0) { |
376 DCHECK(client); | 379 DCHECK(client); |
377 if (config.touch_ack_timeout_supported) { | 380 if (config.touch_ack_timeout_supported) { |
378 timeout_handler_.reset( | 381 timeout_handler_.reset( |
379 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); | 382 new TouchTimeoutHandler(this, config.touch_ack_timeout_delay)); |
380 } | 383 } |
381 } | 384 } |
382 | 385 |
383 TouchEventQueue::~TouchEventQueue() { | 386 TouchEventQueue::~TouchEventQueue() { |
384 if (!touch_queue_.empty()) | 387 if (!touch_queue_.empty()) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 const LatencyInfo& latency_info) { | 426 const LatencyInfo& latency_info) { |
424 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck"); | 427 TRACE_EVENT0("input", "TouchEventQueue::ProcessTouchAck"); |
425 | 428 |
426 DCHECK(!dispatching_touch_ack_); | 429 DCHECK(!dispatching_touch_ack_); |
427 dispatching_touch_ = false; | 430 dispatching_touch_ = false; |
428 | 431 |
429 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) | 432 if (timeout_handler_ && timeout_handler_->ConfirmTouchEvent(ack_result)) |
430 return; | 433 return; |
431 | 434 |
432 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); | 435 touchmove_slop_suppressor_->ConfirmTouchEvent(ack_result); |
433 | |
434 if (touch_queue_.empty()) | 436 if (touch_queue_.empty()) |
435 return; | 437 return; |
436 | 438 |
437 PopTouchEventToClient(ack_result, latency_info); | 439 PopTouchEventToClient(ack_result, latency_info); |
438 TryForwardNextEventToRenderer(); | 440 TryForwardNextEventToRenderer(); |
439 } | 441 } |
440 | 442 |
443 void TouchEventQueue::ProcessAsyncTouchAck() { | |
444 TRACE_EVENT0("input", "TouchEventQueue::ProcessAsyncTouchAck"); | |
445 | |
446 DCHECK(!dispatching_touch_ack_); | |
447 dispatching_touch_ = false; | |
448 --sent_async_touch_move_count_; | |
449 if (ignore_ack_ > 0) | |
450 --ignore_ack_; | |
451 receive_async_touch_move_ack_ = true; | |
452 | |
453 if (pending_async_touchmove_) { | |
454 touch_queue_.push_front( | |
455 new CoalescedWebTouchEvent(*pending_async_touchmove_, true)); | |
456 SendTouchEventImmediately(pending_async_touchmove_.get()); | |
457 } | |
458 } | |
459 | |
441 void TouchEventQueue::TryForwardNextEventToRenderer() { | 460 void TouchEventQueue::TryForwardNextEventToRenderer() { |
442 DCHECK(!dispatching_touch_ack_); | 461 DCHECK(!dispatching_touch_ack_); |
443 // If there are queued touch events, then try to forward them to the renderer | 462 // 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. | 463 // immediately, or ACK the events back to the client if appropriate. |
445 while (!touch_queue_.empty()) { | 464 while (!touch_queue_.empty()) { |
446 PreFilterResult filter_result = | 465 PreFilterResult filter_result = |
447 FilterBeforeForwarding(touch_queue_.front()->coalesced_event().event); | 466 FilterBeforeForwarding(touch_queue_.front()->coalesced_event().event); |
448 switch (filter_result) { | 467 switch (filter_result) { |
449 case ACK_WITH_NO_CONSUMER_EXISTS: | 468 case ACK_WITH_NO_CONSUMER_EXISTS: |
450 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | 469 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
(...skipping 22 matching lines...) Expand all Loading... | |
473 // application be sent touches at key points in the gesture stream, | 492 // application be sent touches at key points in the gesture stream, |
474 // e.g., when the application slop region is exceeded or touchmove | 493 // e.g., when the application slop region is exceeded or touchmove |
475 // coalescing fails because of different modifiers. | 494 // coalescing fails because of different modifiers. |
476 bool send_touchmove_now = size() > 1; | 495 bool send_touchmove_now = size() > 1; |
477 send_touchmove_now |= pending_async_touchmove_ && | 496 send_touchmove_now |= pending_async_touchmove_ && |
478 !pending_async_touchmove_->CanCoalesceWith(touch); | 497 !pending_async_touchmove_->CanCoalesceWith(touch); |
479 send_touchmove_now |= | 498 send_touchmove_now |= |
480 touch.event.timeStampSeconds >= | 499 touch.event.timeStampSeconds >= |
481 last_sent_touch_timestamp_sec_ + kAsyncTouchMoveIntervalSec; | 500 last_sent_touch_timestamp_sec_ + kAsyncTouchMoveIntervalSec; |
482 | 501 |
502 if (ignore_ack_ == 0) | |
503 send_touchmove_now &= receive_async_touch_move_ack_; | |
483 if (!send_touchmove_now) { | 504 if (!send_touchmove_now) { |
484 if (!pending_async_touchmove_) { | 505 if (!pending_async_touchmove_) { |
485 pending_async_touchmove_.reset(new TouchEventWithLatencyInfo(touch)); | 506 pending_async_touchmove_.reset(new TouchEventWithLatencyInfo(touch)); |
486 } else { | 507 } else { |
487 DCHECK(pending_async_touchmove_->CanCoalesceWith(touch)); | 508 DCHECK(pending_async_touchmove_->CanCoalesceWith(touch)); |
488 pending_async_touchmove_->CoalesceWith(touch); | 509 pending_async_touchmove_->CoalesceWith(touch); |
489 } | 510 } |
490 DCHECK_EQ(1U, size()); | 511 DCHECK_EQ(1U, size()); |
491 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 512 PopTouchEventToClient(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
492 // It's possible (though unlikely) that ack'ing the current touch will | 513 // 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 | 514 // 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 | 515 // forwarding of the queued event will be deferred while the ack is being |
495 // dispatched (see |OnTouchEvent()|), try forwarding it now. | 516 // dispatched (see |OnTouchEvent()|), try forwarding it now. |
496 TryForwardNextEventToRenderer(); | 517 TryForwardNextEventToRenderer(); |
497 return; | 518 return; |
498 } | 519 } |
520 receive_async_touch_move_ack_ = false; | |
499 } | 521 } |
500 | 522 |
501 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; | 523 last_sent_touch_timestamp_sec_ = touch.event.timeStampSeconds; |
502 | 524 |
503 // Flush any pending async touch move. If it can be combined with the current | 525 // 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 | 526 // (touchmove) event, great, otherwise send it immediately but separately. Its |
505 // ack will trigger forwarding of the original |touch| event. | 527 // ack will trigger forwarding of the original |touch| event. |
506 if (pending_async_touchmove_) { | 528 if (pending_async_touchmove_) { |
507 if (pending_async_touchmove_->CanCoalesceWith(touch)) { | 529 if (pending_async_touchmove_->CanCoalesceWith(touch)) { |
508 pending_async_touchmove_->CoalesceWith(touch); | 530 pending_async_touchmove_->CoalesceWith(touch); |
509 pending_async_touchmove_->event.cancelable = !send_touch_events_async_; | 531 pending_async_touchmove_->event.cancelable = !send_touch_events_async_; |
510 touch = *pending_async_touchmove_; | 532 touch = *pending_async_touchmove_; |
511 pending_async_touchmove_.reset(); | 533 pending_async_touchmove_.reset(); |
534 if (!touch.event.cancelable) | |
535 ++sent_async_touch_move_count_; | |
512 } else { | 536 } else { |
537 // Once we flish the pending async touch move, we ignore all the acks | |
tdresser
2015/03/23 19:21:44
flish -> flush
lanwei
2015/03/24 18:46:38
Done.
| |
538 // from the aysnc touch moves that we sent out and wait for acks back. | |
tdresser
2015/03/23 19:21:44
Fix aysnc spelling.
lanwei
2015/03/24 18:46:38
Done.
| |
539 ignore_ack_ = ++sent_async_touch_move_count_; | |
tdresser
2015/03/23 19:21:44
Split into two statements.
lanwei
2015/03/24 18:46:38
Done.
| |
513 scoped_ptr<TouchEventWithLatencyInfo> async_move = | 540 scoped_ptr<TouchEventWithLatencyInfo> async_move = |
514 pending_async_touchmove_.Pass(); | 541 pending_async_touchmove_.Pass(); |
515 async_move->event.cancelable = false; | 542 async_move->event.cancelable = false; |
516 touch_queue_.push_front(new CoalescedWebTouchEvent(*async_move, true)); | 543 touch_queue_.push_front(new CoalescedWebTouchEvent(*async_move, true)); |
517 SendTouchEventImmediately(async_move.get()); | 544 SendTouchEventImmediately(async_move.get()); |
518 return; | 545 return; |
519 } | 546 } |
520 } | 547 } |
521 | 548 |
522 // Note: Touchstart events are marked cancelable to allow transitions between | 549 // Note: Touchstart events are marked cancelable to allow transitions between |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
750 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 777 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
751 send_touch_events_async_ = false; | 778 send_touch_events_async_ = false; |
752 has_handler_for_current_sequence_ |= | 779 has_handler_for_current_sequence_ |= |
753 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 780 ack_result != INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
754 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { | 781 } else if (WebTouchEventTraits::IsTouchSequenceEnd(event)) { |
755 has_handler_for_current_sequence_ = false; | 782 has_handler_for_current_sequence_ = false; |
756 } | 783 } |
757 } | 784 } |
758 | 785 |
759 } // namespace content | 786 } // namespace content |
OLD | NEW |