diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:22:21 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-13 22:22:21 +0000 |
commit | 29bf1506e14e141e08d945a42ff19f2941c4dc41 (patch) | |
tree | 9109c31f17b62e8a6ec877a46a79c69d22fffb13 /ui/base | |
parent | 58c86a7f73d4e4c771db31cbb3c611a9532a858f (diff) | |
download | chromium_src-29bf1506e14e141e08d945a42ff19f2941c4dc41.zip chromium_src-29bf1506e14e141e08d945a42ff19f2941c4dc41.tar.gz chromium_src-29bf1506e14e141e08d945a42ff19f2941c4dc41.tar.bz2 |
ui-gestures: Added some type-specific accessors to gesture-events.
Adding type-specific accessors to the gesture-events should now make the code
much more readable.
BUG=none
TEST=existing tests don't break
Review URL: https://chromiumcodereview.appspot.com/10543053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141997 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r-- | ui/base/gestures/gesture_sequence.cc | 2 | ||||
-rw-r--r-- | ui/base/gestures/gesture_types.cc | 63 | ||||
-rw-r--r-- | ui/base/gestures/gesture_types.h | 110 |
3 files changed, 174 insertions, 1 deletions
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc index 7e3302c..586d792 100644 --- a/ui/base/gestures/gesture_sequence.cc +++ b/ui/base/gestures/gesture_sequence.cc @@ -771,7 +771,7 @@ void GestureSequence::AppendLongPressGestureEvent() { point->first_touch_position(), flags_, base::Time::FromDoubleT(point->last_touch_time()), - point->point_id(), 0.f, 1 << point->touch_id())); + 0.f, 0.f, 1 << point->touch_id())); helper_->DispatchLongPressGestureEvent(gesture.get()); } diff --git a/ui/base/gestures/gesture_types.cc b/ui/base/gestures/gesture_types.cc new file mode 100644 index 0000000..fbda748 --- /dev/null +++ b/ui/base/gestures/gesture_types.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2012 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/base/gestures/gesture_types.h" + +namespace ui { + +GestureEventDetails::GestureEventDetails(ui::EventType type, + float delta_x, + float delta_y) + : type_(type) { + switch (type_) { + case ui::ET_GESTURE_SCROLL_UPDATE: + data.scroll.x = delta_x; + data.scroll.y = delta_y; + break; + + case ui::ET_SCROLL_FLING_START: + data.velocity.x = delta_x; + data.velocity.y = delta_y; + break; + + case ui::ET_GESTURE_TAP: + data.radius.x = delta_x; + data.radius.y = 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_BEGIN: + case ui::ET_GESTURE_END: + data.touch_points = static_cast<int>(delta_x); + CHECK_EQ(0.f, delta_y) << "Unknown data in delta_y for begin/end"; + 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; + + default: + data.generic.delta_x = delta_x; + data.generic.delta_y = delta_y; + if (delta_x != 0.f || delta_y != 0.f) { + DLOG(WARNING) << "A gesture event (" << type << ") had unknown data: (" + << delta_x << "," << delta_y; + } + break; + } +} + +} // namespace ui diff --git a/ui/base/gestures/gesture_types.h b/ui/base/gestures/gesture_types.h index 902b1f0..a55914c 100644 --- a/ui/base/gestures/gesture_types.h +++ b/ui/base/gestures/gesture_types.h @@ -6,11 +6,121 @@ #define UI_BASE_GESTURES_GESTURE_TYPES_H_ #pragma once +#include "base/logging.h" #include "base/time.h" #include "ui/base/events.h" namespace ui { +struct UI_EXPORT GestureEventDetails { + public: + GestureEventDetails(EventType type, float delta_x, float delta_y); + + float scroll_x() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll.x; + } + float scroll_y() const { + CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_); + return data.scroll.y; + } + + float velocity_x() const { + CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); + return data.velocity.x; + } + float velocity_y() const { + CHECK_EQ(ui::ET_SCROLL_FLING_START, type_); + return data.velocity.y; + } + + float radius_x() const { + CHECK_EQ(ui::ET_GESTURE_TAP, type_); + return data.radius.x; + } + float radius_y() const { + CHECK_EQ(ui::ET_GESTURE_TAP, type_); + return data.radius.y; + } + + int touch_id() const { + CHECK_EQ(ui::ET_GESTURE_LONG_PRESS, type_); + return data.touch_id; + } + + int touch_points() const { + DCHECK(type_ == ui::ET_GESTURE_BEGIN || type_ == ui::ET_GESTURE_END); + return data.touch_points; + } + + 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; + } + + float generic_x() const { + return data.generic.delta_x; + } + + float generic_y() const { + return data.generic.delta_y; + } + + private: + ui::EventType type_; + union { + struct { // SCROLL delta. + float x; + float y; + } scroll; + + float scale; // PINCH scale. + + struct { // FLING velocity. + float x; + float y; + } velocity; + + struct { // TAP radius. + float x; + float y; + } radius; + + int touch_id; // LONG_PRESS touch-id. + + int touch_points; // Number of active touch points for BEGIN/END. + + struct { // SWIPE direction. + bool left; + bool right; + bool up; + bool down; + } swipe; + + struct { + float delta_x; + float delta_y; + } generic; + } data; +}; + // An abstract type to represent touch-events. The gesture-recognizer uses this // interface to communicate with the touch-events. class UI_EXPORT TouchEvent { |