| 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 | |
| 7 | |
| 8 #include "ui/events/gestures/motion_event_aura.h" | 5 #include "ui/events/gestures/motion_event_aura.h" |
| 9 | 6 |
| 10 #include <cmath> | |
| 11 | |
| 12 #include "base/logging.h" | 7 #include "base/logging.h" |
| 13 #include "ui/events/gestures/gesture_configuration.h" | 8 #include "ui/events/gestures/gesture_configuration.h" |
| 14 | 9 |
| 15 namespace ui { | 10 namespace ui { |
| 16 | 11 |
| 17 MotionEventAura::MotionEventAura() | 12 MotionEventAura::MotionEventAura() |
| 18 : pointer_count_(0), cached_action_index_(-1) { | 13 : pointer_count_(0), cached_action_index_(-1) { |
| 19 } | 14 } |
| 20 | 15 |
| 21 MotionEventAura::MotionEventAura( | 16 MotionEventAura::MotionEventAura( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 const TouchEvent& touch) { | 34 const TouchEvent& touch) { |
| 40 PointData point_data; | 35 PointData point_data; |
| 41 point_data.x = touch.x(); | 36 point_data.x = touch.x(); |
| 42 point_data.y = touch.y(); | 37 point_data.y = touch.y(); |
| 43 point_data.raw_x = touch.root_location_f().x(); | 38 point_data.raw_x = touch.root_location_f().x(); |
| 44 point_data.raw_y = touch.root_location_f().y(); | 39 point_data.raw_y = touch.root_location_f().y(); |
| 45 point_data.touch_id = touch.touch_id(); | 40 point_data.touch_id = touch.touch_id(); |
| 46 point_data.pressure = touch.force(); | 41 point_data.pressure = touch.force(); |
| 47 point_data.source_device_id = touch.source_device_id(); | 42 point_data.source_device_id = touch.source_device_id(); |
| 48 | 43 |
| 49 float radius_x = touch.radius_x(); | 44 // TODO(tdresser): at some point we should start using both radii if they are |
| 50 float radius_y = touch.radius_y(); | 45 // available, but for now we use the max. |
| 51 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f; | 46 point_data.major_radius = std::max(touch.radius_x(), touch.radius_y()); |
| 52 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0"; | 47 if (!point_data.major_radius) |
| 53 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0"; | 48 point_data.major_radius = GestureConfiguration::default_radius(); |
| 54 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) | |
| 55 << "Unexpected touch rotation angle"; | |
| 56 | |
| 57 if (radius_x > radius_y) { | |
| 58 // The case radius_x == radius_y is omitted from here on purpose: for | |
| 59 // circles, we want to pass the angle (which could be any value in such | |
| 60 // cases but always seem to be set to zero) unchanged. | |
| 61 point_data.touch_major = 2.f * radius_x; | |
| 62 point_data.touch_minor = 2.f * radius_y; | |
| 63 point_data.orientation = rotation_angle_rad - M_PI_2; | |
| 64 } else { | |
| 65 point_data.touch_major = 2.f * radius_y; | |
| 66 point_data.touch_minor = 2.f * radius_x; | |
| 67 point_data.orientation = rotation_angle_rad; | |
| 68 } | |
| 69 | |
| 70 if (!point_data.touch_major) { | |
| 71 point_data.touch_major = 2.f * GestureConfiguration::default_radius(); | |
| 72 point_data.touch_minor = 2.f * GestureConfiguration::default_radius(); | |
| 73 point_data.orientation = 0; | |
| 74 } | |
| 75 | |
| 76 return point_data; | 49 return point_data; |
| 77 } | 50 } |
| 78 | 51 |
| 79 void MotionEventAura::OnTouch(const TouchEvent& touch) { | 52 void MotionEventAura::OnTouch(const TouchEvent& touch) { |
| 80 switch (touch.type()) { | 53 switch (touch.type()) { |
| 81 case ET_TOUCH_PRESSED: | 54 case ET_TOUCH_PRESSED: |
| 82 AddTouch(touch); | 55 AddTouch(touch); |
| 83 break; | 56 break; |
| 84 case ET_TOUCH_RELEASED: | 57 case ET_TOUCH_RELEASED: |
| 85 case ET_TOUCH_CANCELLED: | 58 case ET_TOUCH_CANCELLED: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return active_touches_[pointer_index].raw_x; | 111 return active_touches_[pointer_index].raw_x; |
| 139 } | 112 } |
| 140 | 113 |
| 141 float MotionEventAura::GetRawY(size_t pointer_index) const { | 114 float MotionEventAura::GetRawY(size_t pointer_index) const { |
| 142 DCHECK_LT(pointer_index, pointer_count_); | 115 DCHECK_LT(pointer_index, pointer_count_); |
| 143 return active_touches_[pointer_index].raw_y; | 116 return active_touches_[pointer_index].raw_y; |
| 144 } | 117 } |
| 145 | 118 |
| 146 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { | 119 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { |
| 147 DCHECK_LT(pointer_index, pointer_count_); | 120 DCHECK_LT(pointer_index, pointer_count_); |
| 148 return active_touches_[pointer_index].touch_major; | 121 return active_touches_[pointer_index].major_radius * 2; |
| 149 } | |
| 150 | |
| 151 float MotionEventAura::GetTouchMinor(size_t pointer_index) const { | |
| 152 DCHECK_LE(pointer_index, pointer_count_); | |
| 153 return active_touches_[pointer_index].touch_minor; | |
| 154 } | |
| 155 | |
| 156 float MotionEventAura::GetOrientation(size_t pointer_index) const { | |
| 157 DCHECK_LE(pointer_index, pointer_count_); | |
| 158 return active_touches_[pointer_index].orientation; | |
| 159 } | 122 } |
| 160 | 123 |
| 161 float MotionEventAura::GetPressure(size_t pointer_index) const { | 124 float MotionEventAura::GetPressure(size_t pointer_index) const { |
| 162 DCHECK_LT(pointer_index, pointer_count_); | 125 DCHECK_LT(pointer_index, pointer_count_); |
| 163 return active_touches_[pointer_index].pressure; | 126 return active_touches_[pointer_index].pressure; |
| 164 } | 127 } |
| 165 | 128 |
| 166 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { | 129 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { |
| 167 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. | 130 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. |
| 168 DCHECK_LT(pointer_index, pointer_count_); | 131 DCHECK_LT(pointer_index, pointer_count_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 165 } |
| 203 | 166 |
| 204 MotionEventAura::PointData::PointData() | 167 MotionEventAura::PointData::PointData() |
| 205 : x(0), | 168 : x(0), |
| 206 y(0), | 169 y(0), |
| 207 raw_x(0), | 170 raw_x(0), |
| 208 raw_y(0), | 171 raw_y(0), |
| 209 touch_id(0), | 172 touch_id(0), |
| 210 pressure(0), | 173 pressure(0), |
| 211 source_device_id(0), | 174 source_device_id(0), |
| 212 touch_major(0), | 175 major_radius(0) { |
| 213 touch_minor(0), | |
| 214 orientation(0) { | |
| 215 } | 176 } |
| 216 | 177 |
| 217 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { | 178 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { |
| 218 DCHECK_LT(pointer_index, pointer_count_); | 179 DCHECK_LT(pointer_index, pointer_count_); |
| 219 return active_touches_[pointer_index].source_device_id; | 180 return active_touches_[pointer_index].source_device_id; |
| 220 } | 181 } |
| 221 | 182 |
| 222 void MotionEventAura::AddTouch(const TouchEvent& touch) { | 183 void MotionEventAura::AddTouch(const TouchEvent& touch) { |
| 223 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) | 184 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) |
| 224 return; | 185 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 size_t MotionEventAura::GetIndexFromId(int id) const { | 231 size_t MotionEventAura::GetIndexFromId(int id) const { |
| 271 for (size_t i = 0; i < pointer_count_; ++i) { | 232 for (size_t i = 0; i < pointer_count_; ++i) { |
| 272 if (active_touches_[i].touch_id == id) | 233 if (active_touches_[i].touch_id == id) |
| 273 return i; | 234 return i; |
| 274 } | 235 } |
| 275 NOTREACHED(); | 236 NOTREACHED(); |
| 276 return 0; | 237 return 0; |
| 277 } | 238 } |
| 278 | 239 |
| 279 } // namespace ui | 240 } // namespace ui |
| OLD | NEW |