Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Side by Side Diff: ui/events/ozone/evdev/event_factory_evdev.cc

Issue 858333006: [PATCH 9.6/11] ozone: evdev: Remove extra PostTask during dispatch from EventFactoryEvdev (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_factory_evdev.h" 5 #include "ui/events/ozone/evdev/event_factory_evdev.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/task_runner.h" 9 #include "base/task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; 110 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_;
111 }; 111 };
112 112
113 } // namespace 113 } // namespace
114 114
115 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, 115 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor,
116 DeviceManager* device_manager, 116 DeviceManager* device_manager,
117 KeyboardLayoutEngine* keyboard_layout) 117 KeyboardLayoutEngine* keyboard_layout)
118 : last_device_id_(0), 118 : last_device_id_(0),
119 device_manager_(device_manager), 119 device_manager_(device_manager),
120 dispatch_callback_( 120 keyboard_(&modifiers_,
121 base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), 121 keyboard_layout,
122 keyboard_(&modifiers_, keyboard_layout, dispatch_callback_), 122 base::Bind(&EventFactoryEvdev::DispatchUiEvent,
123 base::Unretained(this))),
123 cursor_(cursor), 124 cursor_(cursor),
124 input_controller_(&keyboard_, &button_map_), 125 input_controller_(&keyboard_, &button_map_),
125 initialized_(false), 126 initialized_(false),
126 weak_ptr_factory_(this) { 127 weak_ptr_factory_(this) {
127 DCHECK(device_manager_); 128 DCHECK(device_manager_);
128 } 129 }
129 130
130 EventFactoryEvdev::~EventFactoryEvdev() { 131 EventFactoryEvdev::~EventFactoryEvdev() {
131 } 132 }
132 133
(...skipping 28 matching lines...) Expand all
161 } 162 }
162 163
163 void EventFactoryEvdev::DispatchKeyEvent(int device_id, 164 void EventFactoryEvdev::DispatchKeyEvent(int device_id,
164 unsigned int code, 165 unsigned int code,
165 bool down) { 166 bool down) {
166 keyboard_.OnKeyChange(code, down); 167 keyboard_.OnKeyChange(code, down);
167 } 168 }
168 169
169 void EventFactoryEvdev::DispatchMouseMoveEvent(int device_id, 170 void EventFactoryEvdev::DispatchMouseMoveEvent(int device_id,
170 const gfx::PointF& location) { 171 const gfx::PointF& location) {
171 scoped_ptr<MouseEvent> event(new MouseEvent( 172 MouseEvent event(ui::ET_MOUSE_MOVED, location, location,
172 ui::ET_MOUSE_MOVED, location, location, modifiers_.GetModifierFlags(), 173 modifiers_.GetModifierFlags(),
173 /* changed_button_flags */ 0)); 174 /* changed_button_flags */ 0);
174 event->set_source_device_id(device_id); 175 event.set_source_device_id(device_id);
175 PostUiEvent(event.Pass()); 176 DispatchUiEvent(&event);
176 } 177 }
177 178
178 void EventFactoryEvdev::DispatchMouseButtonEvent(int device_id, 179 void EventFactoryEvdev::DispatchMouseButtonEvent(int device_id,
179 const gfx::PointF& location, 180 const gfx::PointF& location,
180 unsigned int button, 181 unsigned int button,
181 bool down, 182 bool down,
182 bool allow_remap) { 183 bool allow_remap) {
183 // Mouse buttons can be remapped, touchpad taps & clicks cannot. 184 // Mouse buttons can be remapped, touchpad taps & clicks cannot.
184 if (allow_remap) 185 if (allow_remap)
185 button = button_map_.GetMappedButton(button); 186 button = button_map_.GetMappedButton(button);
186 187
187 int modifier = EVDEV_MODIFIER_NONE; 188 int modifier = EVDEV_MODIFIER_NONE;
188 switch (button) { 189 switch (button) {
189 case BTN_LEFT: 190 case BTN_LEFT:
190 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON; 191 modifier = EVDEV_MODIFIER_LEFT_MOUSE_BUTTON;
191 break; 192 break;
192 case BTN_RIGHT: 193 case BTN_RIGHT:
193 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON; 194 modifier = EVDEV_MODIFIER_RIGHT_MOUSE_BUTTON;
194 break; 195 break;
195 case BTN_MIDDLE: 196 case BTN_MIDDLE:
196 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON; 197 modifier = EVDEV_MODIFIER_MIDDLE_MOUSE_BUTTON;
197 break; 198 break;
198 default: 199 default:
199 return; 200 return;
200 } 201 }
201 202
202 int flag = modifiers_.GetEventFlagFromModifier(modifier); 203 int flag = modifiers_.GetEventFlagFromModifier(modifier);
203 modifiers_.UpdateModifier(modifier, down); 204 modifiers_.UpdateModifier(modifier, down);
204 205
205 scoped_ptr<MouseEvent> event( 206 MouseEvent event(down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED,
206 new MouseEvent(down ? ui::ET_MOUSE_PRESSED : ui::ET_MOUSE_RELEASED, 207 location, location, modifiers_.GetModifierFlags() | flag,
207 location, location, modifiers_.GetModifierFlags() | flag, 208 /* changed_button_flags */ flag);
208 /* changed_button_flags */ flag)); 209 event.set_source_device_id(device_id);
209 event->set_source_device_id(device_id); 210 DispatchUiEvent(&event);
210 PostUiEvent(event.Pass());
211 } 211 }
212 212
213 void EventFactoryEvdev::DispatchMouseWheelEvent(int device_id, 213 void EventFactoryEvdev::DispatchMouseWheelEvent(int device_id,
214 const gfx::PointF& location, 214 const gfx::PointF& location,
215 const gfx::Vector2d& delta) { 215 const gfx::Vector2d& delta) {
216 scoped_ptr<MouseWheelEvent> event(new MouseWheelEvent( 216 MouseWheelEvent event(delta, location, location,
217 delta, location, location, modifiers_.GetModifierFlags(), 217 modifiers_.GetModifierFlags(),
218 0 /* changed_button_flags */)); 218 0 /* changed_button_flags */);
219 event->set_source_device_id(device_id); 219 event.set_source_device_id(device_id);
220 PostUiEvent(event.Pass()); 220 DispatchUiEvent(&event);
221 } 221 }
222 222
223 void EventFactoryEvdev::DispatchScrollEvent(const ScrollEventParams& params) { 223 void EventFactoryEvdev::DispatchScrollEvent(const ScrollEventParams& params) {
224 scoped_ptr<ScrollEvent> event(new ScrollEvent( 224 ScrollEvent event(params.type, params.location, params.timestamp,
225 params.type, params.location, params.timestamp, 225 modifiers_.GetModifierFlags(), params.delta.x(),
226 modifiers_.GetModifierFlags(), params.delta.x(), params.delta.y(), 226 params.delta.y(), params.ordinal_delta.x(),
227 params.ordinal_delta.x(), params.ordinal_delta.y(), params.finger_count)); 227 params.ordinal_delta.y(), params.finger_count);
228 event->set_source_device_id(params.device_id); 228 event.set_source_device_id(params.device_id);
229 PostUiEvent(event.Pass()); 229 DispatchUiEvent(&event);
230 } 230 }
231 231
232 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) { 232 void EventFactoryEvdev::DispatchTouchEvent(const TouchEventParams& params) {
233 float x = params.location.x(); 233 float x = params.location.x();
234 float y = params.location.y(); 234 float y = params.location.y();
235 double radius_x = params.radii.x(); 235 double radius_x = params.radii.x();
236 double radius_y = params.radii.y(); 236 double radius_y = params.radii.y();
237 237
238 // Transform the event to align touches to the image based on display mode. 238 // Transform the event to align touches to the image based on display mode.
239 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x, 239 DeviceDataManager::GetInstance()->ApplyTouchTransformer(params.device_id, &x,
240 &y); 240 &y);
241 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, 241 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
242 &radius_x); 242 &radius_x);
243 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id, 243 DeviceDataManager::GetInstance()->ApplyTouchRadiusScale(params.device_id,
244 &radius_y); 244 &radius_y);
245 245 TouchEvent touch_event(params.type, gfx::PointF(x, y),
246 scoped_ptr<TouchEvent> touch_event(new TouchEvent( 246 /* flags */ 0, params.touch_id, params.timestamp,
247 params.type, gfx::PointF(x, y), 247 radius_x, radius_y,
248 /* flags */ 0, params.touch_id, params.timestamp, radius_x, radius_y, 248 /* angle */ 0.f, params.pressure);
249 /* angle */ 0., params.pressure)); 249 touch_event.set_source_device_id(params.device_id);
250 touch_event->set_source_device_id(params.device_id); 250 DispatchUiEvent(&touch_event);
251 PostUiEvent(touch_event.Pass());
252 } 251 }
253 252
254 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { 253 void EventFactoryEvdev::DispatchUiEvent(Event* event) {
alexst (slow to review) 2015/01/28 19:04:58 Is there a reason we can't just remove this method
spang 2015/01/28 19:38:05 The only reason is that because there's an implici
255 base::ThreadTaskRunnerHandle::Get()->PostTask( 254 DispatchEvent(event);
256 FROM_HERE,
257 base::Bind(&EventFactoryEvdev::DispatchUiEventTask,
258 weak_ptr_factory_.GetWeakPtr(),
259 base::Passed(&event)));
260 } 255 }
261 256
262 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( 257 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated(
263 const std::vector<KeyboardDevice>& devices) { 258 const std::vector<KeyboardDevice>& devices) {
264 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); 259 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
265 observer->OnKeyboardDevicesUpdated(devices); 260 observer->OnKeyboardDevicesUpdated(devices);
266 } 261 }
267 262
268 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated( 263 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated(
269 const std::vector<TouchscreenDevice>& devices) { 264 const std::vector<TouchscreenDevice>& devices) {
270 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); 265 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
271 observer->OnTouchscreenDevicesUpdated(devices); 266 observer->OnTouchscreenDevicesUpdated(devices);
272 } 267 }
273 268
274 void EventFactoryEvdev::DispatchMouseDevicesUpdated( 269 void EventFactoryEvdev::DispatchMouseDevicesUpdated(
275 const std::vector<InputDevice>& devices) { 270 const std::vector<InputDevice>& devices) {
276 // There's no list of mice in DeviceDataManager. 271 // There's no list of mice in DeviceDataManager.
277 input_controller_.SetHasMouse(devices.size() != 0); 272 input_controller_.SetHasMouse(devices.size() != 0);
278 } 273 }
279 274
280 void EventFactoryEvdev::DispatchTouchpadDevicesUpdated( 275 void EventFactoryEvdev::DispatchTouchpadDevicesUpdated(
281 const std::vector<InputDevice>& devices) { 276 const std::vector<InputDevice>& devices) {
282 // There's no list of touchpads in DeviceDataManager. 277 // There's no list of touchpads in DeviceDataManager.
283 input_controller_.SetHasTouchpad(devices.size() != 0); 278 input_controller_.SetHasTouchpad(devices.size() != 0);
284 } 279 }
285 280
286 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) {
287 DispatchEvent(event.get());
288 }
289 281
290 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { 282 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
291 if (event.device_type() != DeviceEvent::INPUT) 283 if (event.device_type() != DeviceEvent::INPUT)
292 return; 284 return;
293 285
294 switch (event.action_type()) { 286 switch (event.action_type()) {
295 case DeviceEvent::ADD: 287 case DeviceEvent::ADD:
296 case DeviceEvent::CHANGE: { 288 case DeviceEvent::CHANGE: {
297 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value()); 289 TRACE_EVENT1("ozone", "OnDeviceAdded", "path", event.path().value());
298 input_device_factory_->AddInputDevice(NextDeviceId(), event.path()); 290 input_device_factory_->AddInputDevice(NextDeviceId(), event.path());
299 break; 291 break;
300 } 292 }
301 case DeviceEvent::REMOVE: { 293 case DeviceEvent::REMOVE: {
302 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); 294 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value());
303 input_device_factory_->RemoveInputDevice(event.path()); 295 input_device_factory_->RemoveInputDevice(event.path());
304 break; 296 break;
305 } 297 }
306 } 298 }
307 } 299 }
308 300
309 void EventFactoryEvdev::OnDispatcherListChanged() { 301 void EventFactoryEvdev::OnDispatcherListChanged() {
310 if (!initialized_) 302 if (!initialized_)
311 Init(); 303 Init();
312 } 304 }
313 305
314 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, 306 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget,
315 const gfx::PointF& location) { 307 const gfx::PointF& location) {
316 if (cursor_) { 308 if (!cursor_)
317 cursor_->MoveCursorTo(widget, location); 309 return;
318 PostUiEvent(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, 310
319 cursor_->GetLocation(), 311 cursor_->MoveCursorTo(widget, location);
320 cursor_->GetLocation(), 312
321 modifiers_.GetModifierFlags(), 313 base::ThreadTaskRunnerHandle::Get()->PostTask(
322 /* changed_button_flags */ 0))); 314 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent,
323 } 315 weak_ptr_factory_.GetWeakPtr(), -1 /* device_id */,
316 cursor_->GetLocation()));
324 } 317 }
325 318
326 int EventFactoryEvdev::NextDeviceId() { 319 int EventFactoryEvdev::NextDeviceId() {
327 return ++last_device_id_; 320 return ++last_device_id_;
328 } 321 }
329 322
330 } // namespace ui 323 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_factory_evdev.h ('k') | ui/events/ozone/evdev/input_injector_evdev_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698