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

Henry Castro hcastro at collabora.com
Sat Oct 29 20:03:24 UTC 2016


 loleaflet/dist/spreadsheet.css                |    9 ++++
 loleaflet/src/control/Control.ColumnHeader.js |   11 +++++
 loleaflet/src/control/Control.Header.js       |   56 ++++++++++++++++++++++++++
 loleaflet/src/control/Control.RowHeader.js    |   11 +++++
 loleaflet/src/layer/tile/CalcTileLayer.js     |   19 ++++++++
 5 files changed, 106 insertions(+)

New commits:
commit 3c9eed3bb03880fd0044a361f4f7ca2ed7e31523
Author: Henry Castro <hcastro at collabora.com>
Date:   Sat Oct 29 15:56:44 2016 -0400

    loleaflet: row/column highlighting to reflect the existing selection

diff --git a/loleaflet/dist/spreadsheet.css b/loleaflet/dist/spreadsheet.css
index 9548f0d..19147d7 100644
--- a/loleaflet/dist/spreadsheet.css
+++ b/loleaflet/dist/spreadsheet.css
@@ -108,6 +108,15 @@
 	overflow: hidden;
 	}
 
+.spreadsheet-header-selected {
+	background: #3465A4; /* For browsers that do not support gradients */
+	background: -webkit-linear-gradient(#3465A4, #729FCF, #004586);
+	background: -o-linear-gradient(#3465A4, #729FCF, #004586);
+	background: -moz-linear-gradient(#3465A4, #729FCF, #004586);
+	background: linear-gradient(#3465A4, #729FCF, #004586);
+	color: white;
+	}
+
 .spreadsheet-header-column:hover {
 	background-color: #DDD;
 	}
diff --git a/loleaflet/src/control/Control.ColumnHeader.js b/loleaflet/src/control/Control.ColumnHeader.js
index 70fed02..e6e1351 100644
--- a/loleaflet/src/control/Control.ColumnHeader.js
+++ b/loleaflet/src/control/Control.ColumnHeader.js
@@ -19,6 +19,8 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 		this._map.on('updatescrolloffset', this.setScrollPosition, this);
 		this._map.on('updateviewport', this.setViewPort, this);
 		this._map.on('viewrowcolumnheaders', this.viewRowColumnHeaders, this);
+		this._map.on('updateselectionheader', this._onUpdateSelection, this);
+		this._map.on('clearselectionheader', this._onClearSelection, this);
 		var docContainer = this._map.options.documentContainer;
 		var cornerHeader = L.DomUtil.create('div', 'spreadsheet-header-corner', docContainer.parentElement);
 		L.DomEvent.addListener(cornerHeader, 'click', this._onCornerHeaderClick, this);
@@ -144,6 +146,14 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 		L.DomUtil.setStyle(this._columns, 'left', this._position + 'px');
 	},
 
+	_onClearSelection: function (e) {
+		this.clearSelection(this._columns);
+	},
+
+	_onUpdateSelection: function (e) {
+		this.updateSelection(this._columns, e.start.x, e.end.x);
+	},
+
 	viewRowColumnHeaders: function (e) {
 		this.fillColumns(e.data.columns, e.converter, e.context);
 	},
@@ -158,6 +168,7 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 			column = L.DomUtil.create('div', 'spreadsheet-header-column', this._columns);
 			text = L.DomUtil.create('div', 'spreadsheet-header-column-text', column);
 			resize = L.DomUtil.create('div', 'spreadsheet-header-column-resize', column);
+			column.size = columns[iterator].size;
 			var content = columns[iterator].text;
 			text.setAttribute('rel', 'spreadsheet-column-' + content); // for easy addressing
 			text.innerHTML = content;
diff --git a/loleaflet/src/control/Control.Header.js b/loleaflet/src/control/Control.Header.js
index a3014a1..c56e554 100644
--- a/loleaflet/src/control/Control.Header.js
+++ b/loleaflet/src/control/Control.Header.js
@@ -9,12 +9,68 @@ L.Control.Header = L.Control.extend({
 
 	initialize: function () {
 		this._clicks = 0;
+		this._selection = {start: -1, end: -1};
 	},
 
 	mouseInit: function (element) {
 		L.DomEvent.on(element, 'mousedown', this._onMouseDown, this);
 	},
 
+	select: function (item) {
+		if (item && !L.DomUtil.hasClass(item, 'spreadsheet-header-selected')) {
+			L.DomUtil.addClass(item, 'spreadsheet-header-selected');
+		}
+	},
+
+	unselect: function (item) {
+		if (item && L.DomUtil.hasClass(item, 'spreadsheet-header-selected')) {
+			L.DomUtil.removeClass(item, 'spreadsheet-header-selected');
+		}
+	},
+
+	clearSelection: function (element) {
+		var childs = element.children;
+		for (var iterator = this._selection.start; iterator <= this._selection.end; iterator++) {
+			this.unselect(childs[iterator]);
+		}
+		this._selection.start = this._selection.end = -1;
+	},
+
+	updateSelection: function(element, start, end) {
+		var childs = element.children;
+		var x0 = 0, x1 = 0;
+		var itStart = -1, itEnd = -1;
+		var selected = false;
+		var iterator = 0;
+		for (var len = childs.length; iterator < len; iterator++) {
+			x0 = (iterator > 0 ? childs[iterator - 1].size : 0);
+			x1 = childs[iterator].size;
+			if (x0 <= start && start <= x1) {
+				selected = true;
+				itStart = iterator;
+			}
+			if (selected) {
+				this.select(childs[iterator]);
+			}
+			if (x0 <= end && end <= x1) {
+				itEnd = iterator;
+				break;
+			}
+		}
+		if (this._selection.start !== -1 && itStart !== -1 && itStart > this._selection.start) {
+			for (iterator = this._selection.start; iterator < itStart; iterator++) {
+				this.unselect(childs[iterator]);
+			}
+		}
+		if (this._selection.end !== -1 && itEnd !== -1 && itEnd < this._selection.end) {
+			for (iterator = itEnd + 1; iterator <= this._selection.end; iterator++) {
+				this.unselect(childs[iterator]);
+			}
+		}
+		this._selection.start = itStart;
+		this._selection.end = itEnd;
+	},
+
 	_onMouseDown: function (e) {
 		var target = e.target || e.srcElement;
 
diff --git a/loleaflet/src/control/Control.RowHeader.js b/loleaflet/src/control/Control.RowHeader.js
index 5263875..8575a24 100644
--- a/loleaflet/src/control/Control.RowHeader.js
+++ b/loleaflet/src/control/Control.RowHeader.js
@@ -19,6 +19,8 @@ L.Control.RowHeader = L.Control.Header.extend({
 		this._map.on('updatescrolloffset', this.setScrollPosition, this);
 		this._map.on('updateviewport', this.setViewPort, this);
 		this._map.on('viewrowcolumnheaders', this.viewRowColumnHeaders, this);
+		this._map.on('updateselectionheader', this._onUpdateSelection, this);
+		this._map.on('clearselectionheader', this._onClearSelection, this);
 		var docContainer = this._map.options.documentContainer;
 		var headersContainer = L.DomUtil.create('div', 'spreadsheet-header-rows-container', docContainer.parentElement);
 		this._rows = L.DomUtil.create('div', 'spreadsheet-header-rows', headersContainer);
@@ -140,6 +142,14 @@ L.Control.RowHeader = L.Control.Header.extend({
 		L.DomUtil.setStyle(this._rows, 'top', this._position + 'px');
 	},
 
+	_onClearSelection: function (e) {
+		this.clearSelection(this._rows);
+	},
+
+	_onUpdateSelection: function (e) {
+		this.updateSelection(this._rows, e.start.y, e.end.y);
+	},
+
 	viewRowColumnHeaders: function (e) {
 		this.fillRows(e.data.rows, e.converter, e.context);
 	},
@@ -154,6 +164,7 @@ L.Control.RowHeader = L.Control.Header.extend({
 			row = L.DomUtil.create('div', 'spreadsheet-header-row', this._rows);
 			text = L.DomUtil.create('div', 'spreadsheet-header-row-text', row);
 			resize = L.DomUtil.create('div', 'spreadsheet-header-row-resize', row);
+			row.size = rows[iterator].size;
 			var content = rows[iterator].text;
 			text.setAttribute('rel', 'spreadsheet-row-' + content); // for easy addressing
 			text.innerHTML = content;
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 1157f60..237fb92 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -155,6 +155,19 @@ L.CalcTileLayer = L.TileLayer.extend({
 		});
 	},
 
+	_onUpdateSelectionHeader: function () {
+		var layers = this._selections.getLayers();
+		var layer = layers.pop();
+		if (layers.length === 0 && layer && layer.getLatLngs().length === 1) {
+			var start = this._latLngToTwips(layer.getBounds().getNorthWest()).add([1, 1]);
+			var end = this._latLngToTwips(layer.getBounds().getSouthEast()).subtract([1, 1]);
+			this._map.fire('updateselectionheader', {start: start, end: end});
+		}
+		else {
+			this._map.fire('clearselectionheader');
+		}
+	},
+
 	_onStatusMsg: function (textMsg) {
 		var command = this._map._socket.parseServerCmd(textMsg);
 		if (command.width && command.height && this._documentInfo !== textMsg) {
@@ -210,9 +223,15 @@ L.CalcTileLayer = L.TileLayer.extend({
 				context: this
 			});
 			this._onUpdateViewPort();
+			this._onUpdateSelectionHeader();
 		}
 		else {
 			L.TileLayer.prototype._onCommandValuesMsg.call(this, textMsg);
 		}
+	},
+
+	_onTextSelectionMsg: function (textMsg) {
+		L.TileLayer.prototype._onTextSelectionMsg.call(this, textMsg);
+		this._onUpdateSelectionHeader();
 	}
 });


More information about the Libreoffice-commits mailing list