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

Dennis Francis (via logerrit) logerrit at kemper.freedesktop.org
Wed Jul 8 14:50:18 UTC 2020


 loleaflet/Makefile.am                    |    1 
 loleaflet/src/layer/SplitPanesContext.js |  218 +++++++++++++++++++++++++++++++
 2 files changed, 219 insertions(+)

New commits:
commit 5f174075489365956d451d46e2a4839f7beff811
Author:     Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Tue Jul 7 12:43:32 2020 +0530
Commit:     Dennis Francis <dennis.francis at collabora.com>
CommitDate: Wed Jul 8 16:49:59 2020 +0200

    introduce SplitPanesContext class
    
    This will store the split position and notify others and update the
    splitters when someone changes this.
    
    Change-Id: Ic1a2d665c972c369ce4e1362d0add50f72125d8a
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98350
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Dennis Francis <dennis.francis at collabora.com>

diff --git a/loleaflet/Makefile.am b/loleaflet/Makefile.am
index 762c2079a..49faf56f1 100644
--- a/loleaflet/Makefile.am
+++ b/loleaflet/Makefile.am
@@ -201,6 +201,7 @@ LOLEAFLET_JS =\
 	src/layer/Layer.js \
 	src/layer/tile/GridLayer.js \
 	src/layer/tile/TileLayer.js \
+	src/layer/SplitPanesContext.js \
 	src/layer/tile/TileLayer.TableOverlay.js \
 	src/layer/ObjectFocusDarkOverlay.js \
 	src/layer/tile/WriterTileLayer.js \
diff --git a/loleaflet/src/layer/SplitPanesContext.js b/loleaflet/src/layer/SplitPanesContext.js
new file mode 100644
index 000000000..5d4909298
--- /dev/null
+++ b/loleaflet/src/layer/SplitPanesContext.js
@@ -0,0 +1,218 @@
+/* -*- js-indent-level: 8 -*- */
+/*
+ * SplitPanesContext stores positions/sizes/objects related to split panes.
+ */
+
+/* global */
+
+L.SplitPanesContext = L.Class.extend({
+
+	options: {
+		maxHorizontalSplitPercent: 70,
+		maxVerticalSplitPercent: 70,
+	},
+
+	initialize: function (docLayer, createSplitters) {
+		console.assert(docLayer, 'no docLayer!');
+		console.assert(docLayer._map, 'no map!');
+
+		this._docLayer = docLayer;
+		this._map = docLayer._map;
+		this._setDefaults();
+
+		if (createSplitters === true) {
+			this.updateSplitters();
+		}
+	},
+
+	_setDefaults: function () {
+		this._splitPos = new L.Point(0, 0);
+	},
+
+	setDefaults: function () {
+		this._setDefaults();
+		this.updateSplitters();
+	},
+
+	getMaxSplitPosX: function () {
+		var rawMax = Math.floor(this._map.getSize().x * this.options.maxHorizontalSplitPercent / 100);
+		return this._docLayer.getSnapDocPosX(rawMax);
+	},
+
+	getMaxSplitPosY: function () {
+		var rawMax = Math.floor(this._map.getSize().y * this.options.maxVerticalSplitPercent / 100);
+		return this._docLayer.getSnapDocPosY(rawMax);
+	},
+
+	setSplitPos: function (splitX, splitY) {
+
+		this.setHorizSplitPos(splitX);
+		this.setVertSplitPos(splitY);
+	},
+
+	alignSplitPos: function () {
+		this.alignHorizSplitPos();
+		this.alignVertSplitPos();
+	},
+
+	getSplitPos: function () {
+		return this._splitPos.clone();
+	},
+
+	getSplitPosX: function () {
+		return this._splitPos.x;
+	},
+
+	getSplitPosY: function () {
+		return this._splitPos.y;
+	},
+
+	justifySplitPos: function (split, isHoriz) {
+		if (split <= 0) {
+			return 0;
+		}
+
+		var maxSplitPos = isHoriz ? this.getMaxSplitPosX() : this.getMaxSplitPosY();
+		if (split >= maxSplitPos) {
+			return maxSplitPos;
+		}
+
+		return isHoriz ? this._docLayer.getSnapDocPosX(split) :
+			this._docLayer.getSnapDocPosY(split);
+	},
+
+	setHorizSplitPos: function (splitX) {
+
+		console.assert(typeof splitX === 'number', 'splitX must be a number');
+
+		if (this._splitPos.x === splitX) {
+			return;
+		}
+
+		this._splitPos.x = this.justifySplitPos(splitX, true /* isHoriz */);
+
+		this._updateXSplitter();
+		this._map.fire('splitposchanged');
+	},
+
+	setVertSplitPos: function (splitY) {
+
+		console.assert(typeof splitY === 'number', 'splitY must be a number');
+
+		if (this._splitPos.y === splitY) {
+			return;
+		}
+
+		this._splitPos.y = this.justifySplitPos(splitY, false /* isHoriz */);
+
+		this._updateYSplitter();
+		this._map.fire('splitposchanged');
+	},
+
+	alignHorizSplitPos: function () {
+		this._splitPos.x = this._docLayer.getSnapDocPosX(this._splitPos.x);
+		this._updateXSplitter();
+	},
+
+	alignVertSplitPos: function () {
+		this._splitPos.y = this._docLayer.getSnapDocPosY(this._splitPos.y);
+		this._updateYSplitter();
+	},
+
+	updateSplitters: function () {
+		this._updateXSplitter();
+		this._updateYSplitter();
+	},
+
+	_updateXSplitter: function () {
+		this._docLayer.updateHorizPaneSplitter();
+	},
+
+	_updateYSplitter: function () {
+		this._docLayer.updateVertPaneSplitter();
+	},
+
+	// returns all the pane rectangles for the provided full-map area (all in CSS pixels).
+	getPxBoundList: function (pxBounds) {
+		if (!pxBounds) {
+			pxBounds = this._map.getPixelBounds();
+		}
+		var topLeft = pxBounds.getTopLeft();
+		var bottomRight = pxBounds.getBottomRight();
+		var boundList = [];
+
+		if (this._splitPos.x && this._splitPos.y) {
+			// top-left pane
+			boundList.push(new L.Bounds(
+				new L.Point(0, 0),
+				this._splitPos
+			));
+		}
+
+		if (this._splitPos.y) {
+			// top-right pane or top half pane
+			boundList.push(new L.Bounds(
+				new L.Point(topLeft.x + this._splitPos.x + 1, 0),
+				new L.Point(bottomRight.x, this._splitPos.y)
+			));
+		}
+
+		if (this._splitPos.x) {
+			// bottom-left pane or left half pane
+			boundList.push(new L.Bounds(
+				new L.Point(0, topLeft.y + this._splitPos.y + 1),
+				new L.Point(this._splitPos.x, bottomRight.y)
+			));
+		}
+
+		// bottom-right pane or the full pane (when there are no split-panes active)
+		boundList.push(new L.Bounds(
+			topLeft.add(this._splitPos).add(new L.Point(1, 1)),
+			bottomRight
+		));
+
+		return boundList;
+	},
+
+	getClientVisibleArea: function () {
+		var pixelBounds = this._map.getPixelBounds();
+		var fullSize = pixelBounds.getSize();
+		var cursorPos = this._docLayer.getCursorPos();
+		cursorPos._floor();
+		var oneone = new L.Point(1, 1);
+		var topLeft = pixelBounds.getTopLeft()._add(this._splitPos)._add(oneone);
+		var size = fullSize.subtract(this._splitPos);
+
+		if (this._splitPos.x) {
+			size.x -= 1;
+		}
+
+		if (this._splitPos.y) {
+			size.y -= 1;
+		}
+
+		if (cursorPos.x <= this._splitPos.x) {
+			topLeft.x = 0;
+			size.x = fullSize.x;
+		}
+
+		if (cursorPos.y <= this._splitPos.y) {
+			topLeft.y = 0;
+			size.y = fullSize.y;
+		}
+
+		return new L.Bounds(topLeft, topLeft.add(size));
+	},
+
+	intersectsVisible: function (areaPx) {
+		var pixBounds = this._map.getPixelBounds();
+		var boundList = this.getPxBoundList(pixBounds);
+		for (var i = 0; i < boundList.length; ++i) {
+			if (areaPx.intersects(boundList[i])) {
+				return true;
+			}
+		}
+
+		return false;
+	},
+});


More information about the Libreoffice-commits mailing list