Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1116)

Unified Diff: ui/events/test/motion_event_test_utils.cc

Issue 1287103004: Sync ui/events to chromium @ https://codereview.chromium.org/1210203002 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/test/motion_event_test_utils.h ('k') | ui/events/test/test_event_target.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/test/motion_event_test_utils.cc
diff --git a/ui/events/test/mock_motion_event.cc b/ui/events/test/motion_event_test_utils.cc
similarity index 54%
rename from ui/events/test/mock_motion_event.cc
rename to ui/events/test/motion_event_test_utils.cc
index f3de1ddceee8408c8d96a0a43824e0537316f7f0..0a3f80d26efbee7a552588367b416f4238a070e2 100644
--- a/ui/events/test/mock_motion_event.cc
+++ b/ui/events/test/motion_event_test_utils.cc
@@ -2,9 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ui/events/test/mock_motion_event.h"
+#include "ui/events/test/motion_event_test_utils.h"
+
+#include <sstream>
#include "base/logging.h"
+#include "ui/events/base_event_utils.h"
+#include "ui/events/gesture_detection/bitset_32.h"
+#include "ui/events/gesture_detection/motion_event.h"
using base::TimeTicks;
@@ -19,13 +24,11 @@ PointerProperties CreatePointer() {
}
PointerProperties CreatePointer(float x, float y, int id) {
- PointerProperties pointer(x, y);
- pointer.touch_major = MockMotionEvent::TOUCH_MAJOR;
+ PointerProperties pointer(x, y, MockMotionEvent::TOUCH_MAJOR);
pointer.id = id;
return pointer;
}
-
} // namespace
MockMotionEvent::MockMotionEvent()
@@ -75,6 +78,7 @@ MockMotionEvent::MockMotionEvent(Action action,
const std::vector<gfx::PointF>& positions) {
set_action(action);
set_event_time(time);
+ set_unique_event_id(ui::GetNextTouchEventId());
if (action == ACTION_POINTER_UP || action == ACTION_POINTER_DOWN)
set_action_index(static_cast<int>(positions.size()) - 1);
for (size_t i = 0; i < positions.size(); ++i)
@@ -85,20 +89,11 @@ MockMotionEvent::MockMotionEvent(const MockMotionEvent& other)
: MotionEventGeneric(other) {
}
-MockMotionEvent::~MockMotionEvent() {}
-
-scoped_ptr<MotionEvent> MockMotionEvent::Clone() const {
- return scoped_ptr<MotionEvent>(new MockMotionEvent(*this));
-}
-
-scoped_ptr<MotionEvent> MockMotionEvent::Cancel() const {
- scoped_ptr<MockMotionEvent> event(new MockMotionEvent(*this));
- event->set_action(MotionEvent::ACTION_CANCEL);
- return event.Pass();
+MockMotionEvent::~MockMotionEvent() {
}
-void MockMotionEvent::PressPoint(float x, float y) {
- ResolvePointers();
+MockMotionEvent& MockMotionEvent::PressPoint(float x, float y) {
+ UpdatePointersAndID();
PushPointer(x, y);
if (GetPointerCount() > 1) {
set_action_index(static_cast<int>(GetPointerCount()) - 1);
@@ -106,10 +101,11 @@ void MockMotionEvent::PressPoint(float x, float y) {
} else {
set_action(ACTION_DOWN);
}
+ return *this;
}
-void MockMotionEvent::MovePoint(size_t index, float x, float y) {
- ResolvePointers();
+MockMotionEvent& MockMotionEvent::MovePoint(size_t index, float x, float y) {
+ UpdatePointersAndID();
DCHECK_LT(index, GetPointerCount());
PointerProperties& p = pointer(index);
float dx = x - p.x;
@@ -119,10 +115,11 @@ void MockMotionEvent::MovePoint(size_t index, float x, float y) {
p.raw_x += dx;
p.raw_y += dy;
set_action(ACTION_MOVE);
+ return *this;
}
-void MockMotionEvent::ReleasePoint() {
- ResolvePointers();
+MockMotionEvent& MockMotionEvent::ReleasePoint() {
+ UpdatePointersAndID();
DCHECK_GT(GetPointerCount(), 0U);
if (GetPointerCount() > 1) {
set_action_index(static_cast<int>(GetPointerCount()) - 1);
@@ -130,29 +127,36 @@ void MockMotionEvent::ReleasePoint() {
} else {
set_action(ACTION_UP);
}
+ return *this;
}
-void MockMotionEvent::CancelPoint() {
- ResolvePointers();
+MockMotionEvent& MockMotionEvent::CancelPoint() {
+ UpdatePointersAndID();
DCHECK_GT(GetPointerCount(), 0U);
set_action(ACTION_CANCEL);
+ return *this;
}
-void MockMotionEvent::SetTouchMajor(float new_touch_major) {
+MockMotionEvent& MockMotionEvent::SetTouchMajor(float new_touch_major) {
for (size_t i = 0; i < GetPointerCount(); ++i)
pointer(i).touch_major = new_touch_major;
+ return *this;
}
-void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
+MockMotionEvent& MockMotionEvent::SetRawOffset(float raw_offset_x,
+ float raw_offset_y) {
for (size_t i = 0; i < GetPointerCount(); ++i) {
pointer(i).raw_x = pointer(i).x + raw_offset_x;
pointer(i).raw_y = pointer(i).y + raw_offset_y;
}
+ return *this;
}
-void MockMotionEvent::SetToolType(size_t pointer_index, ToolType tool_type) {
+MockMotionEvent& MockMotionEvent::SetToolType(size_t pointer_index,
+ ToolType tool_type) {
DCHECK_LT(pointer_index, GetPointerCount());
pointer(pointer_index).tool_type = tool_type;
+ return *this;
}
void MockMotionEvent::PushPointer(float x, float y) {
@@ -160,8 +164,9 @@ void MockMotionEvent::PushPointer(float x, float y) {
CreatePointer(x, y, static_cast<int>(GetPointerCount())));
}
-void MockMotionEvent::ResolvePointers() {
+void MockMotionEvent::UpdatePointersAndID() {
set_action_index(-1);
+ set_unique_event_id(ui::GetNextTouchEventId());
switch (GetAction()) {
case ACTION_UP:
case ACTION_POINTER_UP:
@@ -173,5 +178,63 @@ void MockMotionEvent::ResolvePointers() {
}
}
+MockMotionEvent& MockMotionEvent::SetPrimaryPointerId(int id) {
+ DCHECK_GT(GetPointerCount(), 0U);
+ pointer(0).id = id;
+ return *this;
+}
+
+std::string ToString(const MotionEvent& event) {
+ std::stringstream ss;
+ ss << "MotionEvent {"
+ << "\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();
+
+ BitSet32 pointer_ids;
+ for (size_t i = 0; i < pointer_count; ++i) {
+ pointer_ids.mark_bit(event.GetPointerId(i));
+
+ // Print the pointers sorted by id.
+ while (!pointer_ids.is_empty()) {
+ int pi = event.FindPointerIndexOfId(pointer_ids.first_marked_bit());
+ DCHECK_GE(pi, 0);
+ pointer_ids.clear_first_marked_bit();
+ ss << "{"
+ << "\n PointerId: (" << event.GetPointerId(pi) << ")"
+ << "\n Pos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
+ << "\n RawPos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
+ << "\n Size: (" << event.GetTouchMajor(pi) << ", "
+ << event.GetTouchMinor(pi) << ")"
+ << "\n Orientation: " << event.GetOrientation(pi)
+ << "\n Pressure: " << event.GetPressure(pi)
+ << "\n Tool: " << event.GetToolType(pi);
+ if (history_size) {
+ ss << "\n History: [";
+ for (size_t h = 0; h < history_size; ++h) {
+ ss << "\n { " << event.GetHistoricalX(pi, h) << ", "
+ << event.GetHistoricalY(pi, h) << ", "
+ << event.GetHistoricalTouchMajor(pi, h) << ", "
+ << event.GetHistoricalEventTime(pi).ToInternalValue() << " }";
+ if (h + 1 < history_size)
+ ss << ",";
+ }
+ ss << "\n ]";
+ }
+ ss << "\n }";
+ if (i + 1 < pointer_count)
+ ss << ", ";
+ }
+ ss << "]\n}";
+ }
+
+ return ss.str();
+}
+
} // namespace test
} // namespace ui
« no previous file with comments | « ui/events/test/motion_event_test_utils.h ('k') | ui/events/test/test_event_target.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698