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

Jan Holesovsky kendy at collabora.com
Wed Jun 10 10:10:05 PDT 2015


 loleaflet/src/layer/tile/GridLayer.js |   29 +++++++++----
 loleaflet/src/layer/tile/TileLayer.js |   71 +++++++++++++++++++---------------
 2 files changed, 61 insertions(+), 39 deletions(-)

New commits:
commit 73974f7397414b0931b80729ea716387f3c6a130
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jun 10 18:58:34 2015 +0200

    Fix JavaScript part of the tiles invalidation.
    
    Now it is possible to type in in some cases, but for the full functionality,
    tuning together with the server is necessary.

diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 21c4959..acbf219 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -552,7 +552,11 @@ L.GridLayer = L.Layer.extend({
 		var tile = this._tiles[key];
 		if (!tile) { return; }
 
-		this._tileCache[key] = tile.el.src;
+		// FIXME: this _tileCache is used for prev/next slide; but it is
+		// dangerous in connection with typing / invalidation, so let's
+		// comment it out for now
+		//this._tileCache[key] = tile.el.src;
+
 		L.DomUtil.remove(tile.el);
 		delete this._tiles[key];
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index efe6414..24363c3 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -154,30 +154,40 @@ L.TileLayer = L.GridLayer.extend({
 							this._twipsToLatLng(bottomRightTwips));
 			this._onUpdateCursor();
 		}
-		else if (textMsg.startsWith('invalidatetiles:') && !textMsg.match('EMPTY')) {
-			strTwips = textMsg.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._map._fadeAnimated = false;
-
-			for (var key in this._tiles) {
-				var coords = this._tiles[key].coords;
-				var point1 = this._coordsToTwips(coords);
-				var point2 = new L.Point(point1.x + this._tileWidthTwips, point1.y + this._tileHeightTwips);
-				var bounds = new L.Bounds(point1, point2);
-				if (bounds.contains(topLeftTwips) || bounds.contains(bottomRightTwips)) {
-					this._map.socket.send('tile ' +
-						'part=' + coords.part + ' ' +
-						'width=' + this._tileSize + ' ' +
-						'height=' + this._tileSize + ' ' +
-						'tileposx=' + point1.x + ' '	+
-						'tileposy=' + point1.y + ' ' +
-						'tilewidth=' + this._tileWidthTwips + ' ' +
-						'tileheight=' + this._tileHeightTwips);
+		else if (textMsg.startsWith('invalidatetiles:')) {
+			if (textMsg.match('EMPTY')) {
+				// invalidate everything
+				this.redraw();
+				for (var key in this._tiles) {
+					this._addTile(this._tiles[key].coords);
 				}
 			}
+			else {
+				strTwips = textMsg.match(/\d+/g);
+
+				// convert to bounds
+				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);
+				var invalidateBounds = new L.Bounds(topLeftTwips, bottomRightTwips);
+
+				// FIXME - we want the fading when zooming, but not when
+				// typing; we need to modify this so that we fade only
+				// the tiles that do not exist yet
+				this._map._fadeAnimated = false;
+
+				for (var key in this._tiles) {
+					var coords = this._tiles[key].coords;
+					var point1 = this._coordsToTwips(coords);
+					var point2 = new L.Point(point1.x + this._tileWidthTwips, point1.y + this._tileHeightTwips);
+					var tileBounds = new L.Bounds(point1, point2);
+
+					if (invalidateBounds.intersects(tileBounds)) {
+						this._addTile(coords);
+					}
+				}
+				this._update();
+			}
 		}
 		else if (textMsg.startsWith('status:')) {
 			var command = this._parseServerCmd(textMsg);
commit ecfe65b37f9139403817431f36782a2ca57b7e02
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Wed Jun 10 18:10:50 2015 +0200

    Don't actually create the tiles until after we get them from the server.
    
    When a tile is requested, don't create anything yet, just send the request.
    Create the tile after we actually get it from the server.
    
    This is in preparation for the cancellation of the tiles requests.

diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index e787aa5..21c4959 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -488,14 +488,11 @@ L.GridLayer = L.Layer.extend({
 				this.fire('loading');
 			}
 
-			// create DOM fragment to append tiles in one batch
-			var fragment = document.createDocumentFragment();
-
+			// send the requests for tiles (requests only - they are not
+			// created before we actually really get them from the server)
 			for (i = 0; i < queue.length; i++) {
-				this._addTile(queue[i], fragment);
+				this._addTile(queue[i]);
 			}
-
-			this._level.el.appendChild(fragment);
 		}
 	},
 
@@ -586,7 +583,7 @@ L.GridLayer = L.Layer.extend({
 		}
 	},
 
-	_addTile: function (coords, fragment) {
+	_addTileToMap: function (coords, fragment, bitmap_src) {
 		var tilePos = this._getTilePos(coords),
 			key = this._tileCoordsToKey(coords);
 		var tile = this.createTile(this._wrapCoords(coords), L.bind(this._tileReady, this, coords));
@@ -604,6 +601,9 @@ L.GridLayer = L.Layer.extend({
 		// which is slow, and it also fixes gaps between tiles in Safari
 		L.DomUtil.setPosition(tile, tilePos, true);
 
+		// set the bitmap data ('data:image/png;base64,...');
+		tile.src = bitmap_src;
+
 		// save tile in cache
 		this._tiles[key] = {
 			el: tile,
@@ -612,10 +612,15 @@ L.GridLayer = L.Layer.extend({
 		};
 
 		fragment.appendChild(tile);
+
 		this.fire('tileloadstart', {
 			tile: tile,
 			coords: coords
 		});
+	},
+
+	_addTile: function (coords) {
+		var key = this._tileCoordsToKey(coords);
 
 		if (!this._tileCache[key]) {
 			if (this.options.useSocket && this._map.socket) {
@@ -631,7 +636,9 @@ L.GridLayer = L.Layer.extend({
 			}
 		}
 		else {
-			tile.src = this._tileCache[key];
+			var fragment = document.createDocumentFragment();
+			this._addTileToMap(coords, fragment, this._tileCache[key]);
+			this._level.el.appendChild(fragment);
 		}
 	},
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 65d8a02..efe6414 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -213,15 +213,16 @@ L.TileLayer = L.GridLayer.extend({
 			coords.part = command.part;
 			var data = bytes.subarray(index + 1);
 
-			var key = this._tileCoordsToKey(coords);
-			var tile = this._tiles[key];
-			if (tile) {
-				var strBytes = '';
-				for (var i = 0; i < data.length; i++) {
-					strBytes += String.fromCharCode(data[i]);
-				}
-				tile.el.src = 'data:image/png;base64,' + window.btoa(strBytes);
+			// read the tile data
+			var strBytes = '';
+			for (var i = 0; i < data.length; i++) {
+				strBytes += String.fromCharCode(data[i]);
 			}
+
+			// setup the tile
+			var fragment = document.createDocumentFragment();
+			this._addTileToMap(coords, fragment, 'data:image/png;base64,' + window.btoa(strBytes));
+			this._level.el.appendChild(fragment);
 		}
 		else if (textMsg.startsWith('textselection:')) {
 			strTwips = textMsg.match(/\d+/g);


More information about the Libreoffice-commits mailing list