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

Side by Side Diff: ui/events/event.h

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address build problems, add accessor and unit tests. Created 5 years, 4 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
« no previous file with comments | « ui/chromeos/touch_exploration_controller_unittest.cc ('k') | ui/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef UI_EVENTS_EVENT_H_ 5 #ifndef UI_EVENTS_EVENT_H_
6 #define UI_EVENTS_EVENT_H_ 6 #define UI_EVENTS_EVENT_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/event_types.h" 10 #include "base/event_types.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::TimeDelta time_stamp, 315 base::TimeDelta time_stamp,
316 int flags); 316 int flags);
317 317
318 gfx::PointF location_; 318 gfx::PointF location_;
319 319
320 // |location_| multiplied by an optional transformation matrix for 320 // |location_| multiplied by an optional transformation matrix for
321 // rotations, animations and skews. 321 // rotations, animations and skews.
322 gfx::PointF root_location_; 322 gfx::PointF root_location_;
323 }; 323 };
324 324
325 // Structure for handling common fields between touch and mouse to support
326 // PointerEvents API.
327 struct EVENTS_EXPORT PointerEventDetails {
sadrul 2015/08/13 15:44:17 Maybe EventPointerDetails (to be more inline with
328 public:
329 PointerEventDetails() {}
330 explicit PointerEventDetails(EventPointerType pointer_type)
331 : pointer_type_(pointer_type) {}
332 PointerEventDetails(EventPointerType pointer_type,
333 float radius_x,
334 float radius_y,
335 float force,
336 float tilt_x,
337 float tilt_y)
338 : pointer_type_(pointer_type),
339 radius_x_(radius_x),
340 radius_y_(radius_y),
341 force_(force),
342 tilt_x_(tilt_x),
343 tilt_y_(tilt_y) {}
344
345 EventPointerType pointer_type() const { return pointer_type_; };
346
347 // If we aren't provided with a radius on one axis, use the
348 // information from the other axis.
349 float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; }
350 float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; }
351 float force() const { return force_; }
352 float tilt_x() const { return tilt_x_; }
353 float tilt_y() const { return tilt_y_; }
354
355 private:
356 // Needed for TouchEvent::UpdateForRootTransform.
357 friend TouchEvent;
358
359 // The type of pointer device.
360 EventPointerType pointer_type_ = EventPointerType::POINTER_TYPE_UNKNOWN;
361
362 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
363 float radius_x_ = 0.0;
364
365 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
366 float radius_y_ = 0.0;
367
368 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
369 float force_ = 0.0;
370
371 // Angle of tilt of the X (major) axis. 0.0 if unknown.
372 float tilt_x_ = 0.0;
373
374 // Angle of tilt of the Y (minor) axis. 0.0 if unknown.
375 float tilt_y_ = 0.0;
376 };
377
325 class EVENTS_EXPORT MouseEvent : public LocatedEvent { 378 class EVENTS_EXPORT MouseEvent : public LocatedEvent {
326 public: 379 public:
327 explicit MouseEvent(const base::NativeEvent& native_event); 380 explicit MouseEvent(const base::NativeEvent& native_event);
328 381
329 // Create a new MouseEvent based on the provided model. 382 // Create a new MouseEvent based on the provided model.
330 // Uses the provided |type| and |flags| for the new event. 383 // Uses the provided |type| and |flags| for the new event.
331 // If source / target windows are provided, the model location will be 384 // If source / target windows are provided, the model location will be
332 // converted from |source| coordinate system to |target| coordinate system. 385 // converted from |source| coordinate system to |target| coordinate system.
333 template <class T> 386 template <class T>
334 MouseEvent(const MouseEvent& model, T* source, T* target) 387 MouseEvent(const MouseEvent& model, T* source, T* target)
335 : LocatedEvent(model, source, target), 388 : LocatedEvent(model, source, target),
336 changed_button_flags_(model.changed_button_flags_) { 389 changed_button_flags_(model.changed_button_flags_),
337 } 390 pointer_details_(model.pointer_details_) {}
338 391
339 template <class T> 392 template <class T>
340 MouseEvent(const MouseEvent& model, 393 MouseEvent(const MouseEvent& model,
341 T* source, 394 T* source,
342 T* target, 395 T* target,
343 EventType type, 396 EventType type,
344 int flags) 397 int flags)
345 : LocatedEvent(model, source, target), 398 : LocatedEvent(model, source, target),
346 changed_button_flags_(model.changed_button_flags_) { 399 changed_button_flags_(model.changed_button_flags_),
400 pointer_details_(model.pointer_details_) {
347 SetType(type); 401 SetType(type);
348 set_flags(flags); 402 set_flags(flags);
349 } 403 }
350 404
351 // Used for synthetic events in testing, gesture recognizer and Ozone 405 // Used for synthetic events in testing, gesture recognizer and Ozone
352 MouseEvent(EventType type, 406 MouseEvent(EventType type,
353 const gfx::PointF& location, 407 const gfx::PointF& location,
354 const gfx::PointF& root_location, 408 const gfx::PointF& root_location,
355 base::TimeDelta time_stamp, 409 base::TimeDelta time_stamp,
356 int flags, 410 int flags,
357 int changed_button_flags); 411 int changed_button_flags,
412 const PointerEventDetails& details);
sadrul 2015/08/13 15:44:17 Would it be better to always initialize PointerEve
358 413
359 // Conveniences to quickly test what button is down 414 // Conveniences to quickly test what button is down
360 bool IsOnlyLeftMouseButton() const { 415 bool IsOnlyLeftMouseButton() const {
361 return button_flags() == EF_LEFT_MOUSE_BUTTON; 416 return button_flags() == EF_LEFT_MOUSE_BUTTON;
362 } 417 }
363 418
364 bool IsLeftMouseButton() const { 419 bool IsLeftMouseButton() const {
365 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0; 420 return (flags() & EF_LEFT_MOUSE_BUTTON) != 0;
366 } 421 }
367 422
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // Identifies the button that changed. During a press this corresponds to the 455 // Identifies the button that changed. During a press this corresponds to the
401 // button that was pressed and during a release this corresponds to the button 456 // button that was pressed and during a release this corresponds to the button
402 // that was released. 457 // that was released.
403 // NOTE: during a press and release flags() contains the complete set of 458 // NOTE: during a press and release flags() contains the complete set of
404 // flags. Use this to determine the button that was pressed or released. 459 // flags. Use this to determine the button that was pressed or released.
405 int changed_button_flags() const { return changed_button_flags_; } 460 int changed_button_flags() const { return changed_button_flags_; }
406 461
407 // Updates the button that changed. 462 // Updates the button that changed.
408 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; } 463 void set_changed_button_flags(int flags) { changed_button_flags_ = flags; }
409 464
465 // Event details common to MouseEvent and TouchEvent.
466 const PointerEventDetails& pointer_details() const {
467 return pointer_details_;
468 }
469
410 private: 470 private:
411 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease); 471 FRIEND_TEST_ALL_PREFIXES(EventTest, DoubleClickRequiresRelease);
412 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft); 472 FRIEND_TEST_ALL_PREFIXES(EventTest, SingleClickRightLeft);
413 473
414 // Returns the flags for the mouse buttons. 474 // Returns the flags for the mouse buttons.
415 int button_flags() const { 475 int button_flags() const {
416 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON | 476 return flags() & (EF_LEFT_MOUSE_BUTTON | EF_MIDDLE_MOUSE_BUTTON |
417 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON | 477 EF_RIGHT_MOUSE_BUTTON | EF_BACK_MOUSE_BUTTON |
418 EF_FORWARD_MOUSE_BUTTON); 478 EF_FORWARD_MOUSE_BUTTON);
419 } 479 }
420 480
421 // Returns the repeat count based on the previous mouse click, if it is 481 // Returns the repeat count based on the previous mouse click, if it is
422 // recent enough and within a small enough distance. 482 // recent enough and within a small enough distance.
423 static int GetRepeatCount(const MouseEvent& click_event); 483 static int GetRepeatCount(const MouseEvent& click_event);
424 484
425 // Resets the last_click_event_ for unit tests. 485 // Resets the last_click_event_ for unit tests.
426 static void ResetLastClickForTest(); 486 static void ResetLastClickForTest();
427 487
428 // See description above getter for details. 488 // See description above getter for details.
429 int changed_button_flags_; 489 int changed_button_flags_;
430 490
431 static MouseEvent* last_click_event_; 491 static MouseEvent* last_click_event_;
432 492
433 // We can create a MouseEvent for a native event more than once. We set this 493 // We can create a MouseEvent for a native event more than once. We set this
434 // to true when the next event either has a different timestamp or we see a 494 // to true when the next event either has a different timestamp or we see a
435 // release signalling that the press (click) event was completed. 495 // release signalling that the press (click) event was completed.
436 static bool last_click_complete_; 496 static bool last_click_complete_;
497
498 // Structure for holding pointer details for implementing PointerEvents API.
499 PointerEventDetails pointer_details_;
437 }; 500 };
438 501
439 class ScrollEvent; 502 class ScrollEvent;
440 503
441 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent { 504 class EVENTS_EXPORT MouseWheelEvent : public MouseEvent {
442 public: 505 public:
443 // See |offset| for details. 506 // See |offset| for details.
444 static const int kWheelDelta; 507 static const int kWheelDelta;
445 508
446 explicit MouseWheelEvent(const base::NativeEvent& native_event); 509 explicit MouseWheelEvent(const base::NativeEvent& native_event);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 explicit TouchEvent(const base::NativeEvent& native_event); 542 explicit TouchEvent(const base::NativeEvent& native_event);
480 543
481 // Create a new TouchEvent which is identical to the provided model. 544 // Create a new TouchEvent which is identical to the provided model.
482 // If source / target windows are provided, the model location will be 545 // If source / target windows are provided, the model location will be
483 // converted from |source| coordinate system to |target| coordinate system. 546 // converted from |source| coordinate system to |target| coordinate system.
484 template <class T> 547 template <class T>
485 TouchEvent(const TouchEvent& model, T* source, T* target) 548 TouchEvent(const TouchEvent& model, T* source, T* target)
486 : LocatedEvent(model, source, target), 549 : LocatedEvent(model, source, target),
487 touch_id_(model.touch_id_), 550 touch_id_(model.touch_id_),
488 unique_event_id_(model.unique_event_id_), 551 unique_event_id_(model.unique_event_id_),
489 radius_x_(model.radius_x_),
490 radius_y_(model.radius_y_),
491 rotation_angle_(model.rotation_angle_), 552 rotation_angle_(model.rotation_angle_),
492 force_(model.force_),
493 may_cause_scrolling_(model.may_cause_scrolling_), 553 may_cause_scrolling_(model.may_cause_scrolling_),
494 should_remove_native_touch_id_mapping_(false) {} 554 should_remove_native_touch_id_mapping_(false),
555 pointer_details_(model.pointer_details_) {}
495 556
496 TouchEvent(EventType type, 557 TouchEvent(EventType type,
497 const gfx::PointF& location, 558 const gfx::PointF& location,
498 int touch_id, 559 int touch_id,
499 base::TimeDelta time_stamp); 560 base::TimeDelta time_stamp);
500 561
501 TouchEvent(EventType type, 562 TouchEvent(EventType type,
502 const gfx::PointF& location, 563 const gfx::PointF& location,
503 int flags, 564 int flags,
504 int touch_id, 565 int touch_id,
505 base::TimeDelta timestamp, 566 base::TimeDelta timestamp,
506 float radius_x,
507 float radius_y,
508 float angle, 567 float angle,
509 float force); 568 const PointerEventDetails& details);
510 569
511 TouchEvent(const TouchEvent& copy); 570 TouchEvent(const TouchEvent& copy);
512 571
513 ~TouchEvent() override; 572 ~TouchEvent() override;
514 573
515 // The id of the pointer this event modifies. 574 // The id of the pointer this event modifies.
516 int touch_id() const { return touch_id_; } 575 int touch_id() const { return touch_id_; }
517 // A unique identifier for this event. 576 // A unique identifier for this event.
518 uint32 unique_event_id() const { return unique_event_id_; } 577 uint32 unique_event_id() const { return unique_event_id_; }
519 // If we aren't provided with a radius on one axis, use the 578
520 // information from the other axis. 579 // TODO(robert.bradford): Drop these shims.
521 float radius_x() const { return radius_x_ > 0 ? radius_x_ : radius_y_; } 580 float radius_x() const { return pointer_details_.radius_x(); }
522 float radius_y() const { return radius_y_ > 0 ? radius_y_ : radius_x_; } 581 float radius_y() const { return pointer_details_.radius_y(); }
582 float force() const { return pointer_details_.force(); }
583
523 float rotation_angle() const { return rotation_angle_; } 584 float rotation_angle() const { return rotation_angle_; }
524 float force() const { return force_; }
525 585
526 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; } 586 void set_may_cause_scrolling(bool causes) { may_cause_scrolling_ = causes; }
527 bool may_cause_scrolling() const { return may_cause_scrolling_; } 587 bool may_cause_scrolling() const { return may_cause_scrolling_; }
528 588
529 // Used for unit tests. 589 // TODO(robert.bradford): ozone_platform_egltest.cc could use
530 void set_radius_x(const float r) { radius_x_ = r; } 590 // UpdateForRootTransform() instead: crbug.com/519337
531 void set_radius_y(const float r) { radius_y_ = r; } 591 void set_radius_x(const float r) { pointer_details_.radius_x_ = r; }
592 void set_radius_y(const float r) { pointer_details_.radius_y_ = r; }
532 593
533 void set_should_remove_native_touch_id_mapping( 594 void set_should_remove_native_touch_id_mapping(
534 bool should_remove_native_touch_id_mapping) { 595 bool should_remove_native_touch_id_mapping) {
535 should_remove_native_touch_id_mapping_ = 596 should_remove_native_touch_id_mapping_ =
536 should_remove_native_touch_id_mapping; 597 should_remove_native_touch_id_mapping;
537 } 598 }
538 599
539 // Overridden from LocatedEvent. 600 // Overridden from LocatedEvent.
540 void UpdateForRootTransform( 601 void UpdateForRootTransform(
541 const gfx::Transform& inverted_root_transform) override; 602 const gfx::Transform& inverted_root_transform) override;
542 603
543 // Marks the event as not participating in synchronous gesture recognition. 604 // Marks the event as not participating in synchronous gesture recognition.
544 void DisableSynchronousHandling(); 605 void DisableSynchronousHandling();
545 bool synchronous_handling_disabled() const { 606 bool synchronous_handling_disabled() const {
546 return !!(result() & ER_DISABLE_SYNC_HANDLING); 607 return !!(result() & ER_DISABLE_SYNC_HANDLING);
547 } 608 }
548 609
610 // Event details common to MouseEvent and TouchEvent.
611 const PointerEventDetails& pointer_details() const {
612 return pointer_details_;
613 }
614
549 private: 615 private:
550 // Adjusts rotation_angle_ to within the acceptable range. 616 // Adjusts rotation_angle_ to within the acceptable range.
551 void FixRotationAngle(); 617 void FixRotationAngle();
552 618
553 // The identity (typically finger) of the touch starting at 0 and incrementing 619 // The identity (typically finger) of the touch starting at 0 and incrementing
554 // for each separable additional touch that the hardware can detect. 620 // for each separable additional touch that the hardware can detect.
555 const int touch_id_; 621 const int touch_id_;
556 622
557 // A unique identifier for the touch event. 623 // A unique identifier for the touch event.
558 const uint32 unique_event_id_; 624 const uint32 unique_event_id_;
559 625
560 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
561 float radius_x_;
562
563 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
564 float radius_y_;
565
566 // Clockwise angle (in degrees) of the major axis from the X axis. Must be 626 // Clockwise angle (in degrees) of the major axis from the X axis. Must be
567 // less than 180 and non-negative. 627 // less than 180 and non-negative.
568 float rotation_angle_; 628 float rotation_angle_;
569 629
570 // Force (pressure) of the touch. Normalized to be [0, 1]. Default to be 0.0.
571 float force_;
572
573 // Whether the (unhandled) touch event will produce a scroll event (e.g., a 630 // Whether the (unhandled) touch event will produce a scroll event (e.g., a
574 // touchmove that exceeds the platform slop region, or a touchend that 631 // touchmove that exceeds the platform slop region, or a touchend that
575 // causes a fling). Defaults to false. 632 // causes a fling). Defaults to false.
576 bool may_cause_scrolling_; 633 bool may_cause_scrolling_;
577 634
578 // True if this event should remove the mapping between the native 635 // True if this event should remove the mapping between the native
579 // event id and the touch_id_. This should only be the case for 636 // event id and the touch_id_. This should only be the case for
580 // release and cancel events where the associated touch press event 637 // release and cancel events where the associated touch press event
581 // created a mapping between the native id and the touch_id_. 638 // created a mapping between the native id and the touch_id_.
582 bool should_remove_native_touch_id_mapping_; 639 bool should_remove_native_touch_id_mapping_;
640
641 // Structure for holding pointer details for implementing PointerEvents API.
642 PointerEventDetails pointer_details_;
583 }; 643 };
584 644
585 // An interface that individual platforms can use to store additional data on 645 // An interface that individual platforms can use to store additional data on
586 // KeyEvent. 646 // KeyEvent.
587 // 647 //
588 // Currently only used in mojo. 648 // Currently only used in mojo.
589 class EVENTS_EXPORT ExtendedKeyEventData { 649 class EVENTS_EXPORT ExtendedKeyEventData {
590 public: 650 public:
591 virtual ~ExtendedKeyEventData() {} 651 virtual ~ExtendedKeyEventData() {}
592 652
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 931
872 const GestureEventDetails& details() const { return details_; } 932 const GestureEventDetails& details() const { return details_; }
873 933
874 private: 934 private:
875 GestureEventDetails details_; 935 GestureEventDetails details_;
876 }; 936 };
877 937
878 } // namespace ui 938 } // namespace ui
879 939
880 #endif // UI_EVENTS_EVENT_H_ 940 #endif // UI_EVENTS_EVENT_H_
OLDNEW
« no previous file with comments | « ui/chromeos/touch_exploration_controller_unittest.cc ('k') | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698