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

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

Issue 1412623006: Developer Feature: Add Debug Accelerators to Toggle Touchscreen/Touchpad On or Off (CrOS) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sadrul's comment Created 5 years, 1 month 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/devices/x11/device_data_manager_x11.h » ('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/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
15 #if defined(OS_CHROMEOS) 17 #if defined(OS_CHROMEOS)
18 // Determines whether touch events are enabled or disabled on ChromeOS only.
19 bool touch_events_enabled = true;
20
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 // 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;
dtapuska 2015/11/18 04:00:55 If no command switch is set; auto mode is enable a
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
19 #endif // defined(OS_CHROMEOS) 48 #endif // defined(OS_CHROMEOS)
20 49
21
22 } // namespace 50 } // namespace
23 51
24 base::StaticAtomicSequenceNumber g_next_event_id; 52 base::StaticAtomicSequenceNumber g_next_event_id;
25 53
26 uint32 GetNextTouchEventId() { 54 uint32 GetNextTouchEventId() {
27 // Set the first touch event ID to 1 because we set id to 0 for other types 55 // Set the first touch event ID to 1 because we set id to 0 for other types
28 // of events. 56 // of events.
29 uint32 id = g_next_event_id.GetNext(); 57 uint32 id = g_next_event_id.GetNext();
30 if (id == 0) 58 if (id == 0)
31 id = g_next_event_id.GetNext(); 59 id = g_next_event_id.GetNext();
32 DCHECK_NE(0U, id); 60 DCHECK_NE(0U, id);
33 return id; 61 return id;
34 } 62 }
35 63
36 bool IsSystemKeyModifier(int flags) { 64 bool IsSystemKeyModifier(int flags) {
37 // AltGr modifier is used to type alternative keys on certain keyboard layouts 65 // 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. 66 // so we don't consider keys with the AltGr modifier as a system key.
39 return (kSystemKeyModifierMask & flags) != 0 && 67 return (kSystemKeyModifierMask & flags) != 0 &&
40 (EF_ALTGR_DOWN & flags) == 0; 68 (EF_ALTGR_DOWN & flags) == 0;
41 } 69 }
42 70
71 #if defined(OS_CHROMEOS)
72
73 void SetTouchEventsEnabled(bool enabled) {
74 touch_events_enabled = enabled;
75 }
76
77 #endif // defined(OS_CHROMEOS)
78
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
43 } // namespace ui 88 } // namespace ui
44 89
OLDNEW
« no previous file with comments | « ui/events/base_event_utils.h ('k') | ui/events/devices/x11/device_data_manager_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698