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

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: Fix compile error 2 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
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)
16 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; 18 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN;
19
20 // Determines whether touch events are enabled or disabled on ChromeOS only.
21 bool touch_events_enabled = true;
22
17 #else 23 #else
18 const int kSystemKeyModifierMask = EF_ALT_DOWN; 24 const int kSystemKeyModifierMask = EF_ALT_DOWN;
19 #endif // defined(OS_CHROMEOS) 25 #endif // defined(OS_CHROMEOS)
20 26
21
22 } // namespace 27 } // namespace
23 28
24 base::StaticAtomicSequenceNumber g_next_event_id; 29 base::StaticAtomicSequenceNumber g_next_event_id;
25 30
26 uint32 GetNextTouchEventId() { 31 uint32 GetNextTouchEventId() {
27 // Set the first touch event ID to 1 because we set id to 0 for other types 32 // Set the first touch event ID to 1 because we set id to 0 for other types
28 // of events. 33 // of events.
29 uint32 id = g_next_event_id.GetNext(); 34 uint32 id = g_next_event_id.GetNext();
30 if (id == 0) 35 if (id == 0)
31 id = g_next_event_id.GetNext(); 36 id = g_next_event_id.GetNext();
32 DCHECK_NE(0U, id); 37 DCHECK_NE(0U, id);
33 return id; 38 return id;
34 } 39 }
35 40
36 bool IsSystemKeyModifier(int flags) { 41 bool IsSystemKeyModifier(int flags) {
37 // AltGr modifier is used to type alternative keys on certain keyboard layouts 42 // 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. 43 // so we don't consider keys with the AltGr modifier as a system key.
39 return (kSystemKeyModifierMask & flags) != 0 && 44 return (kSystemKeyModifierMask & flags) != 0 &&
40 (EF_ALTGR_DOWN & flags) == 0; 45 (EF_ALTGR_DOWN & flags) == 0;
41 } 46 }
42 47
48 #if defined(OS_CHROMEOS)
49
50 void SetTouchEventsEnabled(bool enabled) {
51 touch_events_enabled = enabled;
52 }
53
54 #endif // defined(OS_CHROMEOS)
55
56 bool AreTouchEventsEnabled() {
57 #if defined(OS_CHROMEOS)
58 return touch_events_enabled;
59 #else
60 const base::CommandLine& command_line =
61 *base::CommandLine::ForCurrentProcess();
62 const std::string touch_enabled_switch =
63 command_line.HasSwitch(switches::kTouchEvents) ?
64 command_line.GetSwitchValueASCII(switches::kTouchEvents) :
65 switches::kTouchEventsAuto;
66
67 if (touch_enabled_switch.empty() ||
68 touch_enabled_switch == switches::kTouchEventsEnabled ||
69 touch_enabled_switch == switches::kTouchEventsAuto) {
70 return true;
71 }
72
73 if (touch_enabled_switch != switches::kTouchEventsDisabled)
74 LOG(ERROR) << "Invalid --touch-events option: " << touch_enabled_switch;
75 return false;
sadrul 2015/11/03 19:09:26 We need to cache the return value, so we don't hav
afakhry 2015/11/04 02:28:21 Done.
76 #endif // defined(OS_CHROMEOS)
77 }
78
43 } // namespace ui 79 } // namespace ui
44 80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698