Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/events/ozone/evdev/event_device_info.h" | |
| 6 | |
| 7 #include <linux/input.h> | |
| 8 | |
| 9 #include "base/threading/thread_restrictions.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { | |
| 16 return ioctl(fd, EVIOCGBIT(type, size), buf) < 0; | |
| 17 } | |
| 18 | |
| 19 bool BitIsSet(const unsigned long* bits, unsigned int bit) { | |
| 20 return (bits[bit / EVDEV_LONG_BITS] & (1UL << (bit % EVDEV_LONG_BITS))); | |
| 21 } | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 EventDeviceInfo::EventDeviceInfo() { | |
| 26 memset(ev_bits_, 0, sizeof(ev_bits_)); | |
| 27 memset(key_bits_, 0, sizeof(key_bits_)); | |
| 28 memset(rel_bits_, 0, sizeof(rel_bits_)); | |
| 29 memset(abs_bits_, 0, sizeof(abs_bits_)); | |
| 30 memset(msc_bits_, 0, sizeof(msc_bits_)); | |
| 31 memset(sw_bits_, 0, sizeof(sw_bits_)); | |
| 32 memset(led_bits_, 0, sizeof(led_bits_)); | |
| 33 memset(prop_bits_, 0, sizeof(prop_bits_)); | |
| 34 } | |
| 35 | |
| 36 EventDeviceInfo::~EventDeviceInfo() {} | |
| 37 | |
| 38 bool EventDeviceInfo::Initialize(int fd) { | |
| 39 base::ThreadRestrictions::AssertIOAllowed(); | |
| 40 | |
| 41 if (GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_))) | |
| 42 return false; | |
| 43 | |
| 44 if (GetEventBits(fd, EV_KEY, key_bits_, sizeof(key_bits_))) | |
| 45 return false; | |
| 46 | |
| 47 if (GetEventBits(fd, EV_REL, rel_bits_, sizeof(rel_bits_))) | |
| 48 return false; | |
| 49 | |
| 50 if (GetEventBits(fd, EV_ABS, abs_bits_, sizeof(abs_bits_))) | |
| 51 return false; | |
| 52 | |
| 53 if (GetEventBits(fd, EV_MSC, msc_bits_, sizeof(msc_bits_))) | |
| 54 return false; | |
| 55 | |
| 56 if (GetEventBits(fd, EV_SW, sw_bits_, sizeof(sw_bits_))) | |
| 57 return false; | |
| 58 | |
| 59 if (GetEventBits(fd, EV_LED, led_bits_, sizeof(led_bits_))) | |
| 60 return false; | |
| 61 | |
| 62 if (ioctl(fd, EVIOCGPROP(sizeof(prop_bits_)), prop_bits_)) | |
|
rjkroege
2013/11/04 23:39:46
you are not using the same ioctl as I was?
And i
spang
2013/11/05 00:10:02
I am above in GetEventbits; this one is different.
| |
| 63 return false; | |
| 64 | |
| 65 return true; | |
| 66 } | |
| 67 | |
| 68 bool EventDeviceInfo::HasEventType(unsigned int type) const { | |
| 69 if (type > EV_MAX) | |
| 70 return false; | |
| 71 return BitIsSet(ev_bits_, type); | |
| 72 } | |
| 73 | |
| 74 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { | |
| 75 if (code > KEY_MAX) | |
| 76 return false; | |
| 77 return BitIsSet(key_bits_, code); | |
| 78 } | |
| 79 | |
| 80 bool EventDeviceInfo::HasRelEvent(unsigned int code) const { | |
| 81 if (code > REL_MAX) | |
| 82 return false; | |
| 83 return BitIsSet(rel_bits_, code); | |
| 84 } | |
| 85 | |
| 86 bool EventDeviceInfo::HasAbsEvent(unsigned int code) const { | |
| 87 if (code > ABS_MAX) | |
| 88 return false; | |
| 89 return BitIsSet(abs_bits_, code); | |
| 90 } | |
| 91 | |
| 92 bool EventDeviceInfo::HasMscEvent(unsigned int code) const { | |
| 93 if (code > MSC_MAX) | |
| 94 return false; | |
| 95 return BitIsSet(msc_bits_, code); | |
| 96 } | |
| 97 | |
| 98 bool EventDeviceInfo::HasSwEvent(unsigned int code) const { | |
| 99 if (code > SW_MAX) | |
| 100 return false; | |
| 101 return BitIsSet(sw_bits_, code); | |
| 102 } | |
| 103 | |
| 104 bool EventDeviceInfo::hasLedEvent(unsigned int code) const { | |
| 105 if (code > LED_MAX) | |
| 106 return false; | |
| 107 return BitIsSet(led_bits_, code); | |
| 108 } | |
| 109 | |
| 110 bool EventDeviceInfo::HasProp(unsigned int code) const { | |
| 111 if (code > INPUT_PROP_MAX) | |
| 112 return false; | |
| 113 return BitIsSet(prop_bits_, code); | |
| 114 } | |
| 115 | |
| 116 } // namespace ui | |
| OLD | NEW |