OLD | NEW |
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/x/touch_factory_x11.h" | 5 #include "ui/events/x/touch_factory_x11.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/XIproto.h> | 10 #include <X11/extensions/XIproto.h> |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "ui/events/x/device_list_cache_x.h" | 22 #include "ui/events/x/device_list_cache_x.h" |
23 #include "ui/gfx/x/x11_types.h" | 23 #include "ui/gfx/x/x11_types.h" |
24 | 24 |
25 namespace ui { | 25 namespace ui { |
26 | 26 |
27 TouchFactory::TouchFactory() | 27 TouchFactory::TouchFactory() |
28 : pointer_device_lookup_(), | 28 : pointer_device_lookup_(), |
29 touch_device_available_(false), | 29 touch_device_available_(false), |
30 touch_events_disabled_(false), | 30 touch_events_disabled_(false), |
31 touch_device_list_(), | 31 touch_device_list_(), |
| 32 max_touch_points_(-1), |
32 id_generator_(0) { | 33 id_generator_(0) { |
33 if (!DeviceDataManager::GetInstance()->IsXInput2Available()) | 34 if (!DeviceDataManager::GetInstance()->IsXInput2Available()) |
34 return; | 35 return; |
35 | 36 |
36 XDisplay* display = gfx::GetXDisplay(); | 37 XDisplay* display = gfx::GetXDisplay(); |
37 UpdateDeviceList(display); | 38 UpdateDeviceList(display); |
38 | 39 |
39 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 40 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
40 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && | 41 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && |
41 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == | 42 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 74 } |
74 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 75 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void TouchFactory::UpdateDeviceList(Display* display) { | 79 void TouchFactory::UpdateDeviceList(Display* display) { |
79 // Detect touch devices. | 80 // Detect touch devices. |
80 touch_device_available_ = false; | 81 touch_device_available_ = false; |
81 touch_device_lookup_.reset(); | 82 touch_device_lookup_.reset(); |
82 touch_device_list_.clear(); | 83 touch_device_list_.clear(); |
| 84 max_touch_points_ = -1; |
83 | 85 |
84 #if !defined(USE_XI2_MT) | 86 #if !defined(USE_XI2_MT) |
85 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 87 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
86 // not provide enough information to detect a touch device. As a result, the | 88 // not provide enough information to detect a touch device. As a result, the |
87 // old version of query function (XListInputDevices) is used instead. | 89 // old version of query function (XListInputDevices) is used instead. |
88 // If XInput2 is not supported, this will return null (with count of -1) so | 90 // If XInput2 is not supported, this will return null (with count of -1) so |
89 // we assume there cannot be any touch devices. | 91 // we assume there cannot be any touch devices. |
90 // With XI2.1 or older, we allow only single touch devices. | 92 // With XI2.1 or older, we allow only single touch devices. |
91 XDeviceList dev_list = | 93 XDeviceList dev_list = |
92 DeviceListCacheX::GetInstance()->GetXDeviceList(display); | 94 DeviceListCacheX::GetInstance()->GetXDeviceList(display); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 for (int k = 0; k < devinfo->num_classes; ++k) { | 127 for (int k = 0; k < devinfo->num_classes; ++k) { |
126 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 128 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
127 if (xiclassinfo->type == XITouchClass) { | 129 if (xiclassinfo->type == XITouchClass) { |
128 XITouchClassInfo* tci = | 130 XITouchClassInfo* tci = |
129 reinterpret_cast<XITouchClassInfo *>(xiclassinfo); | 131 reinterpret_cast<XITouchClassInfo *>(xiclassinfo); |
130 // Only care direct touch device (such as touch screen) right now | 132 // Only care direct touch device (such as touch screen) right now |
131 if (tci->mode == XIDirectTouch) { | 133 if (tci->mode == XIDirectTouch) { |
132 touch_device_lookup_[devinfo->deviceid] = true; | 134 touch_device_lookup_[devinfo->deviceid] = true; |
133 touch_device_list_[devinfo->deviceid] = true; | 135 touch_device_list_[devinfo->deviceid] = true; |
134 touch_device_available_ = true; | 136 touch_device_available_ = true; |
| 137 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) |
| 138 max_touch_points_ = tci->num_touches; |
135 } | 139 } |
136 } | 140 } |
137 } | 141 } |
138 #endif | 142 #endif |
139 pointer_device_lookup_[devinfo->deviceid] = true; | 143 pointer_device_lookup_[devinfo->deviceid] = true; |
140 } | 144 } |
141 } | 145 } |
142 } | 146 } |
143 | 147 |
144 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 148 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 234 } |
231 | 235 |
232 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { | 236 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { |
233 id_generator_.ReleaseNumber(tracking_id); | 237 id_generator_.ReleaseNumber(tracking_id); |
234 } | 238 } |
235 | 239 |
236 bool TouchFactory::IsTouchDevicePresent() { | 240 bool TouchFactory::IsTouchDevicePresent() { |
237 return !touch_events_disabled_ && touch_device_available_; | 241 return !touch_events_disabled_ && touch_device_available_; |
238 } | 242 } |
239 | 243 |
| 244 int TouchFactory::GetMaxTouchPoints() const { |
| 245 return max_touch_points_; |
| 246 } |
| 247 |
240 void TouchFactory::SetTouchDeviceForTest( | 248 void TouchFactory::SetTouchDeviceForTest( |
241 const std::vector<unsigned int>& devices) { | 249 const std::vector<unsigned int>& devices) { |
242 touch_device_lookup_.reset(); | 250 touch_device_lookup_.reset(); |
243 touch_device_list_.clear(); | 251 touch_device_list_.clear(); |
244 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 252 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
245 iter != devices.end(); ++iter) { | 253 iter != devices.end(); ++iter) { |
246 DCHECK(*iter < touch_device_lookup_.size()); | 254 DCHECK(*iter < touch_device_lookup_.size()); |
247 touch_device_lookup_[*iter] = true; | 255 touch_device_lookup_[*iter] = true; |
248 touch_device_list_[*iter] = true; | 256 touch_device_list_[*iter] = true; |
249 } | 257 } |
250 touch_device_available_ = true; | 258 touch_device_available_ = true; |
251 touch_events_disabled_ = false; | 259 touch_events_disabled_ = false; |
252 } | 260 } |
253 | 261 |
254 } // namespace ui | 262 } // namespace ui |
OLD | NEW |