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

Side by Side Diff: ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cros.cc

Issue 661353006: ozone: evdev: Dispatch events in task (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 6 years, 2 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/libgestures_glue/gesture_interpreter_libevdev_cr os.h" 5 #include "ui/events/ozone/evdev/libgestures_glue/gesture_interpreter_libevdev_cr os.h"
6 6
7 #include <gestures/gestures.h> 7 #include <gestures/gestures.h>
8 #include <libevdev/libevdev.h> 8 #include <libevdev/libevdev.h>
9 9
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 move->dx, 213 move->dx,
214 move->dy, 214 move->dy,
215 move->ordinal_dx, 215 move->ordinal_dx,
216 move->ordinal_dy); 216 move->ordinal_dy);
217 if (!cursor_) 217 if (!cursor_)
218 return; // No cursor! 218 return; // No cursor!
219 219
220 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy)); 220 cursor_->MoveCursor(gfx::Vector2dF(move->dx, move->dy));
221 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy 221 // TODO(spang): Use move->ordinal_dx, move->ordinal_dy
222 // TODO(spang): Use move->start_time, move->end_time 222 // TODO(spang): Use move->start_time, move->end_time
223 MouseEvent event(ET_MOUSE_MOVED, 223 Dispatch(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED,
224 cursor_->location(), 224 cursor_->location(),
225 cursor_->location(), 225 cursor_->location(),
226 modifiers_->GetModifierFlags(), 226 modifiers_->GetModifierFlags(),
227 /* changed_button_flags */ 0); 227 /* changed_button_flags */ 0)));
228 Dispatch(&event);
229 } 228 }
230 229
231 void GestureInterpreterLibevdevCros::OnGestureScroll( 230 void GestureInterpreterLibevdevCros::OnGestureScroll(
232 const Gesture* gesture, 231 const Gesture* gesture,
233 const GestureScroll* scroll) { 232 const GestureScroll* scroll) {
234 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]", 233 DVLOG(3) << base::StringPrintf("Gesture Scroll: (%f, %f) [%f, %f]",
235 scroll->dx, 234 scroll->dx,
236 scroll->dy, 235 scroll->dy,
237 scroll->ordinal_dx, 236 scroll->ordinal_dx,
238 scroll->ordinal_dy); 237 scroll->ordinal_dy);
239 if (!cursor_) 238 if (!cursor_)
240 return; // No cursor! 239 return; // No cursor!
241 240
242 // TODO(spang): Support SetNaturalScroll 241 // TODO(spang): Support SetNaturalScroll
243 // TODO(spang): Use scroll->start_time 242 // TODO(spang): Use scroll->start_time
244 ScrollEvent event(ET_SCROLL, 243 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL,
245 cursor_->location(), 244 cursor_->location(),
246 StimeToTimedelta(gesture->end_time), 245 StimeToTimedelta(gesture->end_time),
247 modifiers_->GetModifierFlags(), 246 modifiers_->GetModifierFlags(),
248 scroll->dx, 247 scroll->dx,
249 scroll->dy, 248 scroll->dy,
250 scroll->ordinal_dx, 249 scroll->ordinal_dx,
251 scroll->ordinal_dy, 250 scroll->ordinal_dy,
252 kGestureScrollFingerCount); 251 kGestureScrollFingerCount)));
253 Dispatch(&event);
254 } 252 }
255 253
256 void GestureInterpreterLibevdevCros::OnGestureButtonsChange( 254 void GestureInterpreterLibevdevCros::OnGestureButtonsChange(
257 const Gesture* gesture, 255 const Gesture* gesture,
258 const GestureButtonsChange* buttons) { 256 const GestureButtonsChange* buttons) {
259 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x", 257 DVLOG(3) << base::StringPrintf("Gesture Button Change: down=0x%02x up=0x%02x",
260 buttons->down, 258 buttons->down,
261 buttons->up); 259 buttons->up);
262 260
263 if (!cursor_) 261 if (!cursor_)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 fling->fling_state); 300 fling->fling_state);
303 301
304 if (!cursor_) 302 if (!cursor_)
305 return; // No cursor! 303 return; // No cursor!
306 304
307 EventType type = 305 EventType type =
308 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START 306 (fling->fling_state == GESTURES_FLING_START ? ET_SCROLL_FLING_START
309 : ET_SCROLL_FLING_CANCEL); 307 : ET_SCROLL_FLING_CANCEL);
310 308
311 // Fling is like 2-finger scrolling but with velocity instead of displacement. 309 // Fling is like 2-finger scrolling but with velocity instead of displacement.
312 ScrollEvent event(type, 310 Dispatch(make_scoped_ptr(new ScrollEvent(type,
313 cursor_->location(), 311 cursor_->location(),
314 StimeToTimedelta(gesture->end_time), 312 StimeToTimedelta(gesture->end_time),
315 modifiers_->GetModifierFlags(), 313 modifiers_->GetModifierFlags(),
316 fling->vx, 314 fling->vx,
317 fling->vy, 315 fling->vy,
318 fling->ordinal_vx, 316 fling->ordinal_vx,
319 fling->ordinal_vy, 317 fling->ordinal_vy,
320 kGestureScrollFingerCount); 318 kGestureScrollFingerCount)));
321 Dispatch(&event);
322 } 319 }
323 320
324 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture, 321 void GestureInterpreterLibevdevCros::OnGestureSwipe(const Gesture* gesture,
325 const GestureSwipe* swipe) { 322 const GestureSwipe* swipe) {
326 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]", 323 DVLOG(3) << base::StringPrintf("Gesture Swipe: (%f, %f) [%f, %f]",
327 swipe->dx, 324 swipe->dx,
328 swipe->dy, 325 swipe->dy,
329 swipe->ordinal_dx, 326 swipe->ordinal_dx,
330 swipe->ordinal_dy); 327 swipe->ordinal_dy);
331 328
332 if (!cursor_) 329 if (!cursor_)
333 return; // No cursor! 330 return; // No cursor!
334 331
335 // Swipe is 3-finger scrolling. 332 // Swipe is 3-finger scrolling.
336 ScrollEvent event(ET_SCROLL, 333 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL,
337 cursor_->location(), 334 cursor_->location(),
338 StimeToTimedelta(gesture->end_time), 335 StimeToTimedelta(gesture->end_time),
339 modifiers_->GetModifierFlags(), 336 modifiers_->GetModifierFlags(),
340 swipe->dx, 337 swipe->dx,
341 swipe->dy, 338 swipe->dy,
342 swipe->ordinal_dx, 339 swipe->ordinal_dx,
343 swipe->ordinal_dy, 340 swipe->ordinal_dy,
344 kGestureSwipeFingerCount); 341 kGestureSwipeFingerCount)));
345 Dispatch(&event);
346 } 342 }
347 343
348 void GestureInterpreterLibevdevCros::OnGestureSwipeLift( 344 void GestureInterpreterLibevdevCros::OnGestureSwipeLift(
349 const Gesture* gesture, 345 const Gesture* gesture,
350 const GestureSwipeLift* swipelift) { 346 const GestureSwipeLift* swipelift) {
351 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift"); 347 DVLOG(3) << base::StringPrintf("Gesture Swipe Lift");
352 348
353 if (!cursor_) 349 if (!cursor_)
354 return; // No cursor! 350 return; // No cursor!
355 351
356 // Turn a swipe lift into a fling start. 352 // Turn a swipe lift into a fling start.
357 // TODO(spang): Figure out why and put it in this comment. 353 // TODO(spang): Figure out why and put it in this comment.
358 354
359 ScrollEvent event(ET_SCROLL_FLING_START, 355 Dispatch(make_scoped_ptr(new ScrollEvent(ET_SCROLL_FLING_START,
360 cursor_->location(), 356 cursor_->location(),
361 StimeToTimedelta(gesture->end_time), 357 StimeToTimedelta(gesture->end_time),
362 modifiers_->GetModifierFlags(), 358 modifiers_->GetModifierFlags(),
363 /* x_offset */ 0, 359 /* x_offset */ 0,
364 /* y_offset */ 0, 360 /* y_offset */ 0,
365 /* x_offset_ordinal */ 0, 361 /* x_offset_ordinal */ 0,
366 /* y_offset_ordinal */ 0, 362 /* y_offset_ordinal */ 0,
367 kGestureScrollFingerCount); 363 kGestureScrollFingerCount)));
368 Dispatch(&event);
369
370 } 364 }
371 365
372 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture, 366 void GestureInterpreterLibevdevCros::OnGesturePinch(const Gesture* gesture,
373 const GesturePinch* pinch) { 367 const GesturePinch* pinch) {
374 DVLOG(3) << base::StringPrintf( 368 DVLOG(3) << base::StringPrintf(
375 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz); 369 "Gesture Pinch: dz=%f [%f]", pinch->dz, pinch->ordinal_dz);
376 370
377 if (!cursor_) 371 if (!cursor_)
378 return; // No cursor! 372 return; // No cursor!
379 373
380 NOTIMPLEMENTED(); 374 NOTIMPLEMENTED();
381 } 375 }
382 376
383 void GestureInterpreterLibevdevCros::OnGestureMetrics( 377 void GestureInterpreterLibevdevCros::OnGestureMetrics(
384 const Gesture* gesture, 378 const Gesture* gesture,
385 const GestureMetrics* metrics) { 379 const GestureMetrics* metrics) {
386 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d", 380 DVLOG(3) << base::StringPrintf("Gesture Metrics: [%f, %f] type=%d",
387 metrics->data[0], 381 metrics->data[0],
388 metrics->data[1], 382 metrics->data[1],
389 metrics->type); 383 metrics->type);
390 NOTIMPLEMENTED(); 384 NOTIMPLEMENTED();
391 } 385 }
392 386
393 void GestureInterpreterLibevdevCros::Dispatch(Event* event) { 387 void GestureInterpreterLibevdevCros::Dispatch(scoped_ptr<Event> event) {
394 dispatch_callback_.Run(event); 388 dispatch_callback_.Run(event.Pass());
395 } 389 }
396 390
397 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int modifier, 391 void GestureInterpreterLibevdevCros::DispatchMouseButton(unsigned int modifier,
398 bool down) { 392 bool down) {
399 const gfx::PointF& loc = cursor_->location(); 393 const gfx::PointF& loc = cursor_->location();
400 int flag = modifiers_->GetEventFlagFromModifier(modifier); 394 int flag = modifiers_->GetEventFlagFromModifier(modifier);
401 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED); 395 EventType type = (down ? ET_MOUSE_PRESSED : ET_MOUSE_RELEASED);
402 modifiers_->UpdateModifier(modifier, down); 396 modifiers_->UpdateModifier(modifier, down);
403 MouseEvent event(type, loc, loc, modifiers_->GetModifierFlags() | flag, flag); 397 Dispatch(make_scoped_ptr(new MouseEvent(
404 Dispatch(&event); 398 type, loc, loc, modifiers_->GetModifierFlags() | flag, flag)));
405 } 399 }
406 400
407 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev, 401 void GestureInterpreterLibevdevCros::DispatchChangedKeys(Evdev* evdev,
408 const timeval& time) { 402 const timeval& time) {
409 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)]; 403 unsigned long key_state_diff[EVDEV_BITS_TO_LONGS(KEY_CNT)];
410 404
411 // Find changed keys. 405 // Find changed keys.
412 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i) 406 for (unsigned long i = 0; i < arraysize(key_state_diff); ++i)
413 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i]; 407 key_state_diff[i] = evdev->key_state_bitmask[i] ^ prev_key_state_[i];
414 408
415 // Dispatch events for changed keys. 409 // Dispatch events for changed keys.
416 for (unsigned long i = 0; i < KEY_CNT; ++i) { 410 for (unsigned long i = 0; i < KEY_CNT; ++i) {
417 if (EvdevBitIsSet(key_state_diff, i)) { 411 if (EvdevBitIsSet(key_state_diff, i)) {
418 bool value = EvdevBitIsSet(evdev->key_state_bitmask, i); 412 bool value = EvdevBitIsSet(evdev->key_state_bitmask, i);
419 keyboard_->OnKeyChange(i, value); 413 keyboard_->OnKeyChange(i, value);
420 } 414 }
421 } 415 }
422 416
423 // Update internal key state. 417 // Update internal key state.
424 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i) 418 for (unsigned long i = 0; i < EVDEV_BITS_TO_LONGS(KEY_CNT); ++i)
425 prev_key_state_[i] = evdev->key_state_bitmask[i]; 419 prev_key_state_[i] = evdev->key_state_bitmask[i];
426 } 420 }
427 421
428 } // namespace ui 422 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698