loleaflet/src/control/Parts.js        |    1 
 loleaflet/src/layer/marker/Cursor.js  |   33 +++++++++++--------
 loleaflet/src/layer/tile/TileLayer.js |   58 +++++++++++++++++++---------------
 3 files changed, 54 insertions(+), 38 deletions(-)

New commits:
commit a666c01c03ac3bd680239e22b84ba4fa2f6971e6
Author: Henry Castro <hcas...@collabora.com>
Date:   Wed Sep 7 12:16:23 2016 -0400

    loleaflet: fix part not taken into account for cursors
    
    Also refactor cursor marker

diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index cf90a14..db63f95 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -31,6 +31,7 @@ L.Map.include({
                        docType: docLayer._docType
                });
                this._socket.sendMessage('setclientpart part=' + 
docLayer._selectedPart);
+               docLayer._updateViewCursors();
                docLayer._clearSelections();
                docLayer._updateOnChangePart();
                docLayer._pruneTiles();
diff --git a/loleaflet/src/layer/marker/Cursor.js 
b/loleaflet/src/layer/marker/Cursor.js
index cebc657..7fade22 100644
--- a/loleaflet/src/layer/marker/Cursor.js
+++ b/loleaflet/src/layer/marker/Cursor.js
@@ -8,18 +8,25 @@ L.Cursor = L.Layer.extend({
                opacity: 1
        },
 
-       initialize: function (latlng, options) {
+       initialize: function (latlng, size, options) {
                L.setOptions(this, options);
                this._latlng = L.latLng(latlng);
+               this._size = L.point(size);
        },
 
        onAdd: function () {
-               this._initLayout();
+               if (!this._container) {
+                       this._initLayout();
+               }
+
                this.update();
+               this.getPane().appendChild(this._container);
        },
 
        onRemove: function () {
-               L.DomUtil.remove(this._container);
+               if (this._container) {
+                       this.getPane().removeChild(this._container);
+               }
        },
 
        getEvents: function () {
@@ -32,16 +39,18 @@ L.Cursor = L.Layer.extend({
                return this._latlng;
        },
 
-       setLatLng: function (latlng) {
+       setLatLng: function (latlng, size) {
                var oldLatLng = this._latlng;
                this._latlng = L.latLng(latlng);
+               this._size = L.point(size);
                this.update();
                return this.fire('move', {oldLatLng: oldLatLng, latlng: 
this._latlng});
        },
 
        update: function () {
-               if (this._container) {
+               if (this._container && this._map) {
                        var pos = 
this._map.latLngToLayerPoint(this._latlng).round();
+                       this._setSize();
                        this._setPos(pos);
                }
                return this;
@@ -71,10 +80,6 @@ L.Cursor = L.Layer.extend({
                L.DomEvent
                        .disableClickPropagation(this._cursor)
                        .disableScrollPropagation(this._container);
-
-               if (this._container) {
-                       this.getPane().appendChild(this._container);
-               }
        },
 
        _setPos: function (pos) {
@@ -97,14 +102,14 @@ L.Cursor = L.Layer.extend({
                L.DomUtil.setOpacity(this._container, opacity);
        },
 
-       setSize: function (size) {
-               this._cursor.style.height = size.y + 'px';
-               this._container.style.top = '-' + (this._container.clientHeight 
- size.y - 2) / 2 + 'px';
+       _setSize: function () {
+               this._cursor.style.height = this._size.y + 'px';
+               this._container.style.top = '-' + (this._container.clientHeight 
- this._size.y - 2) / 2 + 'px';
        }
 });
 
-L.cursor = function (latlng, options) {
-       return new L.Cursor(latlng, options);
+L.cursor = function (latlng, size, options) {
+       return new L.Cursor(latlng, size, options);
 };
 
 L.Cursor.getCursorURL = function (localPath) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 388582f..9f70ac2 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -576,8 +576,12 @@ L.TileLayer = L.GridLayer.extend({
                this._viewCursors[viewId].bounds = new L.LatLngBounds(
                        this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
                        this._twipsToLatLng(bottomRightTwips, 
this._map.getZoom())),
-               this._viewCursors[viewId].part = obj.part;
-               this._viewCursors[viewId].visible = true;
+               this._viewCursors[viewId].part = parseInt(obj.part);
+
+               // FIXME. Server not sending view visible cursor
+               if (typeof this._viewCursors[viewId].visible === 'undefined') {
+                       this._viewCursors[viewId].visible = true;
+               }
 
                this._onUpdateViewCursor(viewId);
        },
@@ -1098,14 +1102,12 @@ L.TileLayer = L.GridLayer.extend({
 
                if (this._map._permission === 'edit' && this._isCursorVisible 
&& this._isCursorOverlayVisible
                                && 
!this._isEmptyRectangle(this._visibleCursor)) {
-                       if (this._cursorMarker) {
-                               this._map.removeLayer(this._cursorMarker);
+                       if (!this._cursorMarker) {
+                               this._cursorMarker = L.cursor(null, null, 
{blink: true});
                        }
 
-                       this._cursorMarker = L.cursor(cursorPos, {blink: true});
+                       this._cursorMarker.setLatLng(cursorPos, 
pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())));
                        this._map.addLayer(this._cursorMarker);
-                       
this._cursorMarker.setSize(pixBounds.getSize().multiplyBy(
-                                               
this._map.getZoomScale(this._map.getZoom())));
                }
                else if (this._cursorMarker) {
                        this._map.removeLayer(this._cursorMarker);
@@ -1125,27 +1127,35 @@ L.TileLayer = L.GridLayer.extend({
                var viewCursorPos = 
this._viewCursors[viewId].bounds.getNorthWest();
                var viewCursorMarker = this._viewCursors[viewId].marker;
                var viewCursorVisible = this._viewCursors[viewId].visible;
-
-               if (viewCursorVisible && 
!this._isEmptyRectangle(this._viewCursors[viewId].bounds)) {
-                       if (viewCursorMarker) {
-                               this._map.removeLayer(viewCursorMarker);
+               var viewPart = this._viewCursors[viewId].part;
+
+               if (viewCursorVisible && 
!this._isEmptyRectangle(this._viewCursors[viewId].bounds) &&
+                  (this._docType === 'text' || this._selectedPart === 
viewPart)) {
+                       if (!viewCursorMarker) {
+                               var viewCursorOptions = {
+                                       color: 
L.LOUtil.getViewIdHexColor(viewId),
+                                       blink: false,
+                                       header: true, // we want a 'hat' to our 
view cursors (which will contain view user names)
+                                       headerTimeout: 3000, // hide after some 
interval
+                                       headerName: 
this._map.getViewName(viewId)
+                               };
+
+                               viewCursorMarker = L.cursor(null, null, 
viewCursorOptions);
+                               this._viewCursors[viewId].marker = 
viewCursorMarker;
                        }
-                       var viewCursorOptions = {
-                               color: L.LOUtil.getViewIdHexColor(viewId),
-                               blink: false,
-                               header: true, // we want a 'hat' to our view 
cursors (which will contain view user names)
-                               headerTimeout: 3000, // hide after some interval
-                               headerName: this._map.getViewName(viewId)
-                       };
-                       viewCursorMarker = L.cursor(viewCursorPos, 
viewCursorOptions);
-                       this._map.addLayer(viewCursorMarker);
-                       
viewCursorMarker.setSize(pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())));
 
-               } else if (viewCursorMarker) {
-                       this._map.removeLayer(this._viewCursors[viewId].marker);
+                       viewCursorMarker.setLatLng(viewCursorPos, 
pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())));
+                       this._map.addLayer(viewCursorMarker);
+               }
+               else if (viewCursorMarker) {
+                       this._map.removeLayer(viewCursorMarker);
                }
+       },
 
-               this._viewCursors[viewId].marker = viewCursorMarker;
+       _updateViewCursors: function () {
+               for (var key in this._viewCursors) {
+                       this._onUpdateViewCursor(key);
+               }
        },
 
        // Update dragged graphics selection resize.
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to