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

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

Issue 181833003: [Android] Out with the Android GR, in with the new unified C++ GR (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 5 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/renderer_host/input/motion_event_android.h" 8 #include "content/browser/renderer_host/input/motion_event_android.h"
9 #include "content/browser/renderer_host/input/web_input_event_util.h" 9 #include "content/browser/renderer_host/input/web_input_event_util.h"
10 #include "content/browser/renderer_host/input/web_input_event_util_posix.h" 10 #include "content/browser/renderer_host/input/web_input_event_util_posix.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 case MotionEventAndroid::ACTION_POINTER_UP: 61 case MotionEventAndroid::ACTION_POINTER_UP:
62 return is_action_pointer ? WebTouchPoint::StateReleased 62 return is_action_pointer ? WebTouchPoint::StateReleased
63 : WebTouchPoint::StateStationary; 63 : WebTouchPoint::StateStationary;
64 } 64 }
65 NOTREACHED() << "Invalid MotionEventAndroid::Action."; 65 NOTREACHED() << "Invalid MotionEventAndroid::Action.";
66 return WebTouchPoint::StateUndefined; 66 return WebTouchPoint::StateUndefined;
67 } 67 }
68 68
69 WebTouchPoint BuildWebTouchPoint(const MotionEventAndroid& event, 69 WebTouchPoint BuildWebTouchPoint(const MotionEventAndroid& event,
70 size_t pointer_index, 70 size_t pointer_index,
71 float dpi_scale) { 71 float px_to_dp) {
72 WebTouchPoint touch; 72 WebTouchPoint touch;
73 touch.id = event.GetPointerId(pointer_index); 73 touch.id = event.GetPointerId(pointer_index);
74 touch.state = ToWebTouchPointState(event.GetActionMasked(), 74 touch.state = ToWebTouchPointState(
75 pointer_index == event.GetActionIndex()); 75 event.GetAction(),
76 touch.position.x = event.GetX(pointer_index) / dpi_scale; 76 static_cast<int>(pointer_index) == event.GetActionIndex());
77 touch.position.y = event.GetY(pointer_index) / dpi_scale; 77 touch.position.x = event.GetX(pointer_index) * px_to_dp;
78 touch.position.y = event.GetY(pointer_index) * px_to_dp;
78 // TODO(joth): Raw event co-ordinates. 79 // TODO(joth): Raw event co-ordinates.
79 touch.screenPosition = touch.position; 80 touch.screenPosition = touch.position;
80 81
81 const int radius_major = 82 const int radius_major =
82 static_cast<int>(event.GetTouchMajor(pointer_index) * 0.5f / dpi_scale); 83 static_cast<int>(event.GetTouchMajor(pointer_index) * 0.5f * px_to_dp);
83 const int radius_minor = 84 const int radius_minor =
84 static_cast<int>(event.GetTouchMinor(pointer_index) * 0.5f / dpi_scale); 85 static_cast<int>(event.GetTouchMinor(pointer_index) * 0.5f * px_to_dp);
85 const float major_angle_in_radians_clockwise_from_vertical = 86 const float major_angle_in_radians_clockwise_from_vertical =
86 event.GetOrientation(); 87 event.GetOrientation();
87 88
88 float major_angle_in_degrees_clockwise_from_vertical = 0; 89 float major_angle_in_degrees_clockwise_from_vertical = 0;
89 if (!std::isnan(major_angle_in_radians_clockwise_from_vertical)) { 90 if (!std::isnan(major_angle_in_radians_clockwise_from_vertical)) {
90 major_angle_in_degrees_clockwise_from_vertical = 91 major_angle_in_degrees_clockwise_from_vertical =
91 major_angle_in_radians_clockwise_from_vertical * 180.f / M_PI; 92 major_angle_in_radians_clockwise_from_vertical * 180.f / M_PI;
92 } 93 }
93 // Android provides a major axis orientation clockwise with respect to the 94 // Android provides a major axis orientation clockwise with respect to the
94 // vertical of [-90, 90]. The proposed W3C extension specifies the angle that 95 // vertical of [-90, 90]. The proposed W3C extension specifies the angle that
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 220
220 result.type = type; 221 result.type = type;
221 result.x = x; 222 result.x = x;
222 result.y = y; 223 result.y = y;
223 result.timeStampSeconds = time_sec; 224 result.timeStampSeconds = time_sec;
224 result.sourceDevice = WebGestureEvent::Touchscreen; 225 result.sourceDevice = WebGestureEvent::Touchscreen;
225 226
226 return result; 227 return result;
227 } 228 }
228 229
229 blink::WebTouchEvent WebTouchEventBuilder::Build(jobject motion_event, 230 blink::WebTouchEvent WebTouchEventBuilder::Build(
230 float dpi_scale) { 231 const MotionEventAndroid& event,
231 DCHECK(motion_event); 232 float device_scale_factor) {
232 MotionEventAndroid event(motion_event);
233
234 blink::WebTouchEvent result; 233 blink::WebTouchEvent result;
235 234
236 result.type = ToWebInputEventType(event.GetActionMasked()); 235 result.type = ToWebInputEventType(event.GetAction());
237 DCHECK(WebInputEvent::isTouchEventType(result.type)); 236 DCHECK(WebInputEvent::isTouchEventType(result.type));
238 237
239 result.timeStampSeconds = 238 result.timeStampSeconds =
240 (event.GetEventTime() - base::TimeTicks()).InSecondsF(); 239 (event.GetEventTime() - base::TimeTicks()).InSecondsF();
241 240
242 result.touchesLength = 241 result.touchesLength =
243 std::min(event.GetPointerCount(), 242 std::min(event.GetPointerCount(),
244 static_cast<size_t>(WebTouchEvent::touchesLengthCap)); 243 static_cast<size_t>(WebTouchEvent::touchesLengthCap));
245 DCHECK_GT(result.touchesLength, 0U); 244 DCHECK_GT(result.touchesLength, 0U);
246 245
246 const float px_to_dp = 1.f / device_scale_factor;
247 for (size_t i = 0; i < result.touchesLength; ++i) 247 for (size_t i = 0; i < result.touchesLength; ++i)
248 result.touches[i] = BuildWebTouchPoint(event, i, dpi_scale); 248 result.touches[i] = BuildWebTouchPoint(event, i, px_to_dp);
249 249
250 return result; 250 return result;
251 } 251 }
252 252
253 } // namespace content 253 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/web_input_event_builders_android.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698