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

Side by Side Diff: content/browser/renderer_host/input/motion_event_web.cc

Issue 1187273004: Pass MotionEvent tilt angles to Blink on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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. 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 "content/browser/renderer_host/input/motion_event_web.h" 8 #include "content/browser/renderer_host/input/motion_event_web.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const { 124 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const {
125 DCHECK_LT(pointer_index, GetPointerCount()); 125 DCHECK_LT(pointer_index, GetPointerCount());
126 return 2.f * std::min(event_.touches[pointer_index].radiusX, 126 return 2.f * std::min(event_.touches[pointer_index].radiusX,
127 event_.touches[pointer_index].radiusY); 127 event_.touches[pointer_index].radiusY);
128 } 128 }
129 129
130 float MotionEventWeb::GetOrientation(size_t pointer_index) const { 130 float MotionEventWeb::GetOrientation(size_t pointer_index) const {
131 DCHECK_LT(pointer_index, GetPointerCount()); 131 DCHECK_LT(pointer_index, GetPointerCount());
132 132
133 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle 133 float orientation_rad = event_.touches[pointer_index].rotationAngle
134 * M_PI / 180.f; 134 * M_PI / 180.f;
135 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) 135 DCHECK(0 <= orientation_rad && orientation_rad <= M_PI_2)
136 << "Unexpected touch rotation angle"; 136 << "Unexpected touch rotation angle";
137 137
138 if (event_.touches[pointer_index].radiusX 138 if (GetToolType(pointer_index) == TOOL_TYPE_STYLUS) {
139 > event_.touches[pointer_index].radiusY) { 139 const WebPointerProperties& pointer = event_.touches[pointer_index];
140
jdduke (slow) 2015/08/12 17:00:12 I think we'll want some basic test coverage for th
141 if (pointer.tiltY < 0) {
142 if (pointer.tiltX < 0)
143 orientation_rad += M_PI_2;
144 else
145 orientation_rad -= M_PI;
146 } else {
147 if (pointer.tiltX > 0)
148 orientation_rad -= M_PI_2;
149 }
150 } else if (event_.touches[pointer_index].radiusX
151 > event_.touches[pointer_index].radiusY) {
140 // The case radiusX == radiusY is omitted from here on purpose: for circles, 152 // The case radiusX == radiusY is omitted from here on purpose: for circles,
141 // we want to pass the angle (which could be any value in such cases but 153 // we want to pass the angle (which could be any value in such cases but
142 // always seem to be set to zero) unchanged. 154 // always seem to be set to zero) unchanged.
143 rotation_angle_rad -= (float) M_PI_2; 155 orientation_rad -= (float) M_PI_2;
144 } 156 }
145 157
146 return rotation_angle_rad; 158 return orientation_rad;
147 } 159 }
148 160
149 float MotionEventWeb::GetPressure(size_t pointer_index) const { 161 float MotionEventWeb::GetPressure(size_t pointer_index) const {
150 return 0.f; 162 return 0.f;
151 } 163 }
152 164
165 float MotionEventWeb::GetTilt(size_t pointer_index) const {
166 DCHECK_LT(pointer_index, GetPointerCount());
167
168 if (GetToolType(pointer_index) != TOOL_TYPE_STYLUS)
169 return 0.f;
170
jdduke (slow) 2015/08/12 17:00:13 Same here, a few basic test cases would be nice. W
171 const WebPointerProperties& pointer = event_.touches[pointer_index];
172
173 float tilt_x_r = sin(pointer.tiltX * M_PI / 180.f);
174 float tilt_x_z = cos(pointer.tiltX * M_PI / 180.f);
175 float tilt_y_r = sin(pointer.tiltY * M_PI / 180.f);
176 float tilt_y_z = cos(pointer.tiltY * M_PI / 180.f);
177 float r_x = tilt_x_r * tilt_y_z;
178 float r_y = tilt_y_r * tilt_x_z;
179 float r = sqrt(r_x * r_x + r_y * r_y);
180 float z = tilt_x_z * tilt_y_z;
181
182 return atan2(r, z);
183 }
184
153 base::TimeTicks MotionEventWeb::GetEventTime() const { 185 base::TimeTicks MotionEventWeb::GetEventTime() const {
154 return base::TimeTicks() + 186 return base::TimeTicks() +
155 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * 187 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
156 base::Time::kMicrosecondsPerSecond); 188 base::Time::kMicrosecondsPerSecond);
157 } 189 }
158 190
159 ui::MotionEvent::ToolType MotionEventWeb::GetToolType( 191 ui::MotionEvent::ToolType MotionEventWeb::GetToolType(
160 size_t pointer_index) const { 192 size_t pointer_index) const {
161 DCHECK_LT(pointer_index, GetPointerCount()); 193 DCHECK_LT(pointer_index, GetPointerCount());
162 194
(...skipping 16 matching lines...) Expand all
179 211
180 int MotionEventWeb::GetButtonState() const { 212 int MotionEventWeb::GetButtonState() const {
181 return 0; 213 return 0;
182 } 214 }
183 215
184 int MotionEventWeb::GetFlags() const { 216 int MotionEventWeb::GetFlags() const {
185 return WebEventModifiersToEventFlags(event_.modifiers); 217 return WebEventModifiersToEventFlags(event_.modifiers);
186 } 218 }
187 219
188 } // namespace content 220 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698