Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Unified Diff: ui/events/test/event_generator.cc

Issue 1975533002: Change ui::Event::time_stamp from TimeDelta to TimeTicks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix gesture recognizer tests Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/test/event_generator.cc
diff --git a/ui/events/test/event_generator.cc b/ui/events/test/event_generator.cc
index 2299f10c692db5a632eb07bc9e23cbf1fa412ae8..21198b58709dfd99730a7b0963b6775af42e5b0a 100644
--- a/ui/events/test/event_generator.cc
+++ b/ui/events/test/event_generator.cc
@@ -105,7 +105,7 @@ class TestTouchEvent : public ui::TouchEvent {
const gfx::Point& root_location,
int touch_id,
int flags,
- base::TimeDelta timestamp)
+ base::TimeTicks timestamp)
: TouchEvent(type,
root_location,
flags,
@@ -222,7 +222,7 @@ void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host,
ui::ScopedXI2Event xevent;
xevent.InitMotionEvent(point_in_host, point_for_native, flags_);
static_cast<XEvent*>(xevent)->xmotion.time =
- Now().InMilliseconds() & UINT32_MAX;
+ (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX;
ui::MouseEvent mouseev(xevent);
#elif defined(USE_OZONE)
// Ozone uses the location in native event as a system location.
@@ -400,7 +400,7 @@ void EventGenerator::GestureScrollSequenceWithCallback(
int steps,
const ScrollStepCallback& callback) {
const int kTouchId = 5;
- base::TimeDelta timestamp = Now();
+ base::TimeTicks timestamp = Now();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, 0, kTouchId,
timestamp, 5.0f, 5.0f, 0.0f, 1.0f);
Dispatch(&press);
@@ -460,8 +460,8 @@ void EventGenerator::GestureMultiFingerScrollWithDelays(
points[i] = start[i];
}
- base::TimeDelta press_time_first = Now();
- base::TimeDelta press_time[kMaxTouchPoints];
+ base::TimeTicks press_time_first = Now();
+ base::TimeTicks press_time[kMaxTouchPoints];
bool pressed[kMaxTouchPoints];
for (int i = 0; i < count; ++i) {
pressed[i] = false;
@@ -471,7 +471,8 @@ void EventGenerator::GestureMultiFingerScrollWithDelays(
int last_id = 0;
for (int step = 0; step < steps; ++step) {
- base::TimeDelta move_time = press_time_first +
+ base::TimeTicks move_time =
+ press_time_first +
base::TimeDelta::FromMilliseconds(event_separation_time_ms * step);
while (last_id < count &&
@@ -495,7 +496,8 @@ void EventGenerator::GestureMultiFingerScrollWithDelays(
}
}
- base::TimeDelta release_time = press_time_first +
+ base::TimeTicks release_time =
+ press_time_first +
base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps);
for (int i = 0; i < last_id; ++i) {
ui::TouchEvent release(
@@ -510,7 +512,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start,
float y_offset,
int steps,
int num_fingers) {
- base::TimeDelta timestamp = Now();
+ base::TimeTicks timestamp = Now();
ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
start,
timestamp,
@@ -549,7 +551,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start,
const std::vector<gfx::PointF>& offsets,
int num_fingers) {
size_t steps = offsets.size();
- base::TimeDelta timestamp = Now();
+ base::TimeTicks timestamp = Now();
ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
start,
timestamp,
@@ -602,11 +604,10 @@ void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) {
tick_clock_ = clonable->Clone();
}
-base::TimeDelta EventGenerator::Now() {
+base::TimeTicks EventGenerator::Now() {
// This is the same as what EventTimeForNow() does, but here we do it
// with a tick clock that can be replaced with a simulated clock for tests.
- return base::TimeDelta::FromInternalValue(
- tick_clock_->NowTicks().ToInternalValue());
+ return tick_clock_->NowTicks();
}
void EventGenerator::Init(gfx::NativeWindow root_window,
@@ -636,14 +637,15 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
}
MSG native_event =
{ NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 };
- native_event.time = Now().InMicroseconds();
+ native_event.time = (Now() - base::TimeTicks()).InMicroseconds();
TestKeyEvent keyev(native_event, flags);
#elif defined(USE_X11)
ui::ScopedXI2Event xevent;
xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
key_code,
flags);
- static_cast<XEvent*>(xevent)->xkey.time = Now().InMilliseconds() & UINT32_MAX;
+ static_cast<XEvent*>(xevent)->xkey.time =
+ (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX;
ui::KeyEvent keyev(xevent);
#else
ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;

Powered by Google App Engine
This is Rietveld 408576698