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

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

Issue 800163005: Fixed ui::TouchEvent rotation angle out-of-bound issue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « ui/events/event_unittest.cc ('k') | ui/events/gestures/motion_event_aura_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/events/gestures/motion_event_aura.h" 8 #include "ui/events/gestures/motion_event_aura.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 10 matching lines...) Expand all
21 pointer_properties.y = touch.y(); 21 pointer_properties.y = touch.y();
22 pointer_properties.raw_x = touch.root_location_f().x(); 22 pointer_properties.raw_x = touch.root_location_f().x();
23 pointer_properties.raw_y = touch.root_location_f().y(); 23 pointer_properties.raw_y = touch.root_location_f().y();
24 pointer_properties.id = touch.touch_id(); 24 pointer_properties.id = touch.touch_id();
25 pointer_properties.pressure = touch.force(); 25 pointer_properties.pressure = touch.force();
26 pointer_properties.source_device_id = touch.source_device_id(); 26 pointer_properties.source_device_id = touch.source_device_id();
27 27
28 float radius_x = touch.radius_x(); 28 float radius_x = touch.radius_x();
29 float radius_y = touch.radius_y(); 29 float radius_y = touch.radius_y();
30 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f; 30 float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f;
31
31 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0"; 32 DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0";
32 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0"; 33 DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0";
33 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) 34 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad < M_PI)
34 << "Unexpected touch rotation angle"; 35 << "Unexpected touch rotation angle";
35 36
37 // Make the angle acute to ease subsequent logic. The angle range effectively
38 // changes from [0, pi) to [0, pi/2).
39 if (rotation_angle_rad >= M_PI_2) {
40 rotation_angle_rad -= static_cast<float>(M_PI_2);
41 std::swap(radius_x, radius_y);
42 }
43
36 if (radius_x > radius_y) { 44 if (radius_x > radius_y) {
37 // The case radius_x == radius_y is omitted from here on purpose: for 45 // The case radius_x == radius_y is omitted from here on purpose: for
38 // circles, we want to pass the angle (which could be any value in such 46 // circles, we want to pass the angle (which could be any value in such
39 // cases but always seem to be set to zero) unchanged. 47 // cases but always seem to be set to zero) unchanged.
40 pointer_properties.touch_major = 2.f * radius_x; 48 pointer_properties.touch_major = 2.f * radius_x;
41 pointer_properties.touch_minor = 2.f * radius_y; 49 pointer_properties.touch_minor = 2.f * radius_y;
42 pointer_properties.orientation = rotation_angle_rad - M_PI_2; 50 pointer_properties.orientation = rotation_angle_rad - M_PI_2;
43 } else { 51 } else {
44 pointer_properties.touch_major = 2.f * radius_y; 52 pointer_properties.touch_major = 2.f * radius_y;
45 pointer_properties.touch_minor = 2.f * radius_x; 53 pointer_properties.touch_minor = 2.f * radius_x;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 191 }
184 192
185 int MotionEventAura::GetIndexFromId(int id) const { 193 int MotionEventAura::GetIndexFromId(int id) const {
186 int index = FindPointerIndexOfId(id); 194 int index = FindPointerIndexOfId(id);
187 DCHECK_GE(index, 0); 195 DCHECK_GE(index, 0);
188 DCHECK_LT(index, static_cast<int>(GetPointerCount())); 196 DCHECK_LT(index, static_cast<int>(GetPointerCount()));
189 return index; 197 return index;
190 } 198 }
191 199
192 } // namespace ui 200 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event_unittest.cc ('k') | ui/events/gestures/motion_event_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698