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

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

Issue 1453813003: Fix a regression in checking the status of the touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dtapuska's comments 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/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) && defined(USE_X11)
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 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
20 21
22 #if defined(OS_CHROMEOS)
21 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN; 23 const int kSystemKeyModifierMask = EF_ALT_DOWN | EF_COMMAND_DOWN;
22 #else 24 #else
23 const int kSystemKeyModifierMask = EF_ALT_DOWN; 25 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) 26 #endif // defined(OS_CHROMEOS)
49 27
50 } // namespace 28 } // namespace
51 29
52 base::StaticAtomicSequenceNumber g_next_event_id; 30 base::StaticAtomicSequenceNumber g_next_event_id;
53 31
54 uint32 GetNextTouchEventId() { 32 uint32 GetNextTouchEventId() {
55 // Set the first touch event ID to 1 because we set id to 0 for other types 33 // Set the first touch event ID to 1 because we set id to 0 for other types
56 // of events. 34 // of events.
57 uint32 id = g_next_event_id.GetNext(); 35 uint32 id = g_next_event_id.GetNext();
58 if (id == 0) 36 if (id == 0)
59 id = g_next_event_id.GetNext(); 37 id = g_next_event_id.GetNext();
60 DCHECK_NE(0U, id); 38 DCHECK_NE(0U, id);
61 return id; 39 return id;
62 } 40 }
63 41
64 bool IsSystemKeyModifier(int flags) { 42 bool IsSystemKeyModifier(int flags) {
65 // AltGr modifier is used to type alternative keys on certain keyboard layouts 43 // 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. 44 // so we don't consider keys with the AltGr modifier as a system key.
67 return (kSystemKeyModifierMask & flags) != 0 && 45 return (kSystemKeyModifierMask & flags) != 0 &&
68 (EF_ALTGR_DOWN & flags) == 0; 46 (EF_ALTGR_DOWN & flags) == 0;
69 } 47 }
70 48
71 #if defined(OS_CHROMEOS) 49 #if defined(OS_CHROMEOS) && defined(USE_X11)
72 50
73 void SetTouchEventsEnabled(bool enabled) { 51 void SetTouchEventsCrOsX11MasterSwitch(bool enabled) {
74 touch_events_enabled = enabled; 52 touch_events_enabled = enabled;
75 } 53 }
76 54
77 #endif // defined(OS_CHROMEOS) 55 bool GetTouchEventsCrOsX11MasterSwitch() {
56 return touch_events_enabled;
57 }
78 58
79 bool AreTouchEventsEnabled() { 59 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
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 60
88 } // namespace ui 61 } // namespace ui
89 62
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698