[Libreoffice-commits] online.git: loleaflet/src
Dennis Francis (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jul 8 14:47:36 UTC 2020
loleaflet/src/layer/tile/CalcTileLayer.js | 35 +++++++++++++++++++++++++++++-
loleaflet/src/layer/tile/TileLayer.js | 2 -
loleaflet/src/map/Map.js | 11 +++++++++
3 files changed, 46 insertions(+), 2 deletions(-)
New commits:
commit d60bebc7ad22ea949248e367f76b5bcf33fb5628
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Fri Jun 26 09:56:41 2020 +0530
Commit: Dennis Francis <dennis.francis at collabora.com>
CommitDate: Wed Jul 8 16:47:15 2020 +0200
calc-zoom: preserve the top-left document position on zoom
which is the behaviour in LibreOffice Calc desktop. This is now possible
because we can accurarately determine the pixel position of any cell at
any zoom level from the global sheetGeometry data we get from core.
Change-Id: I5af41770e94c65d803fa9f99906b4ee1ca2f6ac7
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98328
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/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js
index 31398abb4..5c80d35f3 100644
--- a/loleaflet/src/layer/tile/CalcTileLayer.js
+++ b/loleaflet/src/layer/tile/CalcTileLayer.js
@@ -1116,6 +1116,17 @@ L.SheetGeometry = L.Class.extend({
this._rows.getSize(unit));
},
+ // Returns the CSS pixel position/size of the requested cell at a specified zoom.
+ getCellRect: function (columnIndex, rowIndex, zoomScale) {
+ var horizPosSize = this._columns.getElementData(columnIndex, false /* devicePixels */, zoomScale);
+ var vertPosSize = this._rows.getElementData(rowIndex, false /* devicePixels */, zoomScale);
+
+ var topLeft = new L.Point(horizPosSize.startpos, vertPosSize.startpos);
+ var size = new L.Point(horizPosSize.size, vertPosSize.size);
+
+ return new L.Bounds(topLeft, topLeft.add(size));
+ },
+
_testValidity: function (sheetGeomJSON, checkCompleteness) {
if (!sheetGeomJSON.hasOwnProperty('commandName')) {
@@ -1307,7 +1318,29 @@ L.SheetDimension = L.Class.extend({
},
// returns the element pos/size in css pixels by default.
- getElementData: function (index, useDevicePixels) {
+ getElementData: function (index, useDevicePixels, zoomScale) {
+ if (zoomScale !== undefined) {
+ var startpos = 0;
+ var size = 0;
+ this._visibleSizes.forEachSpanInRange(0, index, function (spanData) {
+ var count = spanData.end - spanData.start + 1;
+ var sizeOneCSSPx = Math.floor(spanData.size * zoomScale / 15.0);
+ if (index > spanData.end) {
+ startpos += (sizeOneCSSPx * count);
+ }
+ else if (index >= spanData.start && index <= spanData.end) {
+ // final span
+ startpos += (sizeOneCSSPx * (index - spanData.start));
+ size = sizeOneCSSPx;
+ }
+ });
+
+ return {
+ startpos: startpos,
+ size: size
+ };
+ }
+
var span = this._visibleSizes.getSpanDataByIndex(index);
if (span === undefined) {
return undefined;
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index ec1d425d7..a53074498 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -3318,7 +3318,7 @@ L.TileLayer = L.GridLayer.extend({
// Cells can change position during changes of zoom level in calc
// hence we need to request an updated cell cursor position for this level.
_onCellCursorShift: function (force) {
- if (this._cellCursorMarker || force) {
+ if ((this._cellCursorMarker && !this.options.sheetGeometryDataEnabled) || force) {
this._map._socket.sendMessage('commandvalues command=.uno:CellCursor'
+ '?outputHeight=' + this._tileWidthPx
+ '&outputWidth=' + this._tileHeightPx
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 66103df1c..c3ba4e260 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -468,6 +468,17 @@ L.Map = L.Evented.extend({
// for spreadsheets, when the document is smaller than the viewing area
// we want it to be glued to the row/column headers instead of being centered
this._docLayer._checkSpreadSheetBounds(zoom);
+ var calcLayer = this._docLayer;
+ if (calcLayer.options.sheetGeometryDataEnabled && calcLayer.sheetGeometry) {
+ var sheetGeom = calcLayer.sheetGeometry;
+ var cellRange = sheetGeom.getViewCellRange();
+ var col = cellRange.columnrange.start, row = cellRange.rowrange.start;
+ var zoomScaleAbs = Math.pow(1.2, (zoom - this.options.zoom));
+ var newTopLeftPx = sheetGeom.getCellRect(col, row, zoomScaleAbs).getTopLeft();
+ var newCenterPx = newTopLeftPx.add(this.getSize().divideBy(2)._floor());
+ var newCenterLatLng = this.unproject(newCenterPx, zoom);
+ return this.setView(newCenterLatLng, zoom, {zoom: options});
+ }
}
var curCenter = this.getCenter();
if (this._docLayer && this._docLayer._visibleCursor && this.getBounds().contains(this._docLayer._visibleCursor.getCenter())) {
More information about the Libreoffice-commits
mailing list