Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ui / events / ozone / evdev / event_converter_evdev.cc
blobbe14bf56f324da26405d2f7a9ba3551dab163003
1 // Copyright 2014 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.
5 #include <linux/input.h>
7 #include "ui/events/ozone/evdev/event_converter_evdev.h"
9 #include "base/files/file_path.h"
10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/trace_event/trace_event.h"
13 #include "ui/events/devices/input_device.h"
15 namespace ui {
17 EventConverterEvdev::EventConverterEvdev(int fd,
18 const base::FilePath& path,
19 int id,
20 InputDeviceType type,
21 const std::string& name,
22 uint16_t vendor_id,
23 uint16_t product_id)
24 : fd_(fd),
25 path_(path),
26 input_device_(id, type, name, vendor_id, product_id) {
29 EventConverterEvdev::~EventConverterEvdev() {
30 DCHECK(!enabled_);
31 DCHECK(!watching_);
32 if (fd_ >= 0)
33 close(fd_);
36 void EventConverterEvdev::Start() {
37 base::MessageLoopForUI::current()->WatchFileDescriptor(
38 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this);
39 watching_ = true;
42 void EventConverterEvdev::Stop() {
43 controller_.StopWatchingFileDescriptor();
44 watching_ = false;
47 void EventConverterEvdev::SetEnabled(bool enabled) {
48 if (enabled == enabled_)
49 return;
50 if (enabled) {
51 TRACE_EVENT1("evdev", "EventConverterEvdev::OnEnabled", "path",
52 path_.value());
53 OnEnabled();
54 } else {
55 TRACE_EVENT1("evdev", "EventConverterEvdev::OnDisabled", "path",
56 path_.value());
57 OnDisabled();
59 enabled_ = enabled;
62 void EventConverterEvdev::OnStopped() {
65 void EventConverterEvdev::OnEnabled() {
68 void EventConverterEvdev::OnDisabled() {
71 void EventConverterEvdev::DumpTouchEventLog(const char* filename) {
74 void EventConverterEvdev::OnFileCanWriteWithoutBlocking(int fd) {
75 NOTREACHED();
78 bool EventConverterEvdev::HasKeyboard() const {
79 return false;
82 bool EventConverterEvdev::HasMouse() const {
83 return false;
86 bool EventConverterEvdev::HasTouchpad() const {
87 return false;
90 bool EventConverterEvdev::HasTouchscreen() const {
91 return false;
94 bool EventConverterEvdev::HasCapsLockLed() const {
95 return false;
98 gfx::Size EventConverterEvdev::GetTouchscreenSize() const {
99 NOTREACHED();
100 return gfx::Size();
103 int EventConverterEvdev::GetTouchPoints() const {
104 NOTREACHED();
105 return 0;
108 void EventConverterEvdev::SetKeyFilter(bool enable_filter,
109 std::vector<DomCode> allowed_keys) {
110 NOTREACHED();
113 void EventConverterEvdev::SetCapsLockLed(bool enabled) {
114 if (!HasCapsLockLed())
115 return;
117 input_event events[2];
118 memset(&events, 0, sizeof(events));
120 events[0].type = EV_LED;
121 events[0].code = LED_CAPSL;
122 events[0].value = enabled;
124 events[1].type = EV_SYN;
125 events[1].code = SYN_REPORT;
126 events[1].value = 0;
128 ssize_t written = write(fd_, events, sizeof(events));
130 if (written < 0) {
131 if (errno != ENODEV)
132 PLOG(ERROR) << "cannot set leds for " << path_.value() << ":";
133 Stop();
134 } else if (written != sizeof(events)) {
135 LOG(ERROR) << "short write setting leds for " << path_.value();
136 Stop();
140 void EventConverterEvdev::SetTouchEventLoggingEnabled(bool enabled) {
143 base::TimeDelta EventConverterEvdev::TimeDeltaFromInputEvent(
144 const input_event& event) {
145 return base::TimeDelta::FromMicroseconds(event.time.tv_sec * 1000000 +
146 event.time.tv_usec);
148 } // namespace ui