loleaflet/src/layer/tile/TileLayer.js |   67 ++++++++++++++++++++++------------
 1 file changed, 44 insertions(+), 23 deletions(-)

New commits:
commit a32278cb2bfc50b23361d103915c4e1c70f1a82a
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Mon Jun 29 10:54:32 2015 +0300

    Don't send 2 clicks  before sending dblclick
    
    Mouse events are now put in a queue. If within 250ms from the first
    click arrives another, it's a double click, the previos and the current
    clicks are canceled and a dblclick command is sent instead.

diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 805e0a8..f83038d 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -154,6 +154,7 @@ L.TileLayer = L.GridLayer.extend({
                        }),
                        draggable: true
                });
+               this._mouseEventsQueue = [];
                this._textArea = L.DomUtil.get('clipboard');
                this._textArea.focus();
        },
@@ -669,35 +670,45 @@ L.TileLayer = L.GridLayer.extend({
        },
 
        _onMouseEvent: function (e) {
-               if (this._graphicMarker && this._graphicMarker.isDragged) { 
return; }
+               if (this._graphicMarker && this._graphicMarker.isDragged) {
+                       return;
+               }
 
-               if (this._startMarker.isDragged === true || 
this._endMarker.isDragged === true)
+               if (this._startMarker.isDragged === true || 
this._endMarker.isDragged === true) {
                        return;
+               }
 
                if (e.type === 'mousedown') {
                        this._selecting = true;
-                       this._clearSelections();
+                       if (this._holdMouseEvent) {
+                               clearTimeout(this._holdMouseEvent);
+                       }
                        var mousePos = this._latLngToTwips(e.latlng);
-                       this._mouseDownPos = mousePos;
-                       this._holdStart = setTimeout(L.bind(function() {
-                               this._holdStart = null;
-                               this._postMouseEvent('buttondown', 
this._mouseDownPos.x,
-                                       this._mouseDownPos.y, 1);
-                       }, this), 500);
+                       this._mouseEventsQueue.push(L.bind(function() {
+                               this._postMouseEvent('buttondown', mousePos.x, 
mousePos.y, 1);}, this));
+                       this._holdMouseEvent = 
setTimeout(L.bind(this._executeMouseEvents, this), 500);
 
                        this._editMode = true;
                }
                else if (e.type === 'mouseup') {
                        this._selecting = false;
-                       if (this._holdStart) {
-                               // it was a click
-                               clearTimeout(this._holdStart);
-                               this._holdStart = null;
-                               this._postMouseEvent('buttondown', 
this._mouseDownPos.x,
-                                               this._mouseDownPos.y, 1);
+                       if (this._holdMouseEvent) {
+                               clearTimeout(this._holdMouseEvent);
+                               this._holdMouseEvent = null;
+                       }
+                       if (this._mouseEventsQueue.length === 3) {
+                               // i.e. we have mousedown, mouseup, mousedown 
and here comes another
+                               // mouseup. Those are 2 consecutive clicks == 
doubleclick, we cancel
+                               // everything and wait for the dblclick event 
to arrive where it's handled
+                               this._mouseEventsQueue = [];
+                               return;
                        }
                        mousePos = this._latLngToTwips(e.latlng);
-                       this._postMouseEvent('buttonup', mousePos.x, 
mousePos.y, 1);
+                       this._mouseEventsQueue.push(L.bind(function() {
+                               this._postMouseEvent('buttonup', mousePos.x, 
mousePos.y, 1);
+                               this._textArea.focus();
+                       }, this));
+                       this._holdMouseEvent = 
setTimeout(L.bind(this._executeMouseEvents, this), 250);
 
                        this._editMode = true;
                        if (this._startMarker._icon) {
@@ -706,15 +717,17 @@ L.TileLayer = L.GridLayer.extend({
                        if (this._endMarker._icon) {
                                L.DomUtil.removeClass(this._endMarker._icon, 
'leaflet-not-clickable');
                        }
-                       this._textArea.focus();
                }
                else if (e.type === 'mousemove' && this._selecting) {
-                       if (this._holdStart) {
-                               clearTimeout(this._holdStart);
-                               // it's not a dblclick, so we post the initial 
mousedown
-                               this._postMouseEvent('buttondown', 
this._mouseDownPos.x,
-                                               this._mouseDownPos.y, 1);
-                               this._holdStart = null;
+                       if (this._holdMouseEvent) {
+                               clearTimeout(this._holdMouseEvent);
+                               this._holdMouseEvent = null;
+                               for (var i = 0; i < 
this._mouseEventsQueue.length; i++) {
+                                       // synchronously execute old mouse 
events so we know that
+                                       // they arrive to the server before the 
move command
+                                       this._mouseEventsQueue[i]();
+                               }
+                               this._mouseEventsQueue = [];
                        }
                        mousePos = this._latLngToTwips(e.latlng);
                        this._postMouseEvent('move', mousePos.x, mousePos.y, 1);
@@ -734,6 +747,14 @@ L.TileLayer = L.GridLayer.extend({
                }
        },
 
+       _executeMouseEvents: function () {
+               this._holdMouseEvent = null;
+               for (var i = 0; i < this._mouseEventsQueue.length; i++) {
+                       this._mouseEventsQueue[i]();
+               }
+               this._mouseEventsQueue = [];
+       },
+
        _onSwitchPart: function (e) {
                if (e.type === 'prevpart') {
                        if (this._currentPart > 0) {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to