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

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

Issue 1417803002: Pass MotionEvent tilt angles to Blink on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flattened nested ifs, fixed a special case Created 5 years, 1 month 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
141 if (pointer.tiltY <= 0 && pointer.tiltX < 0) {
142 // Stylus is tilted to the left away from the user or straight
143 // to the left thus the orientation should be within [pi/2,pi).
144 orientation_rad += static_cast<float>(M_PI_2);
145 } else if (pointer.tiltY < 0 && pointer.tiltX >= 0) {
146 // Stylus is tilted to the right away from the user or straight away
147 // from the user thus the orientation should be within [-pi,-pi/2).
148 orientation_rad -= static_cast<float>(M_PI);
149 } else if (pointer.tiltY >= 0 && pointer.tiltX > 0) {
150 // Stylus is tilted to the right towards the user or straight
151 // to the right thus the orientation should be within [-pi/2,0).
152 orientation_rad -= static_cast<float>(M_PI_2);
153 }
154 } else if (event_.touches[pointer_index].radiusX
155 > event_.touches[pointer_index].radiusY) {
140 // The case radiusX == radiusY is omitted from here on purpose: for circles, 156 // 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 157 // we want to pass the angle (which could be any value in such cases but
142 // always seem to be set to zero) unchanged. 158 // always seems to be set to zero) unchanged.
143 rotation_angle_rad -= (float) M_PI_2; 159 orientation_rad -= static_cast<float>(M_PI_2);
144 } 160 }
145 161
146 return rotation_angle_rad; 162 return orientation_rad;
147 } 163 }
148 164
149 float MotionEventWeb::GetPressure(size_t pointer_index) const { 165 float MotionEventWeb::GetPressure(size_t pointer_index) const {
150 return 0.f; 166 return 0.f;
151 } 167 }
152 168
169 float MotionEventWeb::GetTilt(size_t pointer_index) const {
170 DCHECK_LT(pointer_index, GetPointerCount());
171
172 if (GetToolType(pointer_index) != TOOL_TYPE_STYLUS)
173 return 0.f;
174
175 const WebPointerProperties& pointer = event_.touches[pointer_index];
176
177 float tilt_x_r = sin(pointer.tiltX * M_PI / 180.f);
178 float tilt_x_z = cos(pointer.tiltX * M_PI / 180.f);
179 float tilt_y_r = sin(pointer.tiltY * M_PI / 180.f);
180 float tilt_y_z = cos(pointer.tiltY * M_PI / 180.f);
181 float r_x = tilt_x_r * tilt_y_z;
182 float r_y = tilt_y_r * tilt_x_z;
183 float r = sqrt(r_x * r_x + r_y * r_y);
184 float z = tilt_x_z * tilt_y_z;
185
186 return atan2(r, z);
187 }
188
153 base::TimeTicks MotionEventWeb::GetEventTime() const { 189 base::TimeTicks MotionEventWeb::GetEventTime() const {
154 return base::TimeTicks() + 190 return base::TimeTicks() +
155 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * 191 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *
156 base::Time::kMicrosecondsPerSecond); 192 base::Time::kMicrosecondsPerSecond);
157 } 193 }
158 194
159 ui::MotionEvent::ToolType MotionEventWeb::GetToolType( 195 ui::MotionEvent::ToolType MotionEventWeb::GetToolType(
160 size_t pointer_index) const { 196 size_t pointer_index) const {
161 DCHECK_LT(pointer_index, GetPointerCount()); 197 DCHECK_LT(pointer_index, GetPointerCount());
162 198
(...skipping 15 matching lines...) Expand all
178 214
179 int MotionEventWeb::GetButtonState() const { 215 int MotionEventWeb::GetButtonState() const {
180 return 0; 216 return 0;
181 } 217 }
182 218
183 int MotionEventWeb::GetFlags() const { 219 int MotionEventWeb::GetFlags() const {
184 return WebEventModifiersToEventFlags(event_.modifiers); 220 return WebEventModifiersToEventFlags(event_.modifiers);
185 } 221 }
186 222
187 } // namespace content 223 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698