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

Pranav Kant pranavk at collabora.co.uk
Wed Sep 14 18:45:26 UTC 2016


 loleaflet/src/control/Parts.js        |    1 
 loleaflet/src/layer/tile/TileLayer.js |   59 ++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 20 deletions(-)

New commits:
commit 8bd7d83bdcaa2d9654633954f43695a53e07be91
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Sep 15 00:12:17 2016 +0530

    loleaflet: Handle multiview text selections for part documents
    
    Change-Id: I56425cde49b2b3b319204d7172f4ec4080b5bed1

diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 55e9dbb..cdde4d1 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -34,6 +34,7 @@ L.Map.include({
 		docLayer.eachView(docLayer._viewCursors, docLayer._onUpdateViewCursor, docLayer);
 		docLayer.eachView(docLayer._cellViewCursors, docLayer._onUpdateCellViewCursor, docLayer);
 		docLayer.eachView(docLayer._graphicViewMarkers, docLayer._onUpdateGraphicViewSelection, docLayer);
+		docLayer.eachView(docLayer._viewSelections, docLayer._onUpdateTextViewSelection, docLayer);
 		docLayer._clearSelections();
 		docLayer._updateOnChangePart();
 		docLayer._pruneTiles();
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 030b4b4..e6e2c7c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -719,8 +719,8 @@ L.TileLayer = L.GridLayer.extend({
 		}
 
 		// Remove selection, if any.
-		if (this._viewSelections[viewId]) {
-			this._viewSelectionsGroup.removeLayer(this._viewSelections[viewId]);
+		if (this._viewSelections[viewId] && this._viewSelections[viewId].selection) {
+			this._viewSelectionsGroup.removeLayer(this._viewSelections[viewId].selection);
 		}
 
 		// Remove the view and update (to refresh as needed).
@@ -914,6 +914,7 @@ L.TileLayer = L.GridLayer.extend({
 		textMsg = textMsg.substring('textviewselection:'.length + 1);
 		var obj = JSON.parse(textMsg);
 		var viewId = parseInt(obj.viewId);
+		var viewPart = parseInt(obj.part);
 
 		// Ignore if viewid is same as ours
 		if (viewId === this._viewId) {
@@ -921,9 +922,7 @@ L.TileLayer = L.GridLayer.extend({
 		}
 
 		var strTwips = obj.selection.match(/\d+/g);
-		if (this._viewSelections[viewId]) {
-			this._viewSelectionsGroup.removeLayer(this._viewSelections[viewId]);
-		}
+		this._viewSelections[viewId] = this._viewSelections[viewId] || {};
 		if (strTwips != null) {
 			var rectangles = [];
 			for (var i = 0; i < strTwips.length; i += 4) {
@@ -935,16 +934,13 @@ L.TileLayer = L.GridLayer.extend({
 				rectangles.push([bottomLeftTwips, bottomRightTwips, topLeftTwips, topRightTwips]);
 			}
 
-			var polygons = L.PolyUtil.rectanglesToPolygons(rectangles, this);
-			var selection = new L.Polygon(polygons, {
-				pointerEvents: 'none',
-				fillColor: L.LOUtil.getViewIdHexColor(viewId),
-				fillOpacity: 0.25,
-				weight: 2,
-				opacity: 0.25});
-			this._viewSelections[viewId] = selection;
-			this._viewSelectionsGroup.addLayer(selection);
+			this._viewSelections[viewId].part = viewPart;
+			this._viewSelections[viewId].polygons = L.PolyUtil.rectanglesToPolygons(rectangles, this);
+		} else {
+			this._viewSelections[viewId].polygons = null;
 		}
+
+		this._onUpdateTextViewSelection(viewId);
 	},
 
 	_onTextSelectionContentMsg: function (textMsg) {
@@ -1177,6 +1173,35 @@ L.TileLayer = L.GridLayer.extend({
 		}
 	},
 
+	_onUpdateTextViewSelection: function (viewId) {
+		viewId = parseInt(viewId);
+		var viewPolygons = this._viewSelections[viewId].polygons;
+		var viewSelection = this._viewSelections[viewId].selection;
+		var viewPart = this._viewSelections[viewId].part;
+
+		if (viewPolygons &&
+		    (this._docType === 'text' || this._selectedPart === viewPart)) {
+
+			// Reset previous selections
+			if (viewSelection) {
+				this._viewSelectionsGroup.removeLayer(viewSelection);
+			}
+
+			viewSelection = new L.Polygon(viewPolygons, {
+				pointerEvents: 'none',
+				fillColor: L.LOUtil.getViewIdHexColor(viewId),
+				fillOpacity: 0.25,
+				weight: 2,
+				opacity: 0.25
+			});
+			this._viewSelections[viewId].selection = viewSelection;
+			this._viewSelectionsGroup.addLayer(viewSelection);
+		}
+		else if (viewSelection) {
+			this._viewSelectionsGroup.removeLayer(viewSelection);
+		}
+	},
+
 	_onUpdateGraphicViewSelection: function (viewId) {
 		var viewBounds = this._graphicViewMarkers[viewId].bounds;
 		var viewMarker = this._graphicViewMarkers[viewId].marker;
commit 4b18ca3772449d4f8ebd757b01a0efbfcb5c471a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Sep 14 20:07:48 2016 +0530

    loleaflet: Remove unused code
    
    Change-Id: Ieb12e03b68eaacb99acb9853d02191c165f5b70c

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index bcb2efe..030b4b4 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -884,7 +884,6 @@ L.TileLayer = L.GridLayer.extend({
 		this._selections.clearLayers();
 		if (strTwips != null) {
 			var rectangles = [];
-			var selectionCenter = new L.Point(0, 0);
 			for (var i = 0; i < strTwips.length; i += 4) {
 				var topLeftTwips = new L.Point(parseInt(strTwips[i]), parseInt(strTwips[i + 1]));
 				var offset = new L.Point(parseInt(strTwips[i + 2]), parseInt(strTwips[i + 3]));
@@ -892,8 +891,6 @@ L.TileLayer = L.GridLayer.extend({
 				var bottomLeftTwips = topLeftTwips.add(new L.Point(0, offset.y));
 				var bottomRightTwips = topLeftTwips.add(offset);
 				rectangles.push([bottomLeftTwips, bottomRightTwips, topLeftTwips, topRightTwips]);
-				selectionCenter = selectionCenter.add(topLeftTwips);
-				selectionCenter = selectionCenter.add(offset.divideBy(2));
 			}
 
 			var polygons = L.PolyUtil.rectanglesToPolygons(rectangles, this);
@@ -929,7 +926,6 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		if (strTwips != null) {
 			var rectangles = [];
-			var selectionCenter = new L.Point(0, 0);
 			for (var i = 0; i < strTwips.length; i += 4) {
 				var topLeftTwips = new L.Point(parseInt(strTwips[i]), parseInt(strTwips[i + 1]));
 				var offset = new L.Point(parseInt(strTwips[i + 2]), parseInt(strTwips[i + 3]));
@@ -937,8 +933,6 @@ L.TileLayer = L.GridLayer.extend({
 				var bottomLeftTwips = topLeftTwips.add(new L.Point(0, offset.y));
 				var bottomRightTwips = topLeftTwips.add(offset);
 				rectangles.push([bottomLeftTwips, bottomRightTwips, topLeftTwips, topRightTwips]);
-				selectionCenter = selectionCenter.add(topLeftTwips);
-				selectionCenter = selectionCenter.add(offset.divideBy(2));
 			}
 
 			var polygons = L.PolyUtil.rectanglesToPolygons(rectangles, this);


More information about the Libreoffice-commits mailing list