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

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: Removed MotionEvent::GetHistorical{TouchMinor,Orientation} 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( 21 MotionEventAura::MotionEventAura(
(...skipping 17 matching lines...) Expand all
34 const TouchEvent& touch) { 39 const TouchEvent& touch) {
35 PointData point_data; 40 PointData point_data;
36 point_data.x = touch.x(); 41 point_data.x = touch.x();
37 point_data.y = touch.y(); 42 point_data.y = touch.y();
38 point_data.raw_x = touch.root_location_f().x(); 43 point_data.raw_x = touch.root_location_f().x();
39 point_data.raw_y = touch.root_location_f().y(); 44 point_data.raw_y = touch.root_location_f().y();
40 point_data.touch_id = touch.touch_id(); 45 point_data.touch_id = touch.touch_id();
41 point_data.pressure = touch.force(); 46 point_data.pressure = touch.force();
42 point_data.source_device_id = touch.source_device_id(); 47 point_data.source_device_id = touch.source_device_id();
43 48
44 // TODO(tdresser): at some point we should start using both radii if they are 49 float radius_x = touch.radius_x();
45 // available, but for now we use the max. 50 float radius_y = touch.radius_y();
46 point_data.major_radius = std::max(touch.radius_x(), touch.radius_y()); 51 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f;
47 if (!point_data.major_radius) 52 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0";
53 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0";
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 point_data.major_radius = radius_x;
59 point_data.minor_radius = radius_y;
60 point_data.orientation = rotation_angle_rad;
61 } else {
62 point_data.major_radius = radius_y;
63 point_data.minor_radius = radius_x;
64 point_data.orientation = rotation_angle_rad - M_PI_2;
65 }
66
67 if (!point_data.major_radius) {
48 point_data.major_radius = GestureConfiguration::default_radius(); 68 point_data.major_radius = GestureConfiguration::default_radius();
69 point_data.minor_radius = GestureConfiguration::default_radius();
70 point_data.orientation = 0;
71 }
72
49 return point_data; 73 return point_data;
50 } 74 }
51 75
52 void MotionEventAura::OnTouch(const TouchEvent& touch) { 76 void MotionEventAura::OnTouch(const TouchEvent& touch) {
53 switch (touch.type()) { 77 switch (touch.type()) {
54 case ET_TOUCH_PRESSED: 78 case ET_TOUCH_PRESSED:
55 AddTouch(touch); 79 AddTouch(touch);
56 break; 80 break;
57 case ET_TOUCH_RELEASED: 81 case ET_TOUCH_RELEASED:
58 case ET_TOUCH_CANCELLED: 82 case ET_TOUCH_CANCELLED:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return active_touches_[pointer_index].raw_x; 135 return active_touches_[pointer_index].raw_x;
112 } 136 }
113 137
114 float MotionEventAura::GetRawY(size_t pointer_index) const { 138 float MotionEventAura::GetRawY(size_t pointer_index) const {
115 DCHECK_LT(pointer_index, pointer_count_); 139 DCHECK_LT(pointer_index, pointer_count_);
116 return active_touches_[pointer_index].raw_y; 140 return active_touches_[pointer_index].raw_y;
117 } 141 }
118 142
119 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { 143 float MotionEventAura::GetTouchMajor(size_t pointer_index) const {
120 DCHECK_LT(pointer_index, pointer_count_); 144 DCHECK_LT(pointer_index, pointer_count_);
121 return active_touches_[pointer_index].major_radius * 2; 145 return active_touches_[pointer_index].major_radius * 2.f;
146 }
147
148 float MotionEventAura::GetTouchMinor(size_t pointer_index) const {
149 DCHECK_LE(pointer_index, pointer_count_);
150 return active_touches_[pointer_index].minor_radius * 2.f;
151 }
152
153 float MotionEventAura::GetOrientation(size_t pointer_index) const {
154 DCHECK_LE(pointer_index, pointer_count_);
155 return active_touches_[pointer_index].orientation;
122 } 156 }
123 157
124 float MotionEventAura::GetPressure(size_t pointer_index) const { 158 float MotionEventAura::GetPressure(size_t pointer_index) const {
125 DCHECK_LT(pointer_index, pointer_count_); 159 DCHECK_LT(pointer_index, pointer_count_);
126 return active_touches_[pointer_index].pressure; 160 return active_touches_[pointer_index].pressure;
127 } 161 }
128 162
129 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { 163 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const {
130 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. 164 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128.
131 DCHECK_LT(pointer_index, pointer_count_); 165 DCHECK_LT(pointer_index, pointer_count_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 199 }
166 200
167 MotionEventAura::PointData::PointData() 201 MotionEventAura::PointData::PointData()
168 : x(0), 202 : x(0),
169 y(0), 203 y(0),
170 raw_x(0), 204 raw_x(0),
171 raw_y(0), 205 raw_y(0),
172 touch_id(0), 206 touch_id(0),
173 pressure(0), 207 pressure(0),
174 source_device_id(0), 208 source_device_id(0),
175 major_radius(0) { 209 major_radius(0),
210 minor_radius(0),
211 orientation(0) {
176 } 212 }
177 213
178 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { 214 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const {
179 DCHECK_LT(pointer_index, pointer_count_); 215 DCHECK_LT(pointer_index, pointer_count_);
180 return active_touches_[pointer_index].source_device_id; 216 return active_touches_[pointer_index].source_device_id;
181 } 217 }
182 218
183 void MotionEventAura::AddTouch(const TouchEvent& touch) { 219 void MotionEventAura::AddTouch(const TouchEvent& touch) {
184 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) 220 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT)
185 return; 221 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 size_t MotionEventAura::GetIndexFromId(int id) const { 267 size_t MotionEventAura::GetIndexFromId(int id) const {
232 for (size_t i = 0; i < pointer_count_; ++i) { 268 for (size_t i = 0; i < pointer_count_; ++i) {
233 if (active_touches_[i].touch_id == id) 269 if (active_touches_[i].touch_id == id)
234 return i; 270 return i;
235 } 271 }
236 NOTREACHED(); 272 NOTREACHED();
237 return 0; 273 return 0;
238 } 274 }
239 275
240 } // namespace ui 276 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698