[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-3' - 2 commits - loleaflet/build loleaflet/debug loleaflet/src

Mihai Varga mihai.varga at collabora.com
Mon Jul 13 06:02:59 PDT 2015


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

New commits:
commit d605b501df466801517b70c24afecd0d93a4548e
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
    
    Conflicts:
    	loleaflet/build/deps.js

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index 65d5452..b3ce61c 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'
+	},
+
 	ControlStatusIndicator: {
 		src: ['control/Control.js',
 		      'control/Control.StatusIndicator.js'],
diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html
index 7d90824..d259531 100644
--- a/loleaflet/debug/document/document_simple_example.html
+++ b/loleaflet/debug/document/document_simple_example.html
@@ -70,6 +70,7 @@
     ////// Controls /////
     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/Control.Selection.js b/loleaflet/src/control/Control.Selection.js
new file mode 100644
index 0000000..abe3237
--- /dev/null
+++ b/loleaflet/src/control/Control.Selection.js
@@ -0,0 +1,49 @@
+/*
+ * L.Control.Selection enables by mouse drag selection in viewing mode
+ */
+
+L.Control.Selection = L.Control.extend({
+	options: {
+		position: 'topleft'
+	},
+
+	onAdd: function (map) {
+		var partName = 'leaflet-control-editviewswitch',
+			container = L.DomUtil.create('label', partName + ' leaflet-bar');
+
+		this._checkBox = L.DomUtil.create('input', 'editview-cb', container);
+		this._checkBox.type = 'checkbox';
+		L.DomEvent.on(this._checkBox, 'change', this._onChange, this);
+		map.on('updatepermission', this._onUpdatePermission, this);
+		container.appendChild(document.createTextNode('Enable Selection'));
+		return container;
+	},
+
+	_onChange: function () {
+		if (this._checkBox.checked) {
+			this._map.enableSelection();
+		}
+		else {
+			this._map.disableSelection();
+		}
+	},
+
+	_onUpdatePermission: function (e) {
+		if (e.perm === 'edit') {
+			this._checkBox.checked = false;
+			this._checkBox.disabled = true;
+		}
+		else if (e.perm === 'view') {
+			this._checkBox.checked = false;
+			this._checkBox.disabled = false;
+		}
+		else if (e.perm === 'readonly') {
+			this._checkBox.checked = false;
+			this._checkBox.disabled = false;
+		}
+	}
+});
+
+L.control.selection = function (options) {
+	return new L.Control.Selection(options);
+};
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 a6e9bff..f240ca8 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -723,10 +723,6 @@ L.TileLayer = L.GridLayer.extend({
 			return;
 		}
 
-		if (this._permission === 'readonly') {
-			return;
-		}
-
 		if (e.type === 'mousedown') {
 			this._mouseDown = true;
 			if (this._holdMouseEvent) {
@@ -739,7 +735,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;
@@ -764,7 +760,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');
 						}
 					}
@@ -786,7 +782,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;
@@ -798,7 +794,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) {
@@ -820,15 +816,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 9225bf09ac6e372366c144e357ad7539baf6025d
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 f62ecfc..a6e9bff 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -753,19 +753,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');
@@ -835,10 +842,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';
@@ -847,6 +850,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