loleaflet/src/control/Control.PartsPreview.js |   32 +++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

New commits:
commit dcbea7d8ede6bed202fb48ce4a449dc6ef9209fc
Author:     Henry Castro <[email protected]>
AuthorDate: Thu Jul 2 10:59:56 2020 -0400
Commit:     Henry Castro <[email protected]>
CommitDate: Tue Aug 11 21:44:42 2020 +0200

    loleaflet: update preview images when the doc size changes
    
    The unit test checks the aspect ratio of the preview thumbnails,
    this happens when the document size changes (i.e changing paper format)
    
    Change-Id: I0267e797327b73d714947258e004fe64cce9d1dd
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97775
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Henry Castro <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100548

diff --git a/loleaflet/src/control/Control.PartsPreview.js 
b/loleaflet/src/control/Control.PartsPreview.js
index f7f11e348..84b8a1579 100644
--- a/loleaflet/src/control/Control.PartsPreview.js
+++ b/loleaflet/src/control/Control.PartsPreview.js
@@ -39,6 +39,7 @@ L.Control.PartsPreview = L.Control.extend({
                map.on('tilepreview', this._updatePreview, this);
                map.on('insertpage', this._insertPreview, this);
                map.on('deletepage', this._deletePreview, this);
+               map.on('docsize', this._updateAllPreview, this);
        },
 
        createScrollbar: function (axis) {
@@ -176,6 +177,27 @@ L.Control.PartsPreview = L.Control.extend({
                }
        },
 
+       _updateAllPreview: function () {
+               if (this._previewTiles.length === 0) {
+                       return;
+               }
+
+               var previewContBB = 
this._partsPreviewCont.getBoundingClientRect();
+               var bottomBound;
+
+               if (this._direction === 'x') {
+                       this._previewContTop = previewContBB.left;
+                       bottomBound = previewContBB.right + previewContBB.width 
/ 2;
+               } else {
+                       this._previewContTop = previewContBB.top;
+                       bottomBound = previewContBB.bottom + 
previewContBB.height / 2;
+               }
+
+               for (var prev = 0; prev < this._previewTiles.length; prev++) {
+                       this._layoutPreview(prev, this._previewTiles[prev], 
bottomBound);
+               }
+       },
+
        _createPreview: function (i, hashCode, bottomBound) {
                var frame = L.DomUtil.create('div', 'preview-frame', 
this._scrollContainer);
                this._addDnDHandlers(frame);
@@ -215,6 +237,12 @@ L.Control.PartsPreview = L.Control.extend({
                        }
                }, this);
 
+               this._layoutPreview(i, img, bottomBound);
+
+               return img;
+       },
+
+       _layoutPreview: function (i, img, bottomBound) {
                var topBound = this._previewContTop;
                var previewFrameTop = 0;
                var previewFrameBottom = 0;
@@ -260,7 +288,7 @@ L.Control.PartsPreview = L.Control.extend({
                        var imgWidth = imgSize.width;
                        if (imgSize.width < previewImgMinWidth)
                                imgHeight = Math.round(imgHeight * 
previewImgMinWidth / imgSize.width);
-                       var previewFrameBB = frame.getBoundingClientRect();
+                       var previewFrameBB = 
img.parentElement.getBoundingClientRect();
                        if (this._direction === 'x') {
                                this._previewFrameMargin = previewFrameBB.left 
- this._previewContTop;
                                this._previewImgHeight = imgWidth;
@@ -271,8 +299,6 @@ L.Control.PartsPreview = L.Control.extend({
                                this._previewFrameHeight = imgHeight + 2 * 
previewImgBorder;
                        }
                }
-
-               return img;
        },
 
        _setPart: function (e) {
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to