loleaflet/src/layer/tile/GridLayer.js |    8 ++--
 loleaflet/src/layer/tile/TileLayer.js |   59 ++++++++++++++++++++++------------
 2 files changed, 43 insertions(+), 24 deletions(-)

New commits:
commit 21035bf438d71797cdb8840cf04e46ff466cca0b
Author: Henry Castro <hcas...@collabora.com>
Date:   Thu Jun 11 19:48:08 2015 -0400

    loleaflet: Mimic gtktiledviewer editing
    
    gtktiledviewer is the reference code to enable
    editing for calc, writer and impress.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index acbf219..c2d8b25 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -715,15 +715,15 @@ L.GridLayer = L.Layer.extend({
                                coords.y * this._tileHeightTwips);
        },
 
-       _twipsToLatLng: function (twips) {
+       _twipsToLatLng: function (twips, zoom) {
                var pixels = new L.Point(
                                twips.x / this._tileWidthTwips * this._tileSize,
                                twips.y / this._tileHeightTwips * 
this._tileSize);
-               return this._map.unproject(pixels);
+               return this._map.unproject(pixels, zoom);
        },
 
-       _latLngToTwips: function (latLng) {
-               var pixels = this._map.project(latLng);
+       _latLngToTwips: function (latLng, zoom) {
+               var pixels = this._map.project(latLng, zoom);
                return new L.Point(
                                Math.round(pixels.x / this._tileSize * 
this._tileWidthTwips),
                                Math.round(pixels.y / this._tileSize * 
this._tileHeightTwips));
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 70750ec..253e9b0 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -52,8 +52,15 @@ L.TileLayer = L.GridLayer.extend({
                        this.on('tileunload', this._onTileRemove);
                }
                this._documentInfo = '';
-               this._cursorVisible = false;
-               this._cursorBounds = null;
+               // View or edit mode.
+               this._bEdit = false;
+               // Position and size of the visible cursor.
+               this._aVisibleCursor = new L.LatLngBounds( new L.LatLng(0, 0), 
new L.LatLng(0, 0) );
+               // Cursor overlay is visible or hidden (for blinking).
+               this._bCursorOverlayVisible = false;
+               // Cursor is visible or hidden (e.g. for graphic selection).
+               this._bCursorVisible = true;
+               // Marker cursor
                this._cursorMarker = null;
        },
 
@@ -81,8 +88,8 @@ L.TileLayer = L.GridLayer.extend({
                var events = {
                        viewreset: this._viewReset,
                        moveend: this._move,
-                       keypress: this._onKeyPress,
-                       keyup: this._onKeyUp
+                       keypress: this._signalKey,
+                       keyup: this._signalKey
                };
 
                if (!this.options.updateWhenIdle) {
@@ -142,7 +149,7 @@ L.TileLayer = L.GridLayer.extend({
 
                if (textMsg.startsWith('cursorvisible:')) {
                        var command = textMsg.match('cursorvisible: true');
-                       this._cursorVisible = command == undefined ? false : 
true;
+                       this._bCursorVisible = command == undefined ? false : 
true;
                        this._onUpdateCursor();
                }
                else if (textMsg.startsWith('invalidatecursor:')) {
@@ -150,9 +157,10 @@ L.TileLayer = L.GridLayer.extend({
                        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);
-                       this._cursorBounds = new L.LatLngBounds(
-                                                       
this._twipsToLatLng(topLeftTwips),
-                                                       
this._twipsToLatLng(bottomRightTwips));
+                       this._aVisibleCursor = new L.LatLngBounds(
+                                                       
this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
+                                                       
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+                       this._bCursorOverlayVisible = true;
                        this._onUpdateCursor();
                }
                else if (textMsg.startsWith('invalidatetiles:')) {
@@ -513,6 +521,8 @@ L.TileLayer = L.GridLayer.extend({
                                
this._postMouseEvent('buttondown',this._mouseDownPos.x,
                                        this._mouseDownPos.y, 1);
                        }, this), 500);
+
+                       this._bEdit = true;
                }
                else if (e.type === 'mouseup') {
                        this._selecting = false;
@@ -525,6 +535,8 @@ L.TileLayer = L.GridLayer.extend({
                        }
                        var mousePos = this._latLngToTwips(e.latlng);
                        this._postMouseEvent('buttonup', mousePos.x, 
mousePos.y, 1);
+
+                       this._bEdit = true;
                }
                else if (e.type === 'mousemove' && this._selecting) {
                        if (this._holdStart) {
@@ -708,34 +720,41 @@ L.TileLayer = L.GridLayer.extend({
                return unoKeyCode;
        },
 
-       _onKeyPress: function (e) {
-               if (this._cursorMarker) {
+       // Receives a key press or release event.
+       _signalKey: function (e) {
+               if ( !this._bEdit )
+                       return;
+
+               if ( e.type === 'keyup' )
+                       this._postKeyboardEvent('up', e.originalEvent.charCode, 
this._toUNOKeyCode(e.originalEvent.keyCode));
+               else
                        this._postKeyboardEvent('input', 
e.originalEvent.charCode, this._toUNOKeyCode(e.originalEvent.keyCode));
-               }
        },
 
-       _onKeyUp: function (e) {
-               if (this._cursorMarker) {
-                       this._postKeyboardEvent('up', e.originalEvent.charCode, 
this._toUNOKeyCode(e.originalEvent.keyCode));
-               }
+       // Is rRectangle empty?
+       _isEmptyRectangle: function (aBounds) {
+               return aBounds.getSouthWest().equals( new L.LatLng(0,0) ) && 
aBounds.getNorthEast().equals( new L.LatLng(0,0) )
        },
 
+       // Update cursor layer (blinking cursor).
        _onUpdateCursor: function () {
-               if (this._cursorVisible && this._cursorBounds ) {
+               if (this._bEdit && this._bCursorVisible && 
this._bCursorOverlayVisible && !this._isEmptyRectangle(this._aVisibleCursor)) {
                        if (this._cursorMarker)
                                this._map.removeLayer(this._cursorMarker);
 
-                       var pixBounds = 
L.bounds(this._map.latLngToLayerPoint(this._cursorBounds.getSouthWest()),
-                                                
this._map.latLngToLayerPoint(this._cursorBounds.getNorthEast()));
-                       var latBounds = 
L.rectangle(this._cursorBounds).getLatLngs();
+                       var pixBounds = 
L.bounds(this._map.latLngToLayerPoint(this._aVisibleCursor.getSouthWest()),
+                                                
this._map.latLngToLayerPoint(this._aVisibleCursor.getNorthEast()));
 
+                       var latBounds = 
L.rectangle(this._aVisibleCursor).getLatLngs();
                        this._cursorMarker = L.cursor(latBounds[2], {color: 
'red'});
                        this._map.addLayer(this._cursorMarker);
                        this._cursorMarker.setSize(pixBounds.getSize());
                }
                else {
-                       if (this._cursorMarker)
+                       if (this._cursorMarker) {
                                this._map.removeLayer(this._cursorMarker);
+                               this._bCursorOverlayVisible = false;
+                       }
                }
        }
 });
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to