[Libreoffice-commits] online.git: 7 commits - loleaflet/dist loleaflet/src

Pranav Kant pranavk at collabora.co.uk
Sun Aug 7 16:10:26 UTC 2016


 loleaflet/dist/leaflet.css                   |    7 +-
 loleaflet/src/core/LOUtil.js                 |   21 ++++++
 loleaflet/src/core/Socket.js                 |    3 
 loleaflet/src/layer/marker/Cursor.js         |   12 ++-
 loleaflet/src/layer/tile/CalcTileLayer.js    |    1 
 loleaflet/src/layer/tile/ImpressTileLayer.js |    1 
 loleaflet/src/layer/tile/TileLayer.js        |   86 ++++++++++++++++++++++++++-
 loleaflet/src/layer/tile/WriterTileLayer.js  |    1 
 8 files changed, 126 insertions(+), 6 deletions(-)

New commits:
commit 3fdd2cb15126e0f482e41b2505404a5b7950d38c
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:56:43 2016 +0530

    loleaflet: Handle 'viewcursorvisible' message

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 0adf21c..f76128b 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -354,6 +354,9 @@ L.TileLayer = L.GridLayer.extend({
 		else if (textMsg.startsWith('invalidateviewcursor:')) {
 			this._onInvalidateViewCursorMsg(textMsg);
 		}
+		else if (textMsg.startsWith('viewcursorvisible:')) {
+			this._onViewCursorVisibleMsg(textMsg);
+		}
 	},
 
 	_onCommandValuesMsg: function (textMsg) {
@@ -542,6 +545,23 @@ L.TileLayer = L.GridLayer.extend({
 		this._onUpdateViewCursor(viewId);
 	},
 
+	_onViewCursorVisibleMsg: function(textMsg) {
+		textMsg = textMsg.substring('viewcursorvisible:'.length + 1);
+		var obj = JSON.parse(textMsg);
+		var viewId = parseInt(obj.viewId);
+
+		// Ignore if viewid=0 or is same as ours
+		if (viewId === 0 || viewId === this._viewId) {
+			return;
+		}
+
+		if (typeof this._viewCursors[viewId] !== 'undefined') {
+			this._viewCursors[viewId].visible = (obj.visible === 'true');
+		}
+
+		this._onUpdateViewCursor(viewId);
+	},
+
 	_onPartPageRectanglesMsg: function (textMsg) {
 		textMsg = textMsg.substring(19);
 		var pages = textMsg.split(';');
commit d307315f758ff26f16545077cc6a9fd6c1434b6e
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:51:25 2016 +0530

    loleaflet: Ignore irrelevant view messages coming from server
    
    View callbacks with viewid = 0 seems strange; it always lurks
    around but is never attached to any view.
    
    Also, view callbacks with viewid = our own viewid should not be
    sent from the server, lets ignore them for now.

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 3374f02..0adf21c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -522,6 +522,11 @@ L.TileLayer = L.GridLayer.extend({
 		var obj = JSON.parse(textMsg);
 		var viewId = parseInt(obj.viewId);
 
+		// Ignore if viewid=0 or is same as ours
+		if (viewId === 0 || viewId === this._viewId) {
+			return;
+		}
+
 		var strTwips = obj.rectangle.match(/\d+/g);
 		var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
 		var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
commit 6ff4cd69f0740604a8fdd5a5fa5e5aea2edb1b69
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:49:47 2016 +0530

    loleaflet: Handle 'invalidateviewcursor' and show colored cursors
    
    ... for different views based on view ids received from the
    server.

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 15d95b6..3374f02 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -95,6 +95,10 @@ L.TileLayer = L.GridLayer.extend({
 		this._prevCellCursor = L.LatLngBounds.createDefault();
 		// Position and size of the selection start (as if there would be a cursor caret there).
 
+		// View cursors with viewId to 'cursor info' mapping
+		// Eg: 1: {rectangle: 'x, y, w, h', visible: false}
+		this._viewCursors = {};
+
 		this._lastValidPart = -1;
 		// Cursor marker
 		this._cursorMarker = null;
@@ -347,6 +351,9 @@ L.TileLayer = L.GridLayer.extend({
 		else if (textMsg.startsWith('contextmenu:')) {
 			this._onContextMenuMsg(textMsg);
 		}
+		else if (textMsg.startsWith('invalidateviewcursor:')) {
+			this._onInvalidateViewCursorMsg(textMsg);
+		}
 	},
 
 	_onCommandValuesMsg: function (textMsg) {
@@ -510,6 +517,26 @@ L.TileLayer = L.GridLayer.extend({
 		this._onUpdateCursor();
 	},
 
+	_onInvalidateViewCursorMsg: function (textMsg) {
+		textMsg = textMsg.substring('invalidateviewcursor:'.length + 1);
+		var obj = JSON.parse(textMsg);
+		var viewId = parseInt(obj.viewId);
+
+		var strTwips = obj.rectangle.match(/\d+/g);
+		var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
+		var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
+		var bottomRightTwips = topLeftTwips.add(offset);
+
+		this._viewCursors[viewId] = this._viewCursors[viewId] || {};
+		this._viewCursors[viewId].bounds = new L.LatLngBounds(
+			this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
+			this._twipsToLatLng(bottomRightTwips, this._map.getZoom())),
+		this._viewCursors[viewId].part = obj.part;
+		this._viewCursors[viewId].visible = true;
+
+		this._onUpdateViewCursor(viewId);
+	},
+
 	_onPartPageRectanglesMsg: function (textMsg) {
 		textMsg = textMsg.substring(19);
 		var pages = textMsg.split(';');
@@ -883,6 +910,38 @@ L.TileLayer = L.GridLayer.extend({
 		}
 	},
 
+	// Update colored non-blinking view cursor
+	_onUpdateViewCursor: function(viewId) {
+		if (typeof this._viewCursors[viewId] !== 'object' ||
+		    typeof this._viewCursors[viewId].bounds !== 'object') {
+			return;
+		}
+
+		var pixBounds = L.bounds(this._map.latLngToLayerPoint(this._viewCursors[viewId].bounds.getSouthWest()),
+		                         this._map.latLngToLayerPoint(this._viewCursors[viewId].bounds.getNorthEast()));
+		var viewCursorPos = this._viewCursors[viewId].bounds.getNorthWest();
+		var viewCursorMarker = this._viewCursors[viewId].marker;
+		var viewCursorVisible = this._viewCursors[viewId].visible;
+
+		if (viewCursorVisible && !this._isEmptyRectangle(this._viewCursors[viewId].bounds)) {
+			if (viewCursorMarker) {
+				this._map.removeLayer(viewCursorMarker);
+			}
+			var viewCursorOptions = {
+				color: L.LOUtil.getViewIdHexColor(viewId),
+				blink: false
+			};
+			viewCursorMarker = L.cursor(viewCursorPos, viewCursorOptions);
+			this._map.addLayer(viewCursorMarker);
+			viewCursorMarker.setSize(pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())));
+
+		} else if (viewCursorMarker) {
+			this._map.removeLayer(this._viewCursors[viewId].marker);
+		}
+
+		this._viewCursors[viewId].marker = viewCursorMarker;
+	},
+
 	// Update dragged graphics selection resize.
 	_onGraphicEdit: function (e) {
 		if (!e.handle) { return; }
commit 0284235da150ddf6dac70c0add2f304deaa5f0fe
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:49:16 2016 +0530

    loleaflet: Support for non-blinking colored cursors

diff --git a/loleaflet/src/layer/marker/Cursor.js b/loleaflet/src/layer/marker/Cursor.js
index f5a7033..faa5177 100644
--- a/loleaflet/src/layer/marker/Cursor.js
+++ b/loleaflet/src/layer/marker/Cursor.js
@@ -49,8 +49,14 @@ L.Cursor = L.Layer.extend({
 
 	_initLayout: function () {
 		this._container = L.DomUtil.create('div', 'leaflet-cursor-container');
-		// a black rectangle
-		this._cursor = L.DomUtil.create('div', 'leaflet-cursor blinking-cursor', this._container);
+		this._cursor = L.DomUtil.create('div', 'leaflet-cursor', this._container);
+		if (this.options.blink) {
+			L.DomUtil.addClass(this._cursor, 'blinking-cursor');
+		}
+
+		if (this.options.color) {
+			L.DomUtil.setStyle(this._cursor, 'background', this.options.color);
+		}
 
 		L.DomEvent
 			.disableClickPropagation(this._cursor)
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index f2dfdef..15d95b6 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -872,7 +872,7 @@ L.TileLayer = L.GridLayer.extend({
 				this._map.removeLayer(this._cursorMarker);
 			}
 
-			this._cursorMarker = L.cursor(cursorPos);
+			this._cursorMarker = L.cursor(cursorPos, {blink: true});
 			this._map.addLayer(this._cursorMarker);
 			this._cursorMarker.setSize(pixBounds.getSize().multiplyBy(
 						this._map.getZoomScale(this._map.getZoom())));
commit 726b213dcfcf0d2a6feff39774d6f9e87bd0e90a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:43:15 2016 +0530

    loleaflet: Add viewId to color mapping; using colordata.hxx

diff --git a/loleaflet/src/core/LOUtil.js b/loleaflet/src/core/LOUtil.js
index cbdce2a..8b11379 100644
--- a/loleaflet/src/core/LOUtil.js
+++ b/loleaflet/src/core/LOUtil.js
@@ -3,6 +3,21 @@
  */
 
 L.LOUtil = {
+	// Based on core.git's colordata.hxx: COL_AUTHOR1_DARK...COL_AUTHOR9_DARK
+	// consisting of arrays of RGB values
+	// Maybe move the color logic to separate file when it becomes complex
+	darkColors: [
+		[198, 146, 0],
+		[6,  70, 162],
+		[87, 157,  28],
+		[105,  43, 157],
+		[197,   0,  11],
+		[0, 128, 128],
+		[140, 132,  0],
+		[53,  85, 107],
+		[209, 118,   0]
+	],
+
 	startSpinner: function (spinnerCanvas, spinnerSpeed) {
 		var spinnerInterval;
 		spinnerCanvas.width = 50;
@@ -26,5 +41,11 @@ L.LOUtil = {
 		}, 1);
 
 		return spinnerInterval;
+	},
+
+	getViewIdHexColor: function(viewId) {
+		var color = this.darkColors[(viewId + 1) % this.darkColors.length];
+		var hex = color[2] | (color[1] << 8) | (color[0] << 16);
+		return '#' + ('000000' + hex.toString(16)).slice(-6);
 	}
 };
commit 8dd2987871906e1af3e4c5e463f8f075284a74bc
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 18:39:20 2016 +0530

    loleaflet: Store viewId of the view received in 'status:' command

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 2f258d3..87f1ce6 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -381,6 +381,9 @@ L.Socket = L.Class.extend({
 			else if (tokens[i].substring(0, 5) === 'font=') {
 				command.font = window.decodeURIComponent(tokens[i].substring(5));
 			}
+			else if (tokens[i].substring(0, 7) === 'viewid=') {
+				command.viewid = tokens[i].substring(7);
+			}
 		}
 		if (command.tileWidth && command.tileHeight && this._map._docLayer) {
 			var defaultZoom = this._map.options.zoom;
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 9b067f3..2641a12 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -147,6 +147,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 			this._docType = command.type;
 			this._parts = command.parts;
 			this._selectedPart = command.selectedPart;
+			this._viewId = command.viewid;
 			var mapSize = this._map.getSize();
 			var width = this._docWidthTwips / this._tileWidthTwips * this._tileSize;
 			var height = this._docHeightTwips / this._tileHeightTwips * this._tileSize;
diff --git a/loleaflet/src/layer/tile/ImpressTileLayer.js b/loleaflet/src/layer/tile/ImpressTileLayer.js
index 2d8e8c0..8f2358a 100644
--- a/loleaflet/src/layer/tile/ImpressTileLayer.js
+++ b/loleaflet/src/layer/tile/ImpressTileLayer.js
@@ -119,6 +119,7 @@ L.ImpressTileLayer = L.TileLayer.extend({
 			this._updateMaxBounds(true);
 			this._documentInfo = textMsg;
 			this._parts = command.parts;
+			this._viewId = command.viewid;
 			this._selectedPart = command.selectedPart;
 			this._resetPreFetching(true);
 			this._update();
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index a42b67d..ab604aa 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -122,6 +122,7 @@ L.WriterTileLayer = L.TileLayer.extend({
 			this._parts = 1;
 			this._currentPage = command.selectedPart;
 			this._pages = command.parts;
+			this._viewId = parseInt(command.viewid);
 			this._map.fire('pagenumberchanged', {
 				currentPage: this._currentPage,
 				pages: this._pages,
commit d144d4ac4765252f84c6b1cf67ef67b34ad7b378
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sun Aug 7 15:56:40 2016 +0530

    loleaflet: Separate blinking-cursor property from cursor
    
    ... so that it is possibe to make cursor non-blinking whenever we
    want. This will be used in subsequent commits for view cursors.

diff --git a/loleaflet/dist/leaflet.css b/loleaflet/dist/leaflet.css
index e3c12b3..eeeb24c 100644
--- a/loleaflet/dist/leaflet.css
+++ b/loleaflet/dist/leaflet.css
@@ -559,15 +559,18 @@ a.leaflet-control-buttons:hover:first-child {
 	border: 1px solid #666;
 	}
 
-.leaflet-cursor {
+.leaflet-cursor-container {
 	position: absolute;
 	text-align: center;
 	}
 
-.blinking-cursor {
+.leaflet-cursor {
 	background: black;
 	width: 2px;
 	pointer-events: none;
+	}
+
+.blinking-cursor {
 	-webkit-animation: 1s blink step-end 0s infinite;
 	-moz-animation: 1s blink step-end 0s infinite;
 	-ms-animation: 1s blink step-end 0s infinite;
diff --git a/loleaflet/src/layer/marker/Cursor.js b/loleaflet/src/layer/marker/Cursor.js
index 4fb32c2..f5a7033 100644
--- a/loleaflet/src/layer/marker/Cursor.js
+++ b/loleaflet/src/layer/marker/Cursor.js
@@ -48,9 +48,9 @@ L.Cursor = L.Layer.extend({
 	},
 
 	_initLayout: function () {
-		this._container = L.DomUtil.create('div', 'leaflet-cursor');
+		this._container = L.DomUtil.create('div', 'leaflet-cursor-container');
 		// a black rectangle
-		this._cursor = L.DomUtil.create('div', 'blinking-cursor', this._container);
+		this._cursor = L.DomUtil.create('div', 'leaflet-cursor blinking-cursor', this._container);
 
 		L.DomEvent
 			.disableClickPropagation(this._cursor)


More information about the Libreoffice-commits mailing list