| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 if (pending_events_.empty()) { | 679 if (pending_events_.empty()) { |
| 680 base::ThreadTaskRunnerHandle::Get()->PostTask( | 680 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 681 FROM_HERE, | 681 FROM_HERE, |
| 682 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 682 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 683 base::Unretained(this))); | 683 base::Unretained(this))); |
| 684 } | 684 } |
| 685 pending_events_.push_back(std::move(pending_event)); | 685 pending_events_.push_back(std::move(pending_event)); |
| 686 } else { | 686 } else { |
| 687 if (event->IsKeyEvent()) | 687 if (event->IsKeyEvent()) |
| 688 delegate()->DispatchKeyEventToIME(current_target_, event->AsKeyEvent()); | 688 delegate()->DispatchKeyEventToIME(current_target_, event->AsKeyEvent()); |
| 689 MaybeDispatchToPointerWatchers(*event); |
| 689 if (!event->handled()) { | 690 if (!event->handled()) { |
| 690 ui::EventSource* event_source = | 691 ui::EventSource* event_source = |
| 691 delegate()->GetEventSource(current_target_); | 692 delegate()->GetEventSource(current_target_); |
| 692 ui::EventSourceTestApi event_source_test(event_source); | 693 ui::EventSourceTestApi event_source_test(event_source); |
| 693 ui::EventDispatchDetails details = | 694 ui::EventDispatchDetails details = |
| 694 event_source_test.SendEventToProcessor(event); | 695 event_source_test.SendEventToProcessor(event); |
| 695 CHECK(!details.dispatcher_destroyed); | 696 CHECK(!details.dispatcher_destroyed); |
| 696 } | 697 } |
| 697 } | 698 } |
| 698 } | 699 } |
| 699 | 700 |
| 701 void EventGenerator::MaybeDispatchToPointerWatchers(const Event& event) { |
| 702 // Regular pointer events can be dispatched directly. |
| 703 if (event.IsPointerEvent()) { |
| 704 delegate()->DispatchEventToPointerWatchers(current_target_, |
| 705 *event.AsPointerEvent()); |
| 706 return; |
| 707 } |
| 708 |
| 709 // PointerWatchers always use pointer events, so mouse and touch events |
| 710 // need to be converted. |
| 711 if (!PointerEvent::CanConvertFrom(event)) |
| 712 return; |
| 713 if (event.IsMouseEvent()) { |
| 714 delegate()->DispatchEventToPointerWatchers( |
| 715 current_target_, PointerEvent(*event.AsMouseEvent())); |
| 716 } else if (event.IsTouchEvent()) { |
| 717 delegate()->DispatchEventToPointerWatchers( |
| 718 current_target_, PointerEvent(*event.AsTouchEvent())); |
| 719 } |
| 720 } |
| 721 |
| 700 void EventGenerator::DispatchNextPendingEvent() { | 722 void EventGenerator::DispatchNextPendingEvent() { |
| 701 DCHECK(!pending_events_.empty()); | 723 DCHECK(!pending_events_.empty()); |
| 702 ui::Event* event = pending_events_.front().get(); | 724 ui::Event* event = pending_events_.front().get(); |
| 703 DoDispatchEvent(event, false); | 725 DoDispatchEvent(event, false); |
| 704 pending_events_.pop_front(); | 726 pending_events_.pop_front(); |
| 705 if (!pending_events_.empty()) { | 727 if (!pending_events_.empty()) { |
| 706 base::ThreadTaskRunnerHandle::Get()->PostTask( | 728 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 707 FROM_HERE, | 729 FROM_HERE, |
| 708 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 730 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 709 base::Unretained(this))); | 731 base::Unretained(this))); |
| 710 } | 732 } |
| 711 } | 733 } |
| 712 | 734 |
| 713 const EventGeneratorDelegate* EventGenerator::delegate() const { | 735 const EventGeneratorDelegate* EventGenerator::delegate() const { |
| 714 if (delegate_) | 736 if (delegate_) |
| 715 return delegate_.get(); | 737 return delegate_.get(); |
| 716 | 738 |
| 717 DCHECK(default_delegate); | 739 DCHECK(default_delegate); |
| 718 return default_delegate; | 740 return default_delegate; |
| 719 } | 741 } |
| 720 | 742 |
| 721 EventGeneratorDelegate* EventGenerator::delegate() { | 743 EventGeneratorDelegate* EventGenerator::delegate() { |
| 722 return const_cast<EventGeneratorDelegate*>( | 744 return const_cast<EventGeneratorDelegate*>( |
| 723 const_cast<const EventGenerator*>(this)->delegate()); | 745 const_cast<const EventGenerator*>(this)->delegate()); |
| 724 } | 746 } |
| 725 | 747 |
| 726 } // namespace test | 748 } // namespace test |
| 727 } // namespace ui | 749 } // namespace ui |
| OLD | NEW |