Chromium Code Reviews| Index: ui/events/gesture_detection/motion_event.cc |
| diff --git a/ui/events/gesture_detection/motion_event.cc b/ui/events/gesture_detection/motion_event.cc |
| index 71a6912d06fc8f31d1fc35b56f5651018fc6a394..b7775f8d27b2ca96e74a8072f0f24c50c5511995 100644 |
| --- a/ui/events/gesture_detection/motion_event.cc |
| +++ b/ui/events/gesture_detection/motion_event.cc |
| @@ -4,7 +4,11 @@ |
| #include "ui/events/gesture_detection/motion_event.h" |
| +#include <sstream> |
| + |
| #include "base/logging.h" |
| +#include "ui/events/gesture_detection/bitset_32.h" |
| +#include "ui/events/gesture_detection/motion_event_generic.h" |
| namespace ui { |
| @@ -45,49 +49,63 @@ int MotionEvent::FindPointerIndexOfId(int id) const { |
| return -1; |
| } |
| -bool operator==(const MotionEvent& lhs, const MotionEvent& rhs) { |
| - if (lhs.GetId() != rhs.GetId() || lhs.GetAction() != rhs.GetAction() || |
| - lhs.GetActionIndex() != rhs.GetActionIndex() || |
| - lhs.GetPointerCount() != rhs.GetPointerCount() || |
| - lhs.GetButtonState() != rhs.GetButtonState() || |
| - lhs.GetEventTime() != rhs.GetEventTime() || |
| - lhs.GetHistorySize() != rhs.GetHistorySize()) |
| - return false; |
| - |
| - for (size_t i = 0; i < lhs.GetPointerCount(); ++i) { |
| - int rhsi = rhs.FindPointerIndexOfId(lhs.GetPointerId(i)); |
| - if (rhsi == -1) |
| - return false; |
| - |
| - if (lhs.GetX(i) != rhs.GetX(rhsi) || lhs.GetY(i) != rhs.GetY(rhsi) || |
| - lhs.GetRawX(i) != rhs.GetRawX(rhsi) || |
| - lhs.GetRawY(i) != rhs.GetRawY(rhsi) || |
| - lhs.GetTouchMajor(i) != rhs.GetTouchMajor(rhsi) || |
| - lhs.GetTouchMinor(i) != rhs.GetTouchMinor(rhsi) || |
| - lhs.GetOrientation(i) != rhs.GetOrientation(rhsi) || |
| - lhs.GetPressure(i) != rhs.GetPressure(rhsi) || |
| - lhs.GetToolType(i) != rhs.GetToolType(rhsi)) |
| - return false; |
| - |
| - for (size_t h = 0; h < lhs.GetHistorySize(); ++h) { |
| - if (lhs.GetHistoricalX(i, h) != rhs.GetHistoricalX(rhsi, h) || |
| - lhs.GetHistoricalY(i, h) != rhs.GetHistoricalY(rhsi, h) || |
| - lhs.GetHistoricalTouchMajor(i, h) != |
| - rhs.GetHistoricalTouchMajor(rhsi, h)) |
| - return false; |
| - } |
| - } |
| - |
| - for (size_t h = 0; h < lhs.GetHistorySize(); ++h) { |
| - if (lhs.GetHistoricalEventTime(h) != rhs.GetHistoricalEventTime(h)) |
| - return false; |
| - } |
| +scoped_ptr<MotionEvent> MotionEvent::Clone() const { |
| + return MotionEventGeneric::CloneEvent(*this).PassAs<MotionEvent>(); |
| +} |
| - return true; |
| +scoped_ptr<MotionEvent> MotionEvent::Cancel() const { |
| + return MotionEventGeneric::CancelEvent(*this).PassAs<MotionEvent>(); |
| } |
| -bool operator!=(const MotionEvent& lhs, const MotionEvent& rhs) { |
| - return !(lhs == rhs); |
| +std::string MotionEvent::ToString() const { |
| + std::stringstream ss; |
| + ss << "MotionEvent {" |
| + << "\n ID: " << GetId() |
| + << "\n Action: " << GetAction() |
| + << "\n ActionIndex: " << GetActionIndex() |
| + << "\n Flags: " << GetFlags() |
| + << "\n ButtonState: " << GetButtonState() |
| + << "\n Pointers: ["; |
| + const size_t pointer_count = GetPointerCount(); |
| + const size_t history_size = GetHistorySize(); |
| + |
| + BitSet32 pointer_ids; |
| + for (size_t i = 0; i < pointer_count; ++i) { |
| + pointer_ids.mark_bit(GetPointerId(i)); |
| + |
| + // Print the pointers sorted by id. |
| + while (!pointer_ids.is_empty()) { |
| + int pi = FindPointerIndexOfId(pointer_ids.first_marked_bit()); |
| + DCHECK_GE(pi, 0); |
| + pointer_ids.clear_first_marked_bit(); |
| + ss << "{" |
| + << "\n Pos: (" << GetX(pi) << ", " << GetY(pi) << ")" |
| + << "\n RawPos: (" << GetX(pi) << ", " << GetY(pi) << ")" |
| + << "\n Size: (" << GetTouchMajor(pi) << ", " << GetTouchMinor(pi) << ")" |
| + << "\n Orientation: " << GetOrientation(pi) |
| + << "\n Pressure: " << GetOrientation(pi) |
| + << "\n Tool: " << GetToolType(pi); |
| + if (history_size) { |
| + ss << "\n History: ["; |
| + for (size_t h = 0; h < history_size; ++h) { |
| + ss << "\n { " << GetHistoricalX(pi, h) |
| + << ", " << GetHistoricalY(pi, h) |
| + << ", " << GetHistoricalTouchMajor(pi, h) |
| + << ", " << GetHistoricalEventTime(pi).ToInternalValue() |
| + << " }"; |
| + if (h + 1 < history_size) |
| + ss << ","; |
| + } |
| + ss << "\n ]"; |
| + } |
| + ss << "\n }"; |
| + if (i + 1 < pointer_count) |
| + ss << ", "; |
| + } |
|
tdresser
2014/10/20 15:19:15
This indentation looks wrong.
jdduke (slow)
2014/10/21 22:19:58
Done.
|
| + } |
| + ss << "]\n}"; |
| + |
| + return ss.str(); |
| } |
| } // namespace ui |