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

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( 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";
48 point_data.major_radius = GestureConfiguration::default_radius(); 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 // 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
49 return point_data; 76 return point_data;
50 } 77 }
51 78
52 void MotionEventAura::OnTouch(const TouchEvent& touch) { 79 void MotionEventAura::OnTouch(const TouchEvent& touch) {
53 switch (touch.type()) { 80 switch (touch.type()) {
54 case ET_TOUCH_PRESSED: 81 case ET_TOUCH_PRESSED:
55 AddTouch(touch); 82 AddTouch(touch);
56 break; 83 break;
57 case ET_TOUCH_RELEASED: 84 case ET_TOUCH_RELEASED:
58 case ET_TOUCH_CANCELLED: 85 case ET_TOUCH_CANCELLED:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return active_touches_[pointer_index].raw_x; 138 return active_touches_[pointer_index].raw_x;
112 } 139 }
113 140
114 float MotionEventAura::GetRawY(size_t pointer_index) const { 141 float MotionEventAura::GetRawY(size_t pointer_index) const {
115 DCHECK_LT(pointer_index, pointer_count_); 142 DCHECK_LT(pointer_index, pointer_count_);
116 return active_touches_[pointer_index].raw_y; 143 return active_touches_[pointer_index].raw_y;
117 } 144 }
118 145
119 float MotionEventAura::GetTouchMajor(size_t pointer_index) const { 146 float MotionEventAura::GetTouchMajor(size_t pointer_index) const {
120 DCHECK_LT(pointer_index, pointer_count_); 147 DCHECK_LT(pointer_index, pointer_count_);
121 return active_touches_[pointer_index].major_radius * 2; 148 return active_touches_[pointer_index].touch_major;
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;
122 } 159 }
123 160
124 float MotionEventAura::GetPressure(size_t pointer_index) const { 161 float MotionEventAura::GetPressure(size_t pointer_index) const {
125 DCHECK_LT(pointer_index, pointer_count_); 162 DCHECK_LT(pointer_index, pointer_count_);
126 return active_touches_[pointer_index].pressure; 163 return active_touches_[pointer_index].pressure;
127 } 164 }
128 165
129 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { 166 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const {
130 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. 167 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128.
131 DCHECK_LT(pointer_index, pointer_count_); 168 DCHECK_LT(pointer_index, pointer_count_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 202 }
166 203
167 MotionEventAura::PointData::PointData() 204 MotionEventAura::PointData::PointData()
168 : x(0), 205 : x(0),
169 y(0), 206 y(0),
170 raw_x(0), 207 raw_x(0),
171 raw_y(0), 208 raw_y(0),
172 touch_id(0), 209 touch_id(0),
173 pressure(0), 210 pressure(0),
174 source_device_id(0), 211 source_device_id(0),
175 major_radius(0) { 212 touch_major(0),
213 touch_minor(0),
214 orientation(0) {
176 } 215 }
177 216
178 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { 217 int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const {
179 DCHECK_LT(pointer_index, pointer_count_); 218 DCHECK_LT(pointer_index, pointer_count_);
180 return active_touches_[pointer_index].source_device_id; 219 return active_touches_[pointer_index].source_device_id;
181 } 220 }
182 221
183 void MotionEventAura::AddTouch(const TouchEvent& touch) { 222 void MotionEventAura::AddTouch(const TouchEvent& touch) {
184 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT) 223 if (pointer_count_ == MotionEvent::MAX_TOUCH_POINT_COUNT)
185 return; 224 return;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 size_t MotionEventAura::GetIndexFromId(int id) const { 270 size_t MotionEventAura::GetIndexFromId(int id) const {
232 for (size_t i = 0; i < pointer_count_; ++i) { 271 for (size_t i = 0; i < pointer_count_; ++i) {
233 if (active_touches_[i].touch_id == id) 272 if (active_touches_[i].touch_id == id)
234 return i; 273 return i;
235 } 274 }
236 NOTREACHED(); 275 NOTREACHED();
237 return 0; 276 return 0;
238 } 277 }
239 278
240 } // namespace ui 279 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gestures/motion_event_aura.h ('k') | ui/events/gestures/motion_event_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698