Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ozone/evdev/event_device_info.h" | 5 #include "ui/events/ozone/evdev/event_device_info.h" |
| 6 | 6 |
| 7 #include <linux/input.h> | 7 #include <linux/input.h> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 int index = code - EVDEV_ABS_MT_FIRST; | 244 int index = code - EVDEV_ABS_MT_FIRST; |
| 245 if (index < 0 || index >= EVDEV_ABS_MT_COUNT) | 245 if (index < 0 || index >= EVDEV_ABS_MT_COUNT) |
| 246 return; | 246 return; |
| 247 slot_values_[index][slot] = value; | 247 slot_values_[index][slot] = value; |
| 248 } | 248 } |
| 249 | 249 |
| 250 void EventDeviceInfo::SetDeviceType(InputDeviceType type) { | 250 void EventDeviceInfo::SetDeviceType(InputDeviceType type) { |
| 251 device_type_ = type; | 251 device_type_ = type; |
| 252 } | 252 } |
| 253 | 253 |
| 254 void EventDeviceInfo::SetId(uint16_t vendor_id, uint16_t product_id) { | |
| 255 vendor_id_ = vendor_id; | |
| 256 product_id_ = product_id; | |
| 257 } | |
| 258 | |
| 254 bool EventDeviceInfo::HasEventType(unsigned int type) const { | 259 bool EventDeviceInfo::HasEventType(unsigned int type) const { |
| 255 if (type > EV_MAX) | 260 if (type > EV_MAX) |
| 256 return false; | 261 return false; |
| 257 return EvdevBitIsSet(ev_bits_, type); | 262 return EvdevBitIsSet(ev_bits_, type); |
| 258 } | 263 } |
| 259 | 264 |
| 260 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { | 265 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { |
| 261 if (code > KEY_MAX) | 266 if (code > KEY_MAX) |
| 262 return false; | 267 return false; |
| 263 return EvdevBitIsSet(key_bits_, code); | 268 return EvdevBitIsSet(key_bits_, code); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 } | 425 } |
| 421 | 426 |
| 422 bool EventDeviceInfo::HasTablet() const { | 427 bool EventDeviceInfo::HasTablet() const { |
| 423 return HasAbsXY() && HasPointer() && HasStylus(); | 428 return HasAbsXY() && HasPointer() && HasStylus(); |
| 424 } | 429 } |
| 425 | 430 |
| 426 bool EventDeviceInfo::HasTouchscreen() const { | 431 bool EventDeviceInfo::HasTouchscreen() const { |
| 427 return HasAbsXY() && HasDirect(); | 432 return HasAbsXY() && HasDirect(); |
| 428 } | 433 } |
| 429 | 434 |
| 435 bool EventDeviceInfo::HasGamepad() const { | |
| 436 if (!HasEventType(EV_KEY)) | |
| 437 return false; | |
| 438 | |
| 439 // If the device has gamepad button, and it's not keyboard or tablet, it will | |
| 440 // be considered to be a gamepad. Note: this WILL have false positives and | |
| 441 // false negatives. A concrete solution will use ID_INPUT_JOYSTICK with some | |
| 442 // patch removing false positives. | |
| 443 bool support_gamepad_btn = false; | |
| 444 for (int key = BTN_JOYSTICK; key <= BTN_THUMBR; ++key) | |
|
spang
2017/05/03 22:00:37
Please brace all multiline blocks such as the oute
jkwang
2017/05/05 00:07:45
Done.
| |
| 445 if (HasKeyEvent(key)) | |
| 446 support_gamepad_btn = true; | |
| 447 | |
| 448 return support_gamepad_btn && !HasTablet() && !HasKeyboard(); | |
| 449 } | |
| 450 | |
| 430 EventDeviceInfo::LegacyAbsoluteDeviceType | 451 EventDeviceInfo::LegacyAbsoluteDeviceType |
| 431 EventDeviceInfo::ProbeLegacyAbsoluteDevice() const { | 452 EventDeviceInfo::ProbeLegacyAbsoluteDevice() const { |
| 432 if (!HasAbsXY()) | 453 if (!HasAbsXY()) |
| 433 return LegacyAbsoluteDeviceType::LADT_NONE; | 454 return LegacyAbsoluteDeviceType::LADT_NONE; |
| 434 | 455 |
| 435 // Treat internal stylus devices as touchscreens. | 456 // Treat internal stylus devices as touchscreens. |
| 436 if (device_type_ == INPUT_DEVICE_INTERNAL && HasStylus()) | 457 if (device_type_ == INPUT_DEVICE_INTERNAL && HasStylus()) |
| 437 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; | 458 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; |
| 438 | 459 |
| 439 if (HasStylus()) | 460 if (HasStylus()) |
| 440 return LegacyAbsoluteDeviceType::LADT_TABLET; | 461 return LegacyAbsoluteDeviceType::LADT_TABLET; |
| 441 | 462 |
| 442 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH)) | 463 if (HasKeyEvent(BTN_TOOL_FINGER) && HasKeyEvent(BTN_TOUCH)) |
| 443 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD; | 464 return LegacyAbsoluteDeviceType::LADT_TOUCHPAD; |
| 444 | 465 |
| 445 if (HasKeyEvent(BTN_TOUCH)) | 466 if (HasKeyEvent(BTN_TOUCH)) |
| 446 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; | 467 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; |
| 447 | 468 |
| 448 // ABS_Z mitigation for extra device on some Elo devices. | 469 // ABS_Z mitigation for extra device on some Elo devices. |
| 449 if (HasKeyEvent(BTN_LEFT) && !HasAbsEvent(ABS_Z)) | 470 if (HasKeyEvent(BTN_LEFT) && !HasAbsEvent(ABS_Z)) |
| 450 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; | 471 return LegacyAbsoluteDeviceType::LADT_TOUCHSCREEN; |
| 451 | 472 |
| 452 return LegacyAbsoluteDeviceType::LADT_NONE; | 473 return LegacyAbsoluteDeviceType::LADT_NONE; |
| 453 } | 474 } |
| 454 | 475 |
| 455 } // namespace ui | 476 } // namespace ui |
| OLD | NEW |