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

Side by Side Diff: ui/events/base_event_utils.cc

Issue 2007083002: Validate that ui::Event::time_stamp comes from the same clock as TimeTicks::Now (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@453559-use-timeticks-ui-event
Patch Set: Address feedback Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « ui/events/base_event_utils.h ('k') | ui/events/cocoa/events_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/base_event_utils.h" 5 #include "ui/events/base_event_utils.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "ui/events/event_constants.h" 13 #include "ui/events/event_constants.h"
13 #include "ui/events/event_switches.h" 14 #include "ui/events/event_switches.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace { 18 namespace {
18 19
(...skipping 17 matching lines...) Expand all
36 return id; 37 return id;
37 } 38 }
38 39
39 bool IsSystemKeyModifier(int flags) { 40 bool IsSystemKeyModifier(int flags) {
40 // AltGr modifier is used to type alternative keys on certain keyboard layouts 41 // AltGr modifier is used to type alternative keys on certain keyboard layouts
41 // so we don't consider keys with the AltGr modifier as a system key. 42 // so we don't consider keys with the AltGr modifier as a system key.
42 return (kSystemKeyModifierMask & flags) != 0 && 43 return (kSystemKeyModifierMask & flags) != 0 &&
43 (EF_ALTGR_DOWN & flags) == 0; 44 (EF_ALTGR_DOWN & flags) == 0;
44 } 45 }
45 46
47 base::LazyInstance<std::unique_ptr<base::TickClock>>::Leaky g_tick_clock =
48 LAZY_INSTANCE_INITIALIZER;
49
50 base::TimeTicks EventTimeForNow() {
51 return g_tick_clock.Get() ? g_tick_clock.Get()->NowTicks()
52 : base::TimeTicks::Now();
53 }
54
55 void SetEventTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
56 g_tick_clock.Get() = std::move(tick_clock);
57 }
58
46 double EventTimeStampToSeconds(base::TimeTicks time_stamp) { 59 double EventTimeStampToSeconds(base::TimeTicks time_stamp) {
47 return (time_stamp - base::TimeTicks()).InSecondsF(); 60 return (time_stamp - base::TimeTicks()).InSecondsF();
48 } 61 }
49 62
50 base::TimeTicks EventTimeStampFromSeconds(double time_stamp_seconds) { 63 base::TimeTicks EventTimeStampFromSeconds(double time_stamp_seconds) {
51 return base::TimeTicks() + base::TimeDelta::FromSecondsD(time_stamp_seconds); 64 return base::TimeTicks() + base::TimeDelta::FromSecondsD(time_stamp_seconds);
52 } 65 }
53 66
54 } // namespace ui 67 } // namespace ui
55 68
OLDNEW
« no previous file with comments | « ui/events/base_event_utils.h ('k') | ui/events/cocoa/events_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698