[Libreoffice-commits] online.git: 3 commits - loleaflet/build loleaflet/src

Andrzej Hunt andrzej.hunt at collabora.com
Thu Oct 29 15:44:12 UTC 2015


 loleaflet/build/deps.js                  |    3 -
 loleaflet/src/dom/DomEvent.MultiClick.js |   66 +++++++++++++++++++++++++++++++
 loleaflet/src/dom/DomEvent.js            |    6 ++
 loleaflet/src/map/Map.js                 |    2 
 loleaflet/src/map/handler/Map.Mouse.js   |   31 +++++++++++---
 5 files changed, 99 insertions(+), 9 deletions(-)

New commits:
commit b394f337c7aa3a2650fe5abdbcfd849c5829ca57
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Thu Oct 29 15:26:01 2015 +0100

    loleaflet: tdf#94609 Support triple and quadruple click selection
    
    Currently probably only supported on desktop (clicking) browsers.

diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index f79ace4..effe453 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -573,7 +573,7 @@ L.Map = L.Evented.extend({
 		var onOff = remove ? 'off' : 'on';
 
 		L.DomEvent[onOff](this._container, 'click dblclick mousedown mouseup ' +
-			'mouseover mouseout mousemove contextmenu keydown keypress keyup', this._handleDOMEvent, this);
+			'mouseover mouseout mousemove contextmenu keydown keypress keyup trplclick qdrplclick', this._handleDOMEvent, this);
 		L.DomEvent[onOff](this._textArea, 'copy paste keydown keypress keyup', this._handleDOMEvent, this);
 
 		if (this.options.trackResize) {
diff --git a/loleaflet/src/map/handler/Map.Mouse.js b/loleaflet/src/map/handler/Map.Mouse.js
index 4d03770..6477be4 100644
--- a/loleaflet/src/map/handler/Map.Mouse.js
+++ b/loleaflet/src/map/handler/Map.Mouse.js
@@ -14,12 +14,12 @@ L.Map.Mouse = L.Handler.extend({
 	},
 
 	addHooks: function () {
-		this._map.on('mousedown mouseup mouseover mouseout mousemove dblclick',
+		this._map.on('mousedown mouseup mouseover mouseout mousemove dblclick trplclick qdrplclick',
 			this._onMouseEvent, this);
 	},
 
 	removeHooks: function () {
-		this._map.off('mousedown mouseup mouseover mouseout mousemove dblclick',
+		this._map.off('mousedown mouseup mouseover mouseout mousemove dblclick trplclick qdrplclick',
 			this._onMouseEvent, this);
 	},
 
@@ -81,10 +81,22 @@ L.Map.Mouse = L.Handler.extend({
 			if (this._clickTime && Date.now() - this._clickTime <= 250) {
 				// double click, a click was sent already
 				this._mouseEventsQueue = [];
+				this._clickCount++;
+				if (this._clickCount < 4) {
+					// Reset the timer in order to keep resetting until
+					// we could have sent through a quadruple click. After this revert
+					// to normal behaviour so that a following single-click is treated
+					// as a separate click, in order to match LO desktop behaviour.
+					// (Clicking five times results in paragraph selection after 4 clicks,
+					// followed by resetting to a single cursor and no selection on the
+					// fifth click.)
+					this._clickTime = Date.now();
+				}
 				return;
 			}
 			else {
 				this._clickTime = Date.now();
+				this._clickCount = 1;
 				mousePos = docLayer._latLngToTwips(e.latlng);
 				var timeOut = 250;
 				if (docLayer._permission === 'edit') {
@@ -145,10 +157,17 @@ L.Map.Mouse = L.Handler.extend({
 				this._map.fire('handleautoscroll', { pos: e.containerPoint, map: this._map });
 			}
 		}
-		else if (e.type === 'dblclick') {
+		else if (e.type === 'dblclick' || e.type === 'trplclick' || e.type === 'qdrplclick') {
 			mousePos = docLayer._latLngToTwips(e.latlng);
-			docLayer._postMouseEvent('buttondown', mousePos.x, mousePos.y, 2, buttons, modifier);
-			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, 2, buttons, modifier);
+			var clicks = {
+				dblclick: 2,
+				trplclick: 3,
+				qdrplclick: 4
+			};
+			var count = clicks[e.type];
+
+			docLayer._postMouseEvent('buttondown', mousePos.x, mousePos.y, count, buttons, modifier);
+			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, count, buttons, modifier);
 		}
 	},
 
commit 2879547c67416aaaf1103d810257651099f98271
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Thu Oct 29 15:19:50 2015 +0100

    loleaflet: Implement DomEvent trplclick and qdrplclick support
    
    Browsers only support single and double click, so we need
    to do our own trplclick and qdrplclick synthesis.

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 277e40b..c9b3d1a 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -221,7 +221,8 @@ var deps = {
 	},
 
 	Mouse: {
-		src: ['map/handler/Map.Mouse.js'],
+		src: ['dom/DomEvent.MultiClick.js',
+		      'map/handler/Map.Mouse.js'],
 		desc: 'Handles mouse interaction with the document.'
 	},
 
diff --git a/loleaflet/src/dom/DomEvent.MultiClick.js b/loleaflet/src/dom/DomEvent.MultiClick.js
new file mode 100644
index 0000000..a9c4e47
--- /dev/null
+++ b/loleaflet/src/dom/DomEvent.MultiClick.js
@@ -0,0 +1,66 @@
+/*
+ * Extends the event handling code with triple and quadruple click support
+ * This is vaguely based on the DomEvent.DoubleTap implementation.
+ */
+
+L.extend(L.DomEvent, {
+
+	addMultiClickListener: function (obj, handler, id, type) {
+		var last = [],
+		    delay = 250;
+
+		function onClick(e) {
+			var now = Date.now();
+			var delta = 0;
+			if (last) {
+				delta = now - (last[last.length - 1] || now);
+			}
+
+			var doubleTap = (delta > 0 && delta <= delay);
+
+			var tripleTap = false;
+			if (last.length > 1 && doubleTap) {
+				var delta2 = last[last.length - 1] - last[last.length - 2];
+				tripleTap = (delta2 > 0 && delta2 <= delay);
+			}
+
+			if (tripleTap) {
+
+				var quadTap = false;
+				if (last.length > 2 && tripleTap) {
+					var delta3 = last[last.length - 2] - last[last.length - 3];
+					quadTap = (delta3 > 0 && delta3 <= delay);
+				}
+
+				// We can't modify e as it's a native DOM object, hence we copy
+				// what we need instead. (I am however unable to actually find any
+				// documentation regarding this anywhere.)
+				var eOut = {
+					type: quadTap ? 'qdrplclick' : 'trplclick',
+					clientX: e.clientX,
+					clientY: e.clientY,
+					button: e.button,
+					target: e.target
+				};
+
+				handler(eOut);
+			}
+
+			last.push(now);
+			while (last.length > 3) {
+				last.shift();
+			}
+		}
+
+		obj['_leaflet_click' + id] = onClick;
+
+		obj.addEventListener('click', onClick, false);
+		return this;
+	},
+
+	removeMultiClickListener: function (obj, id, type) {
+		obj.removeEventListener('click', obj['_leaflet_click' + id], false);
+
+		return this;
+	}
+});
diff --git a/loleaflet/src/dom/DomEvent.js b/loleaflet/src/dom/DomEvent.js
index b60e174..7de458b 100644
--- a/loleaflet/src/dom/DomEvent.js
+++ b/loleaflet/src/dom/DomEvent.js
@@ -58,6 +58,9 @@ L.DomEvent = {
 		} else if (L.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) {
 			this.addDoubleTapListener(obj, handler, id);
 
+		} else if (type === "trplclick" || type === "qdrplclick") {
+			this.addMultiClickListener(obj, handler, id, type);
+
 		} else if ('addEventListener' in obj) {
 
 			if (type === 'mousewheel') {
@@ -105,6 +108,9 @@ L.DomEvent = {
 		} else if (L.Browser.touch && (type === 'dblclick') && this.removeDoubleTapListener) {
 			this.removeDoubleTapListener(obj, id);
 
+		} else if (type === 'trplclick' || type === 'qdrplclick') {
+			this.removeMultiClickListener(obj, id, type);
+
 		} else if ('removeEventListener' in obj) {
 
 			if (type === 'mousewheel') {
commit a7269e40c39823de8e9b314375c0e419f37ac642
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Thu Oct 29 14:33:06 2015 +0100

    loleaflet: Cleanup dblclick handling
    
    We only seem to need to send the dblclick event (nCount = 2)
    and not an enclosing single click (nCount = 1) too - the single
    click is effectively overridden by the double click.
    
    The buttonup calls also had an erronous additional parameter, which
    seems to have been added accidentally in:
    14dca89150ca550e8031888b1cd5b1f37ee626da

diff --git a/loleaflet/src/map/handler/Map.Mouse.js b/loleaflet/src/map/handler/Map.Mouse.js
index b3f9eba..4d03770 100644
--- a/loleaflet/src/map/handler/Map.Mouse.js
+++ b/loleaflet/src/map/handler/Map.Mouse.js
@@ -147,10 +147,8 @@ L.Map.Mouse = L.Handler.extend({
 		}
 		else if (e.type === 'dblclick') {
 			mousePos = docLayer._latLngToTwips(e.latlng);
-			docLayer._postMouseEvent('buttondown', mousePos.x, mousePos.y, 1, buttons, modifier);
 			docLayer._postMouseEvent('buttondown', mousePos.x, mousePos.y, 2, buttons, modifier);
-			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, 2, 1, buttons, modifier);
-			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, 1, 1, buttons, modifier);
+			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, 2, buttons, modifier);
 		}
 	},
 


More information about the Libreoffice-commits mailing list