@@ -64,6 +64,12 @@ xdGestureHandler.prototype = {
64
64
// current direction chain e.g. LRLRUDUD
65
65
_directionChain : "" ,
66
66
67
+ // nsITimer to handle gesture timeout
68
+ _gestureTimer : null ,
69
+
70
+ // nsITimer to handle swipe gesture
71
+ _swipeTimer : null ,
72
+
67
73
// xdIGestureObserver
68
74
_gestureObserver : null ,
69
75
@@ -93,6 +99,10 @@ xdGestureHandler.prototype = {
93
99
var prefBranch2 = Cc [ "@mozilla.org/preferences-service;1" ] . getService ( Ci . nsIPrefBranch2 ) ;
94
100
prefBranch2 . removeObserver ( PREFS_DOMAIN , this ) ;
95
101
this . _clearTimeout ( ) ;
102
+ if ( this . _swipeTimer ) {
103
+ this . _swipeTimer . cancel ( ) ;
104
+ this . _swipeTimer = null ;
105
+ }
96
106
this . sourceNode = null ;
97
107
this . _drawArea = null ;
98
108
this . _gestureObserver = null ;
@@ -128,6 +138,7 @@ xdGestureHandler.prototype = {
128
138
this . _trailSize = getPref ( "mousetrail.size" ) ;
129
139
this . _trailColor = getPref ( "mousetrail.color" ) ;
130
140
this . _gestureTimeout = getPref ( "gesture_timeout" ) ;
141
+ this . _swipeTimeout = getPref ( "swipe_timeout" ) ;
131
142
this . _mouseGestureEnabled = getPref ( "mousegesture" ) ;
132
143
this . _wheelGestureEnabled = getPref ( "wheelgesture" ) ;
133
144
this . _rockerGestureEnabled = getPref ( "rockergesture" ) ;
@@ -351,18 +362,46 @@ xdGestureHandler.prototype = {
351
362
event . preventDefault ( ) ;
352
363
if ( this . _state != STATE_READY )
353
364
return ;
365
+ // single swipe gesture
366
+ if ( this . _swipeTimeout == 0 ) {
367
+ var direction ;
368
+ switch ( event . direction ) {
369
+ case event . DIRECTION_LEFT : direction = "left" ; break ;
370
+ case event . DIRECTION_RIGHT : direction = "right" ; break ;
371
+ case event . DIRECTION_UP : direction = "up" ; break ;
372
+ case event . DIRECTION_DOWN : direction = "down" ; break ;
373
+ }
374
+ this . sourceNode = event . target ;
375
+ this . _lastX = event . screenX ;
376
+ this . _lastY = event . screenY ;
377
+ this . _invokeExtraGesture ( event , "swipe-" + direction ) ;
378
+ this . sourceNode = null ;
379
+ return ;
380
+ }
381
+ // continuous swipe gesture
382
+ if ( this . _swipeTimer ) {
383
+ this . _swipeTimer . cancel ( ) ;
384
+ this . _swipeTimer = null ;
385
+ }
386
+ this . _swipeTimer = Cc [ "@mozilla.org/timer;1" ] . createInstance ( Ci . nsITimer ) ;
387
+ this . _swipeTimer . initWithCallback ( this , this . _swipeTimeout , Ci . nsITimer . TYPE_ONE_SHOT ) ;
388
+ if ( ! this . _directionChain ) {
389
+ this . sourceNode = event . target ;
390
+ this . _lastX = event . screenX ;
391
+ this . _lastY = event . screenY ;
392
+ }
354
393
var direction ;
355
394
switch ( event . direction ) {
356
- case event . DIRECTION_LEFT : direction = "left" ; break ;
357
- case event . DIRECTION_RIGHT : direction = "right" ; break ;
358
- case event . DIRECTION_UP : direction = "up" ; break ;
359
- case event . DIRECTION_DOWN : direction = "down" ; break ;
395
+ case event . DIRECTION_LEFT : direction = "L" ; break ;
396
+ case event . DIRECTION_RIGHT : direction = "R" ; break ;
397
+ case event . DIRECTION_UP : direction = "U" ; break ;
398
+ case event . DIRECTION_DOWN : direction = "D" ; break ;
399
+ }
400
+ var lastDirection = this . _directionChain . charAt ( this . _directionChain . length - 1 ) ;
401
+ if ( direction != lastDirection ) {
402
+ this . _directionChain += direction ;
403
+ this . _gestureObserver . onDirectionChanged ( event , this . _directionChain ) ;
360
404
}
361
- this . sourceNode = event . target ;
362
- this . _lastX = event . screenX ;
363
- this . _lastY = event . screenY ;
364
- this . _invokeExtraGesture ( event , "swipe-" + direction ) ;
365
- this . sourceNode = null ;
366
405
break ;
367
406
}
368
407
// #debug-begin
@@ -545,8 +584,6 @@ xdGestureHandler.prototype = {
545
584
546
585
/* ::::: nsITimerCallback ::::: */
547
586
548
- _gestureTimer : null ,
549
-
550
587
// start timer for gesture timeout
551
588
_setTimeout : function FGH__setTimeout ( aMsec ) {
552
589
this . _clearTimeout ( ) ;
@@ -563,12 +600,22 @@ xdGestureHandler.prototype = {
563
600
} ,
564
601
565
602
notify : function ( aTimer ) {
566
- log ( "gesture-timeout" ) ; // #debug
567
- this . _suppressContext = true ;
568
- this . _shouldFireContext = false ;
569
- this . _directionChain = "" ;
570
- this . _stopGesture ( ) ;
571
- this . _gestureObserver . onExtraGesture ( null , "gesture-timeout" ) ;
603
+ switch ( aTimer ) {
604
+ case this . _gestureTimer :
605
+ log ( "gesture-timeout" ) ; // #debug
606
+ this . _suppressContext = true ;
607
+ this . _shouldFireContext = false ;
608
+ this . _directionChain = "" ;
609
+ this . _stopGesture ( ) ;
610
+ this . _gestureObserver . onExtraGesture ( null , "gesture-timeout" ) ;
611
+ break ;
612
+ case this . _swipeTimer :
613
+ this . _gestureObserver . onMouseGesture ( null , this . _directionChain ) ;
614
+ this . sourceNode = null ;
615
+ this . _directionChain = "" ;
616
+ this . _swipeTimer = null ;
617
+ break ;
618
+ }
572
619
} ,
573
620
574
621
openPopupAtPointer : function FGH_openPopupAtPointer ( aPopup ) {
0 commit comments