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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 DispatchKeyEvent(false, key_code, flags); | 592 DispatchKeyEvent(false, key_code, flags); |
| 593 } | 593 } |
| 594 | 594 |
| 595 void EventGenerator::Dispatch(ui::Event* event) { | 595 void EventGenerator::Dispatch(ui::Event* event) { |
| 596 DoDispatchEvent(event, async_); | 596 DoDispatchEvent(event, async_); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) { | 599 void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) { |
| 600 scoped_refptr<ClonableTickClock> clonable = | 600 scoped_refptr<ClonableTickClock> clonable = |
| 601 new ClonableTickClock(std::move(tick_clock)); | 601 new ClonableTickClock(std::move(tick_clock)); |
| 602 #if defined(USE_X11) | 602 ui::SetEventTickClockForTesting(clonable->Clone()); |
| 603 ResetTimestampRolloverCountersForTesting(clonable->Clone()); | |
| 604 #endif | |
| 605 tick_clock_ = clonable->Clone(); | 603 tick_clock_ = clonable->Clone(); |
| 606 } | 604 } |
| 607 | 605 |
| 608 base::TimeTicks EventGenerator::Now() { | 606 base::TimeTicks EventGenerator::Now() { |
| 609 // This is the same as what EventTimeForNow() does, but here we do it | 607 // This is the same as what EventTimeForNow() does, but here we do it |
| 610 // with a tick clock that can be replaced with a simulated clock for tests. | 608 // with a tick clock that can be replaced with a simulated clock for tests. |
| 609 // TODO(majidvp): The tick clock used by |ui::EventTimeForNow()| is now | |
| 610 // mockable so we no longer need this. | |
|
sadrul
2016/06/23 16:38:37
So SetTickClick() and Now() from EventGenerator ca
majidvp
2016/06/24 19:40:56
Yes. I think we can replace them with ui::SetEvent
| |
| 611 return tick_clock_->NowTicks(); | 611 return tick_clock_->NowTicks(); |
| 612 } | 612 } |
| 613 | 613 |
| 614 void EventGenerator::Init(gfx::NativeWindow root_window, | 614 void EventGenerator::Init(gfx::NativeWindow root_window, |
| 615 gfx::NativeWindow window_context) { | 615 gfx::NativeWindow window_context) { |
| 616 SetTickClock(WrapUnique(new TestTickClock())); | 616 SetTickClock(WrapUnique(new TestTickClock())); |
| 617 delegate()->SetContext(this, root_window, window_context); | 617 delegate()->SetContext(this, root_window, window_context); |
| 618 if (window_context) | 618 if (window_context) |
| 619 current_location_ = delegate()->CenterOfWindow(window_context); | 619 current_location_ = delegate()->CenterOfWindow(window_context); |
| 620 current_target_ = delegate()->GetTargetAt(current_location_); | 620 current_target_ = delegate()->GetTargetAt(current_location_); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 return default_delegate; | 736 return default_delegate; |
| 737 } | 737 } |
| 738 | 738 |
| 739 EventGeneratorDelegate* EventGenerator::delegate() { | 739 EventGeneratorDelegate* EventGenerator::delegate() { |
| 740 return const_cast<EventGeneratorDelegate*>( | 740 return const_cast<EventGeneratorDelegate*>( |
| 741 const_cast<const EventGenerator*>(this)->delegate()); | 741 const_cast<const EventGenerator*>(this)->delegate()); |
| 742 } | 742 } |
| 743 | 743 |
| 744 } // namespace test | 744 } // namespace test |
| 745 } // namespace ui | 745 } // namespace ui |
| OLD | NEW |