Index: ui/events/gesture_detection/motion_event_generic.cc |
diff --git a/ui/events/gesture_detection/motion_event_generic.cc b/ui/events/gesture_detection/motion_event_generic.cc |
index ad853f52c13617bd94bd99d5eff4267f459e3e84..6b4b61d746fa8b6e6af6281c3dc6ec154fd5b96c 100644 |
--- a/ui/events/gesture_detection/motion_event_generic.cc |
+++ b/ui/events/gesture_detection/motion_event_generic.cc |
@@ -21,7 +21,7 @@ PointerProperties::PointerProperties() |
orientation(0) { |
} |
-PointerProperties::PointerProperties(float x, float y) |
+PointerProperties::PointerProperties(float x, float y, float touch_major) |
: id(0), |
tool_type(MotionEvent::TOOL_TYPE_UNKNOWN), |
x(x), |
@@ -29,17 +29,23 @@ PointerProperties::PointerProperties(float x, float y) |
raw_x(x), |
raw_y(y), |
pressure(0), |
- touch_major(0), |
+ touch_major(touch_major), |
touch_minor(0), |
orientation(0) { |
} |
-MotionEventGeneric::MotionEventGeneric() |
- : action_(ACTION_CANCEL), |
- id_(0), |
- action_index_(0), |
- button_state_(0), |
- flags_(0) { |
+PointerProperties::PointerProperties(const MotionEvent& event, |
+ size_t pointer_index) |
+ : id(event.GetPointerId(pointer_index)), |
+ tool_type(event.GetToolType(pointer_index)), |
+ x(event.GetX(pointer_index)), |
+ y(event.GetY(pointer_index)), |
+ raw_x(event.GetRawX(pointer_index)), |
+ raw_y(event.GetRawY(pointer_index)), |
+ pressure(event.GetPressure(pointer_index)), |
+ touch_major(event.GetTouchMajor(pointer_index)), |
+ touch_minor(event.GetTouchMinor(pointer_index)), |
+ orientation(event.GetOrientation(pointer_index)) { |
} |
MotionEventGeneric::MotionEventGeneric(Action action, |
@@ -62,6 +68,9 @@ MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric& other) |
button_state_(other.button_state_), |
flags_(other.flags_), |
pointers_(other.pointers_) { |
+ const size_t history_size = other.GetHistorySize(); |
+ for (size_t h = 0; h < history_size; ++h) |
+ PushHistoricalEvent(other.historical_events_[h]->Clone()); |
} |
MotionEventGeneric::~MotionEventGeneric() { |
@@ -146,20 +155,119 @@ base::TimeTicks MotionEventGeneric::GetEventTime() const { |
return event_time_; |
} |
-scoped_ptr<MotionEvent> MotionEventGeneric::Clone() const { |
- return scoped_ptr<MotionEvent>(new MotionEventGeneric(*this)); |
+size_t MotionEventGeneric::GetHistorySize() const { |
+ return historical_events_.size(); |
+} |
+ |
+base::TimeTicks MotionEventGeneric::GetHistoricalEventTime( |
+ size_t historical_index) const { |
+ DCHECK_LT(historical_index, historical_events_.size()); |
+ return historical_events_[historical_index]->GetEventTime(); |
+} |
+ |
+float MotionEventGeneric::GetHistoricalTouchMajor( |
+ size_t pointer_index, |
+ size_t historical_index) const { |
+ DCHECK_LT(historical_index, historical_events_.size()); |
+ return historical_events_[historical_index]->GetTouchMajor(pointer_index); |
+} |
+ |
+float MotionEventGeneric::GetHistoricalX(size_t pointer_index, |
+ size_t historical_index) const { |
+ DCHECK_LT(historical_index, historical_events_.size()); |
+ return historical_events_[historical_index]->GetX(pointer_index); |
+} |
+ |
+float MotionEventGeneric::GetHistoricalY(size_t pointer_index, |
+ size_t historical_index) const { |
+ DCHECK_LT(historical_index, historical_events_.size()); |
+ return historical_events_[historical_index]->GetY(pointer_index); |
} |
-scoped_ptr<MotionEvent> MotionEventGeneric::Cancel() const { |
- scoped_ptr<MotionEventGeneric> event(new MotionEventGeneric(*this)); |
- event->set_action(ACTION_CANCEL); |
- return event.Pass(); |
+// static |
+scoped_ptr<MotionEventGeneric> MotionEventGeneric::CloneEvent( |
+ const MotionEvent& event) { |
+ bool with_history = true; |
+ return make_scoped_ptr(new MotionEventGeneric(event, with_history)); |
+} |
+ |
+// static |
+scoped_ptr<MotionEventGeneric> MotionEventGeneric::CancelEvent( |
+ const MotionEvent& event) { |
+ bool with_history = false; |
+ scoped_ptr<MotionEventGeneric> cancel_event( |
+ new MotionEventGeneric(event, with_history)); |
+ cancel_event->set_action(ACTION_CANCEL); |
+ return cancel_event.Pass(); |
} |
void MotionEventGeneric::PushPointer(const PointerProperties& pointer) { |
+ DCHECK_EQ(0U, GetHistorySize()); |
pointers_->push_back(pointer); |
} |
+void MotionEventGeneric::PushHistoricalEvent(scoped_ptr<MotionEvent> event) { |
+ DCHECK(event); |
+ DCHECK_EQ(event->GetAction(), ACTION_MOVE); |
+ DCHECK_EQ(event->GetPointerCount(), GetPointerCount()); |
+ DCHECK_EQ(event->GetAction(), GetAction()); |
+ DCHECK_LE(event->GetEventTime().ToInternalValue(), |
+ GetEventTime().ToInternalValue()); |
+ historical_events_.push_back(event.release()); |
+} |
+ |
+MotionEventGeneric::MotionEventGeneric() |
+ : action_(ACTION_CANCEL), id_(0), action_index_(0), button_state_(0) { |
+} |
+ |
+MotionEventGeneric::MotionEventGeneric(const MotionEvent& event, |
+ bool with_history) |
+ : action_(event.GetAction()), |
+ event_time_(event.GetEventTime()), |
+ id_(event.GetId()), |
+ action_index_( |
+ (action_ == ACTION_POINTER_UP || action_ == ACTION_POINTER_DOWN) |
+ ? event.GetActionIndex() |
+ : 0), |
+ button_state_(event.GetButtonState()), |
+ flags_(event.GetFlags()) { |
+ const size_t pointer_count = event.GetPointerCount(); |
+ for (size_t i = 0; i < pointer_count; ++i) |
+ PushPointer(PointerProperties(event, i)); |
+ |
+ if (!with_history) |
+ return; |
+ |
+ const size_t history_size = event.GetHistorySize(); |
+ for (size_t h = 0; h < history_size; ++h) { |
+ scoped_ptr<MotionEventGeneric> historical_event(new MotionEventGeneric()); |
+ historical_event->set_action(ACTION_MOVE); |
+ historical_event->set_event_time(event.GetHistoricalEventTime(h)); |
+ for (size_t i = 0; i < pointer_count; ++i) { |
+ historical_event->PushPointer( |
+ PointerProperties(event.GetHistoricalX(i, h), |
+ event.GetHistoricalY(i, h), |
+ event.GetHistoricalTouchMajor(i, h))); |
+ } |
+ PushHistoricalEvent(historical_event.Pass()); |
+ } |
+} |
+ |
+MotionEventGeneric& MotionEventGeneric::operator=( |
+ const MotionEventGeneric& other) { |
+ action_ = other.action_; |
+ event_time_ = other.event_time_; |
+ id_ = other.id_; |
+ action_index_ = other.action_index_; |
+ button_state_ = other.button_state_; |
+ flags_ = other.flags_; |
+ pointers_ = other.pointers_; |
+ const size_t history_size = other.GetHistorySize(); |
+ for (size_t h = 0; h < history_size; ++h) |
+ PushHistoricalEvent(other.historical_events_[h]->Clone()); |
+ return *this; |
+} |
+ |
void MotionEventGeneric::PopPointer() { |
DCHECK_GT(pointers_->size(), 0U); |
pointers_->pop_back(); |