Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/gesture_detection/motion_event.h" | 5 #include "ui/events/gesture_detection/motion_event.h" |
| 6 | 6 |
| 7 #include <sstream> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/events/gesture_detection/bitset_32.h" | |
| 11 #include "ui/events/gesture_detection/motion_event_generic.h" | |
| 8 | 12 |
| 9 namespace ui { | 13 namespace ui { |
| 10 | 14 |
| 11 size_t MotionEvent::GetHistorySize() const { | 15 size_t MotionEvent::GetHistorySize() const { |
| 12 return 0; | 16 return 0; |
| 13 } | 17 } |
| 14 | 18 |
| 15 base::TimeTicks MotionEvent::GetHistoricalEventTime( | 19 base::TimeTicks MotionEvent::GetHistoricalEventTime( |
| 16 size_t historical_index) const { | 20 size_t historical_index) const { |
| 17 NOTIMPLEMENTED(); | 21 NOTIMPLEMENTED(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 38 | 42 |
| 39 int MotionEvent::FindPointerIndexOfId(int id) const { | 43 int MotionEvent::FindPointerIndexOfId(int id) const { |
| 40 const size_t pointer_count = GetPointerCount(); | 44 const size_t pointer_count = GetPointerCount(); |
| 41 for (size_t i = 0; i < pointer_count; ++i) { | 45 for (size_t i = 0; i < pointer_count; ++i) { |
| 42 if (GetPointerId(i) == id) | 46 if (GetPointerId(i) == id) |
| 43 return static_cast<int>(i); | 47 return static_cast<int>(i); |
| 44 } | 48 } |
| 45 return -1; | 49 return -1; |
| 46 } | 50 } |
| 47 | 51 |
| 48 bool operator==(const MotionEvent& lhs, const MotionEvent& rhs) { | 52 scoped_ptr<MotionEvent> MotionEvent::Clone() const { |
| 49 if (lhs.GetId() != rhs.GetId() || lhs.GetAction() != rhs.GetAction() || | 53 return MotionEventGeneric::CloneEvent(*this).PassAs<MotionEvent>(); |
| 50 lhs.GetActionIndex() != rhs.GetActionIndex() || | 54 } |
| 51 lhs.GetPointerCount() != rhs.GetPointerCount() || | |
| 52 lhs.GetButtonState() != rhs.GetButtonState() || | |
| 53 lhs.GetEventTime() != rhs.GetEventTime() || | |
| 54 lhs.GetHistorySize() != rhs.GetHistorySize()) | |
| 55 return false; | |
| 56 | 55 |
| 57 for (size_t i = 0; i < lhs.GetPointerCount(); ++i) { | 56 scoped_ptr<MotionEvent> MotionEvent::Cancel() const { |
| 58 int rhsi = rhs.FindPointerIndexOfId(lhs.GetPointerId(i)); | 57 return MotionEventGeneric::CancelEvent(*this).PassAs<MotionEvent>(); |
| 59 if (rhsi == -1) | 58 } |
| 60 return false; | |
| 61 | 59 |
| 62 if (lhs.GetX(i) != rhs.GetX(rhsi) || lhs.GetY(i) != rhs.GetY(rhsi) || | 60 std::string MotionEvent::ToString() const { |
| 63 lhs.GetRawX(i) != rhs.GetRawX(rhsi) || | 61 std::stringstream ss; |
| 64 lhs.GetRawY(i) != rhs.GetRawY(rhsi) || | 62 ss << "MotionEvent {" |
| 65 lhs.GetTouchMajor(i) != rhs.GetTouchMajor(rhsi) || | 63 << "\n ID: " << GetId() |
| 66 lhs.GetTouchMinor(i) != rhs.GetTouchMinor(rhsi) || | 64 << "\n Action: " << GetAction() |
| 67 lhs.GetOrientation(i) != rhs.GetOrientation(rhsi) || | 65 << "\n ActionIndex: " << GetActionIndex() |
| 68 lhs.GetPressure(i) != rhs.GetPressure(rhsi) || | 66 << "\n Flags: " << GetFlags() |
| 69 lhs.GetToolType(i) != rhs.GetToolType(rhsi)) | 67 << "\n ButtonState: " << GetButtonState() |
| 70 return false; | 68 << "\n Pointers: ["; |
| 69 const size_t pointer_count = GetPointerCount(); | |
| 70 const size_t history_size = GetHistorySize(); | |
| 71 | 71 |
| 72 for (size_t h = 0; h < lhs.GetHistorySize(); ++h) { | 72 BitSet32 pointer_ids; |
| 73 if (lhs.GetHistoricalX(i, h) != rhs.GetHistoricalX(rhsi, h) || | 73 for (size_t i = 0; i < pointer_count; ++i) { |
| 74 lhs.GetHistoricalY(i, h) != rhs.GetHistoricalY(rhsi, h) || | 74 pointer_ids.mark_bit(GetPointerId(i)); |
| 75 lhs.GetHistoricalTouchMajor(i, h) != | 75 |
| 76 rhs.GetHistoricalTouchMajor(rhsi, h)) | 76 // Print the pointers sorted by id. |
| 77 return false; | 77 while (!pointer_ids.is_empty()) { |
| 78 int pi = FindPointerIndexOfId(pointer_ids.first_marked_bit()); | |
| 79 DCHECK_GE(pi, 0); | |
| 80 pointer_ids.clear_first_marked_bit(); | |
| 81 ss << "{" | |
| 82 << "\n Pos: (" << GetX(pi) << ", " << GetY(pi) << ")" | |
| 83 << "\n RawPos: (" << GetX(pi) << ", " << GetY(pi) << ")" | |
| 84 << "\n Size: (" << GetTouchMajor(pi) << ", " << GetTouchMinor(pi) << ")" | |
| 85 << "\n Orientation: " << GetOrientation(pi) | |
| 86 << "\n Pressure: " << GetOrientation(pi) | |
| 87 << "\n Tool: " << GetToolType(pi); | |
| 88 if (history_size) { | |
| 89 ss << "\n History: ["; | |
| 90 for (size_t h = 0; h < history_size; ++h) { | |
| 91 ss << "\n { " << GetHistoricalX(pi, h) | |
| 92 << ", " << GetHistoricalY(pi, h) | |
| 93 << ", " << GetHistoricalTouchMajor(pi, h) | |
| 94 << ", " << GetHistoricalEventTime(pi).ToInternalValue() | |
| 95 << " }"; | |
| 96 if (h + 1 < history_size) | |
| 97 ss << ","; | |
| 98 } | |
| 99 ss << "\n ]"; | |
| 100 } | |
| 101 ss << "\n }"; | |
| 102 if (i + 1 < pointer_count) | |
| 103 ss << ", "; | |
| 78 } | 104 } |
|
tdresser
2014/10/20 15:19:15
This indentation looks wrong.
jdduke (slow)
2014/10/21 22:19:58
Done.
| |
| 79 } | 105 } |
| 106 ss << "]\n}"; | |
| 80 | 107 |
| 81 for (size_t h = 0; h < lhs.GetHistorySize(); ++h) { | 108 return ss.str(); |
| 82 if (lhs.GetHistoricalEventTime(h) != rhs.GetHistoricalEventTime(h)) | |
| 83 return false; | |
| 84 } | |
| 85 | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 bool operator!=(const MotionEvent& lhs, const MotionEvent& rhs) { | |
| 90 return !(lhs == rhs); | |
| 91 } | 109 } |
| 92 | 110 |
| 93 } // namespace ui | 111 } // namespace ui |
| OLD | NEW |