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

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

Issue 2256343003: Update ui::PointerEvent to support mouse wheel and capture change events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 bool IsTouchEvent() const { 124 bool IsTouchEvent() const {
125 return type_ == ET_TOUCH_RELEASED || 125 return type_ == ET_TOUCH_RELEASED ||
126 type_ == ET_TOUCH_PRESSED || 126 type_ == ET_TOUCH_PRESSED ||
127 type_ == ET_TOUCH_MOVED || 127 type_ == ET_TOUCH_MOVED ||
128 type_ == ET_TOUCH_CANCELLED; 128 type_ == ET_TOUCH_CANCELLED;
129 } 129 }
130 130
131 bool IsPointerEvent() const { 131 bool IsPointerEvent() const {
132 return type_ == ET_POINTER_DOWN || type_ == ET_POINTER_MOVED || 132 return type_ == ET_POINTER_DOWN || type_ == ET_POINTER_MOVED ||
133 type_ == ET_POINTER_UP || type_ == ET_POINTER_CANCELLED || 133 type_ == ET_POINTER_UP || type_ == ET_POINTER_CANCELLED ||
134 type_ == ET_POINTER_ENTERED || type_ == ET_POINTER_EXITED; 134 type_ == ET_POINTER_ENTERED || type_ == ET_POINTER_EXITED ||
135 type_ == ET_POINTER_WHEEL_CHANGED ||
136 type_ == ET_POINTER_CAPTURE_CHANGED;
135 } 137 }
136 138
137 // Convenience methods to check pointer type of |this|. Returns false if 139 // Convenience methods to check pointer type of |this|. Returns false if
138 // |this| is not a PointerEvent. 140 // |this| is not a PointerEvent.
139 bool IsMousePointerEvent() const; 141 bool IsMousePointerEvent() const;
140 bool IsTouchPointerEvent() const; 142 bool IsTouchPointerEvent() const;
141 143
142 bool IsGestureEvent() const { 144 bool IsGestureEvent() const {
143 switch (type_) { 145 switch (type_) {
144 case ET_GESTURE_SCROLL_BEGIN: 146 case ET_GESTURE_SCROLL_BEGIN:
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 float tilt_x, 407 float tilt_x,
406 float tilt_y) 408 float tilt_y)
407 : pointer_type(pointer_type), 409 : pointer_type(pointer_type),
408 // If we aren't provided with a radius on one axis, use the 410 // If we aren't provided with a radius on one axis, use the
409 // information from the other axis. 411 // information from the other axis.
410 radius_x(radius_x > 0 ? radius_x : radius_y), 412 radius_x(radius_x > 0 ? radius_x : radius_y),
411 radius_y(radius_y > 0 ? radius_y : radius_x), 413 radius_y(radius_y > 0 ? radius_y : radius_x),
412 force(force), 414 force(force),
413 tilt_x(tilt_x), 415 tilt_x(tilt_x),
414 tilt_y(tilt_y) {} 416 tilt_y(tilt_y) {}
417 PointerDetails(EventPointerType pointer_type, int offset_x, int offset_y)
418 : pointer_type(pointer_type),
419 force(std::numeric_limits<float>::quiet_NaN()),
420 offset_x(offset_x),
421 offset_y(offset_y) {}
415 422
416 bool operator==(const PointerDetails& other) const { 423 bool operator==(const PointerDetails& other) const {
417 return pointer_type == other.pointer_type && 424 return pointer_type == other.pointer_type && radius_x == other.radius_x &&
418 radius_x == other.radius_x &&
419 radius_y == other.radius_y && 425 radius_y == other.radius_y &&
420 (force == other.force || 426 (force == other.force ||
421 (std::isnan(force) && std::isnan(other.force))) && 427 (std::isnan(force) && std::isnan(other.force))) &&
422 tilt_x == other.tilt_x && 428 tilt_x == other.tilt_x && tilt_y == other.tilt_y &&
423 tilt_y == other.tilt_y; 429 offset_x == other.offset_x && offset_y == other.offset_y;
424 } 430 }
425 431
426 // The type of pointer device. 432 // The type of pointer device.
427 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN; 433 EventPointerType pointer_type = EventPointerType::POINTER_TYPE_UNKNOWN;
428 434
429 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown. 435 // Radius of the X (major) axis of the touch ellipse. 0.0 if unknown.
430 float radius_x = 0.0; 436 float radius_x = 0.0;
431 437
432 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown. 438 // Radius of the Y (minor) axis of the touch ellipse. 0.0 if unknown.
433 float radius_y = 0.0; 439 float radius_y = 0.0;
434 440
435 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means 441 // Force (pressure) of the touch. Normalized to be [0, 1] except NaN means
436 // pressure is not supported by the input device. 442 // pressure is not supported by the input device.
437 float force = 0.0; 443 float force = 0.0;
438 444
439 // Tilt of a pen/stylus from surface normal as plane angle in degrees, values 445 // Tilt of a pen/stylus from surface normal as plane angle in degrees, values
440 // lie in [-90,90]. A positive tilt_x is to the right and a positive tilt_y 446 // lie in [-90,90]. A positive tilt_x is to the right and a positive tilt_y
441 // is towards the user. 0.0 if unknown. 447 // is towards the user. 0.0 if unknown.
442 float tilt_x = 0.0; 448 float tilt_x = 0.0;
443 float tilt_y = 0.0; 449 float tilt_y = 0.0;
450
451 // Only used by mouse wheel events. The amount to scroll. This is in multiples
452 // of kWheelDelta.
453 // Note: x_offset() > 0/y_offset() > 0 means scroll left/up.
454 int offset_x = 0;
455 int offset_y = 0;
sadrul 2016/08/19 04:18:27 Maybe use a gfx::Vector2dF instead?
riajiang 2016/08/19 16:19:39 Done.
444 }; 456 };
445 457
446 class EVENTS_EXPORT MouseEvent : public LocatedEvent { 458 class EVENTS_EXPORT MouseEvent : public LocatedEvent {
447 public: 459 public:
448 explicit MouseEvent(const base::NativeEvent& native_event); 460 explicit MouseEvent(const base::NativeEvent& native_event);
449 461
450 // |pointer_event.IsMousePointerEvent()| must be true. 462 // |pointer_event.IsMousePointerEvent()| must be true.
451 explicit MouseEvent(const PointerEvent& pointer_event); 463 explicit MouseEvent(const PointerEvent& pointer_event);
452 464
453 // Create a new MouseEvent based on the provided model. 465 // Create a new MouseEvent based on the provided model.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 bool should_remove_native_touch_id_mapping_; 718 bool should_remove_native_touch_id_mapping_;
707 719
708 // Structure for holding pointer details for implementing PointerEvents API. 720 // Structure for holding pointer details for implementing PointerEvents API.
709 PointerDetails pointer_details_; 721 PointerDetails pointer_details_;
710 }; 722 };
711 723
712 class EVENTS_EXPORT PointerEvent : public LocatedEvent { 724 class EVENTS_EXPORT PointerEvent : public LocatedEvent {
713 public: 725 public:
714 static const int32_t kMousePointerId; 726 static const int32_t kMousePointerId;
715 727
716 // Returns true if a PointerEvent can be constructed from the given mouse or 728 // Returns true if |event| is a MouseEvent or TouchEvent.
sadrul 2016/08/19 04:18:27 Something more like: Returns true if a PointerEven
riajiang 2016/08/19 16:19:39 Done.
717 // touch event. For example, PointerEvent does not support ET_MOUSEWHEEL or
718 // ET_MOUSE_CAPTURE_CHANGED.
719 static bool CanConvertFrom(const Event& event); 729 static bool CanConvertFrom(const Event& event);
720 730
721 PointerEvent(const PointerEvent& pointer_event); 731 PointerEvent(const PointerEvent& pointer_event);
722 explicit PointerEvent(const MouseEvent& mouse_event); 732 explicit PointerEvent(const MouseEvent& mouse_event);
723 explicit PointerEvent(const TouchEvent& touch_event); 733 explicit PointerEvent(const TouchEvent& touch_event);
724 734
725 PointerEvent(EventType type, 735 PointerEvent(EventType type,
726 const gfx::Point& location, 736 const gfx::Point& location,
727 const gfx::Point& root_location, 737 const gfx::Point& root_location,
728 int flags, 738 int flags,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 // dispatched. This field gets a non-zero value only for gestures that are 1012 // dispatched. This field gets a non-zero value only for gestures that are
1003 // released through TouchDispositionGestureFilter::SendGesture. The gesture 1013 // released through TouchDispositionGestureFilter::SendGesture. The gesture
1004 // events that aren't fired directly in response to processing a touch-event 1014 // events that aren't fired directly in response to processing a touch-event
1005 // (e.g. timer fired ones), this id is zero. See crbug.com/618738. 1015 // (e.g. timer fired ones), this id is zero. See crbug.com/618738.
1006 uint32_t unique_touch_event_id_; 1016 uint32_t unique_touch_event_id_;
1007 }; 1017 };
1008 1018
1009 } // namespace ui 1019 } // namespace ui
1010 1020
1011 #endif // UI_EVENTS_EVENT_H_ 1021 #endif // UI_EVENTS_EVENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698