blob: d4545bc45c4560dddc39c2c217a5e0045dd39914 [file] [log] [blame]
lanwei2574b1b2015-04-29 17:42:551// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ui/events/base_event_utils.h"
6
7#include "base/atomic_sequence_num.h"
afakhrye8eac602015-11-10 02:31:228#include "base/command_line.h"
majidvpc9cc06af2016-06-24 21:58:309#include "base/lazy_instance.h"
lanwei2574b1b2015-04-29 17:42:5510#include "base/logging.h"
majidvp9b3bda82016-06-09 18:12:0911#include "base/time/time.h"
avidf8474b2015-12-24 03:49:5012#include "build/build_config.h"
afakhry8518ee72015-09-04 22:50:0413#include "ui/events/event_constants.h"
afakhrye8eac602015-11-10 02:31:2214#include "ui/events/event_switches.h"
lanwei2574b1b2015-04-29 17:42:5515
16namespace ui {
17
afakhry8518ee72015-09-04 22:50:0418namespace {
19
20#if defined(OS_CHROMEOS)
21const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN;
22#else
23const int kSystemKeyModifierMask = EF_ALT_DOWN;
afakhrye8eac602015-11-10 02:31:2224#endif // defined(OS_CHROMEOS)
afakhry8518ee72015-09-04 22:50:0425
26} // namespace
27
lanwei2574b1b2015-04-29 17:42:5528base::StaticAtomicSequenceNumber g_next_event_id;
29
avidf8474b2015-12-24 03:49:5030uint32_t GetNextTouchEventId() {
lanwei2574b1b2015-04-29 17:42:5531 // Set the first touch event ID to 1 because we set id to 0 for other types
32 // of events.
avidf8474b2015-12-24 03:49:5033 uint32_t id = g_next_event_id.GetNext();
lanwei2574b1b2015-04-29 17:42:5534 if (id == 0)
35 id = g_next_event_id.GetNext();
36 DCHECK_NE(0U, id);
37 return id;
38}
39
afakhry8518ee72015-09-04 22:50:0440bool IsSystemKeyModifier(int flags) {
afakhry3d96df642015-09-18 16:00:2541 // AltGr modifier is used to type alternative keys on certain keyboard layouts
42 // so we don't consider keys with the AltGr modifier as a system key.
43 return (kSystemKeyModifierMask & flags) != 0 &&
44 (EF_ALTGR_DOWN & flags) == 0;
afakhry8518ee72015-09-04 22:50:0445}
46
majidvpc9cc06af2016-06-24 21:58:3047base::LazyInstance<std::unique_ptr<base::TickClock>>::Leaky g_tick_clock =
48 LAZY_INSTANCE_INITIALIZER;
49
50base::TimeTicks EventTimeForNow() {
51 return g_tick_clock.Get() ? g_tick_clock.Get()->NowTicks()
52 : base::TimeTicks::Now();
53}
54
55void SetEventTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock) {
56 g_tick_clock.Get() = std::move(tick_clock);
57}
58
majidvp9b3bda82016-06-09 18:12:0959double EventTimeStampToSeconds(base::TimeTicks time_stamp) {
60 return (time_stamp - base::TimeTicks()).InSecondsF();
61}
62
63base::TimeTicks EventTimeStampFromSeconds(double time_stamp_seconds) {
64 return base::TimeTicks() + base::TimeDelta::FromSecondsD(time_stamp_seconds);
65}
66
lanwei2574b1b2015-04-29 17:42:5567} // namespace ui
68