loleaflet/src/core/Socket.js | 109 ++++++++++++++++++---------------- loleaflet/src/map/Map.js | 19 +++++ loleaflet/src/map/handler/Map.WOPI.js | 12 ++- 3 files changed, 84 insertions(+), 56 deletions(-)
New commits: commit e952a0a6ed8814849e1cf084025966093a0a77ea Author: Pranav Kant <pran...@collabora.co.uk> Date: Fri Aug 11 21:39:12 2017 +0530 loleaflet: new event, docloaded, to sync. various things First, use the docloaded event to see whether we should be dimming the document (make it inactive) or not. There is no point in inactivating a document before document has completely loaded; so don't start the timer until after the document is completely loaded. It turns out that we were only emitting the WOPI's App_LoadingStatus with DocumentLoaded for the first document load, but not for subsequent reconnections. The problem here was that doclayerinit event is only emitted during first document load (when TileLayer is -actually- initialized), which was responsible for emitting this event. By bifurcating the document load from document layer initialization, we solve this problem. Change-Id: I0b7b97fc6244ba9ebd6318d68d78d3abef2c0c08 (cherry picked from commit d0be89bffa339e6cefc88cd3ca56ccd86ec1f517) Reviewed-on: https://gerrit.libreoffice.org/41057 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Reviewed-by: Jan Holesovsky <ke...@collabora.com> Tested-by: Jan Holesovsky <ke...@collabora.com> diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 9843d6e7..e37473be 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -62,6 +62,9 @@ L.Socket = L.Class.extend({ this.socket.onmessage = function () {}; this.socket.close(); + // Reset wopi's app loaded so that reconnecting again informs outerframe about initialization + this._map['wopi'].resetAppLoaded(); + this._map.fire('docloaded', {status: false}); clearTimeout(this._accessTokenExpireTimeout); }, @@ -509,59 +512,64 @@ L.Socket = L.Class.extend({ var img = 'data:image/png;base64,' + window.btoa(strBytes); } - if (textMsg.startsWith('status:') && !this._map._docLayer) { - // first status message, we need to create the document layer - var tileWidthTwips = this._map.options.tileWidthTwips; - var tileHeightTwips = this._map.options.tileHeightTwips; - if (this._map.options.zoom !== this._map.options.defaultZoom) { - var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom); - tileWidthTwips = Math.round(tileWidthTwips * scale); - tileHeightTwips = Math.round(tileHeightTwips * scale); - } + if (textMsg.startsWith('status:')) { + if (!this._map._docLayer) { + // first status message, we need to create the document layer + var tileWidthTwips = this._map.options.tileWidthTwips; + var tileHeightTwips = this._map.options.tileHeightTwips; + if (this._map.options.zoom !== this._map.options.defaultZoom) { + var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom); + tileWidthTwips = Math.round(tileWidthTwips * scale); + tileHeightTwips = Math.round(tileHeightTwips * scale); + } - var docLayer = null; - if (command.type === 'text') { - docLayer = new L.WriterTileLayer('', { - permission: this._map.options.permission, - tileWidthTwips: tileWidthTwips, - tileHeightTwips: tileHeightTwips, - docType: command.type - }); - } - else if (command.type === 'spreadsheet') { - docLayer = new L.CalcTileLayer('', { - permission: this._map.options.permission, - tileWidthTwips: tileWidthTwips, - tileHeightTwips: tileHeightTwips, - docType: command.type - }); - } - else { - if (command.type === 'presentation' && - this._map.options.defaultZoom === this._map.options.zoom) { - // If we have a presentation document and the zoom level has not been set - // in the options, resize the document so that it fits the viewing area - var verticalTiles = this._map.getSize().y / 256; - tileWidthTwips = Math.round(command.height / verticalTiles); - tileHeightTwips = Math.round(command.height / verticalTiles); + var docLayer = null; + if (command.type === 'text') { + docLayer = new L.WriterTileLayer('', { + permission: this._map.options.permission, + tileWidthTwips: tileWidthTwips, + tileHeightTwips: tileHeightTwips, + docType: command.type + }); } - docLayer = new L.ImpressTileLayer('', { - permission: this._map.options.permission, - tileWidthTwips: tileWidthTwips, - tileHeightTwips: tileHeightTwips, - docType: command.type - }); + else if (command.type === 'spreadsheet') { + docLayer = new L.CalcTileLayer('', { + permission: this._map.options.permission, + tileWidthTwips: tileWidthTwips, + tileHeightTwips: tileHeightTwips, + docType: command.type + }); + } + else { + if (command.type === 'presentation' && + this._map.options.defaultZoom === this._map.options.zoom) { + // If we have a presentation document and the zoom level has not been set + // in the options, resize the document so that it fits the viewing area + var verticalTiles = this._map.getSize().y / 256; + tileWidthTwips = Math.round(command.height / verticalTiles); + tileHeightTwips = Math.round(command.height / verticalTiles); + } + docLayer = new L.ImpressTileLayer('', { + permission: this._map.options.permission, + tileWidthTwips: tileWidthTwips, + tileHeightTwips: tileHeightTwips, + docType: command.type + }); + } + + this._map._docLayer = docLayer; + this._map.addLayer(docLayer); + this._map.fire('doclayerinit'); + } + else if (this._reconnecting) { + // we are reconnecting ... + this._reconnecting = false; + this._map._docLayer._onMessage('invalidatetiles: EMPTY', null); + this._map.fire('statusindicator', {statusType: 'reconnected'}); + this._map.setPermission(this._map.options.permission); } - this._map._docLayer = docLayer; - this._map.addLayer(docLayer); - this._map.fire('doclayerinit'); - } else if (textMsg.startsWith('status:') && this._reconnecting) { - // we are reconnecting ... - this._reconnecting = false; - this._map._docLayer._onMessage('invalidatetiles: EMPTY', null); - this._map.fire('statusindicator', {statusType: 'reconnected'}); - this._map.setPermission(this._map.options.permission); + this._map.fire('docloaded', {status: true}); } // these can arrive very early during the startup @@ -606,8 +614,9 @@ L.Socket = L.Class.extend({ this._map.fire('error', {msg: _('Well, this is embarrassing, we cannot connect to your document. Please try again.'), cmd: 'socket', kind: 'closed', id: 4}); } - // Reset wopi's app loaded so that reconnecting again informs outerframe about initialization again + // Reset wopi's app loaded so that reconnecting again informs outerframe about initialization this._map['wopi'].resetAppLoaded(); + this._map.fire('docloaded', {status: false}); if (!this._reconnecting) { this._reconnecting = true; diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 5ac07a4d..5d6f08a2 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -143,10 +143,24 @@ L.Map = L.Evented.extend({ // This becomes true if document was ever modified by the user this._everModified = false; + // Document is completely loaded or not + this._docLoaded = false; + this.on('commandstatechanged', function(e) { if (e.commandName === '.uno:ModifiedStatus') this._everModified = this._everModified || (e.state === 'true'); }, this); + + this.on('docloaded', function(e) { + if (e.status) { + // so that dim timer starts from now() + this.lastActiveTime = Date.now(); + if (!document.hasFocus()) { + this._deactivate(); + } + } + this._docLoaded = e.status; + }, this); }, // public methods that modify map state @@ -883,7 +897,8 @@ L.Map = L.Evented.extend({ _dimIfInactive: function () { console.debug('_dimIfInactive: diff=' + (Date.now() - this.lastActiveTime)); - if ((Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) { + if (this._docLoaded && // don't dim if document hasn't been loaded yet + (Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) { this._dim(); } else { this._startInactiveTimer(); @@ -904,7 +919,7 @@ L.Map = L.Evented.extend({ }, _deactivate: function () { - if (this._serverRecycling || this._documentIdle) { + if (this._serverRecycling || this._documentIdle || !this._docLoaded) { return; } diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index 44f4917b..b13bff44 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -17,7 +17,7 @@ L.Map.WOPI = L.Handler.extend({ DisableCopy: false, _appLoadedConditions: { - doclayerinit: false, + docloaded: false, updatepermission: false, viewinfo: false /* Whether view information has already arrived */ }, @@ -32,7 +32,7 @@ L.Map.WOPI = L.Handler.extend({ this._map.on('postMessage', this._postMessage, this); // init messages - this._map.on('doclayerinit', this._postLoaded, this); + this._map.on('docloaded', this._postLoaded, this); this._map.on('updatepermission', this._postLoaded, this); // This indicates that 'viewinfo' message has already arrived this._map.on('viewinfo', this._postLoaded, this); @@ -45,7 +45,7 @@ L.Map.WOPI = L.Handler.extend({ this._map.off('postMessage', this._postMessage, this); // init messages - this._map.off('doclayerinit', this._postLoaded, this); + this._map.off('docloaded', this._postLoaded, this); this._map.off('updatepermission', this._postLoaded, this); this._map.off('viewinfo', this._postLoaded, this); @@ -81,7 +81,11 @@ L.Map.WOPI = L.Handler.extend({ return; } - if (e.type === 'doclayerinit') { + if (e.type === 'docloaded') { + // doc unloaded + if (!e.status) + return; + this.DocumentLoadedTime = Date.now(); } this._appLoadedConditions[e.type] = true; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits