Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Touch Handler. Class that handles all touch events and | 6 * Touch Handler. Class that handles all touch events and |
| 7 * uses them to interpret higher level gestures and behaviors. TouchEvent is a | 7 * uses them to interpret higher level gestures and behaviors. TouchEvent is a |
| 8 * built in mobile safari type: | 8 * built in mobile safari type: |
| 9 * [http://developer.apple.com/safari/library/documentation/UserExperience/Refer ence/TouchEventClassReference/TouchEvent/TouchEvent.html]. | 9 * [http://developer.apple.com/safari/library/documentation/UserExperience/Refer ence/TouchEventClassReference/TouchEvent/TouchEvent.html]. |
| 10 * | 10 * |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 bool isTracking() { | 226 bool isTracking() { |
| 227 return _tracking; | 227 return _tracking; |
| 228 } | 228 } |
| 229 | 229 |
| 230 /** | 230 /** |
| 231 * Touch end handler. | 231 * Touch end handler. |
| 232 */ | 232 */ |
| 233 void _onEnd(int timeStamp, [TouchEvent e = null]) { | 233 void _onEnd(int timeStamp, [TouchEvent e = null]) { |
| 234 _touching = false; | 234 _touching = false; |
| 235 _touchable.onTouchEnd(); | 235 _touchable.onTouchEnd(); |
| 236 if (!_tracking || _draggable === null) { | 236 if (!_tracking || _draggable == null) { |
| 237 return; | 237 return; |
| 238 } | 238 } |
| 239 Touch touch = _getLastTouch(); | 239 Touch touch = _getLastTouch(); |
| 240 int clientX = touch.clientX; | 240 int clientX = touch.clientX; |
| 241 int clientY = touch.clientY; | 241 int clientY = touch.clientY; |
| 242 if (_dragging) { | 242 if (_dragging) { |
| 243 _endTime = timeStamp; | 243 _endTime = timeStamp; |
| 244 _endTouchX = clientX; | 244 _endTouchX = clientX; |
| 245 _endTouchY = clientY; | 245 _endTouchY = clientY; |
| 246 _recentTouchesX = _removeOldTouches(_recentTouchesX, timeStamp); | 246 _recentTouchesX = _removeOldTouches(_recentTouchesX, timeStamp); |
| 247 _recentTouchesY = _removeOldTouches(_recentTouchesY, timeStamp); | 247 _recentTouchesY = _removeOldTouches(_recentTouchesY, timeStamp); |
| 248 _draggable.onDragEnd(); | 248 _draggable.onDragEnd(); |
| 249 if (e !== null) { | 249 if (e != null) { |
| 250 e.preventDefault(); | 250 e.preventDefault(); |
| 251 } | 251 } |
| 252 ClickBuster.preventGhostClick(_startTouchX, _startTouchY); | 252 ClickBuster.preventGhostClick(_startTouchX, _startTouchY); |
| 253 } | 253 } |
| 254 _endTracking(); | 254 _endTracking(); |
| 255 } | 255 } |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * Touch move handler. | 258 * Touch move handler. |
| 259 */ | 259 */ |
| 260 void _onMove(TouchEvent e) { | 260 void _onMove(TouchEvent e) { |
| 261 if (!_tracking || _draggable === null) { | 261 if (!_tracking || _draggable == null) { |
| 262 return; | 262 return; |
| 263 } | 263 } |
| 264 final touch = e.touches[0]; | 264 final touch = e.touches[0]; |
| 265 int clientX = touch.clientX; | 265 int clientX = touch.clientX; |
| 266 int clientY = touch.clientY; | 266 int clientY = touch.clientY; |
| 267 int moveX = _lastTouchX - clientX; | 267 int moveX = _lastTouchX - clientX; |
| 268 int moveY = _lastTouchY - clientY; | 268 int moveY = _lastTouchY - clientY; |
| 269 _totalMoveX += moveX.abs(); | 269 _totalMoveX += moveX.abs(); |
| 270 _totalMoveY += moveY.abs(); | 270 _totalMoveY += moveY.abs(); |
| 271 _lastTouchX = clientX; | 271 _lastTouchX = clientX; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 } | 303 } |
| 304 | 304 |
| 305 /** | 305 /** |
| 306 * Touch start handler. | 306 * Touch start handler. |
| 307 */ | 307 */ |
| 308 void _onStart(TouchEvent e) { | 308 void _onStart(TouchEvent e) { |
| 309 if (_touching) { | 309 if (_touching) { |
| 310 return; | 310 return; |
| 311 } | 311 } |
| 312 _touching = true; | 312 _touching = true; |
| 313 if (!_touchable.onTouchStart(e) || _draggable === null) { | 313 if (!_touchable.onTouchStart(e) || _draggable == null) { |
| 314 return; | 314 return; |
| 315 } | 315 } |
| 316 final touch = e.touches[0]; | 316 final touch = e.touches[0]; |
| 317 _startTouchX = _lastTouchX = touch.clientX; | 317 _startTouchX = _lastTouchX = touch.clientX; |
| 318 _startTouchY = _lastTouchY = touch.clientY; | 318 _startTouchY = _lastTouchY = touch.clientY; |
| 319 _startTime = e.timeStamp; | 319 _startTime = e.timeStamp; |
| 320 // TODO(jacobr): why don't we just clear the lists? | 320 // TODO(jacobr): why don't we just clear the lists? |
| 321 _recentTouchesX = new List<int>(); | 321 _recentTouchesX = new List<int>(); |
| 322 _recentTouchesY = new List<int>(); | 322 _recentTouchesY = new List<int>(); |
| 323 _recentTouchesX.add(touch.clientX); | 323 _recentTouchesX.add(touch.clientX); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 List<int> _removeTouchesInWrongDirection(List<int> recentTouches, | 363 List<int> _removeTouchesInWrongDirection(List<int> recentTouches, |
| 364 int lastMove, int recentMove) { | 364 int lastMove, int recentMove) { |
| 365 if (lastMove !=0 && recentMove != 0 && recentTouches.length > 2 && | 365 if (lastMove !=0 && recentMove != 0 && recentTouches.length > 2 && |
| 366 _xor(lastMove > 0, recentMove > 0)) { | 366 _xor(lastMove > 0, recentMove > 0)) { |
| 367 return _removeFirstN(recentTouches, recentTouches.length - 2); | 367 return _removeFirstN(recentTouches, recentTouches.length - 2); |
| 368 } | 368 } |
| 369 return recentTouches; | 369 return recentTouches; |
| 370 } | 370 } |
| 371 | 371 |
| 372 // TODO(jacobr): why doesn't bool implement the xor operator directly? | 372 // TODO(jacobr): why doesn't bool implement the xor operator directly? |
| 373 static bool _xor(bool a, bool b) { | 373 static bool _xor(bool a, bool b) => a != b; |
|
Lasse Reichstein Nielsen
2012/11/12 13:10:41
Are we sure this isn't an attempt to do boolify on
floitsch
2012/11/12 22:18:43
Afaics the only use is in line 366. Not inlining,
| |
| 374 return (a === true || b === true) && !(a === true && b === true); | |
| 375 } | |
| 376 | 374 |
| 377 /** | 375 /** |
| 378 * Reset the touchable element. | 376 * Reset the touchable element. |
| 379 */ | 377 */ |
| 380 void reset() { | 378 void reset() { |
| 381 _endTracking(); | 379 _endTracking(); |
| 382 _touching = false; | 380 _touching = false; |
| 383 } | 381 } |
| 384 | 382 |
| 385 /** | 383 /** |
| 386 * Call this method to enable drag behavior on a draggable delegate. | 384 * Call this method to enable drag behavior on a draggable delegate. |
| 387 * The [draggable] object can be the same as the [_touchable] object, they are | 385 * The [draggable] object can be the same as the [_touchable] object, they are |
| 388 * assigned to different members to allow for strong typing with interfaces. | 386 * assigned to different members to allow for strong typing with interfaces. |
| 389 */ | 387 */ |
| 390 void setDraggable(Draggable draggable) { | 388 void setDraggable(Draggable draggable) { |
| 391 _draggable = draggable; | 389 _draggable = draggable; |
| 392 } | 390 } |
| 393 } | 391 } |
| OLD | NEW |