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.
5 #include "ui/events/gesture_detection/motion_event_generic.h"
7 #include "base/logging.h"
11 PointerProperties::PointerProperties()
13 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN
),
22 PointerProperties::PointerProperties(float x
, float y
)
24 tool_type(MotionEvent::TOOL_TYPE_UNKNOWN
),
33 MotionEventGeneric::MotionEventGeneric()
34 : action_(ACTION_CANCEL
), id_(0), action_index_(0), button_state_(0) {
37 MotionEventGeneric::MotionEventGeneric(Action action
,
38 base::TimeTicks event_time
,
39 const PointerProperties
& pointer
)
41 event_time_(event_time
),
48 MotionEventGeneric::MotionEventGeneric(const MotionEventGeneric
& other
)
49 : action_(other
.action_
),
50 event_time_(other
.event_time_
),
52 action_index_(other
.action_index_
),
53 button_state_(other
.button_state_
),
54 pointers_(other
.pointers_
) {
57 MotionEventGeneric::~MotionEventGeneric() {
60 int MotionEventGeneric::GetId() const {
64 MotionEvent::Action
MotionEventGeneric::GetAction() const {
68 int MotionEventGeneric::GetActionIndex() const {
72 size_t MotionEventGeneric::GetPointerCount() const {
73 return pointers_
->size();
76 int MotionEventGeneric::GetPointerId(size_t pointer_index
) const {
77 DCHECK_LT(pointer_index
, pointers_
->size());
78 return pointers_
[pointer_index
].id
;
81 float MotionEventGeneric::GetX(size_t pointer_index
) const {
82 DCHECK_LT(pointer_index
, pointers_
->size());
83 return pointers_
[pointer_index
].x
;
86 float MotionEventGeneric::GetY(size_t pointer_index
) const {
87 DCHECK_LT(pointer_index
, pointers_
->size());
88 return pointers_
[pointer_index
].y
;
91 float MotionEventGeneric::GetRawX(size_t pointer_index
) const {
92 DCHECK_LT(pointer_index
, pointers_
->size());
93 return pointers_
[pointer_index
].raw_x
;
96 float MotionEventGeneric::GetRawY(size_t pointer_index
) const {
97 DCHECK_LT(pointer_index
, pointers_
->size());
98 return pointers_
[pointer_index
].raw_y
;
101 float MotionEventGeneric::GetTouchMajor(size_t pointer_index
) const {
102 DCHECK_LT(pointer_index
, pointers_
->size());
103 return pointers_
[pointer_index
].touch_major
;
106 float MotionEventGeneric::GetPressure(size_t pointer_index
) const {
107 DCHECK_LT(pointer_index
, pointers_
->size());
108 return pointers_
[pointer_index
].pressure
;
111 MotionEvent::ToolType
MotionEventGeneric::GetToolType(
112 size_t pointer_index
) const {
113 DCHECK_LT(pointer_index
, pointers_
->size());
114 return pointers_
[pointer_index
].tool_type
;
117 int MotionEventGeneric::GetButtonState() const {
118 return button_state_
;
121 base::TimeTicks
MotionEventGeneric::GetEventTime() const {
125 scoped_ptr
<MotionEvent
> MotionEventGeneric::Clone() const {
126 return scoped_ptr
<MotionEvent
>(new MotionEventGeneric(*this));
129 scoped_ptr
<MotionEvent
> MotionEventGeneric::Cancel() const {
130 scoped_ptr
<MotionEventGeneric
> event(new MotionEventGeneric(*this));
131 event
->set_action(ACTION_CANCEL
);
132 return event
.PassAs
<MotionEvent
>();
135 void MotionEventGeneric::PushPointer(const PointerProperties
& pointer
) {
136 pointers_
->push_back(pointer
);
139 void MotionEventGeneric::PopPointer() {
140 DCHECK_GT(pointers_
->size(), 0U);
141 pointers_
->pop_back();