Skip to content

Commit

Permalink
Change ui::Event::time_stamp from TimeDelta to TimeTicks
Browse files Browse the repository at this point in the history
Event timestamp values are now consistently coming from the same clock as
base::TimeTicks. Historically this was not the case in particular on Windows
platform which is why we were using  base::TimeDelta instead.

Now that this has been addressed we should use base::TimeTicks to make it clear
that these values are expected to come from the same clock and remove some
crufty code.

The changes in the CL are pretty simple and mechanical:
- Introduce a pair of conversion functions in ui/events/base_event_utils.h to
convert between  WebInputEvent::timeStampSeconds (double) and
ui::Event::timeStamp (TimeTicks)
- TimeDelta() =>TimeTicks()
- TimeDelta::FromMilliseconds(0) => base::TimeTicks()
- TimeDelta::FromInternalValue(TimeTicks::Now().ToInternalValue())  => TimeTicks::Now()
- TimeDelta::FromMilliseconds(Time::Now().ToDoubleT() * 1000) => TimeTicks::Now()
- Time::NowFromSystemTime() - base::Time() => TimeTicks::Now()

BUG=453559

Review-Url: https://codereview.chromium.org/1975533002
Cr-Commit-Position: refs/heads/master@{#398947}
  • Loading branch information
majido authored and Commit bot committed Jun 9, 2016
1 parent b38a7f9 commit 9b3bda8
Show file tree
Hide file tree
Showing 144 changed files with 649 additions and 684 deletions.
2 changes: 1 addition & 1 deletion ash/drag_drop/drag_drop_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ TEST_F(DragDropControllerTest, TouchDragDropCompletesOnFling) {
gfx::Point mid = start + gfx::Vector2d(drag_view->bounds().width() / 6, 0);
gfx::Point end = start + gfx::Vector2d(drag_view->bounds().width() / 3, 0);

base::TimeDelta timestamp = ui::EventTimeForNow();
base::TimeTicks timestamp = ui::EventTimeForNow();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, 0, timestamp);
generator.Dispatch(&press);

Expand Down
2 changes: 1 addition & 1 deletion ash/keyboard_uma_event_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void KeyboardUMAEventFilter::OnKeyEvent(ui::KeyEvent* event) {

// Reset the timer on non-character keystrokes.
if (!isprint(event->GetCharacter())) {
last_keystroke_time_ = base::TimeDelta();
last_keystroke_time_ = base::TimeTicks();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion ash/keyboard_uma_event_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class KeyboardUMAEventFilter : public ui::EventHandler {

private:
// The timestamp of the last character keystroke.
base::TimeDelta last_keystroke_time_;
base::TimeTicks last_keystroke_time_;

DISALLOW_COPY_AND_ASSIGN(KeyboardUMAEventFilter);
};
Expand Down
9 changes: 4 additions & 5 deletions ash/shelf/shelf_button_pressed_metric_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ class DummyEvent : public ui::Event {
int DummyEvent::next_unique_id_ = 0;

DummyEvent::DummyEvent()
: Event(ui::ET_GESTURE_TAP, base::TimeDelta(), 0),
unique_id_(next_unique_id_++) {
}
: Event(ui::ET_GESTURE_TAP, base::TimeTicks(), 0),
unique_id_(next_unique_id_++) {}

DummyEvent::~DummyEvent() {
}
Expand Down Expand Up @@ -162,7 +161,7 @@ void ShelfButtonPressedMetricTrackerTest::ButtonPressed(
TEST_F(ShelfButtonPressedMetricTrackerTest,
Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByMouse) {
const ui::MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, gfx::Point(),
gfx::Point(), base::TimeDelta(), 0, 0);
gfx::Point(), base::TimeTicks(), 0, 0);

base::UserActionTester user_action_tester;
ButtonPressed(mouse_event);
Expand All @@ -175,7 +174,7 @@ TEST_F(ShelfButtonPressedMetricTrackerTest,
TEST_F(ShelfButtonPressedMetricTrackerTest,
Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByTouch) {
const ui::TouchEvent touch_event(ui::ET_GESTURE_TAP, gfx::Point(), 0,
base::TimeDelta());
base::TimeTicks());

base::UserActionTester user_action_tester;
ButtonPressed(touch_event);
Expand Down
16 changes: 8 additions & 8 deletions ash/shelf/shelf_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ ShelfView::ShelfView(ShelfModel* model,
leading_inset_(kDefaultLeadingInset),
cancelling_drag_model_changed_(false),
last_hidden_index_(0),
closing_event_time_(base::TimeDelta()),
closing_event_time_(base::TimeTicks()),
got_deleted_(nullptr),
drag_and_drop_item_pinned_(false),
drag_and_drop_shelf_id_(0),
Expand Down Expand Up @@ -1794,7 +1794,7 @@ void ShelfView::ShowMenu(ui::MenuModel* menu_model,
const gfx::Point& click_point,
bool context_menu,
ui::MenuSourceType source_type) {
closing_event_time_ = base::TimeDelta();
closing_event_time_ = base::TimeTicks();
launcher_menu_runner_.reset(new views::MenuRunner(
menu_model, context_menu ? views::MenuRunner::CONTEXT_MENU : 0));

Expand Down Expand Up @@ -1847,7 +1847,8 @@ void ShelfView::ShowMenu(ui::MenuModel* menu_model,

// Unpinning an item will reset |launcher_menu_runner_| before coming here.
if (launcher_menu_runner_)
closing_event_time_ = launcher_menu_runner_->closing_event_time();
closing_event_time_ =
base::TimeTicks() + launcher_menu_runner_->closing_event_time();
Shell::GetInstance()->UpdateShelfVisibility();
}

Expand Down Expand Up @@ -1879,15 +1880,14 @@ void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
}

bool ShelfView::IsRepostEvent(const ui::Event& event) {
if (closing_event_time_.is_zero())
if (closing_event_time_.is_null())
return false;

base::TimeDelta delta =
base::TimeDelta(event.time_stamp() - closing_event_time_);
closing_event_time_ = base::TimeDelta();
base::TimeTicks last_closing_event_time = closing_event_time_;
closing_event_time_ = base::TimeTicks();
// If the current (press down) event is a repost event, the time stamp of
// these two events should be the same.
return (delta.InMilliseconds() == 0);
return last_closing_event_time == event.time_stamp();
}

const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
Expand Down
2 changes: 1 addition & 1 deletion ash/shelf/shelf_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class ASH_EXPORT ShelfView : public views::View,
mutable int last_hidden_index_;

// The timestamp of the event which closed the last menu - or 0.
base::TimeDelta closing_event_time_;
base::TimeTicks closing_event_time_;

// When this object gets deleted while a menu is shown, this pointed
// element will be set to false.
Expand Down
4 changes: 2 additions & 2 deletions ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) {
maximize_mode_controller->EnableMaximizeModeWindowManager(true);
ASSERT_FALSE(tray_view()->visible());

ui::GestureEvent tap(
0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
default_view()->OnGestureEvent(&tap);
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_TRUE(tray_view()->visible());
Expand Down
4 changes: 2 additions & 2 deletions ash/system/ime/tray_ime_chromeos_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ TEST_F(TrayIMETest, PerformActionOnDetailedView) {
test::VirtualKeyboardTestHelper::SuppressKeyboard();
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
views::View* toggle = GetScrollChildView(0);
ui::GestureEvent tap(0, 0, 0, base::TimeDelta(),
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
// Enable the keyboard.
toggle->OnGestureEvent(&tap);
Expand All @@ -151,7 +151,7 @@ TEST_F(TrayIMETest, PerformActionOnDetailedView) {
// With no IMEs the toggle should be the first child.
toggle = GetScrollChildView(0);
// Clicking again should disable the keyboard.
tap = ui::GestureEvent(0, 0, 0, base::TimeDelta(),
tap = ui::GestureEvent(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
toggle->OnGestureEvent(&tap);
EXPECT_FALSE(keyboard::IsKeyboardEnabled());
Expand Down
10 changes: 5 additions & 5 deletions ash/system/overview/overview_button_tray_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ TEST_F(OverviewButtonTrayTest, PerformAction) {
// Overview Mode only works when there is a window
std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
ui::GestureEvent tap(
0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
GetTray()->PerformAction(tap);
EXPECT_TRUE(Shell::GetInstance()->window_selector_controller()->
IsSelecting());
Expand All @@ -119,7 +119,7 @@ TEST_F(OverviewButtonTrayTest, TrayOverviewUserAction) {
// Tapping on the control when there are no windows (and thus the user cannot
// enter overview mode) should still record the action.
base::UserActionTester user_action_tester;
ui::GestureEvent tap(0, 0, 0, base::TimeDelta(),
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
GetTray()->PerformAction(tap);
ASSERT_FALSE(
Expand Down Expand Up @@ -208,8 +208,8 @@ TEST_F(OverviewButtonTrayTest, ActiveStateOnlyDuringOverviewMode) {
// Overview Mode only works when there is a window
std::unique_ptr<aura::Window> window(
CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
ui::GestureEvent tap(
0, 0, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_TAP));
ui::GestureEvent tap(0, 0, 0, base::TimeTicks(),
ui::GestureEventDetails(ui::ET_GESTURE_TAP));
GetTray()->PerformAction(tap);
EXPECT_TRUE(
Shell::GetInstance()->window_selector_controller()->IsSelecting());
Expand Down
2 changes: 1 addition & 1 deletion ash/system/toast/toast_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const int32_t kLongLongDuration = INT32_MAX;

class DummyEvent : public ui::Event {
public:
DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeDelta(), 0) {}
DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {}
~DummyEvent() override {}
};

Expand Down
2 changes: 1 addition & 1 deletion ash/touch/touch_hud_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct TouchPointLog {
: id(touch.touch_id()),
type(touch.type()),
location(touch.root_location()),
timestamp(touch.time_stamp().InMillisecondsF()),
timestamp((touch.time_stamp() - base::TimeTicks()).InMillisecondsF()),
radius_x(touch.pointer_details().radius_x),
radius_y(touch.pointer_details().radius_y),
pressure(touch.pointer_details().force),
Expand Down
2 changes: 1 addition & 1 deletion ash/touch/touch_observer_hud_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ class TouchHudProjectionTest : public TouchHudTestBase {
}

private:
base::TimeDelta event_time;
base::TimeTicks event_time;

DISALLOW_COPY_AND_ASSIGN(TouchHudProjectionTest);
};
Expand Down
8 changes: 4 additions & 4 deletions ash/touch/touch_uma.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ namespace {

struct WindowTouchDetails {
// Move and start times of the touch points. The key is the touch-id.
std::map<int, base::TimeDelta> last_move_time_;
std::map<int, base::TimeDelta> last_start_time_;
std::map<int, base::TimeTicks> last_move_time_;
std::map<int, base::TimeTicks> last_start_time_;

// The first and last positions of the touch points.
std::map<int, gfx::Point> start_touch_position_;
std::map<int, gfx::Point> last_touch_position_;

// Last time-stamp of the last touch-end event.
base::TimeDelta last_release_time_;
base::TimeTicks last_release_time_;

// Stores the time of the last touch released on this window (if there was a
// multi-touch gesture on the window, then this is the release-time of the
// last touch on the window).
base::TimeDelta last_mt_time_;
base::TimeTicks last_mt_time_;
};

DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails,
Expand Down
2 changes: 1 addition & 1 deletion ash/touch/touch_uma.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ASH_EXPORT TouchUMA {
// quick succession, regardless of the target window.
bool touch_in_progress_;
int burst_length_;
base::TimeDelta last_touch_down_time_;
base::TimeTicks last_touch_down_time_;

DISALLOW_COPY_AND_ASSIGN(TouchUMA);
};
Expand Down
3 changes: 1 addition & 2 deletions ash/wm/gestures/overview_gesture_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ TEST_F(OverviewGestureHandlerTest, SwipeUpDownWithoutReleasing) {
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
ui::test::EventGenerator generator(root_window, root_window);
base::TimeDelta timestamp = base::TimeDelta::FromInternalValue(
base::TimeTicks::Now().ToInternalValue());
base::TimeTicks timestamp = base::TimeTicks::Now();
gfx::Point start;
int num_fingers = 3;
base::TimeDelta step_delay(base::TimeDelta::FromMilliseconds(5));
Expand Down
5 changes: 2 additions & 3 deletions ash/wm/system_gesture_event_filter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ ui::GestureEvent* CreateGesture(ui::EventType type,
int touch_id) {
ui::GestureEventDetails details =
ui::GestureEventDetails(type, delta_x, delta_y);
return new ui::GestureEvent(x, y, 0,
base::TimeDelta::FromMilliseconds(base::Time::Now().ToDoubleT() * 1000),
ui::GestureEventDetails(type, delta_x, delta_y));
return new ui::GestureEvent(x, y, 0, base::TimeTicks::Now(),
ui::GestureEventDetails(type, delta_x, delta_y));
}

TEST_F(SystemGestureEventFilterTest, TwoFingerDrag) {
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/window_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestingCursorClientObserver : public aura::client::CursorClientObserver {
DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver);
};

base::TimeDelta getTime() {
base::TimeTicks getTime() {
return ui::EventTimeForNow();
}

Expand Down
5 changes: 0 additions & 5 deletions base/time/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ std::ostream& operator<<(std::ostream& os, TimeDelta time_delta) {

// Time -----------------------------------------------------------------------

// static
Time Time::Max() {
return Time(std::numeric_limits<int64_t>::max());
}

// static
Time Time::FromTimeT(time_t tt) {
if (tt == 0)
Expand Down
10 changes: 6 additions & 4 deletions base/time/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ class TimeBase {
// Returns true if this object represents the maximum time.
bool is_max() const { return us_ == std::numeric_limits<int64_t>::max(); }

// Returns the maximum time, which should be greater than any reasonable time
// with which we might compare it.
static TimeClass Max() {
return TimeClass(std::numeric_limits<int64_t>::max());
}

// For serializing only. Use FromInternalValue() to reconstitute. Please don't
// use this and do arithmetic on it, as it is more error prone than using the
// provided operators.
Expand Down Expand Up @@ -438,10 +444,6 @@ class BASE_EXPORT Time : public time_internal::TimeBase<Time> {
// times are increasing, or that two calls to Now() won't be the same.
static Time Now();

// Returns the maximum time, which should be greater than any reasonable time
// with which we might compare it.
static Time Max();

// Returns the current time. Same as Now() except that this function always
// uses system time so that there are no discrepancies between the returned
// time and system time even on virtual environments including our test bot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ class TouchExplorationTest : public InProcessBrowserTest {
ad->ToggleSpokenFeedback(ui::A11Y_NOTIFICATION_NONE);
}

base::TimeDelta Now() {
return base::TimeDelta::FromInternalValue(
simulated_clock_->NowTicks().ToInternalValue());
}
base::TimeTicks Now() { return simulated_clock_->NowTicks(); }

ui::GestureDetector::Config gesture_detector_config_;
base::SimpleTestTickClock* simulated_clock_;
Expand All @@ -90,7 +87,7 @@ IN_PROC_BROWSER_TEST_F(TouchExplorationTest, MAYBE_NoRewritingEventsWhenOff) {
SwitchTouchExplorationMode(false);
ui::test::EventGenerator generator(root_window_);

base::TimeDelta initial_time = Now();
base::TimeTicks initial_time = Now();
ui::TouchEvent initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(99, 200), 1, initial_time);
generator.Dispatch(&initial_press);
Expand Down Expand Up @@ -139,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(TouchExplorationTest, DISABLED_RewritesEventsWhenOn) {
SwitchTouchExplorationMode(true);
ui::test::EventGenerator generator(root_window_);

base::TimeDelta initial_time = Now();
base::TimeTicks initial_time = Now();
ui::TouchEvent initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time);
generator.Dispatch(&initial_press);
Expand Down Expand Up @@ -209,7 +206,7 @@ IN_PROC_BROWSER_TEST_F(TouchExplorationTest, DISABLED_SplitTapExplore) {

// The cursor should be shown immediately after the press, and hidden
// after the move.
base::TimeDelta initial_time = Now();
base::TimeTicks initial_time = Now();
ui::TouchEvent initial_press(
ui::ET_TOUCH_PRESSED, gfx::Point(100, 200), 1, initial_time);
generator.Dispatch(&initial_press);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/chromeos/events/event_rewriter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ TEST_F(EventRewriterTest, TestRewriteNonNativeEvent) {
const int kTouchId = 2;
gfx::Point location(0, 0);
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId,
base::TimeDelta());
base::TimeTicks());
press.set_flags(ui::EF_CONTROL_DOWN);
#if defined(USE_X11)
ui::UpdateX11EventForFlags(&press);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace {
class TestEvent : public ui::Event {
public:
explicit TestEvent(ui::EventType type)
: ui::Event(type, base::TimeDelta(), 0) {
}
: ui::Event(type, base::TimeTicks(), 0) {}
~TestEvent() override {}

private:
Expand Down
7 changes: 2 additions & 5 deletions chrome/browser/ui/views/ash/tab_scrubber_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,8 @@ class TabScrubberTest : public InProcessBrowserTest,
event_generator.set_async(true);
}
event_generator.ScrollSequence(gfx::Point(0, 0),
ui::EventTimeForNow(),
x_offset,
0,
1,
3);
base::TimeDelta::FromMilliseconds(100),
x_offset, 0, 1, 3);
if (wait_for_active)
RunUntilTabActive(browser, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ TEST_F(DesktopMediaPickerViewsTest, DoneCallbackCalledOnDoubleTap) {
media_lists_[DesktopMediaID::TYPE_SCREEN]->AddSourceByFullMediaID(kFakeId);
ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
details.set_tap_count(2);
ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details);
ui::GestureEvent double_tap(10, 10, 0, base::TimeTicks(), details);

GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent(
&double_tap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ TEST_F(DesktopMediaPickerViewsDeprecatedTest, DoneCallbackCalledOnDoubleTap) {
window_list_->AddSource(kFakeId);
ui::GestureEventDetails details(ui::ET_GESTURE_TAP);
details.set_tap_count(2);
ui::GestureEvent double_tap(10, 10, 0, base::TimeDelta(), details);
ui::GestureEvent double_tap(10, 10, 0, base::TimeTicks(), details);

GetPickerDialogView()->GetMediaSourceViewForTesting(0)->OnGestureEvent(
&double_tap);
Expand Down
Loading

0 comments on commit 9b3bda8

Please sign in to comment.