| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/location.h" | 6 #include "base/location.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool IsPendingAckTouchStart() const { | 253 bool IsPendingAckTouchStart() const { |
| 254 return queue_->IsPendingAckTouchStart(); | 254 return queue_->IsPendingAckTouchStart(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void OnHasTouchEventHandlers(bool has_handlers) { | 257 void OnHasTouchEventHandlers(bool has_handlers) { |
| 258 queue_->OnHasTouchEventHandlers(has_handlers); | 258 queue_->OnHasTouchEventHandlers(has_handlers); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void OnHasTouchMoveEventHandlers(bool has_handlers) { |
| 262 queue_->OnHasTouchMoveEventHandlers(has_handlers); |
| 263 } |
| 264 |
| 261 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } | 265 void SetAckTimeoutDisabled() { queue_->SetAckTimeoutEnabled(false); } |
| 262 | 266 |
| 263 void SetIsMobileOptimizedSite(bool is_mobile_optimized) { | 267 void SetIsMobileOptimizedSite(bool is_mobile_optimized) { |
| 264 queue_->SetIsMobileOptimizedSite(is_mobile_optimized); | 268 queue_->SetIsMobileOptimizedSite(is_mobile_optimized); |
| 265 } | 269 } |
| 266 | 270 |
| 267 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } | 271 bool IsTimeoutRunning() const { return queue_->IsTimeoutRunningForTesting(); } |
| 268 | 272 |
| 269 bool HasPendingAsyncTouchMove() const { | 273 bool HasPendingAsyncTouchMove() const { |
| 270 return queue_->HasPendingAsyncTouchMoveForTesting(); | 274 return queue_->HasPendingAsyncTouchMoveForTesting(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 313 |
| 310 private: | 314 private: |
| 311 void SendTouchEvent() { | 315 void SendTouchEvent() { |
| 312 SendTouchEvent(touch_event_); | 316 SendTouchEvent(touch_event_); |
| 313 touch_event_.ResetPoints(); | 317 touch_event_.ResetPoints(); |
| 314 } | 318 } |
| 315 | 319 |
| 316 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { | 320 void ResetQueueWithConfig(const TouchEventQueue::Config& config) { |
| 317 queue_.reset(new TouchEventQueue(this, config)); | 321 queue_.reset(new TouchEventQueue(this, config)); |
| 318 queue_->OnHasTouchEventHandlers(true); | 322 queue_->OnHasTouchEventHandlers(true); |
| 323 queue_->OnHasTouchMoveEventHandlers(true); |
| 319 } | 324 } |
| 320 | 325 |
| 321 scoped_ptr<TouchEventQueue> queue_; | 326 scoped_ptr<TouchEventQueue> queue_; |
| 322 size_t acked_event_count_; | 327 size_t acked_event_count_; |
| 323 WebTouchEvent last_acked_event_; | 328 WebTouchEvent last_acked_event_; |
| 324 std::vector<WebTouchEvent> sent_events_; | 329 std::vector<WebTouchEvent> sent_events_; |
| 325 InputEventAckState last_acked_event_state_; | 330 InputEventAckState last_acked_event_state_; |
| 326 SyntheticWebTouchEvent touch_event_; | 331 SyntheticWebTouchEvent touch_event_; |
| 327 scoped_ptr<WebTouchEvent> followup_touch_event_; | 332 scoped_ptr<WebTouchEvent> followup_touch_event_; |
| 328 scoped_ptr<WebGestureEvent> followup_gesture_event_; | 333 scoped_ptr<WebGestureEvent> followup_gesture_event_; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 EXPECT_EQ(0U, GetAndResetSentEventCount()); | 577 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 573 | 578 |
| 574 // The ack should trigger forwarding of the touchmove, as if no touch | 579 // The ack should trigger forwarding of the touchmove, as if no touch |
| 575 // handler registration changes have occurred. | 580 // handler registration changes have occurred. |
| 576 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 581 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 577 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 582 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 578 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 583 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 579 EXPECT_EQ(1U, queued_event_count()); | 584 EXPECT_EQ(1U, queued_event_count()); |
| 580 } | 585 } |
| 581 | 586 |
| 587 TEST_F(TouchEventQueueTest, TouchMoveNotForwardedIfNoTouchMoveHandlers) { |
| 588 OnHasTouchEventHandlers(true); |
| 589 OnHasTouchMoveEventHandlers(false); |
| 590 |
| 591 // Send a touch-press event. |
| 592 PressTouchPoint(1, 1); |
| 593 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 594 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 595 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 596 |
| 597 // As there are no touchmove handlers, touchmoves should not be forwarded. |
| 598 MoveTouchPoint(0, 5, 5); |
| 599 EXPECT_EQ(0U, queued_event_count()); |
| 600 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 601 EXPECT_EQ(0U, GetAndResetSentEventCount()); |
| 602 EXPECT_EQ(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS, acked_event_state()); |
| 603 |
| 604 // If a touchmove handler is added, we should resume forwarding touchmove's |
| 605 // (even if we've dropped previous touchmoves). |
| 606 OnHasTouchMoveEventHandlers(true); |
| 607 MoveTouchPoint(0, 50, 50); |
| 608 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 609 SendTouchEventAck(INPUT_EVENT_ACK_STATE_CONSUMED); |
| 610 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 611 |
| 612 ReleaseTouchPoint(0); |
| 613 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 614 SendTouchEventAck(INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 615 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 616 } |
| 617 |
| 582 // Tests that touch-events are coalesced properly in the queue. | 618 // Tests that touch-events are coalesced properly in the queue. |
| 583 TEST_F(TouchEventQueueTest, Coalesce) { | 619 TEST_F(TouchEventQueueTest, Coalesce) { |
| 584 // Send a touch-press event. | 620 // Send a touch-press event. |
| 585 PressTouchPoint(1, 1); | 621 PressTouchPoint(1, 1); |
| 586 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 622 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 587 | 623 |
| 588 // Send a few touch-move events, followed by a touch-release event. All the | 624 // Send a few touch-move events, followed by a touch-release event. All the |
| 589 // touch-move events should be coalesced into a single event. | 625 // touch-move events should be coalesced into a single event. |
| 590 for (float i = 5; i < 15; ++i) | 626 for (float i = 5; i < 15; ++i) |
| 591 MoveTouchPoint(0, i, i); | 627 MoveTouchPoint(0, i, i); |
| (...skipping 2014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2606 // TouchMove should be allowed and test for touches state. | 2642 // TouchMove should be allowed and test for touches state. |
| 2607 const WebTouchEvent& event2 = sent_event(); | 2643 const WebTouchEvent& event2 = sent_event(); |
| 2608 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); | 2644 EXPECT_EQ(WebInputEvent::TouchMove, event2.type); |
| 2609 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); | 2645 EXPECT_EQ(WebTouchPoint::StateStationary, event2.touches[0].state); |
| 2610 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); | 2646 EXPECT_EQ(WebTouchPoint::StateMoved, event2.touches[1].state); |
| 2611 EXPECT_EQ(1U, GetAndResetSentEventCount()); | 2647 EXPECT_EQ(1U, GetAndResetSentEventCount()); |
| 2612 EXPECT_EQ(1U, GetAndResetAckedEventCount()); | 2648 EXPECT_EQ(1U, GetAndResetAckedEventCount()); |
| 2613 } | 2649 } |
| 2614 | 2650 |
| 2615 } // namespace content | 2651 } // namespace content |
| OLD | NEW |