loleaflet/README | 15 +++ loleaflet/debug/document/document_simple_example.html | 2 loleaflet/src/control/Control.Parts.js | 38 +++++++ loleaflet/src/control/Parts.js | 13 ++ loleaflet/src/control/Scroll.js | 19 +++ loleaflet/src/layer/tile/TileLayer.js | 87 ++++++++++-------- loleaflet/src/map/Map.js | 3 loolwsd/LOOLSession.cpp | 42 ++++++++ loolwsd/LOOLSession.hpp | 2 loolwsd/TileCache.cpp | 13 -- loolwsd/loolwsd.spec.in | 6 + 11 files changed, 188 insertions(+), 52 deletions(-)
New commits: commit 7eb8922c783857ac2b169007dd2fb917e0bfd270 Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 14:14:14 2015 +0300 loleaflet: don't scroll to cursor on zoom Also, scroll to cursor in viewing mode too when changing pages diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 21aebe0..fe6e776 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -107,9 +107,9 @@ L.TileLayer = L.GridLayer.extend({ this.sendMessage('status'); } this._map.on('drag resize zoomend', this._updateScrollOffset, this); - this._map.on('zoomstart zoomend', this._onZoom, this); this._map.on('clearselection', this._clearSelections, this); this._map.on('copy', this._onCopy, this); + this._map.on('zoomend', this._onUpdateCursor, this); this._startMarker.on('drag dragend', this._onSelectionHandleDrag, this); this._endMarker.on('drag dragend', this._onSelectionHandleDrag, this); this._textArea = this._map._textArea; @@ -610,29 +610,29 @@ L.TileLayer = L.GridLayer.extend({ }, // Update cursor layer (blinking cursor). - _onUpdateCursor: function () { + _onUpdateCursor: function (e) { + var pixBounds = L.bounds(this._map.latLngToLayerPoint(this._visibleCursor.getSouthWest()), + this._map.latLngToLayerPoint(this._visibleCursor.getNorthEast())); + var cursorPos = this._visibleCursor.getNorthWest(); + + if (!e && !this._map.getBounds().contains(cursorPos)) { + var center = this._map.project(cursorPos); + center = center.subtract(this._map.getSize().divideBy(2)); + center.x = center.x < 0 ? 0 : center.x; + center.y = center.y < 0 ? 0 : center.y; + this._map.fire('scrollto', {x: center.x, y: center.y}); + } + if (this._permission === 'edit' && this._isCursorVisible && this._isCursorOverlayVisible && !this._isEmptyRectangle(this._visibleCursor)) { if (this._cursorMarker) { this._map.removeLayer(this._cursorMarker); } - var pixBounds = L.bounds(this._map.latLngToLayerPoint(this._visibleCursor.getSouthWest()), - this._map.latLngToLayerPoint(this._visibleCursor.getNorthEast())); - - var cursorPos = this._visibleCursor.getNorthWest(); this._cursorMarker = L.cursor(cursorPos); this._map.addLayer(this._cursorMarker); this._cursorMarker.setSize(pixBounds.getSize().multiplyBy( this._map.getZoomScale(this._map.getZoom()))); - - if (!this._map.getBounds().contains(cursorPos)) { - var center = this._map.project(cursorPos); - center = center.subtract(this._map.getSize().divideBy(2)); - center.x = center.x < 0 ? 0 : center.x; - center.y = center.y < 0 ? 0 : center.y; - this._map.fire('scrollto', {x: center.x, y: center.y}); - } } else if (this._cursorMarker) { this._map.removeLayer(this._cursorMarker); @@ -726,14 +726,6 @@ L.TileLayer = L.GridLayer.extend({ else { e.clipboardData.setData('text/plain', this._selectionTextContent); } - }, - - _onZoom: function (e) { - if (e.type === 'zoomstart') { - } - else if (e.type === 'zoomend') { - this._onUpdateCursor(); - } } }); commit dfe9cb753682fef637c978051586a620a18edc94 Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 13:59:33 2015 +0300 loleaflet: enable page switching in toolbar diff --git a/loleaflet/src/control/Control.Parts.js b/loleaflet/src/control/Control.Parts.js index c789340..d32650a 100644 --- a/loleaflet/src/control/Control.Parts.js +++ b/loleaflet/src/control/Control.Parts.js @@ -30,15 +30,26 @@ L.Control.Parts = L.Control.extend({ map.on('updateparts', this._updateDisabled, this); map.on('tilepreview', this._updatePreview, this); + map.on('pagenumberchanged', this._updateDisabledText, this); return container; }, _prevPart: function () { - this._map.setPart('prev'); + if (this._docType === 'text' && this._currentPage > 0) { + this._map.goToPage(this._currentPage - 1); + } + else { + this._map.setPart('prev'); + } }, _nextPart: function () { - this._map.setPart('next'); + if (this._docType === 'text' && this._currentPage < this._pages - 1) { + this._map.goToPage(this._currentPage + 1); + } + else { + this._map.setPart('next'); + } }, _createButton: function (html, title, className, container, fn) { @@ -62,6 +73,9 @@ L.Control.Parts = L.Control.extend({ var currentPart = e.currentPart; var docType = e.docType; var partNames = e.partNames; + if (docType === 'text') { + return; + } if (currentPart === 0) { L.DomUtil.addClass(this._prevPartButton, className); } else { @@ -129,6 +143,26 @@ L.Control.Parts = L.Control.extend({ } }, + + _updateDisabledText: function (e) { + if (e) { + this._currentPage = e.currentPage; + this._pages = e.pages; + this._docType = e.docType; + } + var className = 'leaflet-disabled'; + if (this._currentPage === 0) { + L.DomUtil.addClass(this._prevPartButton, className); + } else { + L.DomUtil.removeClass(this._prevPartButton, className); + } + if (this._currentPage === this._pages - 1) { + L.DomUtil.addClass(this._nextPartButton, className); + } else { + L.DomUtil.removeClass(this._nextPartButton, className); + } + }, + _setPart: function (e) { var part = e.target.id.match(/\d+/g)[0]; if (part !== null) { commit 66badd36ad08112df54d22bcaaf5d2cb32325e78 Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 13:59:16 2015 +0300 loleaflet: don't emit the updateparts event for text docs diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 6f3326f..21aebe0 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -346,7 +346,7 @@ L.TileLayer = L.GridLayer.extend({ if (this._docType === 'text') { this._currentPart = 0; this._parts = 1; - this._currentPage = command.part; + this._currentPage = command.currentPart; this._pages = command.parts; map.fire('pagenumberchanged', { currentPage: this._currentPage, @@ -354,16 +354,18 @@ L.TileLayer = L.GridLayer.extend({ docType: this._docType }); } - 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 - }); + 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; commit 09132224b650c4c92429b7b1f318c8ae4c59689d Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 13:37:18 2015 +0300 loleaflet: only send the timestamp when provided diff --git a/loleaflet/debug/document/document_simple_example.html b/loleaflet/debug/document/document_simple_example.html index ec279af..4f2fbb5 100644 --- a/loleaflet/debug/document/document_simple_example.html +++ b/loleaflet/debug/document/document_simple_example.html @@ -49,6 +49,7 @@ var filePath = getParameterByName('file_path'); var host = getParameterByName('host'); var edit = getParameterByName('edit') === 'true'; + var timeStamp = getParameterByName('timestamp'); if (filePath === '') { vex.dialog.alert('Wrong file_path, usage: file_path=/path/to/doc/'); } @@ -80,6 +81,7 @@ doc: filePath, useSocket : true, edit: edit, + timeStamp: timeStamp, readOnly: false }); map.addLayer(docLayer); diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index bc248b4..6f3326f 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -99,8 +99,11 @@ L.TileLayer = L.GridLayer.extend({ return; } if (this.options.doc) { - var timestamp = Math.round(+new Date()/1000); - this.sendMessage('load url=' + this.options.doc + ( this.options.doc.indexOf('?') !== -1 ? '&' : '?' ) + 'timestamp=' + timestamp); + var msg = 'load url=' + this.options.doc; + if (this.options.timeStamp) { + msg += '?timestamp=' + this.options.timeStamp; + } + this.sendMessage(msg); this.sendMessage('status'); } this._map.on('drag resize zoomend', this._updateScrollOffset, this); commit 28c94eb340c8405c6c6e7b846800180d41a948ac Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 11:22:17 2015 +0300 loleaflet: allow specifying the imagePath in the map init imagePath is used to load images diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 1cf4091..3420044 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -53,6 +53,9 @@ L.Map = L.Evented.extend({ this.callInitHooks(); + if (this.options.imagePath) { + L.Icon.Default.imagePath = this.options.imagePath; + } this._addLayers(this.options.layers); }, commit 70a832b13642b083c9c9da43e2ad03f114070223 Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 11:09:10 2015 +0300 lolealfet: scrollOffset, scrollLeft, scrollTop methods That scroll to an absolute value, and scrollOffset returns the absloute offset relative to the beginning of the document diff --git a/loleaflet/README b/loleaflet/README index 1e36a95..c2f0531 100644 --- a/loleaflet/README +++ b/loleaflet/README @@ -117,6 +117,12 @@ Scroll (the following are measured in pixels): + scroll down by 'y' (or up if negative) map.scrollRight(x) + scroll right by 'x' (or left if nevative) + map.scrollTop(y) + + scroll to 'y' offset relative to the beginning of the document + map.scrollLeft(x) + + scroll to 'x' offset relative to the beginning of the document + map.scrollOffset() + + returns the scroll offset relative to the beginning of the document - events map.on('docsize', function (e) {}) where: + e.x = document width diff --git a/loleaflet/src/control/Scroll.js b/loleaflet/src/control/Scroll.js index ba0b2de..e20b3e1 100644 --- a/loleaflet/src/control/Scroll.js +++ b/loleaflet/src/control/Scroll.js @@ -15,5 +15,24 @@ L.Map.include({ scrollRight: function (x) { this.scroll(x, 0); + }, + + scrollOffset: function () { + var center = this.project(this.getCenter()); + var centerOffset = center.subtract(this.getSize().divideBy(2)); + var offset = {}; + offset.x = centerOffset.x < 0 ? 0 : Math.round(centerOffset.x); + offset.y = centerOffset.y < 0 ? 0 : Math.round(centerOffset.y); + return offset; + }, + + scrollTop: function (y) { + var offset = this.scrollOffset(); + this.panBy(new L.Point(0, y - offset.y), {animate: false}); + }, + + scrollLeft: function (x) { + var offset = this.scrollOffset(); + this.panBy(new L.Point(x - offset.x, 0), {animate: false}); } }); commit b013c079b6e387cf597e2bc5ea7428a426ede29d Author: Mihai Varga <mihai.va...@collabora.com> Date: Tue Aug 4 10:09:47 2015 +0300 loolwsd: remove cron job when uninstalling the rpm package diff --git a/loolwsd/loolwsd.spec.in b/loolwsd/loolwsd.spec.in index 8a6bbcc..18dfbb0 100644 --- a/loolwsd/loolwsd.spec.in +++ b/loolwsd/loolwsd.spec.in @@ -58,6 +58,7 @@ echo "0 0 */1 * * root find /var/cache/loolwsd -name \"*.png\" -a -atime +10 -ex /usr/bin/loolwsd-systemplate-setup %{_unitdir}/loolwsd.service /var/adm/fillup-templates/sysconfig.loolwsd +/etc/cron.d/loolwsd.cron %doc README commit e230842d9f0b4c794ade252fb0ebde754cc72bdb Author: Henry Castro <hcas...@collabora.com> Date: Mon Aug 3 21:33:47 2015 -0400 loolwsd: remove time stamp query parameter The original URI request with query parameters is processed by loKit. diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index fe1096a..d6fa5aa 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -743,9 +743,17 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok _docURL = tokens[1]; URI aUri; + URI::QueryParameters params; try { aUri = URI(_docURL); + params = aUri.getQueryParameters(); + if ( !params.empty() && params.back().first == "timestamp" ) + { + aUri.setQuery(""); + params.pop_back(); + aUri.setQueryParameters(params); + } } catch(Poco::SyntaxException&) { commit ff0705c83ca937a60553b988dd6494b444db7c15 Author: Henry Castro <hcas...@collabora.com> Date: Mon Aug 3 21:25:34 2015 -0400 loleaflet: add time stamp query parameter diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 6ce236e..bc248b4 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -99,7 +99,8 @@ L.TileLayer = L.GridLayer.extend({ return; } if (this.options.doc) { - this.sendMessage('load url=' + this.options.doc); + var timestamp = Math.round(+new Date()/1000); + this.sendMessage('load url=' + this.options.doc + ( this.options.doc.indexOf('?') !== -1 ? '&' : '?' ) + 'timestamp=' + timestamp); this.sendMessage('status'); } this._map.on('drag resize zoomend', this._updateScrollOffset, this); commit fea8766376a8cae0a42b538f209399b4be8cf261 Author: Mihai Varga <mihai.va...@collabora.com> Date: Mon Aug 3 22:01:11 2015 +0300 loolwsd: fixed poorly placed cronjob diff --git a/loolwsd/loolwsd.spec.in b/loolwsd/loolwsd.spec.in index a4ccc28..8a6bbcc 100644 --- a/loolwsd/loolwsd.spec.in +++ b/loolwsd/loolwsd.spec.in @@ -49,15 +49,15 @@ env BUILDING_FROM_RPMBUILD=yes make install DESTDIR=%{buildroot} %__install -D -m 444 loolwsd.service %{buildroot}%{_unitdir}/loolwsd.service install -d -m 755 %{buildroot}/var/adm/fillup-templates install -D -m 644 sysconfig.loolwsd %{buildroot}/var/adm/fillup-templates +mkdir -p %{buildroot}/etc/cron.d +echo "#Remove old tiles once every 10 days at midnight" > %{buildroot}/etc/cron.d/loolwsd.cron +echo "0 0 */1 * * root find /var/cache/loolwsd -name \"*.png\" -a -atime +10 -exec rm {} \;" >> %{buildroot}/etc/cron.d/loolwsd.cron %files /usr/bin/loolwsd /usr/bin/loolwsd-systemplate-setup %{_unitdir}/loolwsd.service /var/adm/fillup-templates/sysconfig.loolwsd -mkdir -p %{buildroot}/etc/cron.d -echo "#Remove old tiles once every 10 days at midnight" > %{buildroot}/etc/cron.d/loolwsd.cron -echo "0 0 */10 * * root find /var/cache/loolwsd -name \"*.png\" -a -atime +10 -exec rm {} \;" >> %{buildroot}/etc/cron.d/loolwsd.cron %doc README @@ -95,6 +95,8 @@ su %{owner} -c "loolwsd-systemplate-setup ${loolparent}/lool/systemplate ${loroo %service_del_postun loolwsd.service %changelog +* Mon Aug 03 2015 Mihai Varga +- added the cronjob * Tue May 19 2015 Tor Lillqvist - Initial RPM release commit 102dee733fb55f43ed4696fb6ecfe8e7b73cdef1 Author: Mihai Varga <mihai.va...@collabora.com> Date: Mon Aug 3 21:51:55 2015 +0300 Revert "loolwsd: LRU expiry persistent cache" This reverts commit 74dcec1d3fe28fcb47f9424c505d97c04c6e973b. The cronjob replaces this diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp index 2203653..2ee9da7 100644 --- a/loolwsd/TileCache.cpp +++ b/loolwsd/TileCache.cpp @@ -31,9 +31,6 @@ #include "LOOLProtocol.hpp" #include "TileCache.hpp" -// 1 hour tile cache expired -#define TILE_EXPIRED 3600000000 - using Poco::DigestEngine; using Poco::DirectoryIterator; using Poco::File; @@ -96,16 +93,6 @@ std::unique_ptr<std::fstream> TileCache::lookupTile(int part, int width, int hei return nullptr; std::string fileName = dirName + "/" + cachedName; - File fileTile(fileName); - - if ( fileTile.exists() ) - { - Poco::Timestamp timeNow; - if ( timeNow - fileTile.getLastModified() > TILE_EXPIRED ) - fileTile.remove(); - else - fileTile.setLastModified(timeNow); - } std::unique_ptr<std::fstream> result(new std::fstream(fileName, std::ios::in)); commit 1da26714ad357924d18d5c4c008463a4e03c7bab Author: Mihai Varga <mihai.va...@collabora.com> Date: Mon Aug 3 21:48:19 2015 +0300 loolwsd: cron job to delete old tiles from rpm packages place a cronjob file in /etc/cron.d/ which is removed when the loolwsd rpm packages is uninstalled diff --git a/loolwsd/loolwsd.spec.in b/loolwsd/loolwsd.spec.in index 9c579d4..a4ccc28 100644 --- a/loolwsd/loolwsd.spec.in +++ b/loolwsd/loolwsd.spec.in @@ -55,6 +55,9 @@ install -D -m 644 sysconfig.loolwsd %{buildroot}/var/adm/fillup-templates /usr/bin/loolwsd-systemplate-setup %{_unitdir}/loolwsd.service /var/adm/fillup-templates/sysconfig.loolwsd +mkdir -p %{buildroot}/etc/cron.d +echo "#Remove old tiles once every 10 days at midnight" > %{buildroot}/etc/cron.d/loolwsd.cron +echo "0 0 */10 * * root find /var/cache/loolwsd -name \"*.png\" -a -atime +10 -exec rm {} \;" >> %{buildroot}/etc/cron.d/loolwsd.cron %doc README commit a266d966ec14373ff39b8ba44348cc54326061c0 Author: Mihai Varga <mihai.va...@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 1b7d58b2a24c281318a64621eeddcc7316394f05 Author: Mihai Varga <mihai.va...@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 072a1ccb4c7b4e312a355bf129c92f22d8d65f5c Author: Mihai Varga <mihai.va...@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 c3682e87f057bba6dfa6d1a1a23ee333589999ba Author: Mihai Varga <mihai.va...@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 c04bf2701a2f4ab69949456f4e58761643e49fa1 Author: Mihai Varga <mihai.va...@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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits