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

Mihai Varga mihai.varga at collabora.com
Mon Aug 3 09:21:25 PDT 2015


 loleaflet/README                      |    9 +++++++++
 loleaflet/src/control/Parts.js        |   13 +++++++++++++
 loleaflet/src/layer/tile/TileLayer.js |   23 ++++++++++++++++++++++-
 loolwsd/LOOLSession.cpp               |   34 +++++++++++++++++++++++++++++++---
 loolwsd/LOOLSession.hpp               |    2 ++
 5 files changed, 77 insertions(+), 4 deletions(-)

New commits:
commit b38d701b973fa6bf2471973e73a5bf9a1df9f6d9
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Aug 3 19:19:38 2015 +0300

    loleaflet: updated README to reflect new API

diff --git a/loleaflet/README b/loleaflet/README
index c91c0d4..1e36a95 100644
--- a/loleaflet/README
+++ b/loleaflet/README
@@ -135,6 +135,15 @@ Scroll (the following are measured in pixels):
             + e.x = the amount scrolled to the right (or left if negative)
             + e.y = the amount scrolled to the bottom (or top if negative)
 
+Writer pages:
+    - API:
+        map.goToPage(page)
+        map.getNumberOfPages()
+    - events
+        map.on('pagenumberchanged', function (e) {}) where:
+            + e.currentPage = the page on which the cursor lies
+            + e.pages = number of pages
+            + e.docType = document type, should be 'text'
 Contributing
 ------------
 
