loleaflet/src/layer/tile/CalcTileLayer.js | 113 ++++++++++++++++++++++++++++++ loleaflet/src/layer/tile/TileLayer.js | 39 +--------- 2 files changed, 119 insertions(+), 33 deletions(-)
New commits: commit 8c1b87462fa759aafb864cc953acb87e963beabf Author: Dennis Francis <[email protected]> AuthorDate: Tue Jul 7 17:21:35 2020 +0530 Commit: Dennis Francis <[email protected]> CommitDate: Wed Jul 8 17:04:38 2020 +0200 integrate SplitPanesContext with CalcTileLayer... and take split-panes into account when switching views on the arrival of a new cursor message. Change-Id: If97b06ceefd15335555d77b4074fd6991e21b7ab Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98358 Tested-by: Jenkins CollaboraOffice <[email protected]> Tested-by: Jenkins Reviewed-by: Dennis Francis <[email protected]> diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js index 9d711b48f..70fbe3dd0 100644 --- a/loleaflet/src/layer/tile/CalcTileLayer.js +++ b/loleaflet/src/layer/tile/CalcTileLayer.js @@ -56,6 +56,7 @@ L.CalcTileLayer = L.TileLayer.extend({ map.on('AnnotationCancel', this._onAnnotationCancel, this); map.on('AnnotationReply', this._onAnnotationReply, this); map.on('AnnotationSave', this._onAnnotationSave, this); + map.on('splitposchanged', this._calcSplitCell, this); map.uiManager.initializeSpecializedUI('spreadsheet'); }, @@ -68,6 +69,7 @@ L.CalcTileLayer = L.TileLayer.extend({ }, onAdd: function (map) { + this._switchSplitPanesContext(); map.addControl(L.control.tabs()); map.addControl(L.control.columnHeader()); map.addControl(L.control.rowHeader()); @@ -437,6 +439,7 @@ L.CalcTileLayer = L.TileLayer.extend({ var part = parseInt(textMsg.match(/\d+/g)[0]); if (!this.isHiddenPart(part)) { this._clearMsgReplayStore(); + this._switchSplitPanesContext(); this.refreshViewData(undefined, false /* compatDataSrcOnly */, true /* sheetGeometryChanged */); } }, @@ -449,6 +452,7 @@ L.CalcTileLayer = L.TileLayer.extend({ } this._restrictDocumentSize(); this._replayPrintTwipsMsgs(); + this._updateSplitPos(); this._map.fire('zoomchanged'); this.refreshViewData(); this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition'); @@ -721,9 +725,55 @@ L.CalcTileLayer = L.TileLayer.extend({ this._updateHeadersGridLines(undefined, true /* updateCols */, true /* updateRows */); + this._updateSplitPos(); + this._map.fire('sheetgeometrychanged'); }, + _updateSplitPos: function () { + if (this._splitPanesContext) { + if (this._splitPanesContext._splitCell) { + var splitCell = this._splitPanesContext._splitCell; + var newSplitPos = this.sheetGeometry.getCellRect(splitCell.x, splitCell.y).min; + this._splitPanesContext.setSplitPos(newSplitPos.x, newSplitPos.y); // will update the splitters. + } + else { + // Can happen only on load. + this._splitPanesContext.alignSplitPos(); + this._calcSplitCell(); + } + } + }, + + _calcSplitCell: function () { + + if (!this.sheetGeometry || !this._splitPanesContext) { + return; + } + + this._splitPanesContext._splitCell = + this.sheetGeometry.getCellFromPos(this._splitPanesContext.getSplitPos(), 'csspixels'); + }, + + _switchSplitPanesContext: function () { + + if (!this.hasSplitPanesSupport()) { + return; + } + + if (!this._splitPaneCache) { + this._splitPaneCache = {}; + } + + var spContext = this._splitPaneCache[this._selectedPart]; + if (!spContext) { + spContext = new L.SplitPanesContext(this); + } + + this._splitPanesContext = spContext; + this._map._splitPanesContext = spContext; + }, + _onCommandValuesMsg: function (textMsg) { var jsonIdx = textMsg.indexOf('{'); if (jsonIdx === -1) @@ -881,6 +931,69 @@ L.CalcTileLayer = L.TileLayer.extend({ return this._twipsToPixels(this._cellCursorTwips.getTopLeft()); }, + _calculateScrollForNewCursor: function () { + + var scroll = new L.LatLng(0, 0); + + if (!this._cellCursor || this._isEmptyRectangle(this._cellCursor)) { + return scroll; + } + + var map = this._map; + var paneRects = this._splitPanesContext ? + this._splitPanesContext.getPxBoundList() : undefined; + + console.assert(paneRects === undefined || paneRects.length, 'number of panes cannot be zero!'); + + var paneRectsInLatLng = paneRects ? paneRects.map(function (pxBound) { + return new L.LatLngBounds( + map.unproject(pxBound.getTopLeft()), + map.unproject(pxBound.getBottomRight()) + ); + }) : [ map.getBounds() ]; + + var scrollNeeded = true; + for (var i = 0; i < paneRectsInLatLng.length; ++i) { + if (paneRectsInLatLng[i].contains(this._cellCursor)) { + scrollNeeded = false; + break; + } + } + + if (!scrollNeeded) { + return scroll; // zero scroll. + } + + var freePaneBounds = paneRectsInLatLng[paneRectsInLatLng.length - 1]; + var splitPoint = map.unproject(this._splitPanesContext ? this._splitPanesContext.getSplitPos() : new L.Point(0, 0)); + + if (this._cellCursor.getEast() > splitPoint.lng) { + + var freePaneWidth = Math.abs(freePaneBounds.getEast() - freePaneBounds.getWest()); + var cursorWidth = Math.abs(this._cellCursor.getEast() - this._cellCursor.getWest()); + var spacingX = cursorWidth / 4.0; + + if (this._cellCursor.getWest() < freePaneBounds.getWest()) { + scroll.lng = this._cellCursor.getWest() - freePaneBounds.getWest() - spacingX; + } + else if (cursorWidth < freePaneWidth && this._cellCursor.getEast() > freePaneBounds.getEast()) { + scroll.lng = this._cellCursor.getEast() - freePaneBounds.getEast() + spacingX; + } + } + + if (this._cellCursor.getSouth() < splitPoint.lat) { + + var spacingY = Math.abs((this._cellCursor.getSouth() - this._cellCursor.getNorth())) / 4.0; + if (this._cellCursor.getNorth() > freePaneBounds.getNorth()) { + scroll.lat = this._cellCursor.getNorth() - freePaneBounds.getNorth() + spacingY; + } + else if (this._cellCursor.getSouth() < freePaneBounds.getSouth()) { + scroll.lat = this._cellCursor.getSouth() - freePaneBounds.getSouth() - spacingY; + } + } + + return scroll; + }, }); L.MessageStore = L.Class.extend({ diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 73d2da8a5..e5f73a10c 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -2962,40 +2962,13 @@ L.TileLayer = L.GridLayer.extend({ this._map.dialog._updateTextSelection(inputBarId); } var mapBounds = this._map.getBounds(); - if (!mapBounds.contains(this._cellCursor) && !this._cellCursorXY.equals(this._prevCellCursorXY)) { - var scrollX = 0, scrollY = 0; - if (onPgUpDn) { - var mapHalfHeight = (mapBounds.getNorth() - mapBounds.getSouth()) / 2; - var cellCursorOnPgUpDn = (this._cellCursorOnPgUp) ? this._cellCursorOnPgUp : this._cellCursorOnPgDn; - - scrollY = this._cellCursor.getNorth() - cellCursorOnPgUpDn.getNorth(); - if (this._cellCursor.getNorth() > mapBounds.getNorth() + scrollY) { - scrollY = (this._cellCursor.getNorth() - mapBounds.getNorth()) + mapHalfHeight; - } else if (this._cellCursor.getSouth() < mapBounds.getSouth() + scrollY) { - scrollY = (this._cellCursor.getNorth() - mapBounds.getNorth()) + mapHalfHeight; - } - } - else if (horizontalDirection !== 0 || verticalDirection != 0) { - var mapX = Math.abs(mapBounds.getEast() - mapBounds.getWest()); - var cursorX = Math.abs(this._cellCursor.getEast() - this._cellCursor.getWest()); - var spacingX = cursorX / 4.0; - var spacingY = Math.abs((this._cellCursor.getSouth() - this._cellCursor.getNorth())) / 4.0; - - if (this._cellCursor.getWest() < mapBounds.getWest()) { - scrollX = this._cellCursor.getWest() - mapBounds.getWest() - spacingX; - } else if (cursorX < mapX && this._cellCursor.getEast() > mapBounds.getEast()) { - scrollX = this._cellCursor.getEast() - mapBounds.getEast() + spacingX; - } - if (this._cellCursor.getNorth() > mapBounds.getNorth()) { - scrollY = this._cellCursor.getNorth() - mapBounds.getNorth() + spacingY; - } else if (this._cellCursor.getSouth() < mapBounds.getSouth()) { - scrollY = this._cellCursor.getSouth() - mapBounds.getSouth() - spacingY; - } - } - if (scrollX !== 0 || scrollY !== 0) { + if (!this._cellCursorXY.equals(this._prevCellCursorXY)) { + var scroll = this._calculateScrollForNewCursor(); + console.assert(scroll instanceof L.LatLng, '_calculateScrollForNewCursor returned wrong type'); + if (scroll.lng !== 0 || scroll.lat !== 0) { var newCenter = mapBounds.getCenter(); - newCenter.lng += scrollX; - newCenter.lat += scrollY; + newCenter.lng += scroll.lng; + newCenter.lat += scroll.lat; var center = this._map.project(newCenter); center = center.subtract(this._map.getSize().divideBy(2)); center.x = Math.round(center.x < 0 ? 0 : center.x); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
