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

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 24 13:27:39 UTC 2020


 loleaflet/src/geometry/Point.js             |   24 ++++
 loleaflet/src/layer/SplitPanesContext.js    |    4 
 loleaflet/src/layer/tile/CalcTileLayer.js   |  164 ++++++++++++++++++++++++----
 loleaflet/src/layer/tile/CanvasTileLayer.js |    8 +
 4 files changed, 177 insertions(+), 23 deletions(-)

New commits:
commit 12f1fd3a3e50877af02511340dfa99b365330533
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Fri Jul 17 13:29:18 2020 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Fri Jul 24 15:27:20 2020 +0200

    sync freeze(split) indices with core...
    
    via the new uno commands:
    
    .uno:FreezePanesColumn and .uno:FreezePanesRow
    
    This also means the freeze(split) positions for each sheet are shared
    with all users(views) who are using the same document.
    
    An option to allow "independent" freeze(split) panes will be added in a
    follow-up commit but to make such freezes(splits) persist it needs help
    from core which is WIP.
    
    Change-Id: I022148fe2711450d453e74e7ddbf090e0b2f24c1
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/99368
    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/geometry/Point.js b/loleaflet/src/geometry/Point.js
index 37acfb20c..303442c25 100644
--- a/loleaflet/src/geometry/Point.js
+++ b/loleaflet/src/geometry/Point.js
@@ -125,6 +125,30 @@ L.Point.prototype = {
 		       Math.abs(point.y) <= Math.abs(this.y);
 	},
 
+	assign: function (point) {
+		var xChanged = this.setX(point.x);
+		var yChanged = this.setY(point.y);
+		return xChanged || yChanged;
+	},
+
+	setX: function (x) {
+		if (x === this.x) {
+			return false;
+		}
+
+		this.x = x;
+		return true;
+	},
+
+	setY: function (y) {
+		if (y === this.y) {
+			return false;
+		}
+
+		this.y = y;
+		return true;
+	},
+
 	toString: function () {
 		return 'Point(' +
 		        L.Util.formatNum(this.x) + ', ' +
diff --git a/loleaflet/src/layer/SplitPanesContext.js b/loleaflet/src/layer/SplitPanesContext.js
index ed38d817d..74c54d778 100644
--- a/loleaflet/src/layer/SplitPanesContext.js
+++ b/loleaflet/src/layer/SplitPanesContext.js
@@ -86,7 +86,7 @@ L.SplitPanesContext = L.Class.extend({
 		console.assert(typeof splitX === 'number', 'splitX must be a number');
 
 		if (this._splitPos.x === splitX) {
-			if (forceUpdate) {
+			if (forceUpdate || !this._docLayer.hasXSplitter()) {
 				this._updateXSplitter();
 			}
 			return;
@@ -103,7 +103,7 @@ L.SplitPanesContext = L.Class.extend({
 		console.assert(typeof splitY === 'number', 'splitY must be a number');
 
 		if (this._splitPos.y === splitY) {
-			if (forceUpdate) {
+			if (forceUpdate || !this._docLayer.hasYSplitter()) {
 				this._updateYSplitter();
 			}
 			return;
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 1c681594d..6a4db23b5 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -56,8 +56,8 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 		map.on('AnnotationCancel', this._onAnnotationCancel, this);
 		map.on('AnnotationReply', this._onAnnotationReply, this);
 		map.on('AnnotationSave', this._onAnnotationSave, this);
-		map.on('splitposchanged', this._calcSplitCell, this);
-
+		map.on('splitposchanged', this.setSplitCellFromPos, this);
+		map.on('commandstatechanged', this._onCommandStateChanged, this);
 		map.uiManager.initializeSpecializedUI('spreadsheet');
 	},
 
@@ -460,7 +460,7 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 		}
 		this._restrictDocumentSize();
 		this._replayPrintTwipsMsgs();
-		this._updateSplitPos();
+		this.setSplitPosFromCell();
 		this._map.fire('zoomchanged');
 		this.refreshViewData();
 		this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition');
@@ -737,34 +737,28 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 		this._updateHeadersGridLines(undefined, true /* updateCols */,
 			true /* updateRows */);
 
-		this._updateSplitPos();
+		this.setSplitPosFromCell();
 
 		this._map.fire('sheetgeometrychanged');
 	},
 
-	_updateSplitPos: function (force) {
-		if (this._splitPanesContext) {
-			if (this._splitPanesContext._splitCell) {
-				var splitCell = this._splitPanesContext._splitCell;
-				var newSplitPos = this.sheetGeometry.getCellRect(splitCell.x, splitCell.y).min;
-				this._splitPanesContext.setSplitPos(newSplitPos.x, newSplitPos.y, force); // will update the splitters.
-			}
-			else {
-				// Can happen only on load.
-				this._splitPanesContext.alignSplitPos();
-				this._calcSplitCell();
-			}
+	// Calculates the split position in (css-pixels) from the split-cell.
+	setSplitPosFromCell: function (forceSplittersUpdate) {
+		if (!this.sheetGeometry || !this._splitPanesContext) {
+			return;
 		}
+
+		this._splitPanesContext.setSplitPosFromCell(forceSplittersUpdate);
 	},
 
-	_calcSplitCell: function () {
+	// Calculates the split-cell from the split position in (css-pixels).
+	setSplitCellFromPos: function () {
 
 		if (!this.sheetGeometry || !this._splitPanesContext) {
 			return;
 		}
 
-		this._splitPanesContext._splitCell =
-			this.sheetGeometry.getCellFromPos(this._splitPanesContext.getSplitPos(), 'csspixels');
+		this._splitPanesContext.setSplitCellFromPos();
 	},
 
 	_switchSplitPanesContext: function () {
@@ -781,17 +775,79 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 
 		var spContext = this._splitPaneCache[this._selectedPart];
 		if (!spContext) {
-			spContext = new L.SplitPanesContext(this);
+			spContext = new L.CalcSplitPanesContext(this);
 			this._splitPaneCache[this._selectedPart] = spContext;
 		}
 
 		this._splitPanesContext = spContext;
 		if (this.sheetGeometry) {
 			// Force update of the splitter lines.
-			this._updateSplitPos(true);
+			this.setSplitPosFromCell(true);
+		}
+	},
+
+	_onCommandStateChanged: function (e) {
+
+		if (e.commandName === '.uno:FreezePanesColumn') {
+			this._onSplitStateChanged(e, true /* isSplitCol */);
+		}
+		else if (e.commandName === '.uno:FreezePanesRow') {
+			this._onSplitStateChanged(e, false /* isSplitCol */);
+		}
+	},
+
+	_onSplitStateChanged: function (e, isSplitCol) {
+		if (!this._splitPanesContext) {
+			return;
+		}
+
+		if (!this._splitCellState) {
+			this._splitCellState = new L.Point(-1, -1);
+		}
+
+		var newSplitIndex = Math.floor(parseInt(e.state));
+		console.assert(!isNaN(newSplitIndex) && newSplitIndex >= 0, 'invalid argument for ' + e.commandName);
+
+		// This stores the current split-cell state of core, so this should not be modified.
+		this._splitCellState[isSplitCol ? 'x' : 'y'] = newSplitIndex;
+
+		var changed = isSplitCol ? this._splitPanesContext.setSplitCol(newSplitIndex) :
+			this._splitPanesContext.setSplitRow(newSplitIndex);
+
+		if (changed) {
+			this.setSplitPosFromCell();
 		}
 	},
 
+	sendSplitIndex: function (newSplitIndex, isSplitCol) {
+
+		if (!this._map.isPermissionEdit() || !this._splitCellState) {
+			return false;
+		}
+
+		var splitColState = this._splitCellState.x;
+		var splitRowState = this._splitCellState.y;
+		if (splitColState === -1 || splitRowState === -1) {
+			// Did not get the 'first' FreezePanesColumn/FreezePanesRow messages from core yet.
+			return false;
+		}
+
+		var currentState = isSplitCol ? splitColState : splitRowState;
+		if (currentState === newSplitIndex) {
+			return false;
+		}
+
+		var unoName = isSplitCol ? 'FreezePanesColumn' : 'FreezePanesRow';
+		var command = {};
+		command[unoName] = {
+			type: 'int32',
+			value: newSplitIndex
+		};
+
+		this._map.sendUnoCommand('.uno:' + unoName, command);
+		return true;
+	},
+
 	_onCommandValuesMsg: function (textMsg) {
 		var jsonIdx = textMsg.indexOf('{');
 		if (jsonIdx === -1)
@@ -994,6 +1050,72 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({
 
 		return scroll;
 	},
+
+	getSelectedPart: function () {
+		return this._selectedPart;
+	},
+
+});
+
+L.CalcSplitPanesContext = L.SplitPanesContext.extend({
+
+	_setDefaults: function () {
+		this._part = this._docLayer.getSelectedPart();
+		this._splitPos = new L.Point(0, 0);
+		this._splitCell = new L.Point(0, 0);
+	},
+
+	setSplitCell: function (splitCell) {
+		console.assert(splitCell instanceof L.Point, 'invalid argument type');
+		 return this._splitCell.assign(splitCell);
+	},
+
+	setSplitCol: function (splitCol) {
+		console.assert(typeof splitCol === 'number', 'invalid argument type');
+		return this._splitCell.setX(splitCol);
+	},
+
+	setSplitRow: function (splitRow) {
+		console.assert(typeof splitRow === 'number', 'invalid argument type');
+		return this._splitCell.setY(splitRow);
+	},
+
+	getSplitCell: function () {
+		return this._splitCell.clone();
+	},
+
+	getSplitCol: function () {
+		return this._splitCell.x;
+	},
+
+	getSplitRow: function () {
+		return this._splitCell.y;
+	},
+
+	// Calculates the split position in (css-pixels) from the split-cell.
+	setSplitPosFromCell: function (forceSplittersUpdate) {
+		var newSplitPos = this._docLayer.sheetGeometry.getCellRect(this._splitCell.x, this._splitCell.y).min;
+
+		// setSplitPos limits the split position based on the screen size and it fires 'splitposchanged' (if there is any change).
+		// setSplitCellFromPos gets invoked on 'splitposchanged' to sync the split-cell with the position change if any.
+		this.setSplitPos(newSplitPos.x, newSplitPos.y, forceSplittersUpdate);
+
+		// It is possible that the split-position did not change due to screen size limits, so no 'splitposchanged' but
+		// we still need to sync the split-cell.
+		this.setSplitCellFromPos();
+	},
+
+	// Calculates the split-cell from the split position in (css-pixels).
+	setSplitCellFromPos: function () {
+
+		// This should not call setSplitPosFromCell() directly/indirectly.
+
+		var newSplitCell = this._docLayer.sheetGeometry.getCellFromPos(this._splitPos, 'csspixels');
+
+		// Send new state via uno commands if there is any change.
+		this.setSplitCol(newSplitCell.x) && this._docLayer.sendSplitIndex(newSplitCell.x, true /*  isSplitCol */);
+		this.setSplitRow(newSplitCell.y) && this._docLayer.sendSplitIndex(newSplitCell.y, false /* isSplitCol */);
+	},
 });
 
 L.MessageStore = L.Class.extend({
diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 214dc5b54..3190fbb11 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -1370,4 +1370,12 @@ L.CanvasTileLayer = L.TileLayer.extend({
 		}
 	},
 
+	hasXSplitter: function () {
+		return !!(this._xSplitter);
+	},
+
+	hasYSplitter: function () {
+		return !!(this._ySplitter);
+	},
+
 });


More information about the Libreoffice-commits mailing list