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

Side by Side Diff: ui/events/devices/x11/touch_factory_x11.cc

Issue 2467913002: Touch event flag should control only DOM event firing. (Closed)
Patch Set: Deprecate the histogram. Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/devices/x11/touch_factory_x11.h" 5 #include "ui/events/devices/x11/touch_factory_x11.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <X11/cursorfont.h> 9 #include <X11/cursorfont.h>
10 #include <X11/extensions/XInput.h> 10 #include <X11/extensions/XInput.h>
11 #include <X11/extensions/XInput2.h> 11 #include <X11/extensions/XInput2.h>
12 #include <X11/extensions/XIproto.h> 12 #include <X11/extensions/XIproto.h>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
18 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/sys_info.h" 21 #include "base/sys_info.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "ui/events/base_event_utils.h" 23 #include "ui/events/base_event_utils.h"
24 #include "ui/events/devices/x11/device_data_manager_x11.h" 24 #include "ui/events/devices/x11/device_data_manager_x11.h"
25 #include "ui/events/devices/x11/device_list_cache_x11.h" 25 #include "ui/events/devices/x11/device_list_cache_x11.h"
26 #include "ui/events/event_switches.h" 26 #include "ui/events/event_switches.h"
27 27
28 namespace ui { 28 namespace ui {
29 29
30 namespace {
31
32 bool IsTouchEventsFlagDisabled() {
33 auto* command_line = base::CommandLine::ForCurrentProcess();
34 bool touch_flag_status = command_line->HasSwitch(switches::kTouchEvents) &&
35 command_line->GetSwitchValueASCII(switches::kTouchEvents) ==
36 switches::kTouchEventsDisabled;
37 return touch_flag_status;
38 }
39
40 } // namespace
41
42
43 TouchFactory::TouchFactory() 30 TouchFactory::TouchFactory()
44 : pointer_device_lookup_(), 31 : pointer_device_lookup_(),
45 touch_device_list_(), 32 touch_device_list_(),
46 virtual_core_keyboard_device_(-1), 33 virtual_core_keyboard_device_(-1),
47 id_generator_(0), 34 id_generator_(0),
48 touch_events_flag_disabled_(IsTouchEventsFlagDisabled()),
49 touch_screens_enabled_(true) { 35 touch_screens_enabled_(true) {
50 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) 36 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available())
51 return; 37 return;
52 38
53 XDisplay* display = gfx::GetXDisplay(); 39 XDisplay* display = gfx::GetXDisplay();
54 UpdateDeviceList(display); 40 UpdateDeviceList(display);
55 } 41 }
56 42
57 TouchFactory::~TouchFactory() { 43 TouchFactory::~TouchFactory() {
58 } 44 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 137 }
152 } 138 }
153 } 139 }
154 } 140 }
155 141
156 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { 142 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) {
157 DCHECK_EQ(GenericEvent, xev->type); 143 DCHECK_EQ(GenericEvent, xev->type);
158 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); 144 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data);
159 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); 145 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event);
160 146
161 const bool is_touch_disabled = 147 const bool is_touch_disabled = !touch_screens_enabled_;
162 touch_events_flag_disabled_ && !touch_screens_enabled_;
163 148
164 if (event->evtype == XI_TouchBegin || 149 if (event->evtype == XI_TouchBegin ||
165 event->evtype == XI_TouchUpdate || 150 event->evtype == XI_TouchUpdate ||
166 event->evtype == XI_TouchEnd) { 151 event->evtype == XI_TouchEnd) {
167 // Since SetupXI2ForXWindow() selects events from all devices, for a 152 // Since SetupXI2ForXWindow() selects events from all devices, for a
168 // touchscreen attached to a master pointer device, X11 sends two 153 // touchscreen attached to a master pointer device, X11 sends two
169 // events for each touch: one from the slave (deviceid == the id of 154 // events for each touch: one from the slave (deviceid == the id of
170 // the touchscreen device), and one from the master (deviceid == the 155 // the touchscreen device), and one from the master (deviceid == the
171 // id of the master pointer device). Instead of processing both 156 // id of the master pointer device). Instead of processing both
172 // events, discard the event that comes from the slave, and only 157 // events, discard the event that comes from the slave, and only
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 271
287 int TouchFactory::GetSlotForTrackingID(uint32_t tracking_id) { 272 int TouchFactory::GetSlotForTrackingID(uint32_t tracking_id) {
288 return id_generator_.GetGeneratedID(tracking_id); 273 return id_generator_.GetGeneratedID(tracking_id);
289 } 274 }
290 275
291 void TouchFactory::ReleaseSlotForTrackingID(uint32_t tracking_id) { 276 void TouchFactory::ReleaseSlotForTrackingID(uint32_t tracking_id) {
292 id_generator_.ReleaseNumber(tracking_id); 277 id_generator_.ReleaseNumber(tracking_id);
293 } 278 }
294 279
295 bool TouchFactory::IsTouchDevicePresent() { 280 bool TouchFactory::IsTouchDevicePresent() {
296 return !touch_events_flag_disabled_ && 281 return touch_screens_enabled_ &&
297 touch_screens_enabled_ &&
298 touch_device_lookup_.any(); 282 touch_device_lookup_.any();
299 } 283 }
300 284
301 void TouchFactory::ResetForTest() { 285 void TouchFactory::ResetForTest() {
302 pointer_device_lookup_.reset(); 286 pointer_device_lookup_.reset();
303 touch_device_lookup_.reset(); 287 touch_device_lookup_.reset();
304 touch_device_list_.clear(); 288 touch_device_list_.clear();
305 touchscreen_ids_.clear(); 289 touchscreen_ids_.clear();
306 id_generator_.ResetForTest(); 290 id_generator_.ResetForTest();
307 touch_events_flag_disabled_ = false;
308 SetTouchscreensEnabled(true); 291 SetTouchscreensEnabled(true);
309 } 292 }
310 293
311 void TouchFactory::SetTouchDeviceForTest( 294 void TouchFactory::SetTouchDeviceForTest(
312 const std::vector<int>& devices) { 295 const std::vector<int>& devices) {
313 touch_device_lookup_.reset(); 296 touch_device_lookup_.reset();
314 touch_device_list_.clear(); 297 touch_device_list_.clear();
315 for (std::vector<int>::const_iterator iter = devices.begin(); 298 for (std::vector<int>::const_iterator iter = devices.begin();
316 iter != devices.end(); ++iter) { 299 iter != devices.end(); ++iter) {
317 DCHECK(IsValidDevice(*iter)); 300 DCHECK(IsValidDevice(*iter));
318 touch_device_lookup_[*iter] = true; 301 touch_device_lookup_[*iter] = true;
319 touch_device_list_[*iter] = true; 302 touch_device_list_[*iter] = true;
320 } 303 }
321 touch_events_flag_disabled_ = false;
322 SetTouchscreensEnabled(true); 304 SetTouchscreensEnabled(true);
323 } 305 }
324 306
325 void TouchFactory::SetPointerDeviceForTest( 307 void TouchFactory::SetPointerDeviceForTest(
326 const std::vector<int>& devices) { 308 const std::vector<int>& devices) {
327 pointer_device_lookup_.reset(); 309 pointer_device_lookup_.reset();
328 for (std::vector<int>::const_iterator iter = devices.begin(); 310 for (std::vector<int>::const_iterator iter = devices.begin();
329 iter != devices.end(); ++iter) { 311 iter != devices.end(); ++iter) {
330 pointer_device_lookup_[*iter] = true; 312 pointer_device_lookup_[*iter] = true;
331 } 313 }
(...skipping 13 matching lines...) Expand all
345 std::find_if(touchscreens.begin(), touchscreens.end(), 327 std::find_if(touchscreens.begin(), touchscreens.end(),
346 [device_id](const TouchscreenDevice& touchscreen) { 328 [device_id](const TouchscreenDevice& touchscreen) {
347 return touchscreen.id == device_id; 329 return touchscreen.id == device_id;
348 }); 330 });
349 // Internal displays will have a vid and pid of 0. Ignore them. 331 // Internal displays will have a vid and pid of 0. Ignore them.
350 if (it != touchscreens.end() && it->vendor_id && it->product_id) 332 if (it != touchscreens.end() && it->vendor_id && it->product_id)
351 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); 333 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id));
352 } 334 }
353 335
354 } // namespace ui 336 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698