commit 6eef93a288b8f280430d4ca96f070d6aadd09c9b
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Aug 3 19:08:06 2015 +0300

    loleaflet: send the updateparts message too

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 5703147..6ce236e 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -344,24 +344,22 @@ L.TileLayer = L.GridLayer.extend({
 					this._parts = 1;
 					this._currentPage = command.part;
 					this._pages = command.parts;
-					map.fire('updatepages', {
+					map.fire('pagenumberchanged', {
 						currentPage: this._currentPage,
 						pages: this._pages,
 						docType: this._docType
 					});
 				}
-				else {
-					this.sendMessage('setclientpart part=' + this._currentPart);
-					var partNames = textMsg.match(/[^\r\n]+/g);
-					// only get the last matches
-					partNames = partNames.slice(partNames.length - this._parts);
-					this._map.fire('updateparts', {
-						currentPart: this._currentPart,
-						parts: this._parts,
-						docType: this._docType,
-						partNames: partNames
-					});
-				}
+				this.sendMessage('setclientpart part=' + this._currentPart);
+				var partNames = textMsg.match(/[^\r\n]+/g);
+				// only get the last matches
+				partNames = partNames.slice(partNames.length - this._parts);
+				this._map.fire('updateparts', {
+					currentPart: this._currentPart,
+					parts: this._parts,
+					docType: this._docType,
+					partNames: partNames
+				});
 				this._update();
 				if (this._preFetchPart !== this._currentPart) {
 					this._preFetchPart = this._currentPart;
@@ -480,7 +478,7 @@ L.TileLayer = L.GridLayer.extend({
 				this._map.fire('setpart', {currentPart: this._currentPart});
 			}
 			else if (this._docType === 'text') {
-				map.fire('updatepages', {
+				map.fire('pagenumberchanged', {
 					currentPage: part,
 					pages: this._pages,
 					docType: this._docType
commit 6812c6aa0b13b8f94be7cd5943426e421e9130ef
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Aug 3 19:07:02 2015 +0300

    goToPage API
    
    in loleaflet, this is achived by invalidating the cursor and centering
    the viewing area around it

diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 1041604..689ec4a 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -50,5 +50,18 @@ L.Map.include({
 							'tilewidth=' + docLayer._docWidthTwips + ' ' +
 							'tileheight=' + docLayer._docHeightTwips + ' ' +
 							'id=' + id);
+	},
+
+	goToPage: function (page) {
+		var docLayer = this._docLayer;
+		if (page < 0 || page >= docLayer._pages) {
+			return;
+		}
+		docLayer._currentPage = page;
+		docLayer.sendMessage('setpage page=' + page);
+	},
+
+	getNumberOfPages: function () {
+		return this._docLayer._pages;
 	}
 });
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 10171bf..fe1096a 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -264,6 +264,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
              tokens[0] != "selectgraphic" &&
              tokens[0] != "selecttext" &&
              tokens[0] != "setclientpart" &&
+             tokens[0] != "setpage" &&
              tokens[0] != "status" &&
              tokens[0] != "tile" &&
              tokens[0] != "uno")
@@ -577,6 +578,10 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
     {
         return setClientPart(buffer, length, tokens);
     }
+    else if (tokens[0] == "setpage")
+    {
+        return setPage(buffer, length, tokens);
+    }
     else if (tokens[0] == "status")
     {
         return getStatus(buffer, length);
@@ -1016,4 +1021,17 @@ bool ChildProcessSession::setClientPart(const char *buffer, int length, StringTo
     return true;
 }
 
+bool ChildProcessSession::setPage(const char *buffer, int length, StringTokenizer& tokens)
+{
+    int page;
+    if (tokens.count() < 2 ||
+        !getTokenInteger(tokens[1], "page", page))
+    {
+        sendTextFrame("error: cmd=setpage kind=invalid");
+        return false;
+    }
+    _loKitDocument->pClass->setPart(_loKitDocument, page);
+    return true;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index d4007fb..0030f28 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -171,6 +171,7 @@ public:
     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);
+    bool setPage(const char *buffer, int length, Poco::StringTokenizer& tokens);
 
     std::string _jail;
     std::string _loSubPath;
commit 7aa7c59074ba2c92cd4f0b980b87e73e004b0de8
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Aug 3 17:39:45 2015 +0300

    loleaflet: handle parts in Writer
    
    In Writer a part is a page and we only get notified about the
    current page in which the cursor is. Internally (invalidation and
    caching) we work with a single part (0)

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index e537922..5703147 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -261,6 +261,9 @@ L.TileLayer = L.GridLayer.extend({
 				command.height = parseInt(strTwips[3]);
 				command.part = this._currentPart;
 			}
+			if (this._docType === 'text') {
+				command.part = 0;
+			}
 			topLeftTwips = new L.Point(command.x, command.y);
 			offset = new L.Point(command.width, command.height);
 			bottomRightTwips = topLeftTwips.add(offset);
@@ -336,16 +339,29 @@ L.TileLayer = L.GridLayer.extend({
 				this._documentInfo = textMsg;
 				this._parts = command.parts;
 				this._currentPart = command.currentPart;
-				this.sendMessage('setclientpart part=' + this._currentPart);
-				var partNames = textMsg.match(/[^\r\n]+/g);
-				// only get the last matches
-				partNames = partNames.slice(partNames.length - this._parts);
-				this._map.fire('updateparts', {
-					currentPart: this._currentPart,
-					parts: this._parts,
-					docType: this._docType,
-					partNames: partNames
-				});
+				if (this._docType === 'text') {
+					this._currentPart = 0;
+					this._parts = 1;
+					this._currentPage = command.part;
+					this._pages = command.parts;
+					map.fire('updatepages', {
+						currentPage: this._currentPage,
+						pages: this._pages,
+						docType: this._docType
+					});
+				}
+				else {
+					this.sendMessage('setclientpart part=' + this._currentPart);
+					var partNames = textMsg.match(/[^\r\n]+/g);
+					// only get the last matches
+					partNames = partNames.slice(partNames.length - this._parts);
+					this._map.fire('updateparts', {
+						currentPart: this._currentPart,
+						parts: this._parts,
+						docType: this._docType,
+						partNames: partNames
+					});
+				}
 				this._update();
 				if (this._preFetchPart !== this._currentPart) {
 					this._preFetchPart = this._currentPart;
@@ -457,12 +473,19 @@ L.TileLayer = L.GridLayer.extend({
 		}
 		else if (textMsg.startsWith('setpart:')) {
 			var part = parseInt(textMsg.match(/\d+/g)[0]);
-			if (part !== this._currentPart) {
+			if (part !== this._currentPart && this._docType !== 'text') {
 				this._currentPart = part;
 				this._update();
 				this._clearSelections();
 				this._map.fire('setpart', {currentPart: this._currentPart});
 			}
+			else if (this._docType === 'text') {
+				map.fire('updatepages', {
+					currentPage: part,
+					pages: this._pages,
+					docType: this._docType
+				});
+			}
 		}
 		else if (textMsg.startsWith('searchnotfound:')) {
 			this._map.fire('searchnotfound');
commit 992f19e6e8c88db45f977db3a0adcc194975e8d7
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Mon Aug 3 17:29:23 2015 +0300

    loolwsd: handle parts in Writer
    
    In Writer a part is a page and we only notify the client about the
    current page in which the cursor is. Internally (invalidation and
    caching) we work with a single part (0)

diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index cae2804..10171bf 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -599,7 +599,7 @@ bool ChildProcessSession::handleInput(const char *buffer, int length)
                tokens[0] == "resetselection" ||
                tokens[0] == "saveas");
 
-        if (_loKitDocument->pClass->getPart(_loKitDocument) != _clientPart)
+        if (_docType != "text" && _loKitDocument->pClass->getPart(_loKitDocument) != _clientPart)
         {
             _loKitDocument->pClass->setPart(_loKitDocument, _clientPart);
         }
@@ -655,6 +655,10 @@ extern "C"
             {
                 int curPart = srv->_loKitDocument->pClass->getPart(srv->_loKitDocument);
                 srv->sendTextFrame("curpart: part=" + std::to_string(curPart));
+                if (srv->_docType == "text")
+                {
+                    curPart = 0;
+                }
                 StringTokenizer tokens(std::string(pPayload), " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
                 if (tokens.count() == 4)
                 {
@@ -777,7 +781,11 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
 bool ChildProcessSession::getStatus(const char *buffer, int length)
 {
     std::string status = "status: " + LOKitHelper::documentStatus(_loKitDocument);
-
+    StringTokenizer tokens(status, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+    if (!getTokenString(tokens[1], "type", _docType))
+    {
+        Application::instance().logger().information(Util::logPrefix() + "failed to get document type from" + status);
+    }
     sendTextFrame(status);
 
     return true;
@@ -820,7 +828,9 @@ void ChildProcessSession::sendTile(const char *buffer, int length, StringTokeniz
     std::memcpy(output.data(), response.data(), response.size());
 
     unsigned char *pixmap = new unsigned char[4 * width * height];
-    _loKitDocument->pClass->setPart(_loKitDocument, part);
+    if (_docType != "text" && part != _loKitDocument->pClass->getPart(_loKitDocument)) {
+        _loKitDocument->pClass->setPart(_loKitDocument, part);
+    }
     _loKitDocument->pClass->paintTile(_loKitDocument, pixmap, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
 
     if (!Util::encodePNGAndAppendToBuffer(pixmap, width, height, output))
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index d6b7b60..d4007fb 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -155,6 +155,7 @@ public:
     virtual bool getStatus(const char *buffer, int length);
 
     LibreOfficeKitDocument *_loKitDocument;
+    std::string _docType;
 
  protected:
     virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override;


More information about the Libreoffice-commits mailing list