summaryrefslogtreecommitdiffstats
path: root/ui/events
diff options
context:
space:
mode:
authorlanwei <lanwei@chromium.org>2014-11-19 10:59:15 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-19 18:59:33 +0000
commit677624456a92669f432b6855eb705f947c5e1a8f (patch)
treebf369923552bce45928931f7741083fb15be298e /ui/events
parent5eb58501e72f62a0e5d9a316fdc5aa17540ad110 (diff)
downloadchromium_src-677624456a92669f432b6855eb705f947c5e1a8f.zip
chromium_src-677624456a92669f432b6855eb705f947c5e1a8f.tar.gz
chromium_src-677624456a92669f432b6855eb705f947c5e1a8f.tar.bz2
Merge MotionEventAura::PointData and ui::PointerProperties from motion_event_generic.h together
Since MotionEventAura and MotionEventGeneric share a lot of attributes in common, we decide to eliminate the duplicate fields by making MotionEventAura a subclass of MotionEventGeneric. MotionEventAndroid has its own special data type, so we will not make any change to it. Meanwhile, we changed some places which do not have the restriction on action type for the GetActionIndex() method. BUG=425114 Review URL: https://codereview.chromium.org/717413003 Cr-Commit-Position: refs/heads/master@{#304853}
Diffstat (limited to 'ui/events')
-rw-r--r--ui/events/gesture_detection/motion_event.cc5
-rw-r--r--ui/events/gesture_detection/motion_event.h3
-rw-r--r--ui/events/gesture_detection/motion_event_buffer.cc1
-rw-r--r--ui/events/gesture_detection/motion_event_buffer_unittest.cc5
-rw-r--r--ui/events/gesture_detection/motion_event_generic.cc20
-rw-r--r--ui/events/gesture_detection/motion_event_generic.h2
-rw-r--r--ui/events/gestures/motion_event_aura.cc219
-rw-r--r--ui/events/gestures/motion_event_aura.h61
-rw-r--r--ui/events/test/motion_event_test_utils.cc8
9 files changed, 90 insertions, 234 deletions
diff --git a/ui/events/gesture_detection/motion_event.cc b/ui/events/gesture_detection/motion_event.cc
index 3c25a7a..1d8f7c5 100644
--- a/ui/events/gesture_detection/motion_event.cc
+++ b/ui/events/gesture_detection/motion_event.cc
@@ -46,6 +46,11 @@ int MotionEvent::FindPointerIndexOfId(int id) const {
return -1;
}
+int MotionEvent::GetSourceDeviceId(size_t pointer_index) const {
+ NOTIMPLEMENTED();
+ return 0;
+}
+
scoped_ptr<MotionEvent> MotionEvent::Clone() const {
return MotionEventGeneric::CloneEvent(*this);
}
diff --git a/ui/events/gesture_detection/motion_event.h b/ui/events/gesture_detection/motion_event.h
index 469b656..560afcb 100644
--- a/ui/events/gesture_detection/motion_event.h
+++ b/ui/events/gesture_detection/motion_event.h
@@ -76,6 +76,9 @@ class GESTURE_DETECTION_EXPORT MotionEvent {
virtual float GetHistoricalY(size_t pointer_index,
size_t historical_index) const;
+ // Get the id of the device which created the event. Currently Aura only.
+ virtual int GetSourceDeviceId(size_t pointer_index) const;
+
// Utility accessor methods for convenience.
float GetX() const { return GetX(0); }
float GetY() const { return GetY(0); }
diff --git a/ui/events/gesture_detection/motion_event_buffer.cc b/ui/events/gesture_detection/motion_event_buffer.cc
index d1dec70..6bbce21 100644
--- a/ui/events/gesture_detection/motion_event_buffer.cc
+++ b/ui/events/gesture_detection/motion_event_buffer.cc
@@ -147,7 +147,6 @@ scoped_ptr<MotionEventGeneric> ResampleMotionEvent(
DCHECK(event);
event->set_id(event0.GetId());
- event->set_action_index(event0.GetActionIndex());
event->set_button_state(event0.GetButtonState());
return event.Pass();
}
diff --git a/ui/events/gesture_detection/motion_event_buffer_unittest.cc b/ui/events/gesture_detection/motion_event_buffer_unittest.cc
index ba018b2..da3ffe5 100644
--- a/ui/events/gesture_detection/motion_event_buffer_unittest.cc
+++ b/ui/events/gesture_detection/motion_event_buffer_unittest.cc
@@ -83,7 +83,10 @@ class MotionEventBufferTest : public testing::Test,
bool ignore_history) {
EXPECT_EQ(a.GetId(), b.GetId());
EXPECT_EQ(a.GetAction(), b.GetAction());
- EXPECT_EQ(a.GetActionIndex(), b.GetActionIndex());
+ if (a.GetAction() == MotionEvent::ACTION_POINTER_DOWN ||
+ a.GetAction() == MotionEvent::ACTION_POINTER_UP) {
+ EXPECT_EQ(a.GetActionIndex(), b.GetActionIndex());
+ }
EXPECT_EQ(a.GetButtonState(), b.GetButtonState());
EXPECT_EQ(a.GetEventTime(), b.GetEventTime());
diff --git a/ui/events/gesture_detection/motion_event_generic.cc b/ui/events/gesture_detection/motion_event_generic.cc
index 6b4b61d..3789ec6 100644
--- a/ui/events/gesture_detection/motion_event_generic.cc
+++ b/ui/events/gesture_detection/motion_event_generic.cc
@@ -9,16 +9,7 @@
namespace ui {
PointerProperties::PointerProperties()
- : id(0),
- tool_type(MotionEvent::TOOL_TYPE_UNKNOWN),
- x(0),
- y(0),
- raw_x(0),
- raw_y(0),
- pressure(0),
- touch_major(0),
- touch_minor(0),
- orientation(0) {
+ : PointerProperties(0, 0, 0) {
}
PointerProperties::PointerProperties(float x, float y, float touch_major)
@@ -31,7 +22,8 @@ PointerProperties::PointerProperties(float x, float y, float touch_major)
pressure(0),
touch_major(touch_major),
touch_minor(0),
- orientation(0) {
+ orientation(0),
+ source_device_id(0) {
}
PointerProperties::PointerProperties(const MotionEvent& event,
@@ -45,7 +37,8 @@ PointerProperties::PointerProperties(const MotionEvent& event,
pressure(event.GetPressure(pointer_index)),
touch_major(event.GetTouchMajor(pointer_index)),
touch_minor(event.GetTouchMinor(pointer_index)),
- orientation(event.GetOrientation(pointer_index)) {
+ orientation(event.GetOrientation(pointer_index)),
+ source_device_id(0) {
}
MotionEventGeneric::MotionEventGeneric(Action action,
@@ -85,6 +78,9 @@ MotionEvent::Action MotionEventGeneric::GetAction() const {
}
int MotionEventGeneric::GetActionIndex() const {
+ DCHECK(action_ == ACTION_POINTER_DOWN || action_ == ACTION_POINTER_UP);
+ DCHECK_GE(action_index_, 0);
+ DCHECK_LT(action_index_, static_cast<int>(pointers_->size()));
return action_index_;
}
diff --git a/ui/events/gesture_detection/motion_event_generic.h b/ui/events/gesture_detection/motion_event_generic.h
index 359a651..9d7733f 100644
--- a/ui/events/gesture_detection/motion_event_generic.h
+++ b/ui/events/gesture_detection/motion_event_generic.h
@@ -28,6 +28,8 @@ struct GESTURE_DETECTION_EXPORT PointerProperties {
float touch_major;
float touch_minor;
float orientation;
+ // source_device_id is only used on Aura.
+ int source_device_id;
};
// A generic MotionEvent implementation.
diff --git a/ui/events/gestures/motion_event_aura.cc b/ui/events/gestures/motion_event_aura.cc
index 62262d8..11f8ba1 100644
--- a/ui/events/gestures/motion_event_aura.cc
+++ b/ui/events/gestures/motion_event_aura.cc
@@ -13,40 +13,17 @@
#include "ui/events/gesture_detection/gesture_configuration.h"
namespace ui {
-
-MotionEventAura::MotionEventAura()
- : pointer_count_(0), cached_action_index_(-1) {
-}
-
-MotionEventAura::MotionEventAura(
- size_t pointer_count,
- const base::TimeTicks& last_touch_time,
- Action cached_action,
- int cached_action_index,
- int flags,
- const PointData (&active_touches)[MotionEvent::MAX_TOUCH_POINT_COUNT])
- : pointer_count_(pointer_count),
- last_touch_time_(last_touch_time),
- cached_action_(cached_action),
- cached_action_index_(cached_action_index),
- flags_(flags) {
- DCHECK(pointer_count_);
- for (size_t i = 0; i < pointer_count; ++i)
- active_touches_[i] = active_touches[i];
-}
-
-MotionEventAura::~MotionEventAura() {}
-
-MotionEventAura::PointData MotionEventAura::GetPointDataFromTouchEvent(
- const TouchEvent& touch) {
- PointData point_data;
- point_data.x = touch.x();
- point_data.y = touch.y();
- point_data.raw_x = touch.root_location_f().x();
- point_data.raw_y = touch.root_location_f().y();
- point_data.touch_id = touch.touch_id();
- point_data.pressure = touch.force();
- point_data.source_device_id = touch.source_device_id();
+namespace {
+
+PointerProperties GetPointerPropertiesFromTouchEvent(const TouchEvent& touch) {
+ PointerProperties pointer_properties;
+ pointer_properties.x = touch.x();
+ pointer_properties.y = touch.y();
+ pointer_properties.raw_x = touch.root_location_f().x();
+ pointer_properties.raw_y = touch.root_location_f().y();
+ pointer_properties.id = touch.touch_id();
+ pointer_properties.pressure = touch.force();
+ pointer_properties.source_device_id = touch.source_device_id();
float radius_x = touch.radius_x();
float radius_y = touch.radius_y();
@@ -60,24 +37,36 @@ MotionEventAura::PointData MotionEventAura::GetPointDataFromTouchEvent(
// The case radius_x == radius_y is omitted from here on purpose: for
// circles, we want to pass the angle (which could be any value in such
// cases but always seem to be set to zero) unchanged.
- point_data.touch_major = 2.f * radius_x;
- point_data.touch_minor = 2.f * radius_y;
- point_data.orientation = rotation_angle_rad - M_PI_2;
+ pointer_properties.touch_major = 2.f * radius_x;
+ pointer_properties.touch_minor = 2.f * radius_y;
+ pointer_properties.orientation = rotation_angle_rad - M_PI_2;
} else {
- point_data.touch_major = 2.f * radius_y;
- point_data.touch_minor = 2.f * radius_x;
- point_data.orientation = rotation_angle_rad;
+ pointer_properties.touch_major = 2.f * radius_y;
+ pointer_properties.touch_minor = 2.f * radius_x;
+ pointer_properties.orientation = rotation_angle_rad;
}
- if (!point_data.touch_major) {
- point_data.touch_major =
+ if (!pointer_properties.touch_major) {
+ pointer_properties.touch_major =
2.f * GestureConfiguration::GetInstance()->default_radius();
- point_data.touch_minor =
+ pointer_properties.touch_minor =
2.f * GestureConfiguration::GetInstance()->default_radius();
- point_data.orientation = 0;
+ pointer_properties.orientation = 0;
}
- return point_data;
+ // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128.
+ pointer_properties.tool_type = MotionEvent::TOOL_TYPE_UNKNOWN;
+
+ return pointer_properties;
+}
+
+} // namespace
+
+MotionEventAura::MotionEventAura() {
+ set_action_index(-1);
+}
+
+MotionEventAura::~MotionEventAura() {
}
void MotionEventAura::OnTouch(const TouchEvent& touch) {
@@ -101,160 +90,68 @@ void MotionEventAura::OnTouch(const TouchEvent& touch) {
}
UpdateCachedAction(touch);
- flags_ = touch.flags();
- last_touch_time_ = touch.time_stamp() + base::TimeTicks();
+ set_flags(touch.flags());
+ set_event_time(touch.time_stamp() + base::TimeTicks());
}
int MotionEventAura::GetId() const {
return GetPointerId(0);
}
-MotionEvent::Action MotionEventAura::GetAction() const {
- return cached_action_;
-}
-
-int MotionEventAura::GetActionIndex() const {
- DCHECK(cached_action_ == ACTION_POINTER_DOWN ||
- cached_action_ == ACTION_POINTER_UP);
- DCHECK_GE(cached_action_index_, 0);
- DCHECK_LT(cached_action_index_, static_cast<int>(pointer_count_));
- return cached_action_index_;
-}
-
-size_t MotionEventAura::GetPointerCount() const { return pointer_count_; }
-
-int MotionEventAura::GetPointerId(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].touch_id;
-}
-
-float MotionEventAura::GetX(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].x;
-}
-
-float MotionEventAura::GetY(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].y;
-}
-
-float MotionEventAura::GetRawX(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].raw_x;
-}
-
-float MotionEventAura::GetRawY(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].raw_y;
-}
-
-float MotionEventAura::GetTouchMajor(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].touch_major;
-}
-
-float MotionEventAura::GetTouchMinor(size_t pointer_index) const {
- DCHECK_LE(pointer_index, pointer_count_);
- return active_touches_[pointer_index].touch_minor;
-}
-
-float MotionEventAura::GetOrientation(size_t pointer_index) const {
- DCHECK_LE(pointer_index, pointer_count_);
- return active_touches_[pointer_index].orientation;
-}
-
-float MotionEventAura::GetPressure(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].pressure;
-}
-
-MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const {
- // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128.
- DCHECK_LT(pointer_index, pointer_count_);
- return MotionEvent::TOOL_TYPE_UNKNOWN;
-}
-
-int MotionEventAura::GetButtonState() const {
- return 0;
-}
-
-int MotionEventAura::GetFlags() const {
- return flags_;
-}
-
-base::TimeTicks MotionEventAura::GetEventTime() const {
- return last_touch_time_;
-}
-
void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) {
if (event.type() != ET_TOUCH_RELEASED &&
event.type() != ET_TOUCH_CANCELLED) {
return;
}
- DCHECK(pointer_count_);
+ DCHECK(GetPointerCount());
int index_to_delete = GetIndexFromId(event.touch_id());
- cached_action_index_ = 0;
- pointer_count_--;
- active_touches_[index_to_delete] = active_touches_[pointer_count_];
-}
-
-MotionEventAura::PointData::PointData()
- : x(0),
- y(0),
- raw_x(0),
- raw_y(0),
- touch_id(0),
- pressure(0),
- source_device_id(0),
- touch_major(0),
- touch_minor(0),
- orientation(0) {
+ set_action_index(0);
+ pointer(index_to_delete) = pointer(GetPointerCount() - 1);
+ PopPointer();
}
int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const {
- DCHECK_LT(pointer_index, pointer_count_);
- return active_touches_[pointer_index].source_device_id;
+ DCHECK_LT(pointer_index, GetPointerCount());
+ return pointer(pointer_index).source_device_id;
}
void MotionEventAura::AddTouch(const TouchEvent& touch) {
- if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT)
+ if (GetPointerCount() == MotionEvent::MAX_TOUCH_POINT_COUNT)
return;
- active_touches_[pointer_count_] = GetPointDataFromTouchEvent(touch);
- pointer_count_++;
+ PushPointer(GetPointerPropertiesFromTouchEvent(touch));
}
-
void MotionEventAura::UpdateTouch(const TouchEvent& touch) {
- active_touches_[GetIndexFromId(touch.touch_id())] =
- GetPointDataFromTouchEvent(touch);
+ pointer(GetIndexFromId(touch.touch_id())) =
+ GetPointerPropertiesFromTouchEvent(touch);
}
void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) {
- DCHECK(pointer_count_);
+ DCHECK(GetPointerCount());
switch (touch.type()) {
case ET_TOUCH_PRESSED:
- if (pointer_count_ == 1) {
- cached_action_ = ACTION_DOWN;
+ if (GetPointerCount() == 1) {
+ set_action(ACTION_DOWN);
} else {
- cached_action_ = ACTION_POINTER_DOWN;
- cached_action_index_ = GetIndexFromId(touch.touch_id());
+ set_action(ACTION_POINTER_DOWN);
+ set_action_index(GetIndexFromId(touch.touch_id()));
}
break;
case ET_TOUCH_RELEASED:
- if (pointer_count_ == 1) {
- cached_action_ = ACTION_UP;
+ if (GetPointerCount() == 1) {
+ set_action(ACTION_UP);
} else {
- cached_action_ = ACTION_POINTER_UP;
- cached_action_index_ = GetIndexFromId(touch.touch_id());
+ set_action(ACTION_POINTER_UP);
+ set_action_index(GetIndexFromId(touch.touch_id()));
}
break;
case ET_TOUCH_CANCELLED:
- cached_action_ = ACTION_CANCEL;
+ set_action(ACTION_CANCEL);
break;
case ET_TOUCH_MOVED:
- cached_action_ = ACTION_MOVE;
+ set_action(ACTION_MOVE);
break;
default:
NOTREACHED();
@@ -265,7 +162,7 @@ void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) {
int MotionEventAura::GetIndexFromId(int id) const {
int index = FindPointerIndexOfId(id);
DCHECK_GE(index, 0);
- DCHECK_LT(index, static_cast<int>(pointer_count_));
+ DCHECK_LT(index, static_cast<int>(GetPointerCount()));
return index;
}
diff --git a/ui/events/gestures/motion_event_aura.h b/ui/events/gestures/motion_event_aura.h
index 025fac2..2278b36 100644
--- a/ui/events/gestures/motion_event_aura.h
+++ b/ui/events/gestures/motion_event_aura.h
@@ -11,38 +11,21 @@
#include "base/time/time.h"
#include "ui/events/event.h"
#include "ui/events/events_export.h"
-#include "ui/events/gesture_detection/motion_event.h"
+#include "ui/events/gesture_detection/motion_event_generic.h"
namespace ui {
// Implementation of MotionEvent which takes a stream of ui::TouchEvents.
-class EVENTS_EXPORT MotionEventAura : public MotionEvent {
+class EVENTS_EXPORT MotionEventAura : public MotionEventGeneric {
public:
MotionEventAura();
~MotionEventAura() override;
- void OnTouch(const TouchEvent& touch);
-
- // MotionEvent implementation.
+ // MotionEventGeneric:
int GetId() const override;
- Action GetAction() const override;
- int GetActionIndex() const override;
- size_t GetPointerCount() const override;
- int GetPointerId(size_t pointer_index) const override;
- float GetX(size_t pointer_index) const override;
- float GetY(size_t pointer_index) const override;
- float GetRawX(size_t pointer_index) const override;
- float GetRawY(size_t pointer_index) const override;
- float GetTouchMajor(size_t pointer_index) const override;
- float GetTouchMinor(size_t pointer_index) const override;
- float GetOrientation(size_t pointer_index) const override;
- float GetPressure(size_t pointer_index) const override;
- ToolType GetToolType(size_t pointer_index) const override;
- int GetButtonState() const override;
- int GetFlags() const override;
- base::TimeTicks GetEventTime() const override;
+ int GetSourceDeviceId(size_t pointer_index) const override;
- int GetSourceDeviceId(size_t pointer_index) const;
+ void OnTouch(const TouchEvent& touch);
// We can't cleanup removed touch points immediately upon receipt of a
// TouchCancel or TouchRelease, as the MotionEvent needs to be able to report
@@ -52,45 +35,11 @@ class EVENTS_EXPORT MotionEventAura : public MotionEvent {
void CleanupRemovedTouchPoints(const TouchEvent& event);
private:
- struct PointData {
- PointData();
- float x;
- float y;
- float raw_x;
- float raw_y;
- int touch_id;
- float pressure;
- int source_device_id;
- float touch_major;
- float touch_minor;
- float orientation;
- };
-
- MotionEventAura(
- size_t pointer_count,
- const base::TimeTicks& last_touch_time,
- Action cached_action,
- int cached_action_index,
- int flags,
- const PointData (&active_touches)[MotionEvent::MAX_TOUCH_POINT_COUNT]);
-
- static PointData GetPointDataFromTouchEvent(const TouchEvent& touch);
void AddTouch(const TouchEvent& touch);
void UpdateTouch(const TouchEvent& touch);
void UpdateCachedAction(const TouchEvent& touch);
int GetIndexFromId(int id) const;
- size_t pointer_count_;
- base::TimeTicks last_touch_time_;
- Action cached_action_;
- // The index of the touch responsible for last ACTION_POINTER_DOWN or
- // ACTION_POINTER_UP. -1 if no such action has occurred.
- int cached_action_index_;
- int flags_;
-
- // We want constant time indexing by pointer_index, and fast indexing by id.
- PointData active_touches_[MotionEvent::MAX_TOUCH_POINT_COUNT];
-
DISALLOW_COPY_AND_ASSIGN(MotionEventAura);
};
diff --git a/ui/events/test/motion_event_test_utils.cc b/ui/events/test/motion_event_test_utils.cc
index 45350fc..8cf9a7f 100644
--- a/ui/events/test/motion_event_test_utils.cc
+++ b/ui/events/test/motion_event_test_utils.cc
@@ -169,9 +169,11 @@ void MockMotionEvent::ResolvePointers() {
std::string ToString(const MotionEvent& event) {
std::stringstream ss;
ss << "MotionEvent {"
- << "\n ID: " << event.GetId() << "\n Action: " << event.GetAction()
- << "\n ActionIndex: " << event.GetActionIndex()
- << "\n Flags: " << event.GetFlags()
+ << "\n ID: " << event.GetId() << "\n Action: " << event.GetAction();
+ if (event.GetAction() == MotionEvent::ACTION_POINTER_DOWN ||
+ event.GetAction() == MotionEvent::ACTION_POINTER_UP)
+ ss << "\n ActionIndex: " << event.GetActionIndex();
+ ss << "\n Flags: " << event.GetFlags()
<< "\n ButtonState: " << event.GetButtonState() << "\n Pointers: [";
const size_t pointer_count = event.GetPointerCount();
const size_t history_size = event.GetHistorySize();