[Libreoffice-commits] online.git: 3 commits - loleaflet/src loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

Mihai Varga mihai.varga at collabora.com
Tue Jul 21 09:08:52 PDT 2015


 loleaflet/src/control/Parts.js        |    1 +
 loleaflet/src/layer/tile/TileLayer.js |    1 +
 loolwsd/LOOLSession.cpp               |   24 ++++++++++++++++++++++--
 loolwsd/LOOLSession.hpp               |    4 ++++
 loolwsd/TileCache.cpp                 |   22 ++++++++++++++--------
 loolwsd/TileCache.hpp                 |    2 +-
 6 files changed, 43 insertions(+), 11 deletions(-)

New commits:
commit 0492094b4eb3d21d8ff9b5e874ee806640a4b0f1
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Jul 21 16:57:50 2015 +0300

    loleaflet: notify the server about the current part
    
    We need this because we want to prefetch tiles from other parts too.
    In order to render a tile we need to call 'setPart' and then 'paintTile'
    so this might change the current part in the document.
    But when the user is editing/selecting we want to work on the part that
    he/she is viewing

diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 30eddd9..1041604 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -25,6 +25,7 @@ L.Map.include({
 			parts: docLayer._parts,
 			docType: docLayer._docType
 		});
+		docLayer.sendMessage('setclientpart part=' + docLayer._currentPart);
 		docLayer._update();
 		docLayer._pruneTiles();
 		docLayer._clearSelections();
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index b4d8024..99b4df1 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -323,6 +323,7 @@ L.TileLayer = L.GridLayer.extend({
 				this._documentInfo = textMsg;
 				this._parts = command.parts;
 				this._currentPart = command.currentPart;
+				this.sendMessage('setclientpart part=' + this._currentPart);
 				var partNamesStr = bytes === undefined ? textMsg : String.fromCharCode.apply(null, bytes.subarray(index));
 				var partNames = partNamesStr.match(/[^\r\n]+/g);
 				this._map.fire('updateparts', {
commit b9884a470a89fbbcba5b500da62d3e2601299090
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Jul 21 16:56:02 2015 +0300

    loolwsd: be aware of the client's current part
    
    And set lok's part to match the client's when they start editing or
    selecting

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 58e699e..3294806 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -277,6 +277,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
              tokens[0] != "saveas" &&
              tokens[0] != "selectgraphic" &&
              tokens[0] != "selecttext" &&
+             tokens[0] != "setclientpart" &&
              tokens[0] != "status" &&
              tokens[0] != "tile" &&
              tokens[0] != "uno")
@@ -574,7 +575,8 @@ void MasterProcessSession::forwardToPeer(const char *buffer, int length)
 ChildProcessSession::ChildProcessSession(std::shared_ptr<WebSocket> ws, LibreOfficeKit *loKit) :
     LOOLSession(ws, Kind::ToMaster),
     _loKitDocument(NULL),
-    _loKit(loKit)
+    _loKit(loKit),
+    _clientPart(0)
 {
     std::cout << Util::logPrefix() << "ChildProcessSession ctor this=" << this << " ws=" << _ws.get() << std::endl;
 }
@@ -608,6 +610,10 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
         sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
         return false;
     }
+    else if (tokens[0] == "setclientpart")
+    {
+        return setClientPart(buffer, length, tokens);
+    }
     else if (tokens[0] == "status")
     {
         return getStatus(buffer, length);
@@ -630,6 +636,10 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
                tokens[0] == "resetselection" ||
                tokens[0] == "saveas");
 
+        if (_loKitDocument->pClass->getPart(_loKitDocument) != _clientPart)
+        {
+            _loKitDocument->pClass->setPart(_loKitDocument, _clientPart);
+        }
         if (tokens[0] == "gettextselection")
         {
             return getTextSelection(buffer, length, tokens);
@@ -1024,4 +1034,14 @@ bool ChildProcessSession::saveAs(const char *buffer, int length, StringTokenizer
     return true;
 }
 
+bool ChildProcessSession::setClientPart(const char *buffer, int length, StringTokenizer& tokens)
+{
+    if (tokens.count() < 2 ||
+        !getTokenInteger(tokens[1], "part", _clientPart))
+    {
+        return false;
+    }
+    return true;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index aa3ac25..361f6fb 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -175,10 +175,14 @@ public:
     bool selectGraphic(const char *buffer, int length, Poco::StringTokenizer& tokens);
     bool resetSelection(const char *buffer, int length, Poco::StringTokenizer& tokens);
     bool saveAs(const char *buffer, int length, Poco::StringTokenizer& tokens);
+    bool setClientPart(const char *buffer, int length, Poco::StringTokenizer& tokens);
 
     std::string _jail;
     std::string _loSubPath;
     LibreOfficeKit *_loKit;
+
+ private:
+    int _clientPart;
 };
 
 #endif
commit c9fff5d8e3f56c98b052de11b4167ec2c8ace7c0
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Jul 21 14:53:53 2015 +0300

    loolwsd: updated tileCache::invalidateTiles

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index cddf845..58e699e 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -204,7 +204,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
                 peer->_tileCache->setEditing(true);
 
                 assert(firstLine.size() == static_cast<std::string::size_type>(length));
-                peer->_tileCache->invalidateTiles(_curPart, firstLine);
+                peer->_tileCache->invalidateTiles(firstLine);
             }
         }
 
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 36ea9e1..2ee9da7 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -28,6 +28,7 @@
 #include <Poco/URI.h>
 
 #include "LOOLWSD.hpp"
+#include "LOOLProtocol.hpp"
 #include "TileCache.hpp"
 
 using Poco::DigestEngine;
@@ -39,6 +40,8 @@ using Poco::SyntaxException;
 using Poco::Timestamp;
 using Poco::URI;
 
+using namespace LOOLProtocol;
+
 TileCache::TileCache(const std::string& docURL) :
     _docURL(docURL),
     _isEditing(false),
@@ -224,7 +227,7 @@ void TileCache::invalidateTiles(int part, int x, int y, int width, int height)
     }
 }
 
-void TileCache::invalidateTiles(int part, const std::string& tiles)
+void TileCache::invalidateTiles(const std::string& tiles)
 {
     StringTokenizer tokens(tiles, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
@@ -234,18 +237,21 @@ void TileCache::invalidateTiles(int part, const std::string& tiles)
     {
         invalidateTiles(-1, 0, 0, INT_MAX, INT_MAX);
     }
-    else if (tokens.count() != 5)
+    else if (tokens.count() != 6)
     {
         return;
     }
     else
     {
-        int x(std::stoi(tokens[1]));
-        int y(std::stoi(tokens[2]));
-        int width(std::stoi(tokens[3]));
-        int height(std::stoi(tokens[4]));
-
-        invalidateTiles(part, x, y, width, height);
+        int part, x, y, width, height;
+        if (getTokenInteger(tokens[1], "part", part) &&
+            getTokenInteger(tokens[2], "x", x) &&
+            getTokenInteger(tokens[3], "y", y) &&
+            getTokenInteger(tokens[4], "width", width) &&
+            getTokenInteger(tokens[5], "height", height))
+        {
+            invalidateTiles(part, x, y, width, height);
+        }
     }
 }
 
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index ff5f2b9..bcc6416 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -46,7 +46,7 @@ public:
     void saveStatus(const std::string& status);
 
     // The tiles parameter is an invalidatetiles: message as sent by the child process
-    void invalidateTiles(int part, const std::string& tiles);
+    void invalidateTiles(const std::string& tiles);
 
     void invalidateTiles(int part, int x, int y, int width, int height);
 


More information about the Libreoffice-commits mailing list