diff options
author | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-27 21:35:02 +0000 |
---|---|---|
committer | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-27 21:35:02 +0000 |
commit | 79c5a2704f7bf8609444599bdab647805ceac45b (patch) | |
tree | ddff52e9af92f731363474688533681491b4d537 /ui/events | |
parent | 48804709dfdcc7cba1d27154be62c8fe69a37c4d (diff) | |
download | chromium_src-79c5a2704f7bf8609444599bdab647805ceac45b.zip chromium_src-79c5a2704f7bf8609444599bdab647805ceac45b.tar.gz chromium_src-79c5a2704f7bf8609444599bdab647805ceac45b.tar.bz2 |
Unify GestureEventData and GestureEventDetails
BUG=348577
Review URL: https://codereview.chromium.org/189233006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@259997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/events')
-rw-r--r-- | ui/events/event.h | 1 | ||||
-rw-r--r-- | ui/events/events.gyp | 7 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_event_data.cc | 19 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_event_data.h | 64 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_event_details.cc (renamed from ui/events/gestures/gesture_types.cc) | 6 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_event_details.h | 201 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_provider.cc | 93 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_provider_unittest.cc | 45 | ||||
-rw-r--r-- | ui/events/gesture_detection/touch_disposition_gesture_filter.cc | 3 | ||||
-rw-r--r-- | ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc | 3 | ||||
-rw-r--r-- | ui/events/gesture_event_details.cc | 118 | ||||
-rw-r--r-- | ui/events/gesture_event_details.h | 212 | ||||
-rw-r--r-- | ui/events/gestures/gesture_recognizer.h | 1 | ||||
-rw-r--r-- | ui/events/gestures/gesture_sequence.h | 1 | ||||
-rw-r--r-- | ui/events/gestures/gesture_types.h | 186 |
15 files changed, 636 insertions, 324 deletions
diff --git a/ui/events/event.h b/ui/events/event.h index c7182fb..51d73f8 100644 --- a/ui/events/event.h +++ b/ui/events/event.h @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/time/time.h" #include "ui/events/event_constants.h" +#include "ui/events/gesture_event_details.h" #include "ui/events/gestures/gesture_types.h" #include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/latency_info.h" diff --git a/ui/events/events.gyp b/ui/events/events.gyp index bddde8d..51eb945 100644 --- a/ui/events/events.gyp +++ b/ui/events/events.gyp @@ -25,16 +25,20 @@ 'dependencies': [ '<(DEPTH)/base/base.gyp:base', '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../gfx/gfx.gyp:gfx', + '../gfx/gfx.gyp:gfx_geometry', 'dom4_keycode_converter', ], 'defines': [ 'EVENTS_BASE_IMPLEMENTATION', ], 'sources': [ - 'events_base_export.h', 'event_constants.h', 'event_switches.cc', 'event_switches.h', + 'events_base_export.h', + 'gesture_event_details.cc', + 'gesture_event_details.h', 'keycodes/keyboard_code_conversion.cc', 'keycodes/keyboard_code_conversion.h', 'keycodes/keyboard_code_conversion_android.cc', @@ -110,7 +114,6 @@ 'gestures/gesture_recognizer_impl.h', 'gestures/gesture_sequence.cc', 'gestures/gesture_sequence.h', - 'gestures/gesture_types.cc', 'gestures/gesture_types.h', 'gestures/velocity_calculator.cc', 'gestures/velocity_calculator.h', diff --git a/ui/events/gesture_detection/gesture_event_data.cc b/ui/events/gesture_detection/gesture_event_data.cc index af54592..345b630 100644 --- a/ui/events/gesture_detection/gesture_event_data.cc +++ b/ui/events/gesture_detection/gesture_event_data.cc @@ -8,18 +8,27 @@ namespace ui { -GestureEventData::GestureEventData() - : type(ET_UNKNOWN), x(0), y(0) {} - GestureEventData::GestureEventData(EventType type, base::TimeTicks time, float x, float y, - const Details& details) + const GestureEventDetails& details) : type(type), time(time), x(x), y(y), details(details) { DCHECK(ET_GESTURE_TYPE_START <= type && type <= ET_GESTURE_TYPE_END); } -GestureEventData::Details::Details() { memset(this, 0, sizeof(Details)); } +GestureEventData::GestureEventData(EventType type, + base::TimeTicks time, + float x, + float y) + : type(type), + time(time), + x(x), + y(y), + details(GestureEventDetails(type, 0, 0)) { + DCHECK(ET_GESTURE_TYPE_START <= type && type <= ET_GESTURE_TYPE_END); +} + +GestureEventData::GestureEventData() : type(ET_UNKNOWN), x(0), y(0) {} } // namespace ui diff --git a/ui/events/gesture_detection/gesture_event_data.h b/ui/events/gesture_detection/gesture_event_data.h index 008ef3c..280103a 100644 --- a/ui/events/gesture_detection/gesture_event_data.h +++ b/ui/events/gesture_detection/gesture_event_data.h @@ -8,78 +8,30 @@ #include "base/time/time.h" #include "ui/events/event_constants.h" #include "ui/events/gesture_detection/gesture_detection_export.h" +#include "ui/events/gesture_event_details.h" namespace ui { class GestureEventDataPacket; -// Simple transport construct for gesture-related event data. -// TODO(jdduke): Merge this class with ui::GestureEventDetails. struct GESTURE_DETECTION_EXPORT GestureEventData { - struct Details; GestureEventData(EventType type, base::TimeTicks time, float x, float y, - const Details& details); + const GestureEventDetails& details); + + GestureEventData(EventType type, + base::TimeTicks time, + float x, + float y); EventType type; base::TimeTicks time; float x; float y; - // TODO(jdduke): Determine if we can simply re-use blink::WebGestureEvent, as - // this is more or less straight up duplication. - struct GESTURE_DETECTION_EXPORT Details { - Details(); - union { - // Tap information must be set for ET_GESTURE_TAP, - // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events. - struct { - int tap_count; - float width; - float height; - } tap; - - struct { - float width; - float height; - } tap_down; - - struct { - float width; - float height; - } show_press; - - struct { - float width; - float height; - } long_press; - - struct { - // Initial motion that triggered the scroll. - // May be redundant with delta_x/delta_y in the first scroll_update. - float delta_x_hint; - float delta_y_hint; - } scroll_begin; - - struct { - float delta_x; - float delta_y; - float velocity_x; - float velocity_y; - } scroll_update; - - struct { - float velocity_x; - float velocity_y; - } fling_start; - - struct { - float scale; - } pinch_update; - }; - } details; + GestureEventDetails details; private: friend class GestureEventDataPacket; diff --git a/ui/events/gestures/gesture_types.cc b/ui/events/gesture_detection/gesture_event_details.cc index a086c66..1de178d 100644 --- a/ui/events/gestures/gesture_types.cc +++ b/ui/events/gesture_detection/gesture_event_details.cc @@ -1,11 +1,13 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/events/gestures/gesture_types.h" +#include "ui/events/gesture_detection/gesture_event_details.h" namespace ui { +GestureEventDetails::GestureEventDetails() : type_(ET_UNKNOWN) {} + GestureEventDetails::GestureEventDetails(ui::EventType type, float delta_x, float delta_y) diff --git a/ui/events/gesture_detection/gesture_event_details.h b/ui/events/gesture_detection/gesture_event_details.h new file mode 100644 index 0000000..8c924e7 --- /dev/null +++ b/ui/events/gesture_detection/gesture_event_details.h @@ -0,0 +1,201 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ +#define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ + +#include "base/logging.h" +#include "ui/events/event_constants.h" +#include "ui/events/events_base_export.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/rect_conversions.h" + +namespace ui { + +struct EVENTS_BASE_EXPORT GestureEventDetails { + public: + GestureEventDetails(); + GestureEventDetails(EventType type, float delta_x, float delta_y); + GestureEventDetails(EventType type, + float delta_x, float delta_y, + float delta_x_ordinal, float delta_y_ordinal); + + EventType type() const { return type_; } + + int touch_points() const { return touch_points_; } + void set_touch_points(int touch_points) { touch_points_ = touch_points; } + + // TODO(tdresser): Return RectF. See crbug.com/337824. + const gfx::Rect bounding_box() const { + return ToEnclosingRect(bounding_box_); + } + void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; } + + void SetScrollVelocity(float velocity_x, float velocity_y, + float velocity_x_ordinal, float velocity_y_ordinal); + + float scroll_x_hint() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); + return data.scroll_begin.x_hint; + } + + float scroll_y_hint() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); + return data.scroll_begin.y_hint; + } + + float scroll_x() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.x; + } + + float scroll_y() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.y; + } + + float velocity_x() const { + CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x : + data.scroll_update.velocity_x; + } + + float velocity_y() const { + CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y : + data.scroll_update.velocity_y; + } + + // *_ordinal values are unmodified by rail based clamping. + float scroll_x_ordinal() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.x_ordinal; + } + + float scroll_y_ordinal() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.y_ordinal; + } + + float velocity_x_ordinal() const { + CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? + data.fling_velocity.x_ordinal : + data.scroll_update.velocity_x_ordinal; + } + + float velocity_y_ordinal() const { + CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? + data.fling_velocity.y_ordinal : + data.scroll_update.velocity_y_ordinal; + } + + int touch_id() const { + CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); + return data.touch_id; + } + + float first_finger_width() const { + CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); + return data.first_finger_enclosing_rectangle.width; + } + + float first_finger_height() const { + CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); + return data.first_finger_enclosing_rectangle.height; + } + + float scale() const { + CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); + return data.scale; + } + + bool swipe_left() const { + CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.left; + } + + bool swipe_right() const { + CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.right; + } + + bool swipe_up() const { + CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.up; + } + + bool swipe_down() const { + CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.down; + } + + int tap_count() const { + CHECK_EQ(ui::ET_GESTURE_TAP, type_); + return data.tap_count; + } + + private: + ui::EventType type_; + union { + struct { // SCROLL start details. + // Distance that caused the scroll to start. Generally redundant with + // the x/y values from the first scroll_update. + float x_hint; + float y_hint; + } scroll_begin; + + struct { // SCROLL delta. + float x; + float y; + float velocity_x; + float velocity_y; + float x_ordinal; + float y_ordinal; + float velocity_x_ordinal; + float velocity_y_ordinal; + } scroll_update; + + float scale; // PINCH scale. + + struct { // FLING velocity. + float x; + float y; + float x_ordinal; + float y_ordinal; + } fling_velocity; + + int touch_id; // LONG_PRESS touch-id. + + // Dimensions of the first finger's enclosing rectangle for TWO_FINGER_TAP. + struct { + float width; + float height; + } first_finger_enclosing_rectangle; + + struct { // SWIPE direction. + bool left; + bool right; + bool up; + bool down; + } swipe; + + int tap_count; // TAP repeat count. + } data; + + int touch_points_; // Number of active touch points in the gesture. + + // Bounding box is an axis-aligned rectangle that contains all the + // enclosing rectangles of the touch-points in the gesture. + gfx::RectF bounding_box_; +}; + +} // namespace ui + +#endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ diff --git a/ui/events/gesture_detection/gesture_provider.cc b/ui/events/gesture_detection/gesture_provider.cc index 35cd67b..4deeba2 100644 --- a/ui/events/gesture_detection/gesture_provider.cc +++ b/ui/events/gesture_detection/gesture_provider.cc @@ -34,7 +34,7 @@ GestureEventData CreateGesture(EventType type, base::TimeTicks time, float x, float y, - const GestureEventData::Details& details) { + const GestureEventDetails& details) { return GestureEventData(type, time, x, y, details); } @@ -42,32 +42,33 @@ GestureEventData CreateGesture(EventType type, base::TimeTicks time, float x, float y) { - return CreateGesture(type, time, x, y, GestureEventData::Details()); -} + return GestureEventData(type, time, x, y); + } GestureEventData CreateGesture(EventType type, const MotionEvent& event, - const GestureEventData::Details& details) { + const GestureEventDetails& details) { return CreateGesture( type, event.GetEventTime(), event.GetX(), event.GetY(), details); } GestureEventData CreateGesture(EventType type, const MotionEvent& event) { - return CreateGesture(type, event, GestureEventData::Details()); + return CreateGesture(type, event.GetEventTime(), event.GetX(), event.GetY()); } float Round(float f) { return (f > 0.f) ? std::floor(f + 0.5f) : std::ceil(f - 0.5f); } -GestureEventData::Details CreateTapGestureDetails(const MotionEvent& event) { - GestureEventData::Details tap_details; +GestureEventDetails CreateTapGestureDetails(EventType type, + const MotionEvent& event) { // Set the tap count to 1 even for ET_GESTURE_DOUBLE_TAP, in order to be // consistent with double tap behavior on a mobile viewport. See // crbug.com/234986 for context. - tap_details.tap.tap_count = 1; - tap_details.tap.width = tap_details.tap.height = event.GetTouchMajor(); + GestureEventDetails tap_details(type, 1, 0); + tap_details.set_bounding_box( + gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); return tap_details; } @@ -129,8 +130,8 @@ class GestureProvider::ScaleGestureListenerImpl detector.GetFocusX(), detector.GetFocusY())); } - GestureEventData::Details pinch_details; - pinch_details.pinch_update.scale = detector.GetScaleFactor(); + GestureEventDetails pinch_details( + ET_GESTURE_PINCH_UPDATE, detector.GetScaleFactor(), 0); provider_->Send(CreateGesture(ET_GESTURE_PINCH_UPDATE, detector.GetEventTime(), detector.GetFocusX(), @@ -229,8 +230,9 @@ class GestureProvider::GestureListenerImpl accumulated_scroll_error_x_ = 0; accumulated_scroll_error_y_ = 0; - GestureEventData::Details tap_details; - tap_details.tap.width = tap_details.tap.height = e.GetTouchMajor(); + GestureEventDetails tap_details(ET_GESTURE_TAP_DOWN, 0, 0); + tap_details.set_bounding_box( + gfx::RectF(e.GetTouchMajor(), e.GetTouchMajor())); provider_->Send(CreateGesture(ET_GESTURE_TAP_DOWN, e, tap_details)); // Return true to indicate that we want to handle touch. @@ -270,9 +272,8 @@ class GestureProvider::GestureListenerImpl if (!provider_->IsScrollInProgress()) { // Note that scroll start hints are in distance traveled, where // scroll deltas are in the opposite direction. - GestureEventData::Details scroll_details; - scroll_details.scroll_begin.delta_x_hint = -raw_distance_x; - scroll_details.scroll_begin.delta_y_hint = -raw_distance_y; + GestureEventDetails scroll_details( + ET_GESTURE_SCROLL_BEGIN, -raw_distance_x, -raw_distance_y); provider_->Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, e2.GetEventTime(), e1.GetX(), @@ -293,9 +294,7 @@ class GestureProvider::GestureListenerImpl accumulated_scroll_error_y_ += (distance_y - dy); if (dx || dy) { - GestureEventData::Details scroll_details; - scroll_details.scroll_update.delta_x = -dx; - scroll_details.scroll_update.delta_y = -dy; + GestureEventDetails scroll_details(ET_GESTURE_SCROLL_UPDATE, -dx, -dy); provider_->Send( CreateGesture(ET_GESTURE_SCROLL_UPDATE, e2, scroll_details)); } @@ -321,10 +320,10 @@ class GestureProvider::GestureListenerImpl } virtual void OnShowPress(const MotionEvent& e) OVERRIDE { - GestureEventData::Details show_press_details; + GestureEventDetails show_press_details(ET_GESTURE_SHOW_PRESS, 0, 0); // TODO(jdduke): Expose minor axis length and rotation in |MotionEvent|. - show_press_details.show_press.width = e.GetTouchMajor(); - show_press_details.show_press.height = show_press_details.show_press.width; + show_press_details.set_bounding_box( + gfx::RectF(e.GetTouchMajor(), e.GetTouchMajor())); provider_->Send( CreateGesture(ET_GESTURE_SHOW_PRESS, e, show_press_details)); } @@ -352,7 +351,9 @@ class GestureProvider::GestureListenerImpl // Notify Blink about this tapUp event anyway, when none of the above // conditions applied. provider_->Send(CreateGesture( - ET_GESTURE_TAP_UNCONFIRMED, e, CreateTapGestureDetails(e))); + ET_GESTURE_TAP_UNCONFIRMED, + e, + CreateTapGestureDetails(ET_GESTURE_TAP_UNCONFIRMED, e))); } } @@ -370,8 +371,8 @@ class GestureProvider::GestureListenerImpl ignore_single_tap_ = true; - provider_->Send( - CreateGesture(ET_GESTURE_TAP, e, CreateTapGestureDetails(e))); + provider_->Send(CreateGesture( + ET_GESTURE_TAP, e, CreateTapGestureDetails(ET_GESTURE_TAP, e))); return true; } @@ -400,9 +401,8 @@ class GestureProvider::GestureListenerImpl // Begin double-tap drag zoom mode if the move distance is // further than the threshold. if (IsDistanceGreaterThanTouchSlop(distance_x, distance_y)) { - GestureEventData::Details scroll_details; - scroll_details.scroll_begin.delta_x_hint = -distance_x; - scroll_details.scroll_begin.delta_y_hint = -distance_y; + GestureEventDetails scroll_details( + ET_GESTURE_SCROLL_BEGIN, -distance_x, -distance_y); provider_->Send( CreateGesture(ET_GESTURE_SCROLL_BEGIN, e, scroll_details)); provider_->Send( @@ -416,11 +416,10 @@ class GestureProvider::GestureListenerImpl provider_->Send(CreateGesture(ET_GESTURE_SCROLL_UPDATE, e)); float dy = double_tap_y_ - e.GetY(); - GestureEventData::Details pinch_details; - pinch_details.pinch_update.scale = - std::pow(dy > 0 ? 1.0f - kDoubleTapDragZoomSpeed - : 1.0f + kDoubleTapDragZoomSpeed, - std::abs(dy * px_to_dp_)); + float scale = std::pow(dy > 0 ? 1.0f - kDoubleTapDragZoomSpeed + : 1.0f + kDoubleTapDragZoomSpeed, + std::abs(dy * px_to_dp_)); + GestureEventDetails pinch_details(ET_GESTURE_PINCH_UPDATE, scale, 0); provider_->Send(CreateGesture(ET_GESTURE_PINCH_UPDATE, e.GetEventTime(), Round(double_tap_drag_zoom_anchor_x_), @@ -431,8 +430,10 @@ class GestureProvider::GestureListenerImpl case MotionEvent::ACTION_UP: if (double_tap_mode_ != DOUBLE_TAP_MODE_DRAG_ZOOM) { // Normal double-tap gesture. - provider_->Send(CreateGesture( - ET_GESTURE_DOUBLE_TAP, e, CreateTapGestureDetails(e))); + provider_->Send( + CreateGesture(ET_GESTURE_DOUBLE_TAP, + e, + CreateTapGestureDetails(ET_GESTURE_DOUBLE_TAP, e))); } EndDoubleTapDragIfNecessary(e); break; @@ -451,9 +452,9 @@ class GestureProvider::GestureListenerImpl DCHECK(!IsDoubleTapInProgress()); SetIgnoreSingleTap(true); - GestureEventData::Details long_press_details; - long_press_details.long_press.width = e.GetTouchMajor(); - long_press_details.long_press.height = long_press_details.long_press.width; + GestureEventDetails long_press_details(ET_GESTURE_LONG_PRESS, 0, 0); + long_press_details.set_bounding_box( + gfx::RectF(e.GetTouchMajor(), e.GetTouchMajor())); provider_->Send( CreateGesture(ET_GESTURE_LONG_PRESS, e, long_press_details)); @@ -716,16 +717,14 @@ void GestureProvider::Fling(base::TimeTicks time, // ET_SCROLL_FLING_START to send the fling to the correct target. Send if it // has not sent. The distance traveled in one second is a reasonable scroll // start hint. - GestureEventData::Details scroll_details; - scroll_details.scroll_begin.delta_x_hint = velocity_x; - scroll_details.scroll_begin.delta_y_hint = velocity_y; + GestureEventDetails scroll_details( + ET_GESTURE_SCROLL_BEGIN, velocity_x, velocity_y); Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN, time, x, y, scroll_details)); } EndTouchScrollIfNecessary(time, false); - GestureEventData::Details fling_details; - fling_details.fling_start.velocity_x = velocity_x; - fling_details.fling_start.velocity_y = velocity_y; + GestureEventDetails fling_details( + ET_SCROLL_FLING_START, velocity_x, velocity_y); Send(CreateGesture(ET_SCROLL_FLING_START, time, x, y, fling_details)); } @@ -801,9 +800,9 @@ bool GestureProvider::SendLongTapIfNecessary(const MotionEvent& event) { !current_longpress_time_.is_null() && !scale_gesture_listener_->IsScaleGestureDetectionInProgress()) { SendTapCancelIfNecessary(event); - GestureEventData::Details long_tap_details; - long_tap_details.long_press.width = event.GetTouchMajor(); - long_tap_details.long_press.height = long_tap_details.long_press.width; + GestureEventDetails long_tap_details(ET_GESTURE_LONG_TAP, 0, 0); + long_tap_details.set_bounding_box( + gfx::RectF(event.GetTouchMajor(), event.GetTouchMajor())); Send(CreateGesture(ET_GESTURE_LONG_TAP, event, long_tap_details)); return true; } diff --git a/ui/events/gesture_detection/gesture_provider_unittest.cc b/ui/events/gesture_detection/gesture_provider_unittest.cc index 569abe5..1be9ec7 100644 --- a/ui/events/gesture_detection/gesture_provider_unittest.cc +++ b/ui/events/gesture_detection/gesture_provider_unittest.cc @@ -208,10 +208,9 @@ TEST_F(GestureProviderTest, GestureTapTap) { EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); // Ensure tap details have been set. - EXPECT_EQ(10, GetMostRecentGestureEvent().details.tap.width); - EXPECT_EQ(10, GetMostRecentGestureEvent().details.tap.height); - EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap.tap_count); - + EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); + EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); + EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); } // Verify that a DOWN followed shortly by an UP will trigger @@ -231,9 +230,9 @@ TEST_F(GestureProviderTest, GestureTapTapWithDelay) { EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); // Ensure tap details have been set. - EXPECT_EQ(10, GetMostRecentGestureEvent().details.tap.width); - EXPECT_EQ(10, GetMostRecentGestureEvent().details.tap.height); - EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap.tap_count); + EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); + EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); + EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); } @@ -306,8 +305,8 @@ TEST_F(GestureProviderTest, FlingEventSequence) { // We don't want to take a dependency here on exactly how hints are calculated // for a fling (eg. may depend on velocity), so just validate the direction. - int hint_x = GetReceivedGesture(2).details.scroll_begin.delta_x_hint; - int hint_y = GetReceivedGesture(2).details.scroll_begin.delta_y_hint; + int hint_x = GetReceivedGesture(2).details.scroll_x_hint(); + int hint_y = GetReceivedGesture(2).details.scroll_y_hint(); EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) << "ScrollBegin hint should be in positive X axis"; @@ -401,9 +400,9 @@ TEST_F(GestureProviderTest, DoubleTap) { const GestureEventData& double_tap = GetMostRecentGestureEvent(); EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); // Ensure tap details have been set. - EXPECT_EQ(10, double_tap.details.tap.width); - EXPECT_EQ(10, double_tap.details.tap.height); - EXPECT_EQ(1, double_tap.details.tap.tap_count); + EXPECT_EQ(10, double_tap.details.bounding_box().width()); + EXPECT_EQ(10, double_tap.details.bounding_box().height()); + EXPECT_EQ(1, double_tap.details.tap_count()); } TEST_F(GestureProviderTest, DoubleTapDragZoom) { @@ -434,8 +433,8 @@ TEST_F(GestureProviderTest, DoubleTapDragZoom) { EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); ASSERT_TRUE(!!scroll_begin_gesture); - EXPECT_EQ(0, scroll_begin_gesture->details.scroll_begin.delta_x_hint); - EXPECT_EQ(100, scroll_begin_gesture->details.scroll_begin.delta_y_hint); + EXPECT_EQ(0, scroll_begin_gesture->details.scroll_x_hint()); + EXPECT_EQ(100, scroll_begin_gesture->details.scroll_y_hint()); EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, @@ -538,8 +537,8 @@ TEST_F(GestureProviderTest, ScrollUpdateValues) { EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); // No horizontal delta because of snapping. - EXPECT_EQ(0, gesture.details.scroll_update.delta_x); - EXPECT_EQ(-delta_y / 2, gesture.details.scroll_update.delta_y); + EXPECT_EQ(0, gesture.details.scroll_x()); + EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); } // Verify that fractional scroll deltas are rounded as expected and that @@ -585,11 +584,11 @@ TEST_F(GestureProviderTest, FractionalScroll) { // Verify that we're scrolling vertically by the expected amount // (modulo rounding). - EXPECT_GE(gesture.details.scroll_update.delta_y, (int)delta_y); - EXPECT_LE(gesture.details.scroll_update.delta_y, ((int)delta_y) + 1); + EXPECT_GE(gesture.details.scroll_y(), (int)delta_y); + EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1); // And that there has been no horizontal motion at all. - EXPECT_EQ(0, gesture.details.scroll_update.delta_x); + EXPECT_EQ(0, gesture.details.scroll_x()); } } @@ -623,8 +622,8 @@ TEST_F(GestureProviderTest, ScrollBeginValues) { const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); ASSERT_TRUE(!!scroll_begin_gesture); - EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_begin.delta_x_hint); - EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_begin.delta_y_hint); + EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); + EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); } TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { @@ -764,8 +763,8 @@ TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); GestureEventData gesture = GetMostRecentGestureEvent(); - EXPECT_EQ(0, gesture.details.scroll_update.delta_x); - EXPECT_EQ(scroll_delta, gesture.details.scroll_update.delta_y); + EXPECT_EQ(0, gesture.details.scroll_x()); + EXPECT_EQ(scroll_delta, gesture.details.scroll_y()); } TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { diff --git a/ui/events/gesture_detection/touch_disposition_gesture_filter.cc b/ui/events/gesture_detection/touch_disposition_gesture_filter.cc index 414c46b..a64c1b6 100644 --- a/ui/events/gesture_detection/touch_disposition_gesture_filter.cc +++ b/ui/events/gesture_detection/touch_disposition_gesture_filter.cc @@ -6,6 +6,7 @@ #include "base/auto_reset.h" #include "base/logging.h" +#include "ui/events/gesture_event_details.h" namespace ui { namespace { @@ -16,7 +17,7 @@ COMPILE_ASSERT(ET_GESTURE_TYPE_END - ET_GESTURE_TYPE_START < 32, GestureEventData CreateGesture(EventType type) { return GestureEventData( - type, base::TimeTicks(), 0, 0, GestureEventData::Details()); + type, base::TimeTicks(), 0, 0, GestureEventDetails(type, 0, 0)); } enum RequiredTouches { diff --git a/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc b/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc index 687a0b7..79f1096 100644 --- a/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc +++ b/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc @@ -168,8 +168,7 @@ class TouchDispositionGestureFilterTest } static GestureEventData CreateGesture(EventType type) { - return GestureEventData( - type, base::TimeTicks(), 0, 0, GestureEventData::Details()); + return GestureEventData(type, base::TimeTicks(), 0, 0); } private: diff --git a/ui/events/gesture_event_details.cc b/ui/events/gesture_event_details.cc new file mode 100644 index 0000000..983d2a1 --- /dev/null +++ b/ui/events/gesture_event_details.cc @@ -0,0 +1,118 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/events/gesture_event_details.h" + +namespace ui { + +GestureEventDetails::GestureEventDetails() : type_(ET_UNKNOWN) {} + +GestureEventDetails::GestureEventDetails(ui::EventType type, + float delta_x, + float delta_y) + : type_(type), + touch_points_(1) { + switch (type_) { + case ui::ET_GESTURE_SCROLL_BEGIN: + data.scroll_begin.x_hint = delta_x; + data.scroll_begin.y_hint = delta_y; + break; + + case ui::ET_GESTURE_SCROLL_UPDATE: + data.scroll_update.x = delta_x; + data.scroll_update.y = delta_y; + data.scroll_update.x_ordinal = delta_x; + data.scroll_update.y_ordinal = delta_y; + break; + + case ui::ET_SCROLL_FLING_START: + data.fling_velocity.x = delta_x; + data.fling_velocity.y = delta_y; + data.fling_velocity.x_ordinal = delta_x; + data.fling_velocity.y_ordinal = delta_y; + break; + + case ui::ET_GESTURE_LONG_PRESS: + data.touch_id = static_cast<int>(delta_x); + CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for long press."; + break; + + case ui::ET_GESTURE_TWO_FINGER_TAP: + data.first_finger_enclosing_rectangle.width = delta_x; + data.first_finger_enclosing_rectangle.height = delta_y; + break; + + case ui::ET_GESTURE_PINCH_UPDATE: + data.scale = delta_x; + CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for pinch"; + break; + + case ui::ET_GESTURE_MULTIFINGER_SWIPE: + data.swipe.left = delta_x < 0; + data.swipe.right = delta_x > 0; + data.swipe.up = delta_y < 0; + data.swipe.down = delta_y > 0; + break; + + case ui::ET_GESTURE_TAP: + case ui::ET_GESTURE_DOUBLE_TAP: + case ui::ET_GESTURE_TAP_UNCONFIRMED: + data.tap_count = static_cast<int>(delta_x); + CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for tap."; + break; + + default: + if (delta_x != 0.f || delta_y != 0.f) { + DLOG(WARNING) << "A gesture event (" << type << ") had unknown data: (" + << delta_x << "," << delta_y; + } + break; + } +} + +GestureEventDetails::GestureEventDetails(ui::EventType type, + float delta_x, + float delta_y, + float delta_x_ordinal, + float delta_y_ordinal) + : type_(type), + touch_points_(1) { + CHECK(type == ui::ET_GESTURE_SCROLL_UPDATE || + type == ui::ET_SCROLL_FLING_START); + switch (type_) { + case ui::ET_GESTURE_SCROLL_UPDATE: + data.scroll_update.x = delta_x; + data.scroll_update.y = delta_y; + data.scroll_update.x_ordinal = delta_x_ordinal; + data.scroll_update.y_ordinal = delta_y_ordinal; + break; + + case ui::ET_SCROLL_FLING_START: + data.fling_velocity.x = delta_x; + data.fling_velocity.y = delta_y; + data.fling_velocity.x_ordinal = delta_x_ordinal; + data.fling_velocity.y_ordinal = delta_y_ordinal; + break; + + default: + break; + } +} + +void GestureEventDetails::SetScrollVelocity(float velocity_x, + float velocity_y, + float velocity_x_ordinal, + float velocity_y_ordinal) { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + data.scroll_update.velocity_x = velocity_x; + data.scroll_update.velocity_y = velocity_y; + data.scroll_update.velocity_x_ordinal = velocity_x_ordinal; + data.scroll_update.velocity_y_ordinal = velocity_y_ordinal; +} + +GestureEventDetails::Details::Details() { + memset(this, 0, sizeof(Details)); +} + +} // namespace ui diff --git a/ui/events/gesture_event_details.h b/ui/events/gesture_event_details.h new file mode 100644 index 0000000..f1c592f --- /dev/null +++ b/ui/events/gesture_event_details.h @@ -0,0 +1,212 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ +#define UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ + +#include "base/logging.h" +#include "ui/events/event_constants.h" +#include "ui/events/events_base_export.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/rect_conversions.h" + +namespace ui { + +struct EVENTS_BASE_EXPORT GestureEventDetails { + public: + GestureEventDetails(); + GestureEventDetails(EventType type, float delta_x, float delta_y); + GestureEventDetails(EventType type, + float delta_x, float delta_y, + float delta_x_ordinal, float delta_y_ordinal); + + EventType type() const { return type_; } + + int touch_points() const { return touch_points_; } + void set_touch_points(int touch_points) { touch_points_ = touch_points; } + + // TODO(tdresser): Return RectF. See crbug.com/337824. + const gfx::Rect bounding_box() const { + return ToEnclosingRect(bounding_box_); + } + + const gfx::RectF& bounding_box_f() const { + return bounding_box_; + } + + void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; } + + void SetScrollVelocity(float velocity_x, float velocity_y, + float velocity_x_ordinal, float velocity_y_ordinal); + + float scroll_x_hint() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); + return data.scroll_begin.x_hint; + } + + float scroll_y_hint() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); + return data.scroll_begin.y_hint; + } + + float scroll_x() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.x; + } + + float scroll_y() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.y; + } + + float velocity_x() const { + DCHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x : + data.scroll_update.velocity_x; + } + + float velocity_y() const { + DCHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y : + data.scroll_update.velocity_y; + } + + // *_ordinal values are unmodified by rail based clamping. + float scroll_x_ordinal() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.x_ordinal; + } + + float scroll_y_ordinal() const { + DCHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll_update.y_ordinal; + } + + float velocity_x_ordinal() const { + DCHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? + data.fling_velocity.x_ordinal : + data.scroll_update.velocity_x_ordinal; + } + + float velocity_y_ordinal() const { + DCHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || + type_ == ui::ET_SCROLL_FLING_START); + return type_ == ui::ET_SCROLL_FLING_START ? + data.fling_velocity.y_ordinal : + data.scroll_update.velocity_y_ordinal; + } + + int touch_id() const { + DCHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); + return data.touch_id; + } + + float first_finger_width() const { + DCHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); + return data.first_finger_enclosing_rectangle.width; + } + + float first_finger_height() const { + DCHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); + return data.first_finger_enclosing_rectangle.height; + } + + float scale() const { + DCHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); + return data.scale; + } + + bool swipe_left() const { + DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.left; + } + + bool swipe_right() const { + DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.right; + } + + bool swipe_up() const { + DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.up; + } + + bool swipe_down() const { + DCHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); + return data.swipe.down; + } + + int tap_count() const { + DCHECK(type_ == ui::ET_GESTURE_TAP || + type_ == ui::ET_GESTURE_TAP_UNCONFIRMED || + type_ == ET_GESTURE_DOUBLE_TAP); + return data.tap_count; + } + + private: + ui::EventType type_; + union Details { + Details(); + struct { // SCROLL start details. + // Distance that caused the scroll to start. Generally redundant with + // the x/y values from the first scroll_update. + float x_hint; + float y_hint; + } scroll_begin; + + struct { // SCROLL delta. + float x; + float y; + float velocity_x; + float velocity_y; + float x_ordinal; + float y_ordinal; + float velocity_x_ordinal; + float velocity_y_ordinal; + } scroll_update; + + float scale; // PINCH scale. + + struct { // FLING velocity. + float x; + float y; + float x_ordinal; + float y_ordinal; + } fling_velocity; + + int touch_id; // LONG_PRESS touch-id. + + // Dimensions of the first finger's enclosing rectangle for + // TWO_FINGER_TAP. + struct { + float width; + float height; + } first_finger_enclosing_rectangle; + + struct { // SWIPE direction. + bool left; + bool right; + bool up; + bool down; + } swipe; + + // Tap information must be set for ET_GESTURE_TAP, + // ET_GESTURE_TAP_UNCONFIRMED, and ET_GESTURE_DOUBLE_TAP events. + int tap_count; // TAP repeat count. + } data; + + int touch_points_; // Number of active touch points in the gesture. + + // Bounding box is an axis-aligned rectangle that contains all the + // enclosing rectangles of the touch-points in the gesture. + gfx::RectF bounding_box_; +}; + +} // namespace ui + +#endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_EVENT_DETAILS_H_ diff --git a/ui/events/gestures/gesture_recognizer.h b/ui/events/gestures/gesture_recognizer.h index 8363199..f33a7a7 100644 --- a/ui/events/gestures/gesture_recognizer.h +++ b/ui/events/gestures/gesture_recognizer.h @@ -11,6 +11,7 @@ #include "ui/events/event_constants.h" #include "ui/events/events_export.h" #include "ui/events/gestures/gesture_types.h" +#include "ui/gfx/geometry/point_f.h" namespace ui { // A GestureRecognizer is an abstract base class for conversion of touch events diff --git a/ui/events/gestures/gesture_sequence.h b/ui/events/gestures/gesture_sequence.h index 986be0b..62676e9 100644 --- a/ui/events/gestures/gesture_sequence.h +++ b/ui/events/gestures/gesture_sequence.h @@ -7,6 +7,7 @@ #include "base/timer/timer.h" #include "ui/events/event_constants.h" +#include "ui/events/gesture_event_details.h" #include "ui/events/gestures/gesture_point.h" #include "ui/events/gestures/gesture_recognizer.h" #include "ui/gfx/rect.h" diff --git a/ui/events/gestures/gesture_types.h b/ui/events/gestures/gesture_types.h index 5887b75..8514508 100644 --- a/ui/events/gestures/gesture_types.h +++ b/ui/events/gestures/gesture_types.h @@ -5,199 +5,13 @@ #ifndef UI_EVENTS_GESTURES_GESTURE_TYPES_H_ #define UI_EVENTS_GESTURES_GESTURE_TYPES_H_ -#include "base/logging.h" -#include "ui/events/event_constants.h" #include "ui/events/events_export.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/rect_conversions.h" namespace ui { class GestureEvent; class TouchEvent; -struct EVENTS_EXPORT GestureEventDetails { - public: - GestureEventDetails(EventType type, float delta_x, float delta_y); - GestureEventDetails(EventType type, - float delta_x, float delta_y, - float delta_x_ordinal, float delta_y_ordinal); - - EventType type() const { return type_; } - - int touch_points() const { return touch_points_; } - void set_touch_points(int touch_points) { touch_points_ = touch_points; } - - // TODO(tdresser): Return RectF. See crbug.com/337824. - const gfx::Rect bounding_box() const { - return ToEnclosingRect(bounding_box_); - } - void set_bounding_box(const gfx::RectF& box) { bounding_box_ = box; } - - void SetScrollVelocity(float velocity_x, float velocity_y, - float velocity_x_ordinal, float velocity_y_ordinal); - - float scroll_x_hint() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); - return data.scroll_begin.x_hint; - } - - float scroll_y_hint() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_BEGIN, type_); - return data.scroll_begin.y_hint; - } - - float scroll_x() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); - return data.scroll_update.x; - } - - float scroll_y() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); - return data.scroll_update.y; - } - - float velocity_x() const { - CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || - type_ == ui::ET_SCROLL_FLING_START); - return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.x : - data.scroll_update.velocity_x; - } - - float velocity_y() const { - CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || - type_ == ui::ET_SCROLL_FLING_START); - return type_ == ui::ET_SCROLL_FLING_START ? data.fling_velocity.y : - data.scroll_update.velocity_y; - } - - // *_ordinal values are unmodified by rail based clamping. - float scroll_x_ordinal() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); - return data.scroll_update.x_ordinal; - } - - float scroll_y_ordinal() const { - CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); - return data.scroll_update.y_ordinal; - } - - float velocity_x_ordinal() const { - CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || - type_ == ui::ET_SCROLL_FLING_START); - return type_ == ui::ET_SCROLL_FLING_START ? - data.fling_velocity.x_ordinal : - data.scroll_update.velocity_x_ordinal; - } - - float velocity_y_ordinal() const { - CHECK(type_ == ui::ET_GESTURE_SCROLL_UPDATE || - type_ == ui::ET_SCROLL_FLING_START); - return type_ == ui::ET_SCROLL_FLING_START ? - data.fling_velocity.y_ordinal : - data.scroll_update.velocity_y_ordinal; - } - - int touch_id() const { - CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); - return data.touch_id; - } - - float first_finger_width() const { - CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); - return data.first_finger_enclosing_rectangle.width; - } - - float first_finger_height() const { - CHECK_EQ(ui::ET_GESTURE_TWO_FINGER_TAP, type_); - return data.first_finger_enclosing_rectangle.height; - } - - float scale() const { - CHECK_EQ(ui::ET_GESTURE_PINCH_UPDATE, type_); - return data.scale; - } - - bool swipe_left() const { - CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); - return data.swipe.left; - } - - bool swipe_right() const { - CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); - return data.swipe.right; - } - - bool swipe_up() const { - CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); - return data.swipe.up; - } - - bool swipe_down() const { - CHECK_EQ(ui::ET_GESTURE_MULTIFINGER_SWIPE, type_); - return data.swipe.down; - } - - int tap_count() const { - CHECK_EQ(ui::ET_GESTURE_TAP, type_); - return data.tap_count; - } - - private: - ui::EventType type_; - union { - struct { // SCROLL start details. - // Distance that caused the scroll to start. Generally redundant with - // the x/y values from the first scroll_update. - float x_hint; - float y_hint; - } scroll_begin; - - struct { // SCROLL delta. - float x; - float y; - float velocity_x; - float velocity_y; - float x_ordinal; - float y_ordinal; - float velocity_x_ordinal; - float velocity_y_ordinal; - } scroll_update; - - float scale; // PINCH scale. - - struct { // FLING velocity. - float x; - float y; - float x_ordinal; - float y_ordinal; - } fling_velocity; - - int touch_id; // LONG_PRESS touch-id. - - // Dimensions of the first finger's enclosing rectangle for TWO_FINGER_TAP. - struct { - float width; - float height; - } first_finger_enclosing_rectangle; - - struct { // SWIPE direction. - bool left; - bool right; - bool up; - bool down; - } swipe; - - int tap_count; // TAP repeat count. - } data; - - int touch_points_; // Number of active touch points in the gesture. - - // Bounding box is an axis-aligned rectangle that contains all the - // enclosing rectangles of the touch-points in the gesture. - gfx::RectF bounding_box_; -}; - // An abstract type for consumers of gesture-events created by the // gesture-recognizer. class EVENTS_EXPORT GestureConsumer { |