Index: ui/events/test/mock_motion_event.cc |
diff --git a/ui/events/test/mock_motion_event.cc b/ui/events/test/mock_motion_event.cc |
index 98fceae1a8ed9d27e92c6ba6dd5c179074413ddb..528e6e5f80a0121cf4fd5b45fc4864c2fac9e972 100644 |
--- a/ui/events/test/mock_motion_event.cc |
+++ b/ui/events/test/mock_motion_event.cc |
@@ -10,29 +10,35 @@ using base::TimeTicks; |
namespace ui { |
namespace test { |
+namespace { |
+ |
+PointerProperties CreatePointer(float x, float y) { |
+ PointerProperties pointer(x, y); |
+ pointer.touch_major = MockMotionEvent::TOUCH_MAJOR; |
+ return pointer; |
+} |
+ |
+PointerProperties CreatePointer() { |
+ PointerProperties pointer; |
+ pointer.touch_major = MockMotionEvent::TOUCH_MAJOR; |
+ return pointer; |
+} |
+ |
+} // namespace |
MockMotionEvent::MockMotionEvent() |
- : action(ACTION_CANCEL), pointer_count(1), touch_major(TOUCH_MAJOR), id(0), |
- button_state(0) { |
+ : MotionEventGeneric(ACTION_CANCEL, base::TimeTicks(), CreatePointer()) { |
} |
MockMotionEvent::MockMotionEvent(Action action) |
- : action(action), pointer_count(1), touch_major(TOUCH_MAJOR), id(0), |
- button_state(0) { |
+ : MotionEventGeneric(action, base::TimeTicks(), CreatePointer()) { |
} |
MockMotionEvent::MockMotionEvent(Action action, |
TimeTicks time, |
- float x, |
- float y) |
- : action(action), |
- pointer_count(1), |
- time(time), |
- touch_major(TOUCH_MAJOR), |
- id(0), |
- button_state(0) { |
- points[0].SetPoint(x, y); |
- tool_types[0] = TOOL_TYPE_UNKNOWN; |
+ float x0, |
+ float y0) |
+ : MotionEventGeneric(action, time, CreatePointer(x0, y0)) { |
} |
MockMotionEvent::MockMotionEvent(Action action, |
@@ -41,16 +47,8 @@ MockMotionEvent::MockMotionEvent(Action action, |
float y0, |
float x1, |
float y1) |
- : action(action), |
- pointer_count(2), |
- time(time), |
- touch_major(TOUCH_MAJOR), |
- id(0), |
- button_state(0) { |
- points[0].SetPoint(x0, y0); |
- tool_types[0] = TOOL_TYPE_UNKNOWN; |
- points[1].SetPoint(x1, y1); |
- tool_types[1] = TOOL_TYPE_UNKNOWN; |
+ : MotionEventGeneric(action, time, CreatePointer(x0, y0)) { |
+ PushPointer(CreatePointer(x1, y1)); |
} |
MockMotionEvent::MockMotionEvent(Action action, |
@@ -61,107 +59,41 @@ MockMotionEvent::MockMotionEvent(Action action, |
float y1, |
float x2, |
float y2) |
- : action(action), |
- pointer_count(3), |
- time(time), |
- touch_major(TOUCH_MAJOR), |
- id(0), |
- button_state(0) { |
- points[0].SetPoint(x0, y0); |
- tool_types[0] = TOOL_TYPE_UNKNOWN; |
- points[1].SetPoint(x1, y1); |
- tool_types[1] = TOOL_TYPE_UNKNOWN; |
- points[2].SetPoint(x2, y2); |
- tool_types[2] = TOOL_TYPE_UNKNOWN; |
+ : MotionEventGeneric(action, time, CreatePointer(x0, y0)) { |
+ PushPointer(CreatePointer(x1, y1)); |
+ PushPointer(CreatePointer(x2, y2)); |
+} |
+ |
+MockMotionEvent::MockMotionEvent(Action action, |
+ base::TimeTicks time, |
+ const std::vector<gfx::PointF>& positions) { |
+ set_action(action); |
+ set_event_time(time); |
+ for (size_t i = 0; i < positions.size(); ++i) |
+ PushPointer(CreatePointer(positions[i].x(), positions[i].y())); |
} |
MockMotionEvent::MockMotionEvent(const MockMotionEvent& other) |
- : action(other.action), |
- pointer_count(other.pointer_count), |
- time(other.time), |
- touch_major(other.touch_major), |
- id(other.GetId()), |
- button_state(other.GetButtonState()) { |
- for (size_t i = 0; i < pointer_count; ++i) { |
- points[i] = other.points[i]; |
- tool_types[i] = other.tool_types[i]; |
- } |
+ : MotionEventGeneric(other) { |
} |
MockMotionEvent::~MockMotionEvent() {} |
-MotionEvent::Action MockMotionEvent::GetAction() const { return action; } |
- |
int MockMotionEvent::GetActionIndex() const { |
- return static_cast<int>(pointer_count) - 1; |
-} |
- |
-size_t MockMotionEvent::GetPointerCount() const { return pointer_count; } |
- |
-int MockMotionEvent::GetId() const { |
- return id; |
+ return static_cast<int>(GetPointerCount()) - 1; |
tdresser
2014/07/23 12:53:45
This should probably return the event's actual |ac
jdduke (slow)
2014/07/23 17:20:56
Yeah, it's a little tricker but doable.
|
} |
int MockMotionEvent::GetPointerId(size_t pointer_index) const { |
- DCHECK(pointer_index < pointer_count); |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
return static_cast<int>(pointer_index); |
} |
-float MockMotionEvent::GetX(size_t pointer_index) const { |
- return points[pointer_index].x(); |
-} |
- |
-float MockMotionEvent::GetY(size_t pointer_index) const { |
- return points[pointer_index].y(); |
-} |
- |
float MockMotionEvent::GetRawX(size_t pointer_index) const { |
- return GetX(pointer_index) + raw_offset.x(); |
+ return MotionEventGeneric::GetRawX(pointer_index) + raw_offset_.x(); |
tdresser
2014/07/23 12:53:45
Ideally we'd be storing the right thing in |raw_{x
jdduke (slow)
2014/07/23 17:20:56
I'll rip it out.
|
} |
float MockMotionEvent::GetRawY(size_t pointer_index) const { |
- return GetY(pointer_index) + raw_offset.y(); |
-} |
- |
-float MockMotionEvent::GetTouchMajor(size_t pointer_index) const { |
- return touch_major; |
-} |
- |
-float MockMotionEvent::GetPressure(size_t pointer_index) const { |
- return 0; |
-} |
- |
-TimeTicks MockMotionEvent::GetEventTime() const { return time; } |
- |
-size_t MockMotionEvent::GetHistorySize() const { return 0; } |
- |
-TimeTicks MockMotionEvent::GetHistoricalEventTime( |
- size_t historical_index) const { |
- return TimeTicks(); |
-} |
- |
-float MockMotionEvent::GetHistoricalTouchMajor(size_t pointer_index, |
- size_t historical_index) const { |
- return 0; |
-} |
- |
-float MockMotionEvent::GetHistoricalX(size_t pointer_index, |
- size_t historical_index) const { |
- return 0; |
-} |
- |
-float MockMotionEvent::GetHistoricalY(size_t pointer_index, |
- size_t historical_index) const { |
- return 0; |
-} |
- |
-MotionEvent::ToolType MockMotionEvent::GetToolType(size_t pointer_index) const { |
- DCHECK_LT(pointer_index, pointer_count); |
- return tool_types[pointer_index]; |
-} |
- |
-int MockMotionEvent::GetButtonState() const { |
- return button_state; |
+ return MotionEventGeneric::GetRawY(pointer_index) + raw_offset_.y(); |
} |
scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { |
@@ -169,71 +101,79 @@ scoped_ptr<MotionEvent> MockMotionEvent::Clone() const { |
} |
scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const { |
- scoped_ptr<MockMotionEvent> cancel_event(new MockMotionEvent(*this)); |
- cancel_event->action = MotionEvent::ACTION_CANCEL; |
- return cancel_event.PassAs<MotionEvent>(); |
+ scoped_ptr<MockMotionEvent> event(new MockMotionEvent(*this)); |
+ event->set_action(MotionEvent::ACTION_CANCEL); |
+ return event.PassAs<MotionEvent>(); |
} |
void MockMotionEvent::SetId(int new_id) { |
tdresser
2014/07/23 12:53:45
Are we keeping these around just to avoid doing a
jdduke (slow)
2014/07/23 17:20:56
Done.
|
- id = new_id; |
+ MotionEventGeneric::set_id(new_id); |
} |
void MockMotionEvent::SetTime(base::TimeTicks new_time) { |
- time = new_time; |
+ MotionEventGeneric::set_event_time(new_time); |
} |
void MockMotionEvent::PressPoint(float x, float y) { |
- // Reset the pointer count if the previously released and/or cancelled pointer |
- // was the last pointer in the event. |
- if (pointer_count == 1 && (action == ACTION_UP || action == ACTION_CANCEL)) |
- pointer_count = 0; |
- |
- DCHECK_LT(pointer_count, static_cast<size_t>(MAX_POINTERS)); |
- points[pointer_count++] = gfx::PointF(x, y); |
- tool_types[pointer_count] = TOOL_TYPE_UNKNOWN; |
- action = pointer_count > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN; |
+ ResolvePoints(); |
+ PushPointer(CreatePointer(x, y)); |
+ set_action(GetPointerCount() > 1 ? ACTION_POINTER_DOWN : ACTION_DOWN); |
tdresser
2014/07/23 12:53:45
This (and below) should |set_action_index| when ap
jdduke (slow)
2014/07/23 17:20:56
Done.
|
} |
void MockMotionEvent::MovePoint(size_t index, float x, float y) { |
- DCHECK_LT(index, pointer_count); |
- points[index] = gfx::PointF(x, y); |
- tool_types[index] = TOOL_TYPE_UNKNOWN; |
- action = ACTION_MOVE; |
+ ResolvePoints(); |
+ DCHECK_LT(index, GetPointerCount()); |
+ PointerProperties& p = pointer(index); |
+ float dx = x - p.x; |
+ float dy = x - p.y; |
+ p.x = x; |
+ p.y = y; |
+ p.raw_x += dx; |
+ p.raw_y += dy; |
+ set_action(ACTION_MOVE); |
} |
void MockMotionEvent::ReleasePoint() { |
- DCHECK_GT(pointer_count, 0U); |
- if (pointer_count > 1) { |
- --pointer_count; |
- action = ACTION_POINTER_UP; |
- } else { |
- action = ACTION_UP; |
- } |
+ ResolvePoints(); |
+ DCHECK_GT(GetPointerCount(), 0U); |
+ set_action(GetPointerCount() > 1 ? ACTION_POINTER_UP : ACTION_UP); |
} |
void MockMotionEvent::CancelPoint() { |
- DCHECK_GT(pointer_count, 0U); |
- if (pointer_count > 1) |
- --pointer_count; |
- action = ACTION_CANCEL; |
+ ResolvePoints(); |
+ DCHECK_GT(GetPointerCount(), 0U); |
+ set_action(ACTION_CANCEL); |
+} |
+ |
+void MockMotionEvent::ResolvePoints() { |
+ switch (GetAction()) { |
+ case ACTION_UP: |
+ case ACTION_POINTER_UP: |
+ case ACTION_CANCEL: |
+ PopPointer(); |
+ return; |
+ default: |
+ break; |
+ } |
} |
void MockMotionEvent::SetTouchMajor(float new_touch_major) { |
- touch_major = new_touch_major; |
+ for (size_t i = 0; i < GetPointerCount(); ++i) |
+ pointer(i).touch_major = new_touch_major; |
} |
void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) { |
- raw_offset.set_x(raw_offset_x); |
- raw_offset.set_y(raw_offset_y); |
+ raw_offset_.set_x(raw_offset_x); |
+ raw_offset_.set_y(raw_offset_y); |
} |
void MockMotionEvent::SetToolType(size_t pointer_index, ToolType tool_type) { |
- DCHECK_LT(pointer_index, pointer_count); |
- tool_types[pointer_index] = tool_type; |
+ DCHECK_LT(pointer_index, GetPointerCount()); |
+ pointer(pointer_index).tool_type = tool_type; |
} |
void MockMotionEvent::SetButtonState(int new_button_state) { |
- button_state = new_button_state; |
+ MotionEventGeneric::set_button_state(new_button_state); |
} |
} // namespace test |