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 // MSVC++ requires this to be set before any other includes to get M_PI. | |
6 #define _USE_MATH_DEFINES | |
tdresser
2014/08/27 18:31:35
#include <cmath>
mustaq
2014/08/27 20:51:08
Done.
| |
7 | |
5 #include "ui/events/gestures/motion_event_aura.h" | 8 #include "ui/events/gestures/motion_event_aura.h" |
6 | 9 |
7 #include "base/logging.h" | |
tdresser
2014/08/27 18:31:35
"base/logging.h" defines DCHECK.
Include what you
mustaq
2014/08/27 20:51:08
Done.
| |
8 #include "ui/events/gestures/gesture_configuration.h" | 10 #include "ui/events/gestures/gesture_configuration.h" |
9 | 11 |
10 namespace ui { | 12 namespace ui { |
11 | 13 |
12 MotionEventAura::MotionEventAura() | 14 MotionEventAura::MotionEventAura() |
13 : pointer_count_(0), cached_action_index_(-1) { | 15 : pointer_count_(0), cached_action_index_(-1) { |
14 } | 16 } |
15 | 17 |
16 MotionEventAura::MotionEventAura(size_t pointer_count, | 18 MotionEventAura::MotionEventAura(size_t pointer_count, |
17 const base::TimeTicks& last_touch_time, | 19 const base::TimeTicks& last_touch_time, |
(...skipping 15 matching lines...) Expand all Loading... | |
33 const TouchEvent& touch) { | 35 const TouchEvent& touch) { |
34 PointData point_data; | 36 PointData point_data; |
35 point_data.x = touch.x(); | 37 point_data.x = touch.x(); |
36 point_data.y = touch.y(); | 38 point_data.y = touch.y(); |
37 point_data.raw_x = touch.root_location_f().x(); | 39 point_data.raw_x = touch.root_location_f().x(); |
38 point_data.raw_y = touch.root_location_f().y(); | 40 point_data.raw_y = touch.root_location_f().y(); |
39 point_data.touch_id = touch.touch_id(); | 41 point_data.touch_id = touch.touch_id(); |
40 point_data.pressure = touch.force(); | 42 point_data.pressure = touch.force(); |
41 point_data.source_device_id = touch.source_device_id(); | 43 point_data.source_device_id = touch.source_device_id(); |
42 | 44 |
43 // TODO(tdresser): at some point we should start using both radii if they are | 45 float radius_x = touch.radius_x(); |
44 // available, but for now we use the max. | 46 float radius_y = touch.radius_y(); |
45 point_data.major_radius = std::max(touch.radius_x(), touch.radius_y()); | 47 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f; |
46 if (!point_data.major_radius) | 48 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0"; |
49 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0"; | |
50 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) | |
51 << "Unexpected touch rotation angle"; | |
52 | |
53 if (radius_x >= radius_y) { | |
54 point_data.major_radius = radius_x; | |
55 point_data.minor_radius = radius_y; | |
56 point_data.orientation = rotation_angle_rad; | |
57 } else { | |
58 point_data.major_radius = radius_y; | |
59 point_data.minor_radius = radius_x; | |
60 point_data.orientation = rotation_angle_rad - M_PI_2; | |
61 } | |
62 | |
63 if (!point_data.major_radius) { | |
47 point_data.major_radius = GestureConfiguration::default_radius(); | 64 point_data.major_radius = GestureConfiguration::default_radius(); |
65 point_data.minor_radius = GestureConfiguration::default_radius(); | |
66 point_data.orientation = 0; | |
67 } | |
68 | |
48 return point_data; | 69 return point_data; |
49 } | 70 } |
50 | 71 |
51 void MotionEventAura::OnTouch(const TouchEvent& touch) { | 72 void MotionEventAura::OnTouch(const TouchEvent& touch) { |
52 switch (touch.type()) { | 73 switch (touch.type()) { |
53 case ET_TOUCH_PRESSED: | 74 case ET_TOUCH_PRESSED: |
54 AddTouch(touch); | 75 AddTouch(touch); |
55 break; | 76 break; |
56 case ET_TOUCH_RELEASED: | 77 case ET_TOUCH_RELEASED: |
57 case ET_TOUCH_CANCELLED: | 78 case ET_TOUCH_CANCELLED: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return active_touches_[pointer_index].raw_x; | 131 return active_touches_[pointer_index].raw_x; |
111 } | 132 } |
112 | 133 |
113 float MotionEventAura::GetRawY(size_t pointer_index) const { | 134 float MotionEventAura::GetRawY(size_t pointer_index) const { |
114 DCHECK_LT(pointer_index, pointer_count_); | 135 DCHECK_LT(pointer_index, pointer_count_); |
115 return active_touches_[pointer_index].raw_y; | 136 return active_touches_[pointer_index].raw_y; |
116 } | 137 } |
117 | 138 |
118 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { | 139 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { |
119 DCHECK_LT(pointer_index, pointer_count_); | 140 DCHECK_LT(pointer_index, pointer_count_); |
120 return active_touches_[pointer_index].major_radius * 2; | 141 return active_touches_[pointer_index].major_radius * 2.f; |
142 } | |
143 | |
144 float MotionEventAura::GetTouchMinor(size_t pointer_index) const { | |
145 DCHECK_LE(pointer_index, pointer_count_); | |
146 return active_touches_[pointer_index].minor_radius * 2.f; | |
147 } | |
148 | |
149 float MotionEventAura::GetOrientation(size_t pointer_index) const { | |
150 DCHECK_LE(pointer_index, pointer_count_); | |
151 return active_touches_[pointer_index].orientation; | |
121 } | 152 } |
122 | 153 |
123 float MotionEventAura::GetPressure(size_t pointer_index) const { | 154 float MotionEventAura::GetPressure(size_t pointer_index) const { |
124 DCHECK_LT(pointer_index, pointer_count_); | 155 DCHECK_LT(pointer_index, pointer_count_); |
125 return active_touches_[pointer_index].pressure; | 156 return active_touches_[pointer_index].pressure; |
126 } | 157 } |
127 | 158 |
128 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { | 159 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { |
129 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. | 160 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. |
130 DCHECK_LT(pointer_index, pointer_count_); | 161 DCHECK_LT(pointer_index, pointer_count_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 } | 195 } |
165 | 196 |
166 MotionEventAura::PointData::PointData() | 197 MotionEventAura::PointData::PointData() |
167 : x(0), | 198 : x(0), |
168 y(0), | 199 y(0), |
169 raw_x(0), | 200 raw_x(0), |
170 raw_y(0), | 201 raw_y(0), |
171 touch_id(0), | 202 touch_id(0), |
172 pressure(0), | 203 pressure(0), |
173 source_device_id(0), | 204 source_device_id(0), |
174 major_radius(0) { | 205 major_radius(0), |
206 minor_radius(0), | |
207 orientation(0) { | |
175 } | 208 } |
176 | 209 |
177 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { | 210 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { |
178 DCHECK_LT(pointer_index, pointer_count_); | 211 DCHECK_LT(pointer_index, pointer_count_); |
179 return active_touches_[pointer_index].source_device_id; | 212 return active_touches_[pointer_index].source_device_id; |
180 } | 213 } |
181 | 214 |
182 void MotionEventAura::AddTouch(const TouchEvent& touch) { | 215 void MotionEventAura::AddTouch(const TouchEvent& touch) { |
183 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) | 216 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) |
184 return; | 217 return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 size_t MotionEventAura::GetIndexFromId(int id) const { | 263 size_t MotionEventAura::GetIndexFromId(int id) const { |
231 for (size_t i = 0; i < pointer_count_; ++i) { | 264 for (size_t i = 0; i < pointer_count_; ++i) { |
232 if (active_touches_[i].touch_id == id) | 265 if (active_touches_[i].touch_id == id) |
233 return i; | 266 return i; |
234 } | 267 } |
235 NOTREACHED(); | 268 NOTREACHED(); |
236 return 0; | 269 return 0; |
237 } | 270 } |
238 | 271 |
239 } // namespace ui | 272 } // namespace ui |
OLD | NEW |