Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: ui/events/gestures/motion_event_aura.cc

Issue 494833003: Completed webkit radiusX, radiusY and rotationAngle handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
5 #include "ui/events/gestures/motion_event_aura.h" 8 #include "ui/events/gestures/motion_event_aura.h"
6 9
10 #include <cmath>
11
7 #include "base/logging.h" 12 #include "base/logging.h"
8 #include "ui/events/gestures/gesture_configuration.h" 13 #include "ui/events/gestures/gesture_configuration.h"
9 14
10 namespace ui { 15 namespace ui {
11 16
12 MotionEventAura::MotionEventAura() 17 MotionEventAura::MotionEventAura()
13 : pointer_count_(0), cached_action_index_(-1) { 18 : pointer_count_(0), cached_action_index_(-1) {
14 } 19 }
15 20
16 MotionEventAura::MotionEventAura(size_t pointer_count, 21 MotionEventAura::MotionEventAura(size_t pointer_count,
(...skipping 16 matching lines...) Expand all
33 const TouchEvent& touch) { 38 const TouchEvent& touch) {
34 PointData point_data; 39 PointData point_data;
35 point_data.x = touch.x(); 40 point_data.x = touch.x();
36 point_data.y = touch.y(); 41 point_data.y = touch.y();
37 point_data.raw_x = touch.root_location_f().x(); 42 point_data.raw_x = touch.root_location_f().x();
38 point_data.raw_y = touch.root_location_f().y(); 43 point_data.raw_y = touch.root_location_f().y();
39 point_data.touch_id = touch.touch_id(); 44 point_data.touch_id = touch.touch_id();
40 point_data.pressure = touch.force(); 45 point_data.pressure = touch.force();
41 point_data.source_device_id = touch.source_device_id(); 46 point_data.source_device_id = touch.source_device_id();
42 47
43 // TODO(tdresser): at some point we should start using both radii if they are 48 float radius_x = touch.radius_x();
44 // available, but for now we use the max. 49 float radius_y = touch.radius_y();
45 point_data.major_radius = std::max(touch.radius_x(), touch.radius_y()); 50 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f;
46 if (!point_data.major_radius) 51 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0";
52 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0";
53 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2)
54 << "Unexpected touch rotation angle";
55
56 if (radius_x >= radius_y) {
57 point_data.major_radius = radius_x;
58 point_data.minor_radius = radius_y;
59 point_data.orientation = rotation_angle_rad;
60 } else {
61 point_data.major_radius = radius_y;
62 point_data.minor_radius = radius_x;
63 point_data.orientation = rotation_angle_rad - M_PI_2;
64 }
65
66 if (!point_data.major_radius) {
47 point_data.major_radius = GestureConfiguration::default_radius(); 67 point_data.major_radius = GestureConfiguration::default_radius();
68 point_data.minor_radius = GestureConfiguration::default_radius();
69 point_data.orientation = 0;
70 }
71
48 return point_data; 72 return point_data;
49 } 73 }
50 74
51 void MotionEventAura::OnTouch(const TouchEvent& touch) { 75 void MotionEventAura::OnTouch(const TouchEvent& touch) {
52 switch (touch.type()) { 76 switch (touch.type()) {
53 case ET_TOUCH_PRESSED: 77 case ET_TOUCH_PRESSED:
54 AddTouch(touch); 78 AddTouch(touch);
55 break; 79 break;
56 case ET_TOUCH_RELEASED: 80 case ET_TOUCH_RELEASED:
57 case ET_TOUCH_CANCELLED: 81 case ET_TOUCH_CANCELLED:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 return active_touches_[pointer_index].raw_x; 134 return active_touches_[pointer_index].raw_x;
111 } 135 }
112 136
113 float MotionEventAura::GetRawY(size_t pointer_index) const { 137 float MotionEventAura::GetRawY(size_t pointer_index) const {
114 DCHECK_LT(pointer_index, pointer_count_); 138 DCHECK_LT(pointer_index, pointer_count_);
115 return active_touches_[pointer_index].raw_y; 139 return active_touches_[pointer_index].raw_y;
116 } 140 }
117 141
118 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { 142 float MotionEventAura::GetTouchMajor(size_t pointer_index) const {
119 DCHECK_LT(pointer_index, pointer_count_); 143 DCHECK_LT(pointer_index, pointer_count_);
120 return active_touches_[pointer_index].major_radius * 2; 144 return active_touches_[pointer_index].major_radius * 2.f;
145 }
146
147 float MotionEventAura::GetTouchMinor(size_t pointer_index) const {
148 DCHECK_LE(pointer_index, pointer_count_);
149 return active_touches_[pointer_index].minor_radius * 2.f;
150 }
151
152 float MotionEventAura::GetOrientation(size_t pointer_index) const {
153 DCHECK_LE(pointer_index, pointer_count_);
154 return active_touches_[pointer_index].orientation;
121 } 155 }
122 156
123 float MotionEventAura::GetPressure(size_t pointer_index) const { 157 float MotionEventAura::GetPressure(size_t pointer_index) const {
124 DCHECK_LT(pointer_index, pointer_count_); 158 DCHECK_LT(pointer_index, pointer_count_);
125 return active_touches_[pointer_index].pressure; 159 return active_touches_[pointer_index].pressure;
126 } 160 }
127 161
128 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { 162 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const {
129 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. 163 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128.
130 DCHECK_LT(pointer_index, pointer_count_); 164 DCHECK_LT(pointer_index, pointer_count_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 198 }
165 199
166 MotionEventAura::PointData::PointData() 200 MotionEventAura::PointData::PointData()
167 : x(0), 201 : x(0),
168 y(0), 202 y(0),
169 raw_x(0), 203 raw_x(0),
170 raw_y(0), 204 raw_y(0),
171 touch_id(0), 205 touch_id(0),
172 pressure(0), 206 pressure(0),
173 source_device_id(0), 207 source_device_id(0),
174 major_radius(0) { 208 major_radius(0),
209 minor_radius(0),
210 orientation(0) {
175 } 211 }
176 212
177 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { 213 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const {
178 DCHECK_LT(pointer_index, pointer_count_); 214 DCHECK_LT(pointer_index, pointer_count_);
179 return active_touches_[pointer_index].source_device_id; 215 return active_touches_[pointer_index].source_device_id;
180 } 216 }
181 217
182 void MotionEventAura::AddTouch(const TouchEvent& touch) { 218 void MotionEventAura::AddTouch(const TouchEvent& touch) {
183 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) 219 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT)
184 return; 220 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 size_t MotionEventAura::GetIndexFromId(int id) const { 266 size_t MotionEventAura::GetIndexFromId(int id) const {
231 for (size_t i = 0; i < pointer_count_; ++i) { 267 for (size_t i = 0; i < pointer_count_; ++i) {
232 if (active_touches_[i].touch_id == id) 268 if (active_touches_[i].touch_id == id)
233 return i; 269 return i;
234 } 270 }
235 NOTREACHED(); 271 NOTREACHED();
236 return 0; 272 return 0;
237 } 273 }
238 274
239 } // namespace ui 275 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698