loleaflet/src/layer/AnnotationManager.js |  136 +++++++++++++++++--------------
 loleaflet/src/layer/marker/Annotation.js |   16 +++
 loleaflet/src/map/Map.js                 |    9 ++
 3 files changed, 101 insertions(+), 60 deletions(-)

New commits:
commit 9c4fbdd7c51fb1eef545af265075a05d8372c8a4
Author: Henry Castro <hcas...@collabora.com>
Date:   Mon Apr 3 22:41:29 2017 -0400

    loleaflet: add a permanent overlay text selection of the annotation object
    
    Change-Id: I395f7cec22bf187532130b6755fcae58f51c73d2

diff --git a/loleaflet/src/layer/AnnotationManager.js 
b/loleaflet/src/layer/AnnotationManager.js
index 8cf90e24..8308d485 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -11,7 +11,7 @@ L.AnnotationManager = L.Class.extend({
        initialize: function (map) {
                this._map = map;
                this._items = [];
-               this._selected = {};
+               this._selected = null;
                this._map.on('AnnotationCancel', this._onAnnotationCancel, 
this);
                this._map.on('AnnotationClick', this._onAnnotationClick, this);
                this._map.on('AnnotationReply', this._onAnnotationReply, this);
@@ -28,7 +28,7 @@ L.AnnotationManager = L.Class.extend({
                        }
                }
                this._items = [];
-               this._selected = {};
+               this._selected = null;
        },
 
        // Remove only change tracking comments from the document
@@ -40,15 +40,54 @@ L.AnnotationManager = L.Class.extend({
                }
        },
 
+       adjustComment: function(comment) {
+               var rectangles, color, viewId;
+               comment.anchorPos = L.LOUtil.stringToBounds(comment.anchorPos);
+               comment.anchorPix = 
this._map._docLayer._twipsToPixels(comment.anchorPos.min);
+               comment.trackchange = false;
+               rectangles = 
L.PolyUtil.rectanglesToPolygons(L.LOUtil.stringToRectangles(comment.textRange), 
this._map._docLayer);
+               viewId = this._map.getViewId(comment.author);
+               color = viewId >= 0 ? 
L.LOUtil.rgbToHex(this._map.getViewColor(viewId)) : '#43ACE8';
+               if (rectangles.length > 0) {
+                       comment.textSelected = L.polygon(rectangles, {
+                               pointerEvents: 'none',
+                               fillColor: color,
+                               fillOpacity: 0.25,
+                               weight: 2,
+                               opacity: 0.25
+                       });
+               }
+       },
+
+       adjustRedLine: function(redline) {
+               var rectangles, color, viewId;
+               // transform change tracking index into an id
+               redline.id = 'change-' + redline.index;
+               redline.anchorPos = L.LOUtil.stringToBounds(redline.textRange);
+               redline.anchorPix = 
this._map._docLayer._twipsToPixels(redline.anchorPos.min);
+               redline.trackchange = true;
+               redline.text = redline.comment;
+               rectangles = 
L.PolyUtil.rectanglesToPolygons(L.LOUtil.stringToRectangles(redline.textRange), 
this._map._docLayer);
+               viewId = this._map.getViewId(redline.author);
+               color = viewId >= 0 ? 
L.LOUtil.rgbToHex(this._map.getViewColor(viewId)) : '#43ACE8';
+               if (rectangles.length > 0) {
+                       redline.textSelected = L.polygon(rectangles, {
+                               pointerEvents: 'none',
+                               fillColor: color,
+                               fillOpacity: 0.25,
+                               weight: 2,
+                               opacity: 0.25
+                       });
+               }
+       },
+
        // Fill normal comments in the documents
        fill: function (comments) {
                var comment;
                this.clear();
                for (var index in comments) {
                        comment = comments[index];
-                       comment.anchorPos = 
L.LOUtil.stringToBounds(comment.anchorPos);
-                       comment.anchorPix = 
this._map._docLayer._twipsToPixels(comment.anchorPos.min);
-                       comment.trackchange = false;
+                       this.adjustComment(comment);
                        
this._items.push(L.annotation(this._map.options.maxBounds.getSouthEast(), 
comment).addTo(this._map));
                }
                this.layout();
@@ -59,11 +98,7 @@ L.AnnotationManager = L.Class.extend({
                this.clearChanges();
                for (var idx in redlines) {
                        changecomment = redlines[idx];
-                       changecomment.id = 'change-' + changecomment.index;
-                       changecomment.anchorPos = 
L.LOUtil.stringToBounds(changecomment.textRange);
-                       changecomment.anchorPix = 
this._map._docLayer._twipsToPixels(changecomment.anchorPos.min);
-                       changecomment.trackchange = true;
-                       changecomment.text = changecomment.comment;
+                       this.adjustRedLine(changecomment);
                        
this._items.push(L.annotation(this._map.options.maxBounds.getSouthEast(), 
changecomment).addTo(this._map));
                }
                this.layout();
@@ -99,33 +134,19 @@ L.AnnotationManager = L.Class.extend({
        },
 
        unselect: function () {
-               this._selected = -1;
-               this._map._docLayer._selections.clearLayers();
+               this._selected = null;
                this.update();
        },
 
        select: function (annotation) {
                if (annotation) {
-                       this._selected = this.getIndexOf(annotation._data.id);
+                       this._selected = annotation;
                        this.update();
                }
        },
 
        update: function () {
                this.layout();
-               this._map._docLayer._selections.clearLayers();
-               if (this._selected >= 0) {
-                       var rectangles = 
L.PolyUtil.rectanglesToPolygons(L.LOUtil.stringToRectangles(this._items[this._selected]._data.textRange),
 this._map._docLayer);
-                       if (rectangles.length > 0) {
-                               
this._map._docLayer._selections.addLayer(L.polygon(rectangles, {
-                                       pointerEvents: 'none',
-                                       fillColor: '#43ACE8',
-                                       fillOpacity: 0.25,
-                                       weight: 2,
-                                       opacity: 0.25
-                               }));
-                       }
-               }
        },
 
        layoutUp: function (annotation, latLng, layoutBounds) {
@@ -161,27 +182,26 @@ L.AnnotationManager = L.Class.extend({
        layout: function () {
                var docRight = 
this._map.project(this._map.options.maxBounds.getNorthEast());
                var topRight = docRight.add(L.point(this.options.marginX, 
this.options.marginY));
-               var annotation, selected, layoutBounds, point, index;
-               if (this._selected >= 0) {
-                       selected = this._items[this._selected];
-                       
selected.setLatLng(this._map.unproject(L.point(topRight.x, 
selected._data.anchorPix.y)));
-                       layoutBounds = selected.getBounds();
+               var annotation, selectIndex, layoutBounds, point, index;
+               if (this._selected) {
+                       selectIndex = this.getIndexOf(this._selected._data.id);
+                       
this._selected.setLatLng(this._map.unproject(L.point(docRight.x, 
this._selected._data.anchorPix.y)));
+                       layoutBounds = this._selected.getBounds();
+                       layoutBounds.min = 
layoutBounds.min.add([this.options.marginX, 0]);
+                       layoutBounds.max = 
layoutBounds.max.add([this.options.marginX, 0]);
                        layoutBounds.extend(layoutBounds.min.subtract([0, 
this.options.marginY]));
                        layoutBounds.extend(layoutBounds.max.add([0, 
this.options.marginY]));
-                       for (index = this._selected - 1; index >= 0; index--) {
+                       for (index = selectIndex - 1; index >= 0; index--) {
                                annotation = this._items[index];
                                this.layoutUp(annotation, 
this._map.unproject(L.point(topRight.x, annotation._data.anchorPix.y)), 
layoutBounds);
                        }
-                       for (index = this._selected + 1; index < 
this._items.length; index++) {
+                       for (index = selectIndex + 1; index < 
this._items.length; index++) {
                                annotation = this._items[index];
                                this.layoutDown(annotation, 
this._map.unproject(L.point(topRight.x, annotation._data.anchorPix.y)), 
layoutBounds);
                        }
-                       if (selected._data.trackchange) {
-                               
selected.setLatLng(this._map.unproject(L.point(docRight.x, 
selected._data.anchorPix.y)));
-                       } else {
-                               
selected.setLatLng(this._map.unproject(selected._data.anchorPix));
+                       if (!this._selected.isEdit()) {
+                               this._selected.show();
                        }
-                       selected.show();
                } else {
                        point = 
this._map.latLngToLayerPoint(this._map.unproject(topRight));
                        layoutBounds = L.bounds(point, point);
@@ -208,14 +228,14 @@ L.AnnotationManager = L.Class.extend({
        },
 
        modify: function (annotation) {
-               this.select(annotation);
                annotation.edit();
+               this.select(annotation);
                annotation.focus();
        },
 
        reply: function (annotation) {
-               this.select(annotation);
                annotation.reply();
+               this.select(annotation);
                annotation.focus();
        },
 
@@ -256,30 +276,31 @@ L.AnnotationManager = L.Class.extend({
        },
 
        onACKComment: function (obj) {
+               var id;
                var changetrack = obj.redline ? true : false;
                var action = changetrack ? obj.redline.action : 
obj.comment.action;
                if (action === 'Add') {
                        if (changetrack) {
-                               // transform change tracking index into an id
-                               obj.redline.id = 'change-' + obj.redline.index;
-                               obj.redline.anchorPos = 
L.LOUtil.stringToBounds(obj.redline.textRange);
-                               obj.redline.anchorPix = 
this._map._docLayer._twipsToPixels(obj.redline.anchorPos.min);
-                               obj.redline.trackchange = true;
-                               obj.redline.text = obj.redline.comment;
+                               this.adjustRedLine(obj.redline);
                                this.add(obj.redline);
-                               this._map.focus();
                        } else {
-                               obj.comment.anchorPos = 
L.LOUtil.stringToBounds(obj.comment.anchorPos);
-                               obj.comment.anchorPix = 
this._map._docLayer._twipsToPixels(obj.comment.anchorPos.min);
+                               this.adjustComment(obj.comment);
                                this.add(obj.comment);
+                       }
+                       if (this._selected && !this._selected.isEdit()) {
                                this._map.focus();
                        }
                        this.layout();
                } else if (action === 'Remove') {
-                       var id = changetrack ? 'change-' + obj.redline.index : 
obj.comment.id;
-                       if (this.getItem(id)) {
+                       id = changetrack ? 'change-' + obj.redline.index : 
obj.comment.id;
+                       var removed = this.getItem(id);
+                       if (removed) {
                                this._map.removeLayer(this.removeItem(id));
-                               this.unselect();
+                               if (this._selected === removed) {
+                                       this.unselect();
+                               } else {
+                                       this.layout();
+                               }
                        }
                } else if (action === 'Modify') {
                        id = changetrack ? 'change-' + obj.redline.index : 
obj.comment.id;
@@ -287,18 +308,13 @@ L.AnnotationManager = L.Class.extend({
                        if (modified) {
                                var modifiedObj;
                                if (changetrack) {
-                                       obj.redline.anchorPos = 
L.LOUtil.stringToBounds(obj.redline.textRange);
-                                       obj.redline.anchorPix = 
this._map._docLayer._twipsToPixels(obj.redline.anchorPos.min);
-                                       obj.redline.text = obj.redline.comment;
-                                       obj.redline.id = id;
-                                       obj.redline.trackchange = true;
+                                       this.adjustRedLine(obj.redline);
                                        modifiedObj = obj.redline;
                                } else {
-                                       obj.comment.anchorPos = 
L.LOUtil.stringToBounds(obj.comment.anchorPos);
-                                       obj.comment.anchorPix = 
this._map._docLayer._twipsToPixels(obj.comment.anchorPos.min);
+                                       this.adjustComment(obj.comment);
                                        modifiedObj = obj.comment;
                                }
-                               modified._data = modifiedObj;
+                               modified.setData(modifiedObj);
                                modified.update();
                                this.update();
                        }
diff --git a/loleaflet/src/layer/marker/Annotation.js 
b/loleaflet/src/layer/marker/Annotation.js
index a39d78f9..a1630a4a 100644
--- a/loleaflet/src/layer/marker/Annotation.js
+++ b/loleaflet/src/layer/marker/Annotation.js
@@ -32,6 +32,9 @@ L.Annotation = L.Layer.extend({
 
        onRemove: function (map) {
                map._panes.popupPane.removeChild(this._container);
+               if (this._data.textSelected) {
+                       this._map.removeLayer(this._data.textSelected);
+               }
                this._map = null;
        },
 
@@ -43,6 +46,13 @@ L.Annotation = L.Layer.extend({
                this._updatePosition();
        },
 
+       setData: function (data) {
+               if (this._data.textSelected) {
+                       this._map.removeLayer(this._data.textSelected);
+               }
+               this._data = data;
+       },
+
        setLatLng: function (latlng) {
                this._latlng = L.latLng(latlng);
                if (this._map) {
@@ -61,6 +71,9 @@ L.Annotation = L.Layer.extend({
                this._contentNode.style.display = '';
                this._nodeModify.style.display = 'none';
                this._nodeReply.style.display = 'none';
+               if (this._data.textSelected && 
!this._map.hasLayer(this._data.textSelected)) {
+                       this._map.addLayer(this._data.textSelected);
+               }
        },
 
        hide: function () {
@@ -68,6 +81,9 @@ L.Annotation = L.Layer.extend({
                this._contentNode.style.display = 'none';
                this._nodeModify.style.display = 'none';
                this._nodeReply.style.display = 'none';
+               if (this._data.textSelected && 
this._map.hasLayer(this._data.textSelected)) {
+                       this._map.removeLayer(this._data.textSelected);
+               }
        },
 
        edit: function () {
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 11240be6..1c16e138 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -148,6 +148,15 @@ L.Map = L.Evented.extend({
 
        // public methods that modify map state
 
+       getViewId: function (username) {
+               for (var id in this._viewInfo) {
+                       if (this._viewInfo[id].username === username) {
+                               return id;
+                       }
+               }
+               return -1;
+       },
+
        addView: function(viewInfo) {
                this._viewInfo[viewInfo.id] = viewInfo;
                this.fire('postMessage', {msgId: 'View_Added', args: {ViewId: 
viewInfo.id, UserId: viewInfo.userid, UserName: viewInfo.username, Color: 
viewInfo.color, ReadOnly: viewInfo.readonly}});
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to