From da461d13a4de4db7c1423bd2ef1d9fd39f5cca87 Mon Sep 17 00:00:00 2001
From: pekepeke
Date: Sun, 28 Dec 2008 08:34:42 +0000
Subject: 新規追加
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@27514 d0d07461-0603-4401-acd4-de1884942a52
---
mouse_gestures.js | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 249 insertions(+)
create mode 100644 mouse_gestures.js
(limited to 'mouse_gestures.js')
diff --git a/mouse_gestures.js b/mouse_gestures.js
new file mode 100644
index 0000000..48c2d00
--- /dev/null
+++ b/mouse_gestures.js
@@ -0,0 +1,249 @@
+var PLUGIN_INFO =
+
+ Mouse Gestures
+ マウスジェスチャー
+ mouse gestures
+ マウスジェスチャー
+ 0.10
+ pekepeke
+ 2.0pre
+ 2.0pre
+ http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/mouse_gestures.js
+ R' , 'Forward', '#Browser:Forward'],
+ ['L, , , ]
+ -- UDLR
+ ジェスチャーを指定します。
+ UDLRの文字列を指定してください。
+ それぞれ、マウスジェスチャーの↑、↓、←, →に対応しています。
+ 一応、ロッカージェスチャー・ホイールジェスチャー等にも暫定で対応しています(別途、オプションを有効にする必要がある)。
+ ロッカージェスチャはL>R(左→右クリック), L
+
+
+liberator.plugins.MouseGestures = (function() {
+
+ const Ci = Components.interfaces;
+ var global = liberator.globalVariables;
+
+ if (typeof global.mousegesture_list == 'undefined') return;
+ if (liberator.plugins.MouseGestures) liberator.plugins.MouseGestures.registerEvents('remove');
+
+ var Class = function() function() {this.initialize.apply(this, arguments);};
+ var MouseGestures = new Class();
+
+ var doCommandByID = function(id) {
+ if (document.getElementById(id))
+ document.getElementById(id).doCommand();
+ };
+
+ MouseGestures.prototype = {
+ initialize: function(){
+ this.parseSetting();
+
+ var self = this;
+ this.registerEvents('add');
+ window.addEventListener('unload', function() { self.registerEvents('remove'); }, false);
+ },
+ parseSetting: function(){
+ var gestures = {};
+ var self = this;
+ this._showstatus = global.mousegesture_showmsg || true;
+
+ this._enableRocker = global.mousegesture_rocker || false;
+ this._enableWheel = global.mousegesture_wheel || false;
+ if (this._enableRocker) this.captureEvents.push('draggesture');
+ if (this._enableWheel) this.captureEvents.push('DOMMouseScroll');
+ global.mousegesture_list.forEach(function( [gesture, desc, action, noremap] ){
+ action = action || desc;
+ noremap = noremap || false;
+ if (typeof action == 'string') {
+ let str = action;
+ if (str.charAt(0) == ':') action = function() liberator.execute(str.substr(1));
+ else if (str.charAt(0) == '#') action = function() doCommandByID(str.substr(1));
+ else action = function() modules.events.feedkeys(str, noremap);
+ }
+ gestures[gesture] = [desc, action];
+ });
+ this.GESTURES = gestures;
+ },
+ captureEvents : ['mousedown', 'mousemove', 'mouseup', 'contextmenu'],
+ registerEvents: function(action){
+ var self = this;
+ this.captureEvents.forEach(
+ function(type) { getBrowser().mPanelContainer[action + 'EventListener'](type, self, type == 'contextmenu' || type == 'draggesture');
+ });
+ },
+ set status(msg) {
+ if (this._showstatus) commandline.echo(msg,null, commandline.FORCE_SINGLELINE);
+ },
+ handleEvent: function(event) {
+ switch(event.type){
+ case 'mousedown':
+ if (event.button == 2) {
+ this._isMouseDownR = true;
+ this._suppressContext = false;
+ this.startGesture(event);
+ if (this._enableRocker && this._isMouseDownL) {
+ this._isMouseDownR = false;
+ this._suppressContext = true;
+ this._gesture = 'L>R';
+ this.stopGesture(event);
+ }
+ } else if (this._enableRocker && event.button == 0){
+ this._isMouseDownL = true;
+ if (this._isMouseDownR) {
+ this._isMouseDownL = false;
+ this._suppressContext = true;
+ this._gesture = 'L 0 ? '+' : '-');
+ this.stopGesture( event , false);
+ }
+ break;
+ case 'draggesture':
+ this._isMouseDownL = false;
+ break;
+ }
+ },
+ startGesture: function(event) {
+ this._gesture = '';
+ this._x = event.screenX;
+ this._y = event.screenY;
+ this._origDoc = event.originalTarget.ownerDocument;
+ this._links = [];
+ },
+ progressGesture: function(event) {
+ if (!this._origDoc) return;
+ for (let node = event.originalTarget; node; node = node.parentNode) {
+ if (node instanceof Ci.nsIDOMHTMLAnchorElement) {
+ if (this._links.indexOf(node.href) == -1) this._links.push(node.href);
+ break;
+ }
+ }
+ this.timerGesture();
+ var x = event.screenX, y = event.screenY;
+ var distX = Math.abs(x-this._x), distY = Math.abs(y-this._y);
+ var threshold = 15/ (gBrowser.selectedBrowser.markupDocumentViewer.fullZoom || 1.0);
+ if (distX < threshold && distY < threshold) return;
+ var dir = distX > distY ? (x