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

Mihai Varga mihai.varga at collabora.com
Mon Jul 13 05:53:24 PDT 2015


 loleaflet/build/deps.js                               |    7 ++
 loleaflet/debug/document/document_simple_example.html |    1 
 loleaflet/src/control/Permission.js                   |   18 +++++
 loleaflet/src/layer/tile/TileLayer.js                 |   58 ++++++++----------
 4 files changed, 52 insertions(+), 32 deletions(-)

New commits:
commit 0d41a804eb7d696b7ebca1f0ed34fcb85ce4aeca
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Jul 13 15:50:02 2015 +0300

    loleaflet: enabled mouse selection in viewing mode
    
    Mouse selection is enabled by by calling
    map.enableSelection() which disables dragging and selection
    can be disabled to re-enable dragging by calling
    map.disableSelection()
    The above only work for 'view' and 'readonly' mode

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index d656c7a..7f22db1 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -228,6 +228,13 @@ var deps = {
 		desc: 'Switches edit, view and readOnly modes'
 	},
 
+	ControlSelection: {
+		src: ['control/Control.js',
+		      'control/Control.Selection.js'],
+		heading: 'Controls',
+		desc: 'Enables selection in view mode'
+	},
+
 	ControlButtons: {
 		src: ['control/Control.js',
 		      'control/Control.Buttons.js'],
diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html
index bb00203..446bb00 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -71,6 +71,7 @@
     map.addControl(L.control.buttons());
     map.addControl(L.control.search());
     map.addControl(L.control.permissionSwitch());
+    map.addControl(L.control.selection());
     map.addControl(L.control.zoom());
     map.addControl(L.control.parts());
     map.addControl(L.control.statusIndicator());
diff --git a/loleaflet/src/control/Permission.js b/loleaflet/src/control/Permission.js
index 6933f64..f48d2e4 100644
--- a/loleaflet/src/control/Permission.js
+++ b/loleaflet/src/control/Permission.js
@@ -18,6 +18,24 @@ L.Map.include({
 			L.DomUtil.removeClass(this._container, className);
 		}
 		this.fire('updatepermission', {perm : perm});
+	},
+
+	enableSelection: function () {
+		if (this._docLayer._permission === 'edit') {
+			return;
+		}
+		var className = 'leaflet-editmode';
+		this.dragging.disable();
+		L.DomUtil.addClass(this._container, className);
+	},
+
+	disableSelection: function () {
+		if (this._docLayer._permission === 'edit') {
+			return;
+		}
+		var className = 'leaflet-editmode';
+		this.dragging.enable();
+		L.DomUtil.removeClass(this._container, className);
 	}
 });
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index fb69720..8c88a36 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -738,10 +738,6 @@ L.TileLayer = L.GridLayer.extend({
 			return;
 		}
 
-		if (this._permission === 'readonly') {
-			return;
-		}
-
 		if (e.type === 'mousedown') {
 			this._mouseDown = true;
 			if (this._holdMouseEvent) {
@@ -754,7 +750,7 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		else if (e.type === 'mouseup') {
 			this._mouseDown = false;
-			if (this._permission !== 'edit') {
+			if (this._map.dragging.enabled()) {
 				if (this._mouseEventsQueue.length === 0) {
 					// mouse up after panning
 					return;
@@ -779,7 +775,7 @@ L.TileLayer = L.GridLayer.extend({
 					if (this._mouseEventsQueue.length > 1) {
 						// it's a click, fire mousedown
 						this._mouseEventsQueue[0]();
-						if (this._permission !== 'edit') {
+						if (this._permission === 'view') {
 							this._map.setPermission('edit');
 						}
 					}
@@ -801,7 +797,7 @@ L.TileLayer = L.GridLayer.extend({
 			if (this._holdMouseEvent) {
 				clearTimeout(this._holdMouseEvent);
 				this._holdMouseEvent = null;
-				if (this._permission !== 'edit') {
+				if (this._map.dragging.enabled()) {
 					// The user just panned the document
 					this._mouseEventsQueue = [];
 					return;
@@ -813,7 +809,7 @@ L.TileLayer = L.GridLayer.extend({
 				}
 				this._mouseEventsQueue = [];
 			}
-			if (this._permission === 'edit') {
+			if (!this._map.dragging.enabled()) {
 				mousePos = this._latLngToTwips(e.latlng);
 				this._postMouseEvent('move', mousePos.x, mousePos.y, 1);
 				if (this._startMarker._icon) {
@@ -835,15 +831,6 @@ L.TileLayer = L.GridLayer.extend({
 
 	_executeMouseEvents: function () {
 		this._holdMouseEvent = null;
-		if (this._mouseEventsQueue.length === 1 && this._permission !== 'edit') {
-			// long mouse down or a mouseup after panning
-			this._mouseEventsQueue = [];
-			return;
-		}
-		else if (this._permission !== 'edit') {
-			// this time we have a mousedown and mouseup
-			this._map.setPermission('edit');
-		}
 		for (var i = 0; i < this._mouseEventsQueue.length; i++) {
 			this._mouseEventsQueue[i]();
 		}
commit df0224964e8084c41d86c8f2fa86f4a0243cb232
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Jul 13 10:24:40 2015 +0300

    loleaflet: enable selection in viewing mode by dblclicking a word

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index b028e12..fb69720 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -768,19 +768,26 @@ L.TileLayer = L.GridLayer.extend({
 				return;
 			}
 			else {
-				// if it's a click or mouseup after selecting
-				if (this._mouseEventsQueue.length > 0) {
-					// it's a click, fire mousedown
-					this._mouseEventsQueue[0]();
-					this._clickTime = Date.now();
-					if (this._permission !== 'edit') {
-						this._map.setPermission('edit');
-					}
-				}
-				this._mouseEventsQueue = [];
+				this._clickTime = Date.now();
 				mousePos = this._latLngToTwips(e.latlng);
-				this._postMouseEvent('buttonup', mousePos.x, mousePos.y, 1);
-				this._textArea.focus();
+				var timeOut = 250;
+				if (this._permission === 'edit') {
+					timeOut = 0;
+				}
+				this._mouseEventsQueue.push(L.bind(function() {
+					// if it's a click or mouseup after selecting
+					if (this._mouseEventsQueue.length > 1) {
+						// it's a click, fire mousedown
+						this._mouseEventsQueue[0]();
+						if (this._permission !== 'edit') {
+							this._map.setPermission('edit');
+						}
+					}
+					this._mouseEventsQueue = [];
+					this._postMouseEvent('buttonup', mousePos.x, mousePos.y, 1);
+					this._textArea.focus();
+				}, this));
+				this._holdMouseEvent = setTimeout(L.bind(this._executeMouseEvents, this), timeOut);
 
 				if (this._startMarker._icon) {
 					L.DomUtil.removeClass(this._startMarker._icon, 'leaflet-not-clickable');
@@ -850,10 +857,6 @@ L.TileLayer = L.GridLayer.extend({
 
 	// Receives a key press or release event.
 	_signalKey: function (e) {
-		if (this._permission !== 'edit') {
-			return;
-		}
-
 		if (e.originalEvent.ctrlKey) {
 			// we prepare for a copy event
 			this._textArea.value = 'dummy text';
@@ -862,6 +865,10 @@ L.TileLayer = L.GridLayer.extend({
 			return;
 		}
 
+		if (this._permission !== 'edit') {
+			return;
+		}
+
 		var charCode = e.originalEvent.charCode;
 		var keyCode = e.originalEvent.keyCode;
 		if (e.type === 'keydown' && this.handleOnKeyDown[keyCode] && charCode === 0) {


More information about the Libreoffice-commits mailing list