loleaflet/src/layer/marker/Marker.js | 12 +++++---- loleaflet/src/layer/tile/CalcTileLayer.js | 12 ++++++++- loleaflet/src/layer/tile/CanvasTileLayer.js | 28 +++++++++++++---------- loleaflet/src/layer/vector/Renderer.js | 4 +-- loleaflet/src/layer/vector/SplitPanesRenderer.js | 4 --- loleaflet/src/layer/vector/SplitPanesSVG.js | 2 - loleaflet/src/layer/vector/SplitterLine.js | 15 ++++++------ loleaflet/src/map/Map.js | 21 +++++++---------- 8 files changed, 54 insertions(+), 44 deletions(-)
New commits: commit fa043504b92b8cb47403336f56f58f720502aec4 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Thu Jul 9 22:36:24 2020 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Fri Jul 10 16:52:58 2020 +0200 defer splitPanesContext creation till we get the part number... and this context object should be cached as a member only by the document layer. All others must invoke getSplitPanesContext() on the map or the document layer everytime it is needed. Otherwise it is a lot of effort to keep the caches up-to-date on a sheet-switch etc. Change-Id: I262b0f6a10060426d89460defc0d3f0a510b880e Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98496 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/loleaflet/src/layer/marker/Marker.js b/loleaflet/src/layer/marker/Marker.js index d9e1db258..2fe48b10b 100644 --- a/loleaflet/src/layer/marker/Marker.js +++ b/loleaflet/src/layer/marker/Marker.js @@ -40,7 +40,6 @@ L.Marker = L.Layer.extend({ }, onAdd: function (map) { - this._splitPanesContext = map.getSplitPanesContext(); this._zoomAnimated = this._zoomAnimated && map.options.markerZoomAnimation; this._initIcon(); @@ -65,12 +64,13 @@ L.Marker = L.Layer.extend({ getEvents: function () { var events = {viewreset: this.update}; - if (this._splitPanesContext) { + var splitPanesPossible = this._map._docLayer.hasSplitPanesSupport(); + if (splitPanesPossible) { events.moveend = this.update; events.splitposchanged = this.update; } - if (this._zoomAnimated && !this._splitPanesContext) { + if (this._zoomAnimated && !splitPanesPossible) { events.zoomanim = this._animateZoom; } @@ -115,12 +115,14 @@ L.Marker = L.Layer.extend({ return; } - if (!this._splitPanesContext) { + var splitPanesContext = this._map.getSplitPanesContext(); + + if (!splitPanesContext) { this._setPos(this._map.latLngToLayerPoint(this._latlng).round()); return; } - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = splitPanesContext.getSplitPos(); var docPos = this._map.project(this._latlng); var pixelOrigin = this._map.getPixelOrigin(); var mapPanePos = this._map._getMapPanePos(); diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js index 2f1a6ac8a..dfe2fd9e2 100644 --- a/loleaflet/src/layer/tile/CalcTileLayer.js +++ b/loleaflet/src/layer/tile/CalcTileLayer.js @@ -69,7 +69,6 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({ }, onAdd: function (map) { - this._switchSplitPanesContext(); map.addControl(L.control.tabs()); map.addControl(L.control.columnHeader()); map.addControl(L.control.rowHeader()); @@ -539,6 +538,7 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({ _onStatusMsg: function (textMsg) { var command = this._map._socket.parseServerCmd(textMsg); if (command.width && command.height && this._documentInfo !== textMsg) { + var firstSelectedPart = (typeof this._selectedPart !== 'number'); this._docWidthTwips = command.width; this._docHeightTwips = command.height; this._docType = command.type; @@ -575,6 +575,9 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({ }); this._resetPreFetching(true); this._update(); + if (firstSelectedPart) { + this._switchSplitPanesContext(); + } } }, @@ -773,13 +776,18 @@ L.CalcTileLayer = (L.Browser.mobile ? L.TileLayer : L.CanvasTileLayer).extend({ this._splitPaneCache = {}; } + console.assert(typeof this._selectedPart === 'number', 'invalid selectedPart'); + var spContext = this._splitPaneCache[this._selectedPart]; if (!spContext) { spContext = new L.SplitPanesContext(this); + this._splitPaneCache[this._selectedPart] = spContext; } this._splitPanesContext = spContext; - this._map._splitPanesContext = spContext; + if (this.sheetGeometry) { + this._updateSplitPos(); + } }, _onCommandValuesMsg: function (textMsg) { diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js index e086a08ad..4c7bd0394 100644 --- a/loleaflet/src/layer/tile/CanvasTileLayer.js +++ b/loleaflet/src/layer/tile/CanvasTileLayer.js @@ -43,7 +43,6 @@ L.CanvasTilePainter = L.Class.extend({ initialize: function (layer, dpiScale, enableImageSmoothing) { this._layer = layer; this._canvas = this._layer._canvas; - this._splitPanesContext = this._layer.getSplitPanesContext(); if (dpiScale === 1 || dpiScale === 2) { enableImageSmoothing = (enableImageSmoothing === true); @@ -60,8 +59,9 @@ L.CanvasTilePainter = L.Class.extend({ this._topLeft = undefined; this._lastZoom = undefined; this._lastPart = undefined; - this._splitPos = this._splitPanesContext ? - this._splitPanesContext.getSplitPos() : new L.Point(0, 0); + var splitPanesContext = this._layer.getSplitPanesContext(); + this._splitPos = splitPanesContext ? + splitPanesContext.getSplitPos() : new L.Point(0, 0); this._tileSizeCSSPx = undefined; this._updatesRunning = false; @@ -139,9 +139,10 @@ L.CanvasTilePainter = L.Class.extend({ var tileBounds = new L.Bounds(tileTopLeft, tileTopLeft.add(tileSize)); viewBounds = viewBounds || this._map.getPixelBounds(); + var splitPanesContext = this._layer.getSplitPanesContext(); paneBoundsList = paneBoundsList || ( - this._splitPanesContext ? - this._splitPanesContext.getPxBoundList(viewBounds) : + splitPanesContext ? + splitPanesContext.getPxBoundList(viewBounds) : [viewBounds] ); @@ -182,10 +183,11 @@ L.CanvasTilePainter = L.Class.extend({ }, _drawSplits: function () { - if (!this._splitPanesContext) { + var splitPanesContext = this._layer.getSplitPanesContext(); + if (!splitPanesContext) { return; } - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = splitPanesContext.getSplitPos(); this._canvasCtx.save(); this._canvasCtx.scale(this._dpiScale, this._dpiScale); this._canvasCtx.strokeStyle = 'red'; @@ -201,13 +203,14 @@ L.CanvasTilePainter = L.Class.extend({ update: function () { + var splitPanesContext = this._layer.getSplitPanesContext(); var zoom = Math.round(this._map.getZoom()); var pixelBounds = this._map.getPixelBounds(); var newSize = pixelBounds.getSize(); var newTopLeft = pixelBounds.getTopLeft(); var part = this._layer._selectedPart; - var newSplitPos = this._splitPanesContext ? - this._splitPanesContext.getSplitPos(): this._splitPos; + var newSplitPos = splitPanesContext ? + splitPanesContext.getSplitPos(): this._splitPos; var zoomChanged = (zoom !== this._lastZoom); var partChanged = (part !== this._lastPart); @@ -259,7 +262,7 @@ L.CanvasTilePainter = L.Class.extend({ _shiftAndPaint: function (newTopLeft) { - console.assert(!this._splitPanesContext, '_shiftAndPaint is broken for split-panes.'); + console.assert(!this._layer.getSplitPanesContext(), '_shiftAndPaint is broken for split-panes.'); var offset = new L.Point(this._width - 1, this._height - 1); var dx = newTopLeft.x - this._topLeft.x; @@ -359,9 +362,10 @@ L.CanvasTilePainter = L.Class.extend({ var viewSize = new L.Point(this._width, this._height); var viewBounds = new L.Bounds(this._topLeft, this._topLeft.add(viewSize)); + var splitPanesContext = this._layer.getSplitPanesContext(); // Calculate all this here intead of doing it per tile. - var paneBoundsList = this._splitPanesContext ? - this._splitPanesContext.getPxBoundList(viewBounds) : [viewBounds]; + var paneBoundsList = splitPanesContext ? + splitPanesContext.getPxBoundList(viewBounds) : [viewBounds]; var tileRanges = paneBoundsList.map(this._layer._pxBoundsToTileRange, this._layer); var tileSize = this._tileSizeCSSPx || this._layer._getTileSize(); diff --git a/loleaflet/src/layer/vector/Renderer.js b/loleaflet/src/layer/vector/Renderer.js index b2507db6d..85ab7bccb 100644 --- a/loleaflet/src/layer/vector/Renderer.js +++ b/loleaflet/src/layer/vector/Renderer.js @@ -108,7 +108,7 @@ L.Map.include({ var renderer = layer.options.renderer || this._getPaneRenderer(layer.options.pane) || this.options.renderer || this._renderer; if (!renderer) { - if (this._splitPanesContext) { + if (this.getSplitPanesContext()) { renderer = this._renderer = (L.SVG && L.SplitPanesSVG && L.splitPanesSVG()) || (L.Canvas && L.SplitPanesCanvas && L.splitPanesCanvas()); } @@ -132,7 +132,7 @@ L.Map.include({ var renderer = this._paneRenderers[name]; if (renderer === undefined) { - if (this._splitPanesContext) { + if (this.getSplitPanesContext()) { renderer = (L.SVG && L.SplitPanesSVG && L.splitPanesSVG({pane: name})) || (L.Canvas && L.SplitPanesCanvas && L.splitPanesCanvas({pane: name})); } diff --git a/loleaflet/src/layer/vector/SplitPanesRenderer.js b/loleaflet/src/layer/vector/SplitPanesRenderer.js index 4f7f06073..4ef1f72c1 100644 --- a/loleaflet/src/layer/vector/SplitPanesRenderer.js +++ b/loleaflet/src/layer/vector/SplitPanesRenderer.js @@ -18,9 +18,7 @@ L.SplitPanesRenderer = L.Layer.extend({ }, onAdd: function () { - - this._splitPanesContext = this._map.getSplitPanesContext(); - console.assert(this._splitPanesContext, 'no split-panes context object!'); + console.assert(this._map.getSplitPanesContext(), 'no split-panes context object!'); if (!this._container) { this._initContainer(); // defined by renderer implementations diff --git a/loleaflet/src/layer/vector/SplitPanesSVG.js b/loleaflet/src/layer/vector/SplitPanesSVG.js index c0f8974ce..4ad5de6fd 100644 --- a/loleaflet/src/layer/vector/SplitPanesSVG.js +++ b/loleaflet/src/layer/vector/SplitPanesSVG.js @@ -78,7 +78,7 @@ L.SplitPanesSVG = L.SplitPanesRenderer.extend({ var renderer = this._childRenderers[rendererId]; console.assert(renderer && L.stamp(renderer) === L.stamp(childRenderer), 'Child renderer does not belong to parent!'); - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = this._map.getSplitPanesContext().getSplitPos(); var size = this._map.getSize(); var pixelOrigin = this._map.getPixelOrigin(); // Container coordinates. diff --git a/loleaflet/src/layer/vector/SplitterLine.js b/loleaflet/src/layer/vector/SplitterLine.js index a769a58e0..344b91625 100644 --- a/loleaflet/src/layer/vector/SplitterLine.js +++ b/loleaflet/src/layer/vector/SplitterLine.js @@ -29,12 +29,12 @@ L.SplitterLine = L.Rectangle.extend({ _calculateLatLngBounds: function (map) { map = map || this._map; - this._splitPanesContext = this._splitPanesContext || map.getSplitPanesContext(); - console.assert(this._splitPanesContext, 'no _splitPanesContext!'); + var splitPanesContext = map.getSplitPanesContext(); + console.assert(splitPanesContext, 'no splitPanesContext!'); var size = map._docLayer.getMaxDocSize(); var isHoriz = this.options.isHoriz; - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = splitPanesContext.getSplitPos(); this._lastPos = isHoriz ? splitPos.x : splitPos.y; @@ -134,17 +134,18 @@ L.SplitterLine = L.Rectangle.extend({ this._dragStarted = false; if (this._curPos !== undefined) { + var splitPanesContext = this._map.getSplitPanesContext(); if (this.options.isHoriz) { - this._splitPanesContext.setHorizSplitPos(this._curPos); + splitPanesContext.setHorizSplitPos(this._curPos); } else { - this._splitPanesContext.setVertSplitPos(this._curPos); + splitPanesContext.setVertSplitPos(this._curPos); } - var newPoint = this._splitPanesContext.getSplitPos(); + var newPoint = splitPanesContext.getSplitPos(); var newPos = this.options.isHoriz ? newPoint.x : newPoint.y; if (newPos == this._lastPos) { - this._splitPanesContext.updateSplitters(); + splitPanesContext.updateSplitters(); } } diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 97163f1d7..2d4dd2b0e 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -914,10 +914,11 @@ L.Map = L.Evented.extend({ }, containerPointToLayerPoint: function (point) { // (Point) - if (!this._splitPanesContext) { + var splitPanesContext = this.getSplitPanesContext(); + if (!splitPanesContext) { return this.containerPointToLayerPointIgnoreSplits(point); } - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = splitPanesContext.getSplitPos(); var pixelOrigin = this.getPixelOrigin(); var mapPanePos = this._getMapPanePos(); var result = L.point(point); @@ -943,12 +944,12 @@ L.Map = L.Evented.extend({ }, layerPointToContainerPoint: function (point) { // (Point) - - if (!this._splitPanesContext) { + var splitPanesContext = this.getSplitPanesContext(); + if (!splitPanesContext) { return this.layerPointToContainerPointIgnoreSplits(point); } - var splitPos = this._splitPanesContext.getSplitPos(); + var splitPos = splitPanesContext.getSplitPos(); var pixelOrigin = this.getPixelOrigin(); var mapPanePos = this._getMapPanePos(); var result = L.point(point)._add(pixelOrigin); @@ -1824,16 +1825,12 @@ L.Map = L.Evented.extend({ }, getSplitPanesContext: function () { - if (this._splitPanesContext) { - return this._splitPanesContext; - } - var docLayer = this._docLayer; - if (docLayer && typeof docLayer.getSplitPanesContext === 'function') { - this._splitPanesContext = docLayer.getSplitPanesContext(); + if (docLayer) { + return docLayer.getSplitPanesContext(); } - return this._splitPanesContext; + return undefined; } }); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits