OLD | NEW |
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/common/input/synthetic_web_input_event_builders.h" | 5 #include "content/common/input/synthetic_web_input_event_builders.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/input/web_touch_event_traits.h" | 8 #include "content/common/input/web_touch_event_traits.h" |
9 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
10 | 10 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 for (unsigned int i = 0; i < touchesLength; ++i) { | 156 for (unsigned int i = 0; i < touchesLength; ++i) { |
157 if (touches[i].state == WebTouchPoint::StateReleased) | 157 if (touches[i].state == WebTouchPoint::StateReleased) |
158 continue; | 158 continue; |
159 | 159 |
160 touches[point] = touches[i]; | 160 touches[point] = touches[i]; |
161 touches[point].state = WebTouchPoint::StateStationary; | 161 touches[point].state = WebTouchPoint::StateStationary; |
162 ++point; | 162 ++point; |
163 } | 163 } |
164 touchesLength = point; | 164 touchesLength = point; |
165 type = WebInputEvent::Undefined; | 165 type = WebInputEvent::Undefined; |
| 166 causesScrollingIfUncanceled = false; |
166 } | 167 } |
167 | 168 |
168 int SyntheticWebTouchEvent::PressPoint(float x, float y) { | 169 int SyntheticWebTouchEvent::PressPoint(float x, float y) { |
169 if (touchesLength == touchesLengthCap) | 170 if (touchesLength == touchesLengthCap) |
170 return -1; | 171 return -1; |
171 WebTouchPoint& point = touches[touchesLength]; | 172 WebTouchPoint& point = touches[touchesLength]; |
172 point.id = touchesLength; | 173 point.id = touchesLength; |
173 point.position.x = point.screenPosition.x = x; | 174 point.position.x = point.screenPosition.x = x; |
174 point.position.y = point.screenPosition.y = y; | 175 point.position.y = point.screenPosition.y = y; |
175 point.state = WebTouchPoint::StatePressed; | 176 point.state = WebTouchPoint::StatePressed; |
176 point.radiusX = point.radiusY = 1.f; | 177 point.radiusX = point.radiusY = 1.f; |
177 ++touchesLength; | 178 ++touchesLength; |
178 WebTouchEventTraits::ResetType( | 179 WebTouchEventTraits::ResetType( |
179 WebInputEvent::TouchStart, timeStampSeconds, this); | 180 WebInputEvent::TouchStart, timeStampSeconds, this); |
180 return point.id; | 181 return point.id; |
181 } | 182 } |
182 | 183 |
183 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { | 184 void SyntheticWebTouchEvent::MovePoint(int index, float x, float y) { |
184 CHECK(index >= 0 && index < touchesLengthCap); | 185 CHECK_GE(index, 0); |
| 186 CHECK_LT(index, touchesLengthCap); |
| 187 // Always set this bit to avoid otherwise unexpected touchmove suppression. |
| 188 // The caller can opt-out explicitly, if necessary. |
| 189 causesScrollingIfUncanceled = true; |
185 WebTouchPoint& point = touches[index]; | 190 WebTouchPoint& point = touches[index]; |
186 point.position.x = point.screenPosition.x = x; | 191 point.position.x = point.screenPosition.x = x; |
187 point.position.y = point.screenPosition.y = y; | 192 point.position.y = point.screenPosition.y = y; |
188 touches[index].state = WebTouchPoint::StateMoved; | 193 touches[index].state = WebTouchPoint::StateMoved; |
189 WebTouchEventTraits::ResetType( | 194 WebTouchEventTraits::ResetType( |
190 WebInputEvent::TouchMove, timeStampSeconds, this); | 195 WebInputEvent::TouchMove, timeStampSeconds, this); |
191 } | 196 } |
192 | 197 |
193 void SyntheticWebTouchEvent::ReleasePoint(int index) { | 198 void SyntheticWebTouchEvent::ReleasePoint(int index) { |
194 CHECK(index >= 0 && index < touchesLengthCap); | 199 CHECK_GE(index, 0); |
| 200 CHECK_LT(index, touchesLengthCap); |
195 touches[index].state = WebTouchPoint::StateReleased; | 201 touches[index].state = WebTouchPoint::StateReleased; |
196 WebTouchEventTraits::ResetType( | 202 WebTouchEventTraits::ResetType( |
197 WebInputEvent::TouchEnd, timeStampSeconds, this); | 203 WebInputEvent::TouchEnd, timeStampSeconds, this); |
198 } | 204 } |
199 | 205 |
200 void SyntheticWebTouchEvent::CancelPoint(int index) { | 206 void SyntheticWebTouchEvent::CancelPoint(int index) { |
201 CHECK(index >= 0 && index < touchesLengthCap); | 207 CHECK_GE(index, 0); |
| 208 CHECK_LT(index, touchesLengthCap); |
202 touches[index].state = WebTouchPoint::StateCancelled; | 209 touches[index].state = WebTouchPoint::StateCancelled; |
203 WebTouchEventTraits::ResetType( | 210 WebTouchEventTraits::ResetType( |
204 WebInputEvent::TouchCancel, timeStampSeconds, this); | 211 WebInputEvent::TouchCancel, timeStampSeconds, this); |
205 } | 212 } |
206 | 213 |
207 void SyntheticWebTouchEvent::SetTimestamp(base::TimeDelta timestamp) { | 214 void SyntheticWebTouchEvent::SetTimestamp(base::TimeDelta timestamp) { |
208 timeStampSeconds = timestamp.InSecondsF(); | 215 timeStampSeconds = timestamp.InSecondsF(); |
209 } | 216 } |
210 | 217 |
211 } // namespace content | 218 } // namespace content |
OLD | NEW |