[Libreoffice-commits] online.git: 5 commits - loleaflet/README loleaflet/reference.html loleaflet/src loolwsd/LOOLSession.cpp loolwsd/TileCache.cpp
Mihai Varga
mihai.varga at collabora.com
Wed Sep 30 07:22:32 PDT 2015
loleaflet/README | 3 +
loleaflet/reference.html | 20 ++++++++++
loleaflet/src/control/Parts.js | 19 +++++++++
loleaflet/src/core/Socket.js | 1
loleaflet/src/layer/tile/GridLayer.js | 13 ++++++
loleaflet/src/layer/tile/TileLayer.js | 68 ++++++++++++++++++++++++++++++++++
loolwsd/LOOLSession.cpp | 4 ++
loolwsd/TileCache.cpp | 2 -
8 files changed, 128 insertions(+), 2 deletions(-)
New commits:
commit a0e74cb5c4c746e540566b3742229658aca4dbda
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Wed Sep 30 17:22:00 2015 +0300
loolwsd: update page sizes when the doc size changes
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 313e76f..5f5d12e 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -825,6 +825,7 @@ extern "C"
break;
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
srv->getStatus("", 0);
+ srv->getPartPageRectangles("", 0);
break;
case LOK_CALLBACK_SET_PART:
srv->sendTextFrame("setpart: " + std::string(pPayload));
commit 34401c94f66f5b66469dc9257e130ca304279cf4
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Wed Sep 30 17:17:03 2015 +0300
loolwsd: switch to editing dir when invalidating the cursor
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index 4b00dea..313e76f 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -218,6 +218,9 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
{
peer->_tileCache->saveTextFile(std::string(buffer, length), "partpagerectangles.txt");
}
+ else if (tokens[0] == "invalidatecursor:") {
+ peer->_tileCache->setEditing(true);
+ }
else if (tokens[0] == "invalidatetiles:")
{
// FIXME temporarily, set the editing on the 1st invalidate, TODO extend
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 76ca730..cbd0278 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -172,7 +172,7 @@ void TileCache::setEditing(bool editing)
void TileCache::saveTextFile(const std::string& text, std::string fileName)
{
- std::string dirName = cacheDirName(_hasUnsavedChanges);
+ std::string dirName = cacheDirName(_isEditing);
File(dirName).createDirectories();
commit a5757736e98706dcc18e70a816d5f1dd3876cb19
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Wed Sep 30 13:43:12 2015 +0300
loleaflet: goToPage without having a LOK instance
Knowing the page dimension, we can scroll to the desired page
without requesting sending the 'setpage' command to the server
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 1ae0825..d710d47 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -122,7 +122,19 @@ L.Map.include({
else if (typeof (page) === 'number' && page >= 0 && page < docLayer._pages) {
docLayer._currentPage = page;
}
- L.Socket.sendMessage('setpage page=' + docLayer._currentPage);
+ if (docLayer._permission !== 'edit' && docLayer._partPageRectanglesPixels.length > docLayer._currentPage) {
+ // we can scroll to the desired page without having a LOK instance
+ var pageBounds = docLayer._partPageRectanglesPixels[docLayer._currentPage];
+ var pos = new L.Point(
+ pageBounds.min.x + (pageBounds.max.x - pageBounds.min.x) / 2,
+ pageBounds.min.y);
+ pos.y -= this.getSize().y / 4; // offset by a quater of the viewing area so that the previous page is visible
+ this.scrollTop(pos.y, {update: true});
+ this.scrollLeft(pos.x, {update: true});
+ }
+ else {
+ L.Socket.sendMessage('setpage page=' + docLayer._currentPage);
+ }
this.fire('pagenumberchanged', {
currentPage: docLayer._currentPage,
pages: docLayer._pages,
commit 07a305df8081e96ff0111077b706ffd7a111bd63
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Wed Sep 30 13:17:43 2015 +0300
loleaflet: partpagerectangles command integration
An event is fired with the page dimensions.
Also the current page number is updated based on which page contains
the current view's center
diff --git a/loleaflet/README b/loleaflet/README
index 4a32d13..8cc2739 100644
--- a/loleaflet/README
+++ b/loleaflet/README
@@ -193,6 +193,9 @@ Writer pages:
+ e.docType = document type, should be 'text'
map.on('invalidatepreview', function (e) {})
+ e.id = the preview's id
+ map.on('partpagerectangles', function (e) {}) where:
+ + e.pixelRectangles = An array of bounds representing each page's dimension in pixels on the current zoom level
+ + e.twipsRectangles = An array of bounds representing each page's dimension in twips.
Error:
- events
diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 595dd62..d45f019 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -6825,6 +6825,26 @@ map.addControl(new MyControl());
</tr>
</table>
+<h3 id="partpagerectangles-event">PartPageRectangles</h3>
+
+<table data-id='events'>
+ <tr>
+ <th class="width100">property</th>
+ <th>type</th>
+ <th>description</th>
+ </tr>
+ <tr>
+ <td><code><b>pixelRectangles</b></code></td>
+ <td><code><a href="#bounds">Bounds[]</a></code></td>
+ <td>An array of bounds representing each page's dimension in pixels on the current zoom level.</td>
+ </tr>
+ <tr>
+ <td><code><b>twipsRectangles</b></code></td>
+ <td><code><a href="#bounds">Bounds[]</a></code></td>
+ <td>An array of bounds representing each page's dimension in twips.</td>
+ </tr>
+</table>
+
<h3 id="permission-event">PermissionEvent</h3>
<table data-id='events'>
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 55d4c9b..1ae0825 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -123,6 +123,11 @@ L.Map.include({
docLayer._currentPage = page;
}
L.Socket.sendMessage('setpage page=' + docLayer._currentPage);
+ this.fire('pagenumberchanged', {
+ currentPage: docLayer._currentPage,
+ pages: docLayer._pages,
+ docType: docLayer._docType
+ });
},
getNumberOfPages: function () {
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index ba93c2b..99a8c19 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -52,6 +52,7 @@ L.Socket = {
}
this.socket.send(msg);
this.socket.send('status');
+ this.socket.send('partpagerectangles');
for (var i = 0; i < this._msgQueue.length; i++) {
this.socket.send(this._msgQueue[i].msg);
L.Log.log(this._msgQueue[i].msg, this._msgQueue[i].coords);
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index 2922d7e..9c89f7c 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -444,6 +444,7 @@ L.GridLayer = L.Layer.extend({
_move: function () {
this._update();
this._resetPreFetching(true);
+ this._onCurrentPageUpdate();
},
_update: function (center, zoom) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 0bf5474..86d7f2b 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -102,6 +102,7 @@ L.TileLayer = L.GridLayer.extend({
map.on('drag resize zoomend', this._updateScrollOffset, this);
map.on('copy', this._onCopy, this);
map.on('zoomend', this._onUpdateCursor, this);
+ map.on('zoomend', this._onUpdatePartPageRectangles, this);
map.on('dragstart', this._onDragStart, this);
map.on('requestloksession', this._onRequestLOKSession, this);
map.on('error', this._mapOnError, this);
@@ -204,6 +205,9 @@ L.TileLayer = L.GridLayer.extend({
msg += 'height=' + this._docHeightTwips;
this._onInvalidateTilesMsg(msg);
}
+ else if (textMsg.startsWith('partpagerectangles:')) {
+ this._onPartPageRectanglesMsg(textMsg);
+ }
else if (textMsg.startsWith('searchnotfound:')) {
this._onSearchNotFoundMsg(textMsg);
}
@@ -288,6 +292,34 @@ L.TileLayer = L.GridLayer.extend({
this._onUpdateCursor();
},
+ _onPartPageRectanglesMsg: function (textMsg) {
+ textMsg = textMsg.substring(19);
+ var pages = textMsg.split(';');
+ this._partPageRectanglesTwips = [];
+ this._partPageRectanglesPixels = [];
+ for (var i = 0; i < pages.length; i++) {
+ var strTwips = pages[i].match(/\d+/g);
+ if (!strTwips) {
+ // probably not a text file
+ return;
+ }
+ var topLeftTwips = new L.Point(parseInt(strTwips[0]), parseInt(strTwips[1]));
+ var offset = new L.Point(parseInt(strTwips[2]), parseInt(strTwips[3]));
+ var bottomRightTwips = topLeftTwips.add(offset);
+ var pageBoundsTwips = new L.Bounds(topLeftTwips, bottomRightTwips);
+ this._partPageRectanglesTwips.push(pageBoundsTwips);
+ var pageBoundsPixels = new L.Bounds(
+ this._twipsToPixels(topLeftTwips),
+ this._twipsToPixels(bottomRightTwips));
+ this._partPageRectanglesPixels.push(pageBoundsPixels);
+ }
+ this._map.fire('partpagerectangles', {
+ pixelRectangles: this._partPageRectanglesPixels,
+ twipsRectangles: this._partPageRectanglesTwips
+ });
+ this._onCurrentPageUpdate();
+ },
+
_onSearchNotFoundMsg: function (textMsg) {
var originalPhrase = textMsg.substring(16);
this._map.fire('search', {originalPhrase: originalPhrase, count: 0});
@@ -689,6 +721,42 @@ L.TileLayer = L.GridLayer.extend({
this._map.setZoom(Math.min(10, this._map.getZoom() + zoomDelta), {animate: false});
}
}
+ },
+
+ _onCurrentPageUpdate: function () {
+ var mapCenter = this._map.project(this._map.getCenter());
+ if (!this._partPageRectanglesPixels || !(this._currentPage >= 0) ||
+ this._partPageRectanglesPixels[this._currentPage].contains(mapCenter)) {
+ // page number has not changed
+ return;
+ }
+ for (var i = 0; i < this._partPageRectanglesPixels.length; i++) {
+ if (this._partPageRectanglesPixels[i].contains(mapCenter)) {
+ this._currentPage = i;
+ this._map.fire('pagenumberchanged', {
+ currentPage: this._currentPage,
+ pages: this._pages,
+ docType: this._docType
+ });
+ return;
+ }
+ }
+ },
+
+ _onUpdatePartPageRectangles: function () {
+ if (this._partPageRectanglesPixels.length > 0) {
+ this._partPageRectanglesPixels = [];
+ for (var i = 0; i < this._partPageRectanglesTwips.length; i++) {
+ var pageBounds = new L.Bounds(
+ this._twipsToPixels(this._partPageRectanglesTwips[i].min),
+ this._twipsToPixels(this._partPageRectanglesTwips[i].max));
+ this._partPageRectanglesPixels.push(pageBounds);
+ }
+ this._map.fire('partpagerectangles', {
+ pixelRectangles: this._partPageRectanglesPixels,
+ twipsRectangles: this._partPageRectanglesTwips
+ });
+ }
}
});
commit 1c9d9bb94dde621b590ffc692887224b1c2f167e
Author: Mihai Varga <mihai.varga at collabora.com>
Date: Wed Sep 30 13:10:48 2015 +0300
loleaflet: twipsToPixels and back methods
diff --git a/loleaflet/src/layer/tile/GridLayer.js b/loleaflet/src/layer/tile/GridLayer.js
index e010aa3..2922d7e 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -745,6 +745,18 @@ L.GridLayer = L.Layer.extend({
Math.round(pixels.y / this._tileSize * this._tileHeightTwips));
},
+ _twipsToPixels: function (twips) {
+ return new L.Point(
+ twips.x / this._tileWidthTwips * this._tileSize,
+ twips.y / this._tileHeightTwips * this._tileSize);
+ },
+
+ _pixelsToTwips: function (pixels) {
+ return new L.Point(
+ pixels.x * this._tileWidthTwips / this._tileSize,
+ pixels.y * this._tileHeightTwips / this._tileSize);
+ },
+
_noTilesToLoad: function () {
for (var key in this._tiles) {
if (!this._tiles[key].loaded) { return false; }
More information about the Libreoffice-commits
mailing list