OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 ui::EventType wait_until_event_; | 330 ui::EventType wait_until_event_; |
331 | 331 |
332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); | 332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); |
333 }; | 333 }; |
334 | 334 |
335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { | 335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { |
336 public: | 336 public: |
337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) | 337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) |
338 : window_(NULL), | 338 : window_(NULL), |
339 dispatcher_(dispatcher), | 339 dispatcher_(dispatcher), |
340 queue_events_(true), | 340 synchronous_ack_for_next_event_(AckState::PENDING) {} |
341 synchronous_ack_for_next_event_(AckState::PENDING) { | 341 |
342 } | 342 ~QueueTouchEventDelegate() override {} |
343 ~QueueTouchEventDelegate() override { | |
344 while(!queue_.empty()) { | |
345 delete queue_.front(); | |
346 queue_.pop(); | |
347 } | |
348 } | |
349 | 343 |
350 void OnTouchEvent(ui::TouchEvent* event) override { | 344 void OnTouchEvent(ui::TouchEvent* event) override { |
351 event->DisableSynchronousHandling(); | 345 event->DisableSynchronousHandling(); |
352 if (synchronous_ack_for_next_event_ != AckState::PENDING) { | 346 if (synchronous_ack_for_next_event_ != AckState::PENDING) { |
353 ui::GestureRecognizer::Get()->AckSyncTouchEvent( | 347 ui::GestureRecognizer::Get()->AckSyncTouchEvent( |
354 event->unique_event_id(), | 348 event->unique_event_id(), |
355 synchronous_ack_for_next_event_ == AckState::CONSUMED | 349 synchronous_ack_for_next_event_ == AckState::CONSUMED |
356 ? ui::ER_CONSUMED | 350 ? ui::ER_CONSUMED |
357 : ui::ER_UNHANDLED, | 351 : ui::ER_UNHANDLED, |
358 window_); | 352 window_); |
359 synchronous_ack_for_next_event_ = AckState::PENDING; | 353 synchronous_ack_for_next_event_ = AckState::PENDING; |
360 } | 354 } |
361 if (queue_events_) | |
362 queue_.push(new ui::TouchEvent(*event, window_, window_)); | |
363 } | 355 } |
364 | 356 |
365 void ReceivedAck() { | 357 void ReceivedAck() { |
366 ReceivedAckImpl(false); | 358 ReceivedAckImpl(false); |
367 } | 359 } |
368 | 360 |
369 void ReceivedAckPreventDefaulted() { | 361 void ReceivedAckPreventDefaulted() { |
370 ReceivedAckImpl(true); | 362 ReceivedAckImpl(true); |
371 } | 363 } |
372 | 364 |
373 void set_window(Window* w) { window_ = w; } | 365 void set_window(Window* w) { window_ = w; } |
374 void set_queue_events(bool queue) { queue_events_ = queue; } | |
375 void set_synchronous_ack_for_next_event(bool consumed) { | 366 void set_synchronous_ack_for_next_event(bool consumed) { |
376 DCHECK(synchronous_ack_for_next_event_ == AckState::PENDING); | 367 DCHECK(synchronous_ack_for_next_event_ == AckState::PENDING); |
377 synchronous_ack_for_next_event_ = | 368 synchronous_ack_for_next_event_ = |
378 consumed ? AckState::CONSUMED : AckState::UNCONSUMED; | 369 consumed ? AckState::CONSUMED : AckState::UNCONSUMED; |
379 } | 370 } |
380 | 371 |
381 private: | 372 private: |
382 enum class AckState { | 373 enum class AckState { |
383 PENDING, | 374 PENDING, |
384 CONSUMED, | 375 CONSUMED, |
385 UNCONSUMED, | 376 UNCONSUMED, |
386 }; | 377 }; |
387 | 378 |
388 void ReceivedAckImpl(bool prevent_defaulted) { | 379 void ReceivedAckImpl(bool prevent_defaulted) { |
389 scoped_ptr<ui::TouchEvent> event(queue_.front()); | 380 dispatcher_->ProcessedTouchEvent( |
390 dispatcher_->ProcessedTouchEvent(event.get(), window_, | 381 window_, prevent_defaulted ? ui::ER_HANDLED : ui::ER_UNHANDLED); |
391 prevent_defaulted ? ui::ER_HANDLED : ui::ER_UNHANDLED); | |
392 queue_.pop(); | |
393 } | 382 } |
394 | 383 |
395 std::queue<ui::TouchEvent*> queue_; | |
396 Window* window_; | 384 Window* window_; |
397 WindowEventDispatcher* dispatcher_; | 385 WindowEventDispatcher* dispatcher_; |
398 bool queue_events_; | |
399 AckState synchronous_ack_for_next_event_; | 386 AckState synchronous_ack_for_next_event_; |
400 | 387 |
401 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); | 388 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); |
402 }; | 389 }; |
403 | 390 |
404 // A delegate that ignores gesture events but keeps track of [synthetic] mouse | 391 // A delegate that ignores gesture events but keeps track of [synthetic] mouse |
405 // events. | 392 // events. |
406 class GestureEventSynthDelegate : public TestWindowDelegate { | 393 class GestureEventSynthDelegate : public TestWindowDelegate { |
407 public: | 394 public: |
408 GestureEventSynthDelegate() | 395 GestureEventSynthDelegate() |
(...skipping 4020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4429 // The synchronous ack is stuck behind the pending touch move. | 4416 // The synchronous ack is stuck behind the pending touch move. |
4430 EXPECT_0_EVENTS(delegate->events()); | 4417 EXPECT_0_EVENTS(delegate->events()); |
4431 | 4418 |
4432 delegate->ReceivedAck(); | 4419 delegate->ReceivedAck(); |
4433 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE, | 4420 EXPECT_2_EVENTS(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE, |
4434 ui::ET_GESTURE_SCROLL_UPDATE); | 4421 ui::ET_GESTURE_SCROLL_UPDATE); |
4435 } | 4422 } |
4436 | 4423 |
4437 } // namespace test | 4424 } // namespace test |
4438 } // namespace aura | 4425 } // namespace aura |
OLD | NEW |