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

Marco Cecchetti marco.cecchetti at collabora.com
Sat Dec 16 13:21:24 UTC 2017


 loleaflet/src/control/Control.ColumnHeader.js |   11 ++----
 loleaflet/src/control/Control.Header.js       |   43 +++++++++-----------------
 loleaflet/src/control/Control.RowHeader.js    |   11 ++----
 loleaflet/src/layer/tile/CalcTileLayer.js     |   11 ++++--
 loleaflet/src/layer/tile/GridLayer.js         |   16 ++++++++-
 loleaflet/src/layer/tile/TileLayer.js         |   12 ++++++-
 6 files changed, 56 insertions(+), 48 deletions(-)

New commits:
commit 971916046aa9f80e546fd15d3c79cbaf94d18711
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed Dec 13 23:20:30 2017 +0100

    calc: use cursor position for change header highlight quickier
    
    This patch fixes also a bug: when in edit mode the header for cell A1
    are highlighted
    
    Change-Id: If97d8d151f9d216362a9b1472c2b29fbec4f9b73
    Reviewed-on: https://gerrit.libreoffice.org/46536
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>
    Tested-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/loleaflet/src/control/Control.ColumnHeader.js b/loleaflet/src/control/Control.ColumnHeader.js
index 7b0a25ab..d2282a42 100644
--- a/loleaflet/src/control/Control.ColumnHeader.js
+++ b/loleaflet/src/control/Control.ColumnHeader.js
@@ -184,13 +184,10 @@ L.Control.ColumnHeader = L.Control.Header.extend({
 	},
 
 	_onUpdateCurrentColumn: function (e) {
-		var x = e.min.x;
-		var w = e.getSize().x;
-		if (x !== -1) {
-			x = this._twipsToPixels(x);
-			w = this._twipsToPixels(w);
-		}
-		this.updateCurrent(this._data, x, w);
+		var x = e.curX - this._startHeaderIndex;
+		var w = this._twipsToPixels(e.width);
+		var slim = w <= 1;
+		this.updateCurrent(this._data, x, slim);
 	},
 
 	_updateColumnHeader: function () {
diff --git a/loleaflet/src/control/Control.Header.js b/loleaflet/src/control/Control.Header.js
index e77c7799..261b2958 100644
--- a/loleaflet/src/control/Control.Header.js
+++ b/loleaflet/src/control/Control.Header.js
@@ -213,42 +213,31 @@ L.Control.Header = L.Control.extend({
 		this._selection.end = itEnd;
 	},
 
-	updateCurrent: function (data, start, size) {
+	updateCurrent: function (data, cursorPos, slim) {
 		if (!data || data.isEmpty())
 			return;
 
-		if (start < 0) {
+		if (cursorPos < 0) {
 			this.unselect(data.get(this._current));
 			this._current = -1;
 			return;
 		}
 
-		var x0 = 0, x1 = 0;
-		var prevEntry = null;
-		var entry = data.getFirst();
-		var zeroSizeEntry = false;
-		while (entry) {
-			x0 = entry.pos - entry.size;
-			x1 = entry.pos;
-			if (x0 <= start && start < x1) {
-				// we have a slim cursor because of a zero size entry ?
-				zeroSizeEntry = size <= 1 && prevEntry && prevEntry.size === 0;
-				// when a whole row (column) is selected the cell cursor is moved to the first column (row)
-				// but this action should not cause to select/unselect anything, on the contrary we end up
-				// with all column (row) header entries selected but the one where the cell cursor was
-				// previously placed
-				if (this._selection.start === -1 && this._selection.end === -1) {
-					this.unselect(data.get(this._current));
-					// no selection when the cell cursor is slim
-					if (!zeroSizeEntry)
-						this.select(entry);
-				}
-				this._current = zeroSizeEntry ? -1 : entry.index;
-				break;
-			}
-			prevEntry = entry;
-			entry = data.getNext();
+		var prevEntry = cursorPos > 0 ? data.get(cursorPos - 1) : null;
+		var zeroSizeEntry = slim && prevEntry && prevEntry.size === 0;
+
+		var entry = data.get(cursorPos);
+		if (this._selection.start === -1 && this._selection.end === -1) {
+			// when a whole row (column) is selected the cell cursor is moved to the first column (row)
+			// but this action should not cause to select/unselect anything, on the contrary we end up
+			// with all column (row) header entries selected but the one where the cell cursor was
+			// previously placed
+			this.unselect(data.get(this._current));
+			// no selection when the cell cursor is slim
+			if (entry && !zeroSizeEntry)
+				this.select(entry);
 		}
+		this._current = entry && !zeroSizeEntry ? entry.index : -1;
 	},
 
 	_mouseEventToCanvasPos: function(canvas, evt) {
diff --git a/loleaflet/src/control/Control.RowHeader.js b/loleaflet/src/control/Control.RowHeader.js
index be49ecf0..85596138 100644
--- a/loleaflet/src/control/Control.RowHeader.js
+++ b/loleaflet/src/control/Control.RowHeader.js
@@ -175,13 +175,10 @@ L.Control.RowHeader = L.Control.Header.extend({
 	},
 
 	_onUpdateCurrentRow: function (e) {
-		var y = e.min.y;
-		var h = e.getSize().y;
-		if (y !== -1) {
-			y = this._twipsToPixels(y);
-			h = this._twipsToPixels(h);
-		}
-		this.updateCurrent(this._data, y, h);
+		var y = e.curY - this._startHeaderIndex;
+		var h = this._twipsToPixels(e.height);
+		var slim = h <= 1;
+		this.updateCurrent(this._data, y, slim);
 	},
 
 	_updateRowHeader: function () {
diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index b15cd5bb..c628bfb8 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -355,13 +355,16 @@ L.CalcTileLayer = L.TileLayer.extend({
 	},
 
 	_onUpdateCurrentHeader: function() {
-		var pos = new L.Point(-1, -1);
-		var size = new L.Point(-1, -1);
+		var x = -1, y = -1;
+		if (this._cellCursorXY) {
+			x = this._cellCursorXY.x + 1;
+			y = this._cellCursorXY.y + 1;
+		}
+		var size = new L.Point(0, 0);
 		if (this._cellCursor && !this._isEmptyRectangle(this._cellCursor)) {
-			pos = this._cellCursorTwips.min.add([1, 1]);
 			size = this._cellCursorTwips.getSize();
 		}
-		this._map.fire('updatecurrentheader', new L.Bounds(pos, pos.add(size)));
+		this._map.fire('updatecurrentheader', {curX: x, curY: y, width: size.x, height: size.y});
 	},
 
 	_onUpdateSelectionHeader: function () {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 3e0b9eca..eedc1c51 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -671,6 +671,7 @@ L.TileLayer = L.GridLayer.extend({
 		if (textMsg.match('EMPTY')) {
 			this._cellCursorTwips = new L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
 			this._cellCursor = L.LatLngBounds.createDefault();
+			this._cellCursorXY = new L.Point(-1, -1);
 		}
 		else {
 			var strTwips = textMsg.match(/\d+/g);
commit 9e72b2257b6083c40db8c96bb6d70ba11cdbbe03
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Wed Dec 13 18:09:36 2017 +0100

    calc: do not scroll to cell cursor when position is not changed
    
    Old behaviour: when a cell cursor message is handled the document is
    always scrolled in order to make the cell cursor visible.
    
    New behaviour: as the old one except when the position of the cell
    cursor is unchanged: in that case no scroll occurs.
    
    Change-Id: Iee9b8e2d9fc8cb72d0292fb48a20cadeedeb015b
    Reviewed-on: https://gerrit.libreoffice.org/46535
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>
    Tested-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index fa01615d..3e0b9eca 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -661,6 +661,13 @@ L.TileLayer = L.GridLayer.extend({
 		if (!this._prevCellCursor) {
 			this._prevCellCursor = L.LatLngBounds.createDefault();
 		}
+		if (!this._cellCursorXY) {
+			this._cellCursorXY = new L.Point(-1, -1);
+		}
+		if (!this._prevCellCursorXY) {
+			this._prevCellCursorXY = new L.Point(-1, -1);
+		}
+
 		if (textMsg.match('EMPTY')) {
 			this._cellCursorTwips = new L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
 			this._cellCursor = L.LatLngBounds.createDefault();
@@ -674,6 +681,7 @@ L.TileLayer = L.GridLayer.extend({
 			this._cellCursor = new L.LatLngBounds(
 							this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
 							this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+			this._cellCursorXY = new L.Point(parseInt(strTwips[4]), parseInt(strTwips[5]));
 		}
 
 		var horizontalDirection = 0;
@@ -1767,7 +1775,7 @@ L.TileLayer = L.GridLayer.extend({
 	_onUpdateCellCursor: function (horizontalDirection, verticalDirection, onPgUpDn) {
 		if (this._cellCursor && !this._isEmptyRectangle(this._cellCursor)) {
 			var mapBounds = this._map.getBounds();
-			if (!mapBounds.contains(this._cellCursor)) {
+			if (!mapBounds.contains(this._cellCursor) && !this._cellCursorXY.equals(this._prevCellCursorXY)) {
 				var scrollX = 0, scrollY = 0;
 				if (onPgUpDn) {
 					var mapHalfHeight = (mapBounds.getNorth() - mapBounds.getSouth()) / 2;
@@ -1805,6 +1813,7 @@ L.TileLayer = L.GridLayer.extend({
 					center.y = Math.round(center.y < 0 ? 0 : center.y);
 					this._map.fire('scrollto', {x: center.x, y: center.y});
 				}
+				this._prevCellCursorXY = this._cellCursorXY;
 			}
 
 			if (onPgUpDn) {
commit 037a2b246c4c440568f3d5b90521c8c7d2cd3034
Author: Marco Cecchetti <marco.cecchetti at collabora.com>
Date:   Mon Dec 11 11:35:49 2017 +0100

    missing to update a tile content
    
    When a tile has been invalidated, and the new tile content has not yet
    been fetched and in the between a `canceltiles` message occurs, the
    new tile content will never be fetched;
    example: a tile is invalidated but a sudden scroll to the cell cursor
    position causes to move the tile out of the visible area before the
    new content is fetched, so when the tile is back inside the visible
    area its content would be the old invalidated one;
    
    Change-Id: Ib5f2605490cb9b15fba146e185f683cb7b8d31b6
    Reviewed-on: https://gerrit.libreoffice.org/46534
    Reviewed-by: Marco Cecchetti <mrcekets at gmail.com>
    Tested-by: Marco Cecchetti <mrcekets at gmail.com>

diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 407f6612..d080cdfe 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -544,7 +544,13 @@ L.GridLayer = L.Layer.extend({
 				// so we're able to cancel the previous requests that are being processed
 				this._map._socket.sendMessage('canceltiles');
 				for (key in this._tiles) {
-					if (!this._tiles[key].loaded) {
+					// When _invalidCount > 0 the tile has been invalidated, however the new tile content
+					// has not yet been fetched and because of `canceltiles` message it will never be
+					// so we need to remove the tile, or when the tile is back inside the visible area
+					// its content would be the old invalidated one;
+					// example: a tile is invalidated but a sudden scroll to the cell cursor position causes
+					// to move the tile out of the visible area before the new content is fetched
+					if (!this._tiles[key].loaded || this._tiles[key]._invalidCount > 0) {
 						L.DomUtil.remove(this._tiles[key].el);
 						delete this._tiles[key];
 						if (this._debug) {
@@ -617,7 +623,13 @@ L.GridLayer = L.Layer.extend({
 				this._map._socket.sendMessage('canceltiles');
 				for (key in this._tiles) {
 					tile = this._tiles[key];
-					if (!tile.loaded) {
+					// When _invalidCount > 0 the tile has been invalidated, however the new tile content
+					// has not yet been fetched and because of `canceltiles` message it will never be
+					// so we need to remove the tile, or when the tile is back inside the visible area
+					// its content would be the old invalidated one;
+					// example: a tile is invalidated but a sudden scroll to the cell cursor position causes
+					// to move the tile out of the visible area before the new content is fetched
+					if (!tile.loaded || tile._invalidCount > 0) {
 						L.DomUtil.remove(tile.el);
 						delete this._tiles[key];
 						if (this._debug && this._debugDataCancelledTiles) {


More information about the Libreoffice-commits mailing list