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

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Sun Jul 5 14:40:14 UTC 2020


 loleaflet/src/layer/tile/CalcTileLayer.js |  125 ++++++++++++++++++++++++++++++
 loleaflet/src/layer/tile/TileLayer.js     |   14 ++-
 2 files changed, 135 insertions(+), 4 deletions(-)

New commits:
commit e0eca220541fcd8d9ab236e6a274f00e256cc2e7
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Thu May 28 06:41:23 2020 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Sun Jul 5 16:39:53 2020 +0200

    Replay print-twips messages for a couple of reasons...
    
    If L.CalcTileLayer.options.printTwipsMsgsEnabled is set, we will not get
    some messages (with coordinates) from core when zoom changes because
    print-twips coordinates are zoom-invariant. So we need to remember the
    last version of each of them and replay, when zoom is changed.  We also
    need to replay the messages, when sheet-geometry changes. This is
    because it is possible for the updated print-twips messages to arrive
    before the sheet-geometry update message arrives.
    
    Change-Id: Icd77ad77c7642aae24e68fb0b7f229c7ec62484a
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98114
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index db08b2019..f37caa6c5 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -238,7 +238,60 @@ L.CalcTileLayer = L.TileLayer.extend({
 		}
 	},
 
+	_saveMessageForReplay: function (textMsg, viewId) {
+		// If this.options.printTwipsMsgsEnabled is set, we will not get some messages (with coordinates)
+		// from core when zoom changes because print-twips coordinates are zoom-invariant. So we need to
+		// remember the last version of them and replay, when zoom is changed.
+		// We also need to replay the messages, when sheet-geometry changes. This is because it is possible for
+		// the updated print-twips messages to arrive before the sheet-geometry update message arrives.
+		if (!this.options.printTwipsMsgsEnabled) {
+			return;
+		}
+
+		if (!this._printTwipsMessagesForReplay) {
+			var ownViewTypes = [
+				'cellcursor',
+				'referencemarks',
+				'cellselectionarea',
+				'textselection',
+			];
+
+			var otherViewTypes = [
+				'cellviewcursor',
+				'textviewselection',
+			];
+
+			this._printTwipsMessagesForReplay = new L.MessageStore(ownViewTypes, otherViewTypes);
+		}
+
+		var colonIndex = textMsg.indexOf(':');
+		if (colonIndex === -1) {
+			return;
+		}
+
+		var msgType = textMsg.substring(0, colonIndex);
+		this._printTwipsMessagesForReplay.save(msgType, textMsg, viewId);
+	},
+
+	_clearMsgReplayStore: function () {
+		if (!this.options.printTwipsMsgsEnabled || !this._printTwipsMessagesForReplay) {
+			return;
+		}
+
+		this._printTwipsMessagesForReplay.clear();
+	},
+
+	// See _saveMessageForReplay.
+	_replayPrintTwipsMsgs: function () {
+		if (!this.options.printTwipsMsgsEnabled || !this._printTwipsMessagesForReplay) {
+			return;
+		}
+
+		this._printTwipsMessagesForReplay.forEach(this._onMessage.bind(this));
+	},
+
 	_onMessage: function (textMsg, img) {
+		this._saveMessageForReplay(textMsg);
 		if (textMsg.startsWith('comment:')) {
 			var obj = JSON.parse(textMsg.substring('comment:'.length + 1));
 			obj.comment.tab = parseInt(obj.comment.tab);
@@ -377,6 +430,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 	_onSetPartMsg: function (textMsg) {
 		var part = parseInt(textMsg.match(/\d+/g)[0]);
 		if (!this.isHiddenPart(part)) {
+			this._clearMsgReplayStore();
 			this.refreshViewData(undefined, false /* compatDataSrcOnly */, true /* sheetGeometryChanged */);
 		}
 	},
@@ -387,6 +441,7 @@ L.CalcTileLayer = L.TileLayer.extend({
 			this.sheetGeometry.setTileGeometryData(this._tileWidthTwips, this._tileHeightTwips,
 				this._tileSize, this._tilePixelScale);
 		}
+		this._replayPrintTwipsMsgs();
 		this.refreshViewData();
 		this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition');
 	},
@@ -621,6 +676,8 @@ L.CalcTileLayer = L.TileLayer.extend({
 			this.sheetGeometry.update(jsonMsgObj);
 		}
 
+		this._replayPrintTwipsMsgs();
+
 		this.sheetGeometry.setViewArea(this._pixelsToTwips(this._map._getTopLeftPoint()),
 			this._pixelsToTwips(this._map.getSize()));
 		this._updateHeadersGridLines(undefined, true /* updateCols */,
@@ -691,6 +748,74 @@ L.CalcTileLayer = L.TileLayer.extend({
 	}
 });
 
+L.MessageStore = L.Class.extend({
+
+	// ownViewTypes : The types of messages related to own view.
+	// otherViewTypes: The types of messages related to other views.
+	initialize: function (ownViewTypes, otherViewTypes) {
+
+		if (!Array.isArray(ownViewTypes) || !Array.isArray(otherViewTypes)) {
+			console.error('Unexpected argument types');
+			return;
+		}
+
+		var ownMessages = {};
+		ownViewTypes.forEach(function (msgType) {
+			ownMessages[msgType] = '';
+		});
+		this._ownMessages = ownMessages;
+
+		var othersMessages = {};
+		otherViewTypes.forEach(function (msgType) {
+			othersMessages[msgType] = [];
+		});
+		this._othersMessages = othersMessages;
+	},
+
+	clear: function () {
+		var msgs = this._ownMessages;
+		Object.keys(msgs).forEach(function (msgType) {
+			msgs[msgType] = '';
+		});
+
+		msgs = this._othersMessages;
+		Object.keys(msgs).forEach(function (msgType) {
+			msgs[msgType] = [];
+		});
+	},
+
+	save: function (msgType, textMsg, viewId) {
+
+		var othersMessage = (typeof viewId === 'number');
+
+		if (!othersMessage && this._ownMessages.hasOwnProperty(msgType)) {
+			this._ownMessages[msgType] = textMsg;
+			return;
+		}
+
+		if (othersMessage && this._othersMessages.hasOwnProperty(msgType)) {
+			this._othersMessages[msgType][viewId] = textMsg;
+		}
+	},
+
+	forEach: function (callback) {
+		if (typeof callback !== 'function') {
+			console.error('Invalid callback type');
+			return;
+		}
+
+		var ownMessages = this._ownMessages;
+		Object.keys(this._ownMessages).forEach(function (msgType) {
+			callback(ownMessages[msgType]);
+		});
+
+		var othersMessages = this._othersMessages;
+		Object.keys(othersMessages).forEach(function (msgType) {
+			othersMessages[msgType].forEach(callback);
+		});
+	}
+});
+
 
 // TODO: Move these somewhere more appropriate.
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index f2268776c..cc9cc8287 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1344,8 +1344,7 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	_onCellViewCursorMsg: function (textMsg) {
-		textMsg = textMsg.substring('cellviewcursor:'.length + 1);
-		var obj = JSON.parse(textMsg);
+		var obj = JSON.parse(textMsg.substring('cellviewcursor:'.length + 1));
 		var viewId = parseInt(obj.viewId);
 
 		// Ignore if viewid is same as ours
@@ -1374,6 +1373,10 @@ L.TileLayer = L.GridLayer.extend({
 
 		this._cellViewCursors[viewId].part = parseInt(obj.part);
 		this._onUpdateCellViewCursor(viewId);
+
+		if (this.isCalc()) {
+			this._saveMessageForReplay(textMsg, viewId);
+		}
 	},
 
 	_onUpdateCellViewCursor: function (viewId) {
@@ -1694,8 +1697,7 @@ L.TileLayer = L.GridLayer.extend({
 	},
 
 	_onTextViewSelectionMsg: function (textMsg) {
-		textMsg = textMsg.substring('textviewselection:'.length + 1);
-		var obj = JSON.parse(textMsg);
+		var obj = JSON.parse(textMsg.substring('textviewselection:'.length + 1));
 		var viewId = parseInt(obj.viewId);
 		var viewPart = parseInt(obj.part);
 
@@ -1725,6 +1727,10 @@ L.TileLayer = L.GridLayer.extend({
 		}
 
 		this._onUpdateTextViewSelection(viewId);
+
+		if (this.isCalc()) {
+			this._saveMessageForReplay(textMsg, viewId);
+		}
 	},
 
 	_updateReferenceMarks: function() {


More information about the Libreoffice-commits mailing list