OLD | NEW |
---|---|
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 "content/browser/renderer_host/input/motion_event_web.h" | 8 #include "content/browser/renderer_host/input/motion_event_web.h" |
6 | 9 |
10 #include <cmath> | |
11 | |
7 #include "base/logging.h" | 12 #include "base/logging.h" |
8 #include "content/common/input/web_touch_event_traits.h" | 13 #include "content/common/input/web_touch_event_traits.h" |
9 | 14 |
10 using blink::WebInputEvent; | 15 using blink::WebInputEvent; |
11 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
12 using blink::WebTouchPoint; | 17 using blink::WebTouchPoint; |
13 | 18 |
14 namespace content { | 19 namespace content { |
15 namespace { | 20 namespace { |
16 | 21 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 return event_.touches[pointer_index].screenPosition.x; | 100 return event_.touches[pointer_index].screenPosition.x; |
96 } | 101 } |
97 | 102 |
98 float MotionEventWeb::GetRawY(size_t pointer_index) const { | 103 float MotionEventWeb::GetRawY(size_t pointer_index) const { |
99 DCHECK_LT(pointer_index, GetPointerCount()); | 104 DCHECK_LT(pointer_index, GetPointerCount()); |
100 return event_.touches[pointer_index].screenPosition.y; | 105 return event_.touches[pointer_index].screenPosition.y; |
101 } | 106 } |
102 | 107 |
103 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { | 108 float MotionEventWeb::GetTouchMajor(size_t pointer_index) const { |
104 DCHECK_LT(pointer_index, GetPointerCount()); | 109 DCHECK_LT(pointer_index, GetPointerCount()); |
105 // TODO(jdduke): We should be a bit more careful about axes here. | |
106 return 2.f * std::max(event_.touches[pointer_index].radiusX, | 110 return 2.f * std::max(event_.touches[pointer_index].radiusX, |
107 event_.touches[pointer_index].radiusY); | 111 event_.touches[pointer_index].radiusY); |
108 } | 112 } |
109 | 113 |
114 float MotionEventWeb::GetTouchMinor(size_t pointer_index) const { | |
115 DCHECK_LT(pointer_index, GetPointerCount()); | |
116 return 2.f * std::min(event_.touches[pointer_index].radiusX, | |
117 event_.touches[pointer_index].radiusY); | |
118 } | |
119 | |
120 float MotionEventWeb::GetOrientation(size_t pointer_index) const { | |
121 DCHECK_LT(pointer_index, GetPointerCount()); | |
122 | |
123 float rotation_angle_rad = event_.touches[pointer_index].rotationAngle | |
124 * M_PI / 180.f; | |
125 DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2) | |
126 << "Unexpected touch rotation angle"; | |
127 | |
128 if (event_.touches[pointer_index].radiusX | |
jdduke (slow)
2014/08/28 15:31:57
Is this correct? Consider the case where |rotation
mustaq
2014/08/28 18:21:13
I think the rotation angle is measured from vertic
mustaq
2014/08/28 21:56:02
Fixed.
| |
129 < event_.touches[pointer_index].radiusY) { | |
130 rotation_angle_rad -= (float) M_PI_2; | |
131 } | |
132 | |
133 return rotation_angle_rad; | |
134 } | |
135 | |
110 float MotionEventWeb::GetPressure(size_t pointer_index) const { | 136 float MotionEventWeb::GetPressure(size_t pointer_index) const { |
111 return 0.f; | 137 return 0.f; |
112 } | 138 } |
113 | 139 |
114 base::TimeTicks MotionEventWeb::GetEventTime() const { | 140 base::TimeTicks MotionEventWeb::GetEventTime() const { |
115 return base::TimeTicks() + | 141 return base::TimeTicks() + |
116 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * | 142 base::TimeDelta::FromMicroseconds(event_.timeStampSeconds * |
117 base::Time::kMicrosecondsPerSecond); | 143 base::Time::kMicrosecondsPerSecond); |
118 } | 144 } |
119 | 145 |
(...skipping 17 matching lines...) Expand all Loading... | |
137 WebTouchEvent cancel_event(event_); | 163 WebTouchEvent cancel_event(event_); |
138 WebTouchEventTraits::ResetTypeAndTouchStates( | 164 WebTouchEventTraits::ResetTypeAndTouchStates( |
139 blink::WebInputEvent::TouchCancel, | 165 blink::WebInputEvent::TouchCancel, |
140 // TODO(rbyers): Shouldn't we use a fresh timestamp? | 166 // TODO(rbyers): Shouldn't we use a fresh timestamp? |
141 event_.timeStampSeconds, | 167 event_.timeStampSeconds, |
142 &cancel_event); | 168 &cancel_event); |
143 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); | 169 return scoped_ptr<MotionEvent>(new MotionEventWeb(cancel_event)); |
144 } | 170 } |
145 | 171 |
146 } // namespace content | 172 } // namespace content |
OLD | NEW |