Skip to content

Commit c76567b

Browse files
committed
add 'Mouse gesture with continuous swipes' option
1 parent 933b002 commit c76567b

File tree

8 files changed

+103
-20
lines changed

8 files changed

+103
-20
lines changed

chrome/content/firegestures/browser.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ var FireGestures = {
159159
break;
160160
case "FireGestures:MinimizeWindow":
161161
// Fixed bug: window gets focused rapidly after minimizing with rocker gesture
162-
event.preventDefault();
162+
if (event)
163+
event.preventDefault();
163164
window.minimize();
164165
break;
165166
case "FireGestures:MaximizeWindow":
@@ -446,7 +447,7 @@ var FireGestures = {
446447
case "FireGestures:BFHistoryPopup":
447448
case "FireGestures:ClosedTabsPopup":
448449
case "FireGestures:WebSearchPopup":
449-
this._buildPopup(aCommand, event.type == "DOMMouseScroll");
450+
this._buildPopup(aCommand, event && event.type == "DOMMouseScroll");
450451
break;
451452
case "FireGestures:OpenHoveredLinks":
452453
var doc = this.sourceNode.ownerDocument;
@@ -725,7 +726,7 @@ var FireGestures = {
725726
_popupActiveItem: null,
726727

727728
generatePopup: function(event, aAttrsList) {
728-
this._buildPopup("FireGestures:CustomPopup", event.type == "DOMMouseScroll", aAttrsList);
729+
this._buildPopup("FireGestures:CustomPopup", event && event.type == "DOMMouseScroll", aAttrsList);
729730
},
730731

731732
_buildPopup: function(aCommand, aWheelGesture, aAttrsList) {

chrome/content/firegestures/prefs-generic.xul

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<prefpane id="swipePane" label="&swipePane;" flex="1">
128128
<preferences>
129129
<preference id="pref:swipegesture" name="extensions.firegestures.swipegesture" type="bool" />
130+
<preference id="pref:swipetimeout" name="extensions.firegestures.swipe_timeout" type="int" />
130131
</preferences>
131132
<groupbox uigroup="swipegesture">
132133
<!-- dummy -->
@@ -166,6 +167,10 @@
166167
</row>
167168
</rows>
168169
</grid>
170+
<!-- dummy -->
171+
<textbox id="swipetimeout" hidden="true"
172+
preference="pref:swipetimeout"
173+
onsyncfrompreference="return PrefsUI.updateSwipeGestureUIGroup();" />
169174
</groupbox>
170175
</prefpane>
171176

chrome/content/firegestures/prefs.js

+9
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ var PrefsUI = {
213213

214214
updateSwipeGestureUIGroup: function() {
215215
this.updateUIGroup("swipegesture");
216+
if (getElement("pref:swipegesture").value) {
217+
this.updateUIGroup("swipetimeout");
218+
// enable/disable single swipe UI
219+
var enable = getElement("pref:swipetimeout").value == 0;
220+
var elts = document.querySelectorAll('[uigroup="swipegesture"] > grid *');
221+
Array.forEach(elts, function(elt) {
222+
elt.disabled = !enable;
223+
});
224+
}
216225
},
217226

218227
updateUIGroup: function(aGroupName) {

chrome/content/firegestures/prefs.xul

+14
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
<prefpane id="swipePane" label="&swipePane;" flex="1">
282282
<preferences>
283283
<preference id="pref:swipegesture" name="extensions.firegestures.swipegesture" type="bool" />
284+
<preference id="pref:swipetimeout" name="extensions.firegestures.swipe_timeout" type="int" />
284285
</preferences>
285286
<groupbox uigroup="swipegesture">
286287
<caption>
@@ -320,6 +321,19 @@
320321
</row>
321322
</rows>
322323
</grid>
324+
<separator class="groove" />
325+
<checkbox id="swipetimeout" label="&swipe.continuous;"
326+
preference="pref:swipetimeout"
327+
onsyncfrompreference="return PrefsUI.updateSwipeGestureUIGroup();"
328+
onsynctopreference="return this.checked ? 500 : 0;" />
329+
<hbox align="center" class="indent" uigroup="swipetimeout">
330+
<label value="&swipe.continuous.1;:" />
331+
<textbox type="number" min="0" max="2" increment="0.1" decimalplaces="1" size="3"
332+
preference="pref:swipetimeout"
333+
onsyncfrompreference="return getElement('pref:swipetimeout').value / 1000;"
334+
onsynctopreference="return this.value * 1000;" />
335+
<label value="&swipe.continuous.2;" />
336+
</hbox>
323337
</groupbox>
324338
</prefpane>
325339

chrome/locale/en-US/firegestures/prefs.dtd

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<!ENTITY swipe.right "Swipe rightward">
4949
<!ENTITY swipe.up "Swipe upward">
5050
<!ENTITY swipe.down "Swipe downward">
51+
<!ENTITY swipe.continuous "Mouse gesture with continuous swipes">
52+
<!ENTITY swipe.continuous.1 "Time to wait for next direction">
53+
<!ENTITY swipe.continuous.2 "seconds">
5154
<!ENTITY treecol.name "Name">
5255
<!ENTITY treecol.command "Command">
5356
<!ENTITY treecol.script "Script">

chrome/locale/ja/firegestures/prefs.dtd

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<!ENTITY swipe.right "右方向へスワイプ">
4949
<!ENTITY swipe.up "上方向へスワイプ">
5050
<!ENTITY swipe.down "下方向へスワイプ">
51+
<!ENTITY swipe.continuous "連続的なスワイプによるマウスジェスチャ">
52+
<!ENTITY swipe.continuous.1 "次の方向のスワイプまでの待ち時間">
53+
<!ENTITY swipe.continuous.2 "秒">
5154
<!ENTITY treecol.name "名前">
5255
<!ENTITY treecol.command "コマンド">
5356
<!ENTITY treecol.script "スクリプト">

components/xdGestureHandler.js

+64-17
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ xdGestureHandler.prototype = {
6464
// current direction chain e.g. LRLRUDUD
6565
_directionChain: "",
6666

67+
// nsITimer to handle gesture timeout
68+
_gestureTimer: null,
69+
70+
// nsITimer to handle swipe gesture
71+
_swipeTimer: null,
72+
6773
// xdIGestureObserver
6874
_gestureObserver: null,
6975

@@ -93,6 +99,10 @@ xdGestureHandler.prototype = {
9399
var prefBranch2 = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch2);
94100
prefBranch2.removeObserver(PREFS_DOMAIN, this);
95101
this._clearTimeout();
102+
if (this._swipeTimer) {
103+
this._swipeTimer.cancel();
104+
this._swipeTimer = null;
105+
}
96106
this.sourceNode = null;
97107
this._drawArea = null;
98108
this._gestureObserver = null;
@@ -128,6 +138,7 @@ xdGestureHandler.prototype = {
128138
this._trailSize = getPref("mousetrail.size");
129139
this._trailColor = getPref("mousetrail.color");
130140
this._gestureTimeout = getPref("gesture_timeout");
141+
this._swipeTimeout = getPref("swipe_timeout");
131142
this._mouseGestureEnabled = getPref("mousegesture");
132143
this._wheelGestureEnabled = getPref("wheelgesture");
133144
this._rockerGestureEnabled = getPref("rockergesture");
@@ -351,18 +362,46 @@ xdGestureHandler.prototype = {
351362
event.preventDefault();
352363
if (this._state != STATE_READY)
353364
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+
}
354393
var direction;
355394
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);
360404
}
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;
366405
break;
367406
}
368407
// #debug-begin
@@ -545,8 +584,6 @@ xdGestureHandler.prototype = {
545584

546585
/* ::::: nsITimerCallback ::::: */
547586

548-
_gestureTimer: null,
549-
550587
// start timer for gesture timeout
551588
_setTimeout: function FGH__setTimeout(aMsec) {
552589
this._clearTimeout();
@@ -563,12 +600,22 @@ xdGestureHandler.prototype = {
563600
},
564601

565602
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+
}
572619
},
573620

574621
openPopupAtPointer: function FGH_openPopupAtPointer(aPopup) {

defaults/preferences/firegestures-prefs.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ pref("extensions.firegestures.mousetrail.size", 2);
1111
pref("extensions.firegestures.mousetrail.color", "#33FF33");
1212
pref("extensions.firegestures.gesture_timeout", 3000);
1313
pref("extensions.firegestures.status_display", 2000);
14+
pref("extensions.firegestures.swipe_timeout", 0);

0 commit comments

Comments
 (0)