[Libreoffice-commits] online.git: Branch 'feature/latency' - loleaflet/src

Tamás Zolnai tamas.zolnai at collabora.com
Sat Jun 16 14:31:39 UTC 2018


 loleaflet/src/layer/tile/GridLayer.js |   46 +++++++++++++++-------------------
 loleaflet/src/layer/tile/TileLayer.js |   14 ----------
 2 files changed, 21 insertions(+), 39 deletions(-)

New commits:
commit 10557402be22957d3a1fd1b93485199672f0ae10
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date:   Fri Jun 15 16:33:28 2018 +0200

    Send new clientvisiblearea and clientzoom messages
    
    when something is actually changed.
    
    Change-Id: I56983f5700cb9cbd0b660155a4dd0a2396b22e2a

diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 8b613b631..b10189169 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -24,6 +24,9 @@ L.GridLayer = L.Layer.extend({
 
 	initialize: function (options) {
 		L.setOptions(this, options);
+
+		this._clientZoom = '';
+		this._clientVisibleArea = '';
 	},
 
 	onAdd: function () {
@@ -555,10 +558,8 @@ L.GridLayer = L.Layer.extend({
 			this._level.el.appendChild(fragment);
 		}
 
-		this._invalidateClientVisibleArea();
 		this._sendClientVisibleArea();
 
-		this._updateClientZoom();
 		this._sendClientZoom();
 	},
 
@@ -689,36 +690,31 @@ L.GridLayer = L.Layer.extend({
 		}
 	},
 
-	_invalidateClientVisibleArea: function() {
-		if (this._debug) {
-			this._debugInfo.clearLayers();
-			for (var key in this._tiles) {
-				this._tiles[key]._debugPopup = null;
-				this._tiles[key]._debugTile = null;
-			}
-		}
-		this._clientVisibleArea = true;
-	},
-
 	_sendClientVisibleArea: function () {
-		if (this._clientVisibleArea) {
-			// Visible area is dirty, update it on the server.
-			var visibleTopLeft = this._latLngToTwips(this._map.getBounds().getNorthWest());
-			var visibleBottomRight = this._latLngToTwips(this._map.getBounds().getSouthEast());
-			var visibleArea = new L.Bounds(visibleTopLeft, visibleBottomRight);
-			var size = new L.Point(visibleArea.getSize().x, visibleArea.getSize().y);
-			var payload = 'clientvisiblearea x=' + Math.round(visibleTopLeft.x) + ' y=' + Math.round(visibleTopLeft.y) +
-				' width=' + Math.round(size.x) + ' height=' + Math.round(size.y);
-			this._map._socket.sendMessage(payload);
-			this._clientVisibleArea = false;
+		var visibleTopLeft = this._latLngToTwips(this._map.getBounds().getNorthWest());
+		var visibleBottomRight = this._latLngToTwips(this._map.getBounds().getSouthEast());
+		var visibleArea = new L.Bounds(visibleTopLeft, visibleBottomRight);
+		var size = new L.Point(visibleArea.getSize().x, visibleArea.getSize().y);
+		var newClientVisibleArea = 'clientvisiblearea x=' + Math.round(visibleTopLeft.x) + ' y=' + Math.round(visibleTopLeft.y) +
+			' width=' + Math.round(size.x) + ' height=' + Math.round(size.y);
+
+		if (this._clientVisibleArea !== newClientVisibleArea) {
+			// Visible area is dirty, update it on the server
+			this._clientVisibleArea = newClientVisibleArea
+			this._map._socket.sendMessage(this._clientVisibleArea);
 		}
 	},
 
 	_sendClientZoom: function () {
-		if (this._clientZoom) {
+		var newClientZoom = 'tilepixelwidth=' + this._tileWidthPx + ' ' +
+			'tilepixelheight=' + this._tileHeightPx + ' ' +
+			'tiletwipwidth=' + this._tileWidthTwips + ' ' +
+			'tiletwipheight=' + this._tileHeightTwips;
+
+		if (this._clientZoom !== newClientZoom) {
 			// the zoom level has changed
+			this._clientZoom = newClientZoom;
 			this._map._socket.sendMessage('clientzoom ' + this._clientZoom);
-			this._clientZoom = null;
 		}
 	},
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 42087226f..f7d4901ea 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -147,15 +147,11 @@ L.TileLayer = L.GridLayer.extend({
 		this._msgQueue = [];
 		this._toolbarCommandValues = {};
 		this._previewInvalidations = [];
-		this._updateClientZoom();
 
 		this._followThis = -1;
 		this._editorId = -1;
 		this._followUser = false;
 		this._followEditor = false;
-
-		// Mark visible area as dirty by default.
-		this._invalidateClientVisibleArea();
 	},
 
 	onAdd: function (map) {
@@ -256,9 +252,7 @@ L.TileLayer = L.GridLayer.extend({
 		if (this._docType === 'spreadsheet') {
 			map.on('zoomend', this._onCellCursorShift, this);
 		}
-		map.on('zoomend', this._updateClientZoom, this);
 		map.on('zoomend', L.bind(this.eachView, this, this._viewCursors, this._onUpdateViewCursor, this, false));
-		map.on('resize zoomend', this._invalidateClientVisibleArea, this);
 		map.on('dragstart', this._onDragStart, this);
 		map.on('requestloksession', this._onRequestLOKSession, this);
 		map.on('error', this._mapOnError, this);
@@ -489,7 +483,6 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	toggleTileDebugMode: function() {
-		this._invalidateClientVisibleArea();
 		this._debug = !this._debug;
 		if (!this._debug) {
 			this._map.removeLayer(this._debugInfo);
@@ -2250,13 +2243,6 @@ L.TileLayer = L.GridLayer.extend({
 		this._previewInvalidations = [];
 	},
 
-	_updateClientZoom: function () {
-		this._clientZoom = 'tilepixelwidth=' + this._tileWidthPx + ' ' +
-			'tilepixelheight=' + this._tileHeightPx + ' ' +
-			'tiletwipwidth=' + this._tileWidthTwips + ' ' +
-			'tiletwipheight=' + this._tileHeightTwips;
-	},
-
 	_debugGetTimeArray: function() {
 		return {count: 0, ms: 0, best: Number.MAX_SAFE_INTEGER, worst: 0, date: 0};
 	},


More information about the Libreoffice-commits mailing list