summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 22:41:36 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-23 22:41:36 +0000
commit1bbf926efeb7895c3b3aabafa928048edaa205b0 (patch)
treef734be924d2cedadf772d31db222326b3aa10bb1 /ui/base
parent1de1b0b83e23c3f42063bc5124e2ef98a8e7f8b3 (diff)
downloadchromium_src-1bbf926efeb7895c3b3aabafa928048edaa205b0.zip
chromium_src-1bbf926efeb7895c3b3aabafa928048edaa205b0.tar.gz
chromium_src-1bbf926efeb7895c3b3aabafa928048edaa205b0.tar.bz2
gesture recognizer: Expose bounding-box for the points in a gesture-event.
The bounding box is the smallest axis-aligned rectangle that encloses all the bounding-boxes of all the touch-points in the gesture. BUG=none TEST=existing aura_unittests Review URL: https://chromiumcodereview.appspot.com/10808083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/gestures/gesture_configuration.h1
-rw-r--r--ui/base/gestures/gesture_sequence.cc24
-rw-r--r--ui/base/gestures/gesture_types.cc11
-rw-r--r--ui/base/gestures/gesture_types.h22
4 files changed, 22 insertions, 36 deletions
diff --git a/ui/base/gestures/gesture_configuration.h b/ui/base/gestures/gesture_configuration.h
index 206ce91..1b0caa4 100644
--- a/ui/base/gestures/gesture_configuration.h
+++ b/ui/base/gestures/gesture_configuration.h
@@ -21,6 +21,7 @@ class UI_EXPORT GestureConfiguration {
static int default_radius() {
return default_radius_;
}
+ static void set_default_radius(int radius) { default_radius_ = radius; }
static double long_press_time_in_seconds() {
return long_press_time_in_seconds_;
}
diff --git a/ui/base/gestures/gesture_sequence.cc b/ui/base/gestures/gesture_sequence.cc
index e8d5790..c582580 100644
--- a/ui/base/gestures/gesture_sequence.cc
+++ b/ui/base/gestures/gesture_sequence.cc
@@ -493,14 +493,15 @@ void GestureSequence::RecreateBoundingBox() {
for (int i = 0; i < kMaxGesturePoints; ++i) {
if (!points_[i].in_use())
continue;
- if (left > points_[i].x())
- left = points_[i].x();
- if (right < points_[i].x())
- right = points_[i].x();
- if (top > points_[i].y())
- top = points_[i].y();
- if (bottom < points_[i].y())
- bottom = points_[i].y();
+ gfx::Rect rect = points_[i].enclosing_rectangle();
+ if (left > rect.x())
+ left = rect.x();
+ if (right < rect.right())
+ right = rect.right();
+ if (top > rect.y())
+ top = rect.y();
+ if (bottom < rect.bottom())
+ bottom = rect.bottom();
}
bounding_box_last_center_ = bounding_box_.CenterPoint();
bounding_box_.SetRect(left, top, right - left, bottom - top);
@@ -559,6 +560,7 @@ GestureEvent* GestureSequence::CreateGestureEvent(
unsigned int touch_id_bitmask) {
GestureEventDetails gesture_details(details);
gesture_details.set_touch_points(point_count_);
+ gesture_details.set_bounding_box(bounding_box_);
return helper_->CreateGestureEvent(gesture_details, location, flags,
timestamp, touch_id_bitmask);
}
@@ -576,7 +578,7 @@ void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point,
void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point,
Gestures* gestures) {
gestures->push_back(CreateGestureEvent(
- GestureEventDetails(ui::ET_GESTURE_BEGIN, point_count_, 0),
+ GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0),
point.first_touch_position(),
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
@@ -586,7 +588,7 @@ void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point,
void GestureSequence::AppendEndGestureEvent(const GesturePoint& point,
Gestures* gestures) {
gestures->push_back(CreateGestureEvent(
- GestureEventDetails(ui::ET_GESTURE_END, point_count_, 0),
+ GestureEventDetails(ui::ET_GESTURE_END, 0, 0),
point.first_touch_position(),
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
@@ -598,7 +600,7 @@ void GestureSequence::AppendClickGestureEvent(const GesturePoint& point,
gfx::Rect er = point.enclosing_rectangle();
gfx::Point center = er.CenterPoint();
gestures->push_back(CreateGestureEvent(
- GestureEventDetails(ui::ET_GESTURE_TAP, er.width() / 2, er.height() / 2),
+ GestureEventDetails(ui::ET_GESTURE_TAP, 0, 0),
center,
flags_,
base::Time::FromDoubleT(point.last_touch_time()),
diff --git a/ui/base/gestures/gesture_types.cc b/ui/base/gestures/gesture_types.cc
index 8c18e56..2d32980 100644
--- a/ui/base/gestures/gesture_types.cc
+++ b/ui/base/gestures/gesture_types.cc
@@ -22,22 +22,11 @@ GestureEventDetails::GestureEventDetails(ui::EventType type,
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:
- set_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";
diff --git a/ui/base/gestures/gesture_types.h b/ui/base/gestures/gesture_types.h
index 6dd39b6..56dad14 100644
--- a/ui/base/gestures/gesture_types.h
+++ b/ui/base/gestures/gesture_types.h
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/time.h"
#include "ui/base/events.h"
+#include "ui/gfx/rect.h"
namespace ui {
@@ -20,6 +21,9 @@ struct UI_EXPORT GestureEventDetails {
int touch_points() const { return touch_points_; }
void set_touch_points(int touch_points) { touch_points_ = touch_points; }
+ const gfx::Rect& bounding_box() const { return bounding_box_; }
+ void set_bounding_box(const gfx::Rect& box) { bounding_box_ = box; }
+
float scroll_x() const {
CHECK_EQ(ui::ET_GESTURE_SCROLL_UPDATE, type_);
return data.scroll.x;
@@ -38,15 +42,6 @@ struct UI_EXPORT GestureEventDetails {
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;
@@ -97,11 +92,6 @@ struct UI_EXPORT GestureEventDetails {
float y;
} velocity;
- struct { // TAP radius.
- float x;
- float y;
- } radius;
-
int touch_id; // LONG_PRESS touch-id.
struct { // SWIPE direction.
@@ -118,6 +108,10 @@ struct UI_EXPORT GestureEventDetails {
} 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::Rect bounding_box_;
};
// An abstract type to represent touch-events. The gesture-recognizer uses this