loleaflet/html/loleaflet.html.m4      |    7 +
 loleaflet/src/core/Socket.js          |  185 ++++++++++++++++++++++------------
 loleaflet/src/layer/tile/GridLayer.js |    6 -
 loleaflet/src/main.js                 |    2 
 wsd/ClientSession.cpp                 |   21 ++-
 5 files changed, 150 insertions(+), 71 deletions(-)

New commits:
commit 518eaf866eee8192ce56af3a0d2dff6223fb80cf
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Wed Jul 17 13:19:32 2019 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Oct 1 10:13:21 2019 +0200

    Delay fit-to-screen on start for impress
    
    We need to wait to have valid size of the map.
    Bug was visible in NC app but not a browser.
    
    Change-Id: Ifb79ea84636de61dd92e4a9ae34c6f6caf5693c2
    Reviewed-on: https://gerrit.libreoffice.org/79921
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 2095a9759..1ea305adb 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -799,11 +799,27 @@ L.Socket = L.Class.extend({
                }
        },
 
+       _delayedFitToScreen: function(height) {
+               if (this._map.getSize().y > 0) {
+                       // 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;
+                       this._map._docLayer._tileWidthTwips = Math.round(height 
/ verticalTiles);
+                       this._map._docLayer._tileHeightTwips = 
Math.round(height / verticalTiles);
+                       this._map._docLayer._updateTileTwips();
+               } else {
+                       var that = this;
+                       setTimeout(function() {
+                               that._delayedFitToScreen(height);
+                       }, 100);
+               }
+       },
+
        _onStatusMsg: function(textMsg, command) {
+               var that = this;
 
                if (!this._isReady()) {
                        // Retry in a bit.
-                       var that = this;
                        setTimeout(function() {
                                that._onStatusMsg(textMsg, command);
                        }, 100);
@@ -843,12 +859,18 @@ L.Socket = L.Class.extend({
                        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.
-                                       // FIXME: Should this 256 be 
window.tileSize? Unclear to me.
-                                       var verticalTiles = 
this._map.getSize().y / 256;
-                                       tileWidthTwips = 
Math.round(command.height / verticalTiles);
-                                       tileHeightTwips = 
Math.round(command.height / verticalTiles);
+                                       if (this._map.getSize().y > 0) {
+                                               // 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.
+                                               // FIXME: Should this 256 be 
window.tileSize? Unclear to me.
+                                               var verticalTiles = 
this._map.getSize().y / 256;
+                                               tileWidthTwips = 
Math.round(command.height / verticalTiles);
+                                               tileHeightTwips = 
Math.round(command.height / verticalTiles);
+                                       } else {
+                                               setTimeout(function() {
+                                                       
that._delayedFitToScreen(command.height);
+                                               }, 100);
+                                       }
                                }
                                docLayer = new L.ImpressTileLayer('', {
                                        permission: 
this._map.options.permission,
commit a93d8f1e1cadd6a80248f8e6cb9a8eae80f0b657
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Wed Jul 3 00:29:43 2019 -0400
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Tue Oct 1 10:13:05 2019 +0200

    leaflet: check that we are ready to render
    
    On some mobile devices we can start rendering
    when we don't fully have all our variables
    initialized. The result is that we send to WSD
    'NaN' and 'Infinity' coordinates and other
    values.
    
    To avoid this, we try to check that we have downloaded
    and loaded all the JS files and that we have the bare
    minimal map members in valid state before we proceed
    with rendering. If not, we retry with a small delay.
    
    Change-Id: I0c57da8829a830acf4e06ff6206c73debb54bfe6
    Reviewed-on: https://gerrit.libreoffice.org/79920
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 363e77991..72abb80ca 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -71,6 +71,13 @@ var Base64ToArrayBuffer = function(base64Str) {
   }
   return ab;
 }
+
+  window.bundlejsLoaded = false;
+  window.fullyLoadedAndReady = false;
+  window.addEventListener('load', function() {
+    window.fullyLoadedAndReady = true;
+  }, false);
+
 </script>
 
 ifelse(MOBILEAPP,[true],
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 2b24ab49d..2095a9759 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -216,9 +216,31 @@ L.Socket = L.Class.extend({
                return strBytes;
        },
 
+       // Returns true if, and only if, we are ready to start loading
+       // the tiles and rendering the document.
+       _isReady: function() {
+               if (window.bundlejsLoaded == false || 
window.fullyLoadedAndReady == false) {
+                       return false;
+               }
+
+               if (typeof this._map == 'undefined' ||
+                       isNaN(this._map.options.tileWidthTwips) ||
+                       isNaN(this._map.options.tileHeightTwips)) {
+                       return false;
+               }
+
+               var center = this._map.getCenter();
+               if (isNaN(center.lat) || isNaN(center.lng) || 
isNaN(this._map.getZoom())) {
+                       return false;
+               }
+
+               return true;
+       },
+
        _onMessage: function (e) {
                var imgBytes, index, textMsg, img;
 
+               console.info('onMessage: window.fullyLoadedAndReady: ' + 
window.fullyLoadedAndReady + ', bundlejsLoaded: ' + window.bundlejsLoaded);
                if (typeof (e.data) === 'string') {
                        textMsg = e.data;
                }
@@ -751,68 +773,7 @@ L.Socket = L.Class.extend({
                }
 
                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
-                                       });
-                                       if (!this._map.options.backgroundLayer) 
{
-                                               
this._map.options.backgroundLayer = new L.CalcBackground().addTo(this._map);
-                                       }
-                               }
-                               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.
-                                               // FIXME: Should this 256 be 
window.tileSize? Unclear to me.
-                                               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._resetClientVisArea();
-                               this._map._docLayer._requestNewTiles();
-                               this._map.fire('statusindicator', {statusType: 
'reconnected'});
-                               
this._map.setPermission(this._map.options.permission);
-                       }
-
-                       this._map.fire('docloaded', {status: true});
+                       this._onStatusMsg(textMsg, command);
                }
 
                // These can arrive very early during the startup, and never 
again.
@@ -838,6 +799,84 @@ L.Socket = L.Class.extend({
                }
        },
 
+       _onStatusMsg: function(textMsg, command) {
+
+               if (!this._isReady()) {
+                       // Retry in a bit.
+                       var that = this;
+                       setTimeout(function() {
+                               that._onStatusMsg(textMsg, command);
+                       }, 100);
+                       return;
+               }
+
+               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
+                               });
+                               if (!this._map.options.backgroundLayer) {
+                                       this._map.options.backgroundLayer = new 
L.CalcBackground().addTo(this._map);
+                               }
+                       }
+                       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.
+                                       // FIXME: Should this 256 be 
window.tileSize? Unclear to me.
+                                       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._resetClientVisArea();
+                       this._map._docLayer._requestNewTiles();
+                       this._map.fire('statusindicator', {statusType: 
'reconnected'});
+                       this._map.setPermission(this._map.options.permission);
+               }
+
+               this._map.fire('docloaded', {status: true});
+               if (this._map._docLayer) {
+                       this._map._docLayer._onMessage(textMsg);
+               }
+       },
+
        _onSocketError: function () {
                console.debug('_onSocketError:');
                this._map.hideBusy();
diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index 3fcbbbac5..49a06ee18 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -718,8 +718,10 @@ L.GridLayer = L.Layer.extend({
                var visibleBottomRight = 
this._latLngToTwips(this._map.getBounds().getSouthEast());
                var visibleArea = new L.Bounds(visibleTopLeft, 
visibleBottomRight);
                var size = new L.Point(visibleArea.getSize().x, 
visibleArea.getSize().y);
-               var newClientVisibleArea = 'clientvisiblearea x=' + 
Math.round(visibleTopLeft.x) + ' y=' + Math.round(visibleTopLeft.y) +
-                       ' width=' + Math.round(size.x) + ' height=' + 
Math.round(size.y);
+               var newClientVisibleArea = 'clientvisiblearea x=' + 
Math.round(visibleTopLeft.x)
+                                       + ' y=' + Math.round(visibleTopLeft.y)
+                                       + ' width=' + Math.round(size.x)
+                                       + ' height=' + Math.round(size.y);
 
                if (this._clientVisibleArea !== newClientVisibleArea || 
forceUpdate) {
                        // Visible area is dirty, update it on the server
diff --git a/loleaflet/src/main.js b/loleaflet/src/main.js
index dd9c10cec..965aa132e 100644
--- a/loleaflet/src/main.js
+++ b/loleaflet/src/main.js
@@ -96,4 +96,6 @@ if (!L.Browser.mobile) {
        L.DomEvent.on(document, 'contextmenu', L.DomEvent.preventDefault);
 }
 
+window.bundlejsLoaded = true;
+
 }(window));
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index baaa177d9..85469f6ec 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -554,8 +554,10 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
             !getTokenInteger(tokens[3], "width", width) ||
             !getTokenInteger(tokens[4], "height", height))
         {
-            sendTextFrame("error: cmd=clientvisiblearea kind=syntax");
-            return false;
+            // Be forgiving and log instead of disconnecting.
+            // sendTextFrame("error: cmd=clientvisiblearea kind=syntax");
+            LOG_WRN("Invalid syntax for '" << tokens[0] << "' message: [" << 
firstLine << "].");
+            return true;
         }
         else
         {
@@ -628,8 +630,10 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
             !getTokenInteger(tokens[3], "tiletwipwidth", tileTwipWidth) ||
             !getTokenInteger(tokens[4], "tiletwipheight", tileTwipHeight))
         {
-            sendTextFrame("error: cmd=clientzoom kind=syntax");
-            return false;
+            // Be forgiving and log instead of disconnecting.
+            // sendTextFrame("error: cmd=clientzoom kind=syntax");
+            LOG_WRN("Invalid syntax for '" << tokens[0] << "' message: [" << 
firstLine << "].");
+            return true;
         }
         else
         {
@@ -647,8 +651,10 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
         if (tokens.size() != 2 ||
             !getTokenString(tokens[1], "tile", tileID))
         {
-            sendTextFrame("error: cmd=tileprocessed kind=syntax");
-            return false;
+            // Be forgiving and log instead of disconnecting.
+            // sendTextFrame("error: cmd=tileprocessed kind=syntax");
+            LOG_WRN("Invalid syntax for '" << tokens[0] << "' message: [" << 
firstLine << "].");
+            return true;
         }
 
         auto iter = std::find_if(_tilesOnFly.begin(), _tilesOnFly.end(),
@@ -868,7 +874,8 @@ bool ClientSession::sendCombinedTiles(const char* 
/*buffer*/, int /*length*/, co
     catch (const std::exception& exc)
     {
         LOG_ERR("Failed to process tilecombine command: " << exc.what());
-        return sendTextFrame("error: cmd=tile kind=invalid");
+        // Be forgiving and log instead of disconnecting.
+        // return sendTextFrame("error: cmd=tile kind=invalid");
     }
 
     return true;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to