motion_event.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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.GetTouchMinor(i) != rhs.GetTouchMinor(rhsi) ||
67        lhs.GetOrientation(i) != rhs.GetOrientation(rhsi) ||
68        lhs.GetPressure(i) != rhs.GetPressure(rhsi) ||
69        lhs.GetToolType(i) != rhs.GetToolType(rhsi))
70      return false;
71
72    for (size_t h = 0; h < lhs.GetHistorySize(); ++h) {
73      if (lhs.GetHistoricalX(i, h) != rhs.GetHistoricalX(rhsi, h) ||
74          lhs.GetHistoricalY(i, h) != rhs.GetHistoricalY(rhsi, h) ||
75          lhs.GetHistoricalTouchMajor(i, h) !=
76              rhs.GetHistoricalTouchMajor(rhsi, h))
77        return false;
78    }
79  }
80
81  for (size_t h = 0; h < lhs.GetHistorySize(); ++h) {
82    if (lhs.GetHistoricalEventTime(h) != rhs.GetHistoricalEventTime(h))
83      return false;
84  }
85
86  return true;
87}
88
89bool operator!=(const MotionEvent& lhs, const MotionEvent& rhs) {
90  return !(lhs == rhs);
91}
92
93}  // namespace ui
94