motion_event.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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
3// found in the LICENSE file.
4
5#include "ui/events/gesture_detection/motion_event.h"
6
7#include "base/logging.h"
8
9namespace ui {
10
11size_t MotionEvent::GetHistorySize() const {
12  return 0;
13}
14
15base::TimeTicks MotionEvent::GetHistoricalEventTime(
16    size_t historical_index) const {
17  NOTIMPLEMENTED();
18  return base::TimeTicks();
19}
20
21float MotionEvent::GetHistoricalTouchMajor(size_t pointer_index,
22                                           size_t historical_index) const {
23  NOTIMPLEMENTED();
24  return 0.f;
25}
26
27float MotionEvent::GetHistoricalX(size_t pointer_index,
28                                  size_t historical_index) const {
29  NOTIMPLEMENTED();
30  return 0.f;
31}
32
33float MotionEvent::GetHistoricalY(size_t pointer_index,
34                                  size_t historical_index) const {
35  NOTIMPLEMENTED();
36  return 0.f;
37}
38
39int MotionEvent::FindPointerIndexOfId(int id) const {
40  const size_t pointer_count = GetPointerCount();
41  for (size_t i = 0; i < pointer_count; ++i) {
42    if (GetPointerId(i) == id)
43      return static_cast<int>(i);
44  }
45  return -1;
46}
47
48bool operator==(const MotionEvent& lhs, const MotionEvent& rhs) {
49  if (lhs.GetId() != rhs.GetId() || lhs.GetAction() != rhs.GetAction() ||
50      lhs.GetActionIndex() != rhs.GetActionIndex() ||
51      lhs.GetPointerCount() != rhs.GetPointerCount() ||
52      lhs.GetButtonState() != rhs.GetButtonState() ||
53      lhs.GetEventTime() != rhs.GetEventTime() ||
54      lhs.GetHistorySize() != rhs.GetHistorySize())
55    return false;
56
57  for (size_t i = 0; i < lhs.GetPointerCount(); ++i) {
58    int rhsi = rhs.FindPointerIndexOfId(lhs.GetPointerId(i));
59    if (rhsi == -1)
60      return false;
61
62    if (lhs.GetX(i) != rhs.GetX(rhsi) || lhs.GetY(i) != rhs.GetY(rhsi) ||
63        lhs.GetRawX(i) != rhs.GetRawX(rhsi) ||
64        lhs.GetRawY(i) != rhs.GetRawY(rhsi) ||
65        lhs.GetTouchMajor(i) != rhs.GetTouchMajor(rhsi) ||
66        lhs.GetPressure(i) != rhs.GetPressure(rhsi) ||
67        lhs.GetToolType(i) != rhs.GetToolType(rhsi))
68      return false;
69
70    for (size_t h = 0; h < lhs.GetHistorySize(); ++h) {
71      if (lhs.GetHistoricalX(i, h) != rhs.GetHistoricalX(rhsi, h) ||
72          lhs.GetHistoricalY(i, h) != rhs.GetHistoricalY(rhsi, h) ||
73          lhs.GetHistoricalTouchMajor(i, h) !=
74              rhs.GetHistoricalTouchMajor(rhsi, h))
75        return false;
76    }
77  }
78
79  for (size_t h = 0; h < lhs.GetHistorySize(); ++h) {
80    if (lhs.GetHistoricalEventTime(h) != rhs.GetHistoricalEventTime(h))
81      return false;
82  }
83
84  return true;
85}
86
87bool operator!=(const MotionEvent& lhs, const MotionEvent& rhs) {
88  return !(lhs == rhs);
89}
90
91}  // namespace ui
92