loleaflet/src/control/Control.ColumnHeader.js | 2 loleaflet/src/control/Control.RowHeader.js | 2 loleaflet/src/control/Control.Scroll.js | 40 ------------------- loleaflet/src/layer/tile/CalcTileLayer.js | 53 +++++++++++++++++++++++--- loleaflet/src/map/Map.js | 4 + 5 files changed, 55 insertions(+), 46 deletions(-)
New commits: commit cc6250de46333bcb2ec22caf272c2e36ce7327f7 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Mon May 11 21:31:25 2020 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Sun Jul 5 09:55:03 2020 +0200 move the 'updaterowcolumnheaders' event handling code from L.Control.Scroll to a new method requestViewRowColumnData() under L.CalcTileLayer which is arguably a more appropriate place for it and change all the places that calls map.fire() to emit 'updaterowcolumnheaders' to call the new method directly. This helps to improve the code readability a bit by being more explicit and also avoid an unnecessary indirection while code grepping. This also makes it much easier to introduce the change in data source from .uno:ViewRowColumnHeaders to .uno:SheetGeometryData by avoiding lots of abrupt changes in one go. Change-Id: Ia42d7586f06e28a5715fac278967a445089308af Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97939 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/loleaflet/src/control/Control.ColumnHeader.js b/loleaflet/src/control/Control.ColumnHeader.js index f9d3feedb..a2846f78e 100644 --- a/loleaflet/src/control/Control.ColumnHeader.js +++ b/loleaflet/src/control/Control.ColumnHeader.js @@ -193,7 +193,7 @@ L.Control.ColumnHeader = L.Control.Header.extend({ }, _updateColumnHeader: function () { - this._map.fire('updaterowcolumnheaders', {x: this._map._getTopLeftPoint().x, y: 0, offset: {x: undefined, y: 0}}); + this._map._docLayer.requestViewRowColumnData({x: this._map._getTopLeftPoint().x, y: 0, offset: {x: undefined, y: 0}}); }, drawHeaderEntry: function (entry, isOver, isHighlighted, isCurrent) { diff --git a/loleaflet/src/control/Control.RowHeader.js b/loleaflet/src/control/Control.RowHeader.js index 0bf1fcb38..afbba3c45 100644 --- a/loleaflet/src/control/Control.RowHeader.js +++ b/loleaflet/src/control/Control.RowHeader.js @@ -186,7 +186,7 @@ L.Control.RowHeader = L.Control.Header.extend({ }, _updateRowHeader: function () { - this._map.fire('updaterowcolumnheaders', {x: 0, y: this._map._getTopLeftPoint().y, offset: {x: 0, y: undefined}}); + this._map._docLayer.requestViewRowColumnData({x: 0, y: this._map._getTopLeftPoint().y, offset: {x: 0, y: undefined}}); }, drawHeaderEntry: function (entry, isOver, isHighlighted, isCurrent) { diff --git a/loleaflet/src/control/Control.Scroll.js b/loleaflet/src/control/Control.Scroll.js index 650f69ce4..e3f9cf4dc 100644 --- a/loleaflet/src/control/Control.Scroll.js +++ b/loleaflet/src/control/Control.Scroll.js @@ -23,7 +23,6 @@ L.Control.Scroll = L.Control.extend({ map.on('handleautoscroll', this._onHandleAutoScroll, this); map.on('docsize', this._onUpdateSize, this); map.on('updatescrolloffset', this._onUpdateScrollOffset, this); - map.on('updaterowcolumnheaders', this._onUpdateRowColumnHeaders, this); var control = this; var autoHideTimeout = null; @@ -115,7 +114,7 @@ L.Control.Scroll = L.Control.extend({ return; } - this._onUpdateRowColumnHeaders({ x: newLeft, y: newTop, offset: offset}); + this._map._docLayer.requestViewRowColumnData({ x: newLeft, y: newTop, offset: offset}); this._prevScrollY = newTop; this._prevScrollX = newLeft; @@ -268,7 +267,7 @@ L.Control.Scroll = L.Control.extend({ offset.y = 1; } if (e.updateHeaders && this._map._docLayer._docType === 'spreadsheet') { - this._onUpdateRowColumnHeaders({x: e.x, y: e.y, offset: offset}); + this._map._docLayer.requestViewRowColumnData({x: e.x, y: e.y, offset: offset}); } this._map.fire('scrolloffset', offset); this._ignoreScroll = null; @@ -276,41 +275,6 @@ L.Control.Scroll = L.Control.extend({ this._prevScrollY = e.y; this._prevScrollX = e.x; $('.scroll-container').mCustomScrollbar('scrollTo', [e.y, e.x], {callbacks: false, timeout:0}); - }, - - _onUpdateRowColumnHeaders: function(e) { - var offset = e.offset || {}; - - var topLeftPoint = new L.Point(e.x, e.y); - var sizePx = this._map.getSize(); - - if (topLeftPoint.x === undefined) { - topLeftPoint.x = this._map._getTopLeftPoint().x; - } - if (topLeftPoint.y === undefined) { - topLeftPoint.y = this._map._getTopLeftPoint().y; - } - - if (offset.x === 0) { - topLeftPoint.x = -1; - sizePx.x = 0; - } - if (offset.y === 0) { - topLeftPoint.y = -1; - sizePx.y = 0; - } - - var pos = this._map._docLayer._pixelsToTwips(topLeftPoint); - var size = this._map._docLayer._pixelsToTwips(sizePx); - var payload = 'commandvalues command=.uno:ViewRowColumnHeaders?x=' + Math.round(pos.x) + '&y=' + Math.round(pos.y) + - '&width=' + Math.round(size.x) + '&height=' + Math.round(size.y); - - if (e.outline) { - payload += '&columnOutline=' + e.outline.column + '&groupLevel=' + e.outline.level - + '&groupIndex=' + e.outline.index + '&groupHidden=' + e.outline.hidden; - } - - this._map._socket.sendMessage(payload); } }); diff --git a/loleaflet/src/layer/tile/CalcTileLayer.js b/loleaflet/src/layer/tile/CalcTileLayer.js index 323fcc711..06ffa2bef 100644 --- a/loleaflet/src/layer/tile/CalcTileLayer.js +++ b/loleaflet/src/layer/tile/CalcTileLayer.js @@ -264,13 +264,13 @@ L.CalcTileLayer = L.TileLayer.extend({ } } } else if (textMsg.startsWith('invalidateheader: column')) { - this._map.fire('updaterowcolumnheaders', {x: this._map._getTopLeftPoint().x, y: 0, offset: {x: undefined, y: 0}}); + this.requestViewRowColumnData({x: this._map._getTopLeftPoint().x, y: 0, offset: {x: undefined, y: 0}}); this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition'); } else if (textMsg.startsWith('invalidateheader: row')) { - this._map.fire('updaterowcolumnheaders', {x: 0, y: this._map._getTopLeftPoint().y, offset: {x: 0, y: undefined}}); + this.requestViewRowColumnData({x: 0, y: this._map._getTopLeftPoint().y, offset: {x: 0, y: undefined}}); this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition'); } else if (textMsg.startsWith('invalidateheader: all')) { - this._map.fire('updaterowcolumnheaders', {x: this._map._getTopLeftPoint().x, y: this._map._getTopLeftPoint().y, offset: {x: undefined, y: undefined}}); + this.requestViewRowColumnData({x: this._map._getTopLeftPoint().x, y: this._map._getTopLeftPoint().y, offset: {x: undefined, y: undefined}}); this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition'); } else { L.TileLayer.prototype._onMessage.call(this, textMsg, img); @@ -361,14 +361,14 @@ L.CalcTileLayer = L.TileLayer.extend({ this._map.setPart(part, true); this._map.fire('setpart', {selectedPart: this._selectedPart}); // TODO: test it! - this._map.fire('updaterowcolumnheaders'); + this.requestViewRowColumnData(); } }, _onZoomRowColumns: function () { this._sendClientZoom(); // TODO: test it! - this._map.fire('updaterowcolumnheaders'); + this.requestViewRowColumnData(); this._map._socket.sendMessage('commandvalues command=.uno:ViewAnnotationsPosition'); }, @@ -454,6 +454,49 @@ L.CalcTileLayer = L.TileLayer.extend({ } }, + // This send .uno:ViewRowColumnHeaders command to core with the new view coordinates. + requestViewRowColumnData: function (coordinatesData) { + + // There are places that call this function with no arguments to indicate that the + // command arguments should be the current map area coordinates. + if (typeof coordinatesData != 'object') { + coordinatesData = {}; + } + + var offset = coordinatesData.offset || {}; + + var topLeftPoint = new L.Point(coordinatesData.x, coordinatesData.y); + var sizePx = this._map.getSize(); + + if (topLeftPoint.x === undefined) { + topLeftPoint.x = this._map._getTopLeftPoint().x; + } + if (topLeftPoint.y === undefined) { + topLeftPoint.y = this._map._getTopLeftPoint().y; + } + + if (offset.x === 0) { + topLeftPoint.x = -1; + sizePx.x = 0; + } + if (offset.y === 0) { + topLeftPoint.y = -1; + sizePx.y = 0; + } + + var pos = this._pixelsToTwips(topLeftPoint); + var size = this._pixelsToTwips(sizePx); + var payload = 'commandvalues command=.uno:ViewRowColumnHeaders?x=' + Math.round(pos.x) + '&y=' + Math.round(pos.y) + + '&width=' + Math.round(size.x) + '&height=' + Math.round(size.y); + + if (coordinatesData.outline) { + payload += '&columnOutline=' + coordinatesData.outline.column + '&groupLevel=' + coordinatesData.outline.level + + '&groupIndex=' + coordinatesData.outline.index + '&groupHidden=' + coordinatesData.outline.hidden; + } + + this._map._socket.sendMessage(payload); + }, + _handleViewRowColumnHeadersMsg: function (jsonMsgObj) { this._map.fire('viewrowcolumnheaders', { data: jsonMsgObj, diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 285e4954d..dbc376765 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -323,7 +323,9 @@ L.Map = L.Evented.extend({ // TODO: remove duplicated init code this._socket.sendMessage('commandvalues command=.uno:LanguageStatus'); this._socket.sendMessage('commandvalues command=.uno:ViewAnnotations'); - this.fire('updaterowcolumnheaders'); + if (this._docLayer._docType === 'spreadsheet') { + this._docLayer.requestViewRowColumnData(); + } this._docLayer._getToolbarCommandsValues(); }, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits