Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/events/test/event_generator.h" | 5 #include "ui/events/test/event_generator.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | |
| 11 #include "base/time/default_tick_clock.h" | 12 #include "base/time/default_tick_clock.h" |
| 12 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 13 #include "ui/events/event_source.h" | 14 #include "ui/events/event_source.h" |
| 14 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 15 #include "ui/events/test/events_test_utils.h" | 16 #include "ui/events/test/events_test_utils.h" |
| 16 #include "ui/gfx/vector2d_conversions.h" | 17 #include "ui/gfx/vector2d_conversions.h" |
| 17 | 18 |
| 18 #if defined(USE_X11) | 19 #if defined(USE_X11) |
| 19 #include <X11/Xlib.h> | 20 #include <X11/Xlib.h> |
| 20 #include "ui/events/test/events_test_utils_x11.h" | 21 #include "ui/events/test/events_test_utils_x11.h" |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 } else if (event->IsTouchEvent()) { | 583 } else if (event->IsTouchEvent()) { |
| 583 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event)); | 584 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event)); |
| 584 } else if (event->IsScrollEvent()) { | 585 } else if (event->IsScrollEvent()) { |
| 585 pending_event = | 586 pending_event = |
| 586 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event)); | 587 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event)); |
| 587 } else { | 588 } else { |
| 588 NOTREACHED() << "Invalid event type"; | 589 NOTREACHED() << "Invalid event type"; |
| 589 return; | 590 return; |
| 590 } | 591 } |
| 591 if (pending_events_.empty()) { | 592 if (pending_events_.empty()) { |
| 592 base::MessageLoopProxy::current()->PostTask( | 593 base::ThreadTaskRunnerHandle::Get()->PostTask( |
|
sky
2014/09/02 15:34:14
ML::current()->
| |
| 593 FROM_HERE, | 594 FROM_HERE, |
| 594 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 595 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 595 base::Unretained(this))); | 596 base::Unretained(this))); |
| 596 } | 597 } |
| 597 pending_events_.push_back(pending_event); | 598 pending_events_.push_back(pending_event); |
| 598 } else { | 599 } else { |
| 599 ui::EventSource* event_source = delegate()->GetEventSource(current_target_); | 600 ui::EventSource* event_source = delegate()->GetEventSource(current_target_); |
| 600 ui::EventSourceTestApi event_source_test(event_source); | 601 ui::EventSourceTestApi event_source_test(event_source); |
| 601 ui::EventDispatchDetails details = | 602 ui::EventDispatchDetails details = |
| 602 event_source_test.SendEventToProcessor(event); | 603 event_source_test.SendEventToProcessor(event); |
| 603 CHECK(!details.dispatcher_destroyed); | 604 CHECK(!details.dispatcher_destroyed); |
| 604 } | 605 } |
| 605 } | 606 } |
| 606 | 607 |
| 607 void EventGenerator::DispatchNextPendingEvent() { | 608 void EventGenerator::DispatchNextPendingEvent() { |
| 608 DCHECK(!pending_events_.empty()); | 609 DCHECK(!pending_events_.empty()); |
| 609 ui::Event* event = pending_events_.front(); | 610 ui::Event* event = pending_events_.front(); |
| 610 DoDispatchEvent(event, false); | 611 DoDispatchEvent(event, false); |
| 611 pending_events_.pop_front(); | 612 pending_events_.pop_front(); |
| 612 delete event; | 613 delete event; |
| 613 if (!pending_events_.empty()) { | 614 if (!pending_events_.empty()) { |
| 614 base::MessageLoopProxy::current()->PostTask( | 615 base::ThreadTaskRunnerHandle::Get()->PostTask( |
|
sky
2014/09/02 15:34:14
ML::current()->
| |
| 615 FROM_HERE, | 616 FROM_HERE, |
| 616 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 617 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 617 base::Unretained(this))); | 618 base::Unretained(this))); |
| 618 } | 619 } |
| 619 } | 620 } |
| 620 | 621 |
| 621 const EventGeneratorDelegate* EventGenerator::delegate() const { | 622 const EventGeneratorDelegate* EventGenerator::delegate() const { |
| 622 if (delegate_) | 623 if (delegate_) |
| 623 return delegate_.get(); | 624 return delegate_.get(); |
| 624 | 625 |
| 625 DCHECK(default_delegate); | 626 DCHECK(default_delegate); |
| 626 return default_delegate; | 627 return default_delegate; |
| 627 } | 628 } |
| 628 | 629 |
| 629 EventGeneratorDelegate* EventGenerator::delegate() { | 630 EventGeneratorDelegate* EventGenerator::delegate() { |
| 630 return const_cast<EventGeneratorDelegate*>( | 631 return const_cast<EventGeneratorDelegate*>( |
| 631 const_cast<const EventGenerator*>(this)->delegate()); | 632 const_cast<const EventGenerator*>(this)->delegate()); |
| 632 } | 633 } |
| 633 | 634 |
| 634 } // namespace test | 635 } // namespace test |
| 635 } // namespace ui | 636 } // namespace ui |
| OLD | NEW |