OLD | NEW |
---|---|
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/logging.h" | 9 #include "base/logging.h" |
9 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
11 #include "ui/events/event_switches.h" | |
10 | 12 |
11 namespace ui { | 13 namespace ui { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
17 // Determines whether touch events are enabled or disabled. | |
18 bool touch_events_enabled = true; | |
19 | |
15 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
16 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; | 21 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; |
17 #else | 22 #else |
18 const int kSystemKeyModifierMask = EF_ALT_DOWN; | 23 const int kSystemKeyModifierMask = EF_ALT_DOWN; |
24 | |
25 // Whether the status of the touch screen events has been retrieved and cached | |
26 // from the command line on non-ChromeOS platforms. | |
27 bool is_touch_events_status_cached = false; | |
28 | |
29 // Retrieves the status of the touch screen events from the command line on Non- | |
30 // ChromeOS platforms. | |
31 void UpdateAndCacheTouchStatus() { | |
32 if (is_touch_events_status_cached) | |
33 return; | |
34 | |
35 const base::CommandLine& command_line = | |
36 *base::CommandLine::ForCurrentProcess(); | |
37 const std::string touch_enabled_switch = | |
38 command_line.HasSwitch(switches::kTouchEvents) ? | |
39 command_line.GetSwitchValueASCII(switches::kTouchEvents) : | |
40 switches::kTouchEventsAuto; | |
41 | |
42 if (touch_enabled_switch.empty() || | |
43 touch_enabled_switch == switches::kTouchEventsEnabled || | |
44 touch_enabled_switch == switches::kTouchEventsAuto) { | |
45 touch_events_enabled = true; | |
46 } else if (touch_enabled_switch == switches::kTouchEventsDisabled) { | |
47 touch_events_enabled = false; | |
48 } else { | |
49 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch; | |
50 } | |
51 | |
52 is_touch_events_status_cached = true; | |
53 } | |
54 | |
19 #endif // defined(OS_CHROMEOS) | 55 #endif // defined(OS_CHROMEOS) |
20 | 56 |
21 | |
22 } // namespace | 57 } // namespace |
23 | 58 |
24 base::StaticAtomicSequenceNumber g_next_event_id; | 59 base::StaticAtomicSequenceNumber g_next_event_id; |
25 | 60 |
26 uint32 GetNextTouchEventId() { | 61 uint32 GetNextTouchEventId() { |
27 // Set the first touch event ID to 1 because we set id to 0 for other types | 62 // Set the first touch event ID to 1 because we set id to 0 for other types |
28 // of events. | 63 // of events. |
29 uint32 id = g_next_event_id.GetNext(); | 64 uint32 id = g_next_event_id.GetNext(); |
30 if (id == 0) | 65 if (id == 0) |
31 id = g_next_event_id.GetNext(); | 66 id = g_next_event_id.GetNext(); |
32 DCHECK_NE(0U, id); | 67 DCHECK_NE(0U, id); |
33 return id; | 68 return id; |
34 } | 69 } |
35 | 70 |
36 bool IsSystemKeyModifier(int flags) { | 71 bool IsSystemKeyModifier(int flags) { |
37 // AltGr modifier is used to type alternative keys on certain keyboard layouts | 72 // AltGr modifier is used to type alternative keys on certain keyboard layouts |
38 // so we don't consider keys with the AltGr modifier as a system key. | 73 // so we don't consider keys with the AltGr modifier as a system key. |
39 return (kSystemKeyModifierMask & flags) != 0 && | 74 return (kSystemKeyModifierMask & flags) != 0 && |
40 (EF_ALTGR_DOWN & flags) == 0; | 75 (EF_ALTGR_DOWN & flags) == 0; |
41 } | 76 } |
42 | 77 |
78 #if defined(OS_CHROMEOS) | |
79 | |
80 void SetTouchEventsEnabled(bool enabled) { | |
81 touch_events_enabled = enabled; | |
82 } | |
83 | |
84 #endif // defined(OS_CHROMEOS) | |
85 | |
86 bool AreTouchEventsEnabled() { | |
87 #if !defined(OS_CHROMEOS) | |
88 UpdateAndCacheTouchStatus(); | |
sadrul
2015/11/09 21:38:53
You can get rid of is_touch_events_status_cached.
afakhry
2015/11/10 00:37:11
Done! Thanks for the useful suggestion! :)
| |
89 #endif // !defined(OS_CHROMEOS) | |
90 | |
91 return touch_events_enabled; | |
92 } | |
93 | |
43 } // namespace ui | 94 } // namespace ui |
44 | 95 |
OLD | NEW |