| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_converter_evdev_impl.h" | 5 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <linux/input.h> | 8 #include <linux/input.h> |
| 9 | 9 |
| 10 #include "ui/events/event.h" | 10 #include "ui/events/event.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 EventConverterEvdevImpl::EventConverterEvdevImpl( | 24 EventConverterEvdevImpl::EventConverterEvdevImpl( |
| 25 int fd, | 25 int fd, |
| 26 base::FilePath path, | 26 base::FilePath path, |
| 27 int id, | 27 int id, |
| 28 InputDeviceType type, | 28 InputDeviceType type, |
| 29 const EventDeviceInfo& devinfo, | 29 const EventDeviceInfo& devinfo, |
| 30 EventModifiersEvdev* modifiers, | 30 EventModifiersEvdev* modifiers, |
| 31 MouseButtonMapEvdev* button_map, | |
| 32 CursorDelegateEvdev* cursor, | 31 CursorDelegateEvdev* cursor, |
| 33 const KeyEventDispatchCallback& key_callback, | 32 const KeyEventDispatchCallback& key_callback, |
| 34 const EventDispatchCallback& callback) | 33 const MouseMoveEventDispatchCallback& mouse_move_callback, |
| 34 const MouseButtonEventDispatchCallback& mouse_button_callback) |
| 35 : EventConverterEvdev(fd, path, id, type), | 35 : EventConverterEvdev(fd, path, id, type), |
| 36 has_keyboard_(devinfo.HasKeyboard()), | 36 has_keyboard_(devinfo.HasKeyboard()), |
| 37 has_touchpad_(devinfo.HasTouchpad()), | 37 has_touchpad_(devinfo.HasTouchpad()), |
| 38 x_offset_(0), | 38 x_offset_(0), |
| 39 y_offset_(0), | 39 y_offset_(0), |
| 40 cursor_(cursor), | 40 cursor_(cursor), |
| 41 modifiers_(modifiers), | 41 modifiers_(modifiers), |
| 42 button_map_(button_map), | |
| 43 key_callback_(key_callback), | 42 key_callback_(key_callback), |
| 44 callback_(callback) { | 43 mouse_move_callback_(mouse_move_callback), |
| 44 mouse_button_callback_(mouse_button_callback) { |
| 45 } | 45 } |
| 46 | 46 |
| 47 EventConverterEvdevImpl::~EventConverterEvdevImpl() { | 47 EventConverterEvdevImpl::~EventConverterEvdevImpl() { |
| 48 Stop(); | 48 Stop(); |
| 49 close(fd_); | 49 close(fd_); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { | 52 void EventConverterEvdevImpl::OnFileCanReadWithoutBlocking(int fd) { |
| 53 input_event inputs[4]; | 53 input_event inputs[4]; |
| 54 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 54 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 case REL_Y: | 137 case REL_Y: |
| 138 y_offset_ = input.value; | 138 y_offset_ = input.value; |
| 139 break; | 139 break; |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { | 143 void EventConverterEvdevImpl::DispatchMouseButton(const input_event& input) { |
| 144 if (!cursor_) | 144 if (!cursor_) |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 unsigned int modifier; | 147 mouse_button_callback_.Run(MouseButtonEventParams(id_, cursor_->GetLocation(), |
| 148 const int button = button_map_->GetMappedButton(input.code); | 148 input.code, input.value, |
| 149 if (button == BTN_LEFT) | 149 /* allow_remap */ true)); |
| 150 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; | |
| 151 else if (button == BTN_RIGHT) | |
| 152 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; | |
| 153 else if (button == BTN_MIDDLE) | |
| 154 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; | |
| 155 else | |
| 156 return; | |
| 157 | |
| 158 int flag = modifiers_->GetEventFlagFromModifier(modifier); | |
| 159 modifiers_->UpdateModifier(modifier, input.value); | |
| 160 callback_.Run(make_scoped_ptr( | |
| 161 new MouseEvent(input.value ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED, | |
| 162 cursor_->GetLocation(), | |
| 163 cursor_->GetLocation(), | |
| 164 modifiers_->GetModifierFlags() | flag, | |
| 165 flag))); | |
| 166 } | 150 } |
| 167 | 151 |
| 168 void EventConverterEvdevImpl::FlushEvents() { | 152 void EventConverterEvdevImpl::FlushEvents() { |
| 169 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) | 153 if (!cursor_ || (x_offset_ == 0 && y_offset_ == 0)) |
| 170 return; | 154 return; |
| 171 | 155 |
| 172 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); | 156 cursor_->MoveCursor(gfx::Vector2dF(x_offset_, y_offset_)); |
| 173 | 157 |
| 174 callback_.Run(make_scoped_ptr( | 158 mouse_move_callback_.Run(MouseMoveEventParams(id_, cursor_->GetLocation())); |
| 175 new MouseEvent(ui::ET_MOUSE_MOVED, | 159 |
| 176 cursor_->GetLocation(), | |
| 177 cursor_->GetLocation(), | |
| 178 modifiers_->GetModifierFlags(), | |
| 179 /* changed_button_flags */ 0))); | |
| 180 x_offset_ = 0; | 160 x_offset_ = 0; |
| 181 y_offset_ = 0; | 161 y_offset_ = 0; |
| 182 } | 162 } |
| 183 | 163 |
| 184 } // namespace ui | 164 } // namespace ui |
| OLD | NEW |