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/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/events/event_constants.h" | 10 #include "ui/events/event_constants.h" |
11 #include "ui/events/event_switches.h" | 11 #include "ui/events/event_switches.h" |
12 | 12 |
13 namespace ui { | 13 namespace ui { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
18 // Determines whether touch events are enabled or disabled on ChromeOS only. | 18 // Determines whether touch events are enabled or disabled on ChromeOS only. |
19 bool touch_events_enabled = true; | 19 bool touch_events_enabled = true; |
20 | 20 |
21 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; | 21 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; |
22 #else | 22 #else |
23 const int kSystemKeyModifierMask = EF_ALT_DOWN; | 23 const int kSystemKeyModifierMask = EF_ALT_DOWN; |
24 | |
25 // Retrieves the status of the touch screen events from the command line on Non- | |
26 // ChromeOS platforms. | |
27 bool ComputeTouchStatus() { | |
28 const base::CommandLine& command_line = | |
29 *base::CommandLine::ForCurrentProcess(); | |
30 const std::string touch_enabled_switch = | |
31 command_line.HasSwitch(switches::kTouchEvents) ? | |
32 command_line.GetSwitchValueASCII(switches::kTouchEvents) : | |
33 switches::kTouchEventsAuto; | |
34 | |
35 if (touch_enabled_switch.empty() || | |
36 touch_enabled_switch == switches::kTouchEventsEnabled || | |
37 touch_enabled_switch == switches::kTouchEventsAuto) { | |
38 return true; | |
39 } | |
40 | |
41 if (touch_enabled_switch == switches::kTouchEventsDisabled) | |
42 return false; | |
43 | |
44 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch; | |
45 return false; | |
46 } | |
47 | |
48 #endif // defined(OS_CHROMEOS) | 24 #endif // defined(OS_CHROMEOS) |
49 | 25 |
50 } // namespace | 26 } // namespace |
51 | 27 |
52 base::StaticAtomicSequenceNumber g_next_event_id; | 28 base::StaticAtomicSequenceNumber g_next_event_id; |
53 | 29 |
54 uint32 GetNextTouchEventId() { | 30 uint32 GetNextTouchEventId() { |
55 // Set the first touch event ID to 1 because we set id to 0 for other types | 31 // Set the first touch event ID to 1 because we set id to 0 for other types |
56 // of events. | 32 // of events. |
57 uint32 id = g_next_event_id.GetNext(); | 33 uint32 id = g_next_event_id.GetNext(); |
58 if (id == 0) | 34 if (id == 0) |
59 id = g_next_event_id.GetNext(); | 35 id = g_next_event_id.GetNext(); |
60 DCHECK_NE(0U, id); | 36 DCHECK_NE(0U, id); |
61 return id; | 37 return id; |
62 } | 38 } |
63 | 39 |
64 bool IsSystemKeyModifier(int flags) { | 40 bool IsSystemKeyModifier(int flags) { |
65 // 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 |
66 // 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. |
67 return (kSystemKeyModifierMask & flags) != 0 && | 43 return (kSystemKeyModifierMask & flags) != 0 && |
68 (EF_ALTGR_DOWN & flags) == 0; | 44 (EF_ALTGR_DOWN & flags) == 0; |
69 } | 45 } |
70 | 46 |
71 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
72 | 48 |
73 void SetTouchEventsEnabled(bool enabled) { | 49 void SetTouchEventsCrOsMasterSwitch(bool enabled) { |
74 touch_events_enabled = enabled; | 50 touch_events_enabled = enabled; |
75 } | 51 } |
76 | 52 |
| 53 bool GetTouchEventsCrOsMasterSwitch() { |
| 54 return touch_events_enabled; |
| 55 } |
| 56 |
77 #endif // defined(OS_CHROMEOS) | 57 #endif // defined(OS_CHROMEOS) |
78 | 58 |
79 bool AreTouchEventsEnabled() { | |
80 #if defined(OS_CHROMEOS) | |
81 return touch_events_enabled; | |
82 #else | |
83 static bool touch_events_enabled = ComputeTouchStatus(); | |
84 return touch_events_enabled; | |
85 #endif // !defined(OS_CHROMEOS) | |
86 } | |
87 | |
88 } // namespace ui | 59 } // namespace ui |
89 | 60 |
OLD | NEW |