loleaflet/src/control/Control.Scroll.js | 34 +++++++++++++++++++++++++++ loleaflet/src/dom/Draggable.js | 6 ++++ loleaflet/src/layer/tile/TileLayer.js | 40 +++++++++++++++++++++++++++++--- loleaflet/src/map/handler/Map.Mouse.js | 5 ++++ 4 files changed, 82 insertions(+), 3 deletions(-)
New commits: commit acb39fc057db157b988f2cabf50809ab7a582dcd Author: Andrzej Hunt <andrzej.h...@collabora.com> Date: Wed Oct 28 11:26:09 2015 +0100 fdo#94610 autoscroll document for selection This works for both the selection "handles"/cursors, and also for normal (desktop-like?) click+drag selection. diff --git a/loleaflet/src/control/Control.Scroll.js b/loleaflet/src/control/Control.Scroll.js index 8115292..a869951 100644 --- a/loleaflet/src/control/Control.Scroll.js +++ b/loleaflet/src/control/Control.Scroll.js @@ -12,6 +12,7 @@ L.Control.Scroll = L.Control.extend({ map.on('scrollto', this._onScrollTo, this); map.on('scrollby', this._onScrollBy, this); map.on('scrollvelocity', this._onScrollVelocity, this); + map.on('handleautoscroll', this._onHandleAutoScroll, this); map.on('docsize', this._onUpdateSize, this); map.on('updatescrolloffset', this._onUpdateScrollOffset, this); @@ -92,6 +93,24 @@ L.Control.Scroll = L.Control.extend({ } }, + _onHandleAutoScroll: function (e) { + var vx = 0; + var vy = 0; + + if (e.pos.y > e.map._size.y - 50) { + vy = 50; + } else if (e.pos.y < 50) { + vy = -50; + } + if (e.pos.x > e.map._size.x - 50) { + vx = 50; + } else if (e.pos.x < 50 + e.map._container.getBoundingClientRect().x) { + vx = -50; + } + + this._onScrollVelocity({vx: vx, vy: vy}); + }, + _onUpdateSize: function (e) { this._ignoreScroll = true; setTimeout(L.bind(function() {this._ignoreScroll = null;}, this), 200); diff --git a/loleaflet/src/dom/Draggable.js b/loleaflet/src/dom/Draggable.js index 3df1342..7b65378 100644 --- a/loleaflet/src/dom/Draggable.js +++ b/loleaflet/src/dom/Draggable.js @@ -67,6 +67,12 @@ L.Draggable = L.Evented.extend({ this._startPoint = new L.Point(first.clientX, first.clientY); this._startPos = this._newPos = L.DomUtil.getPosition(this._element); + var startBoundingRect = this._element.getBoundingClientRect(); + // Store offset between mouse selection position, and top left + // We don't use this internally, but it is needed for external + // manipulation of the cursor position, e.g. when adjusting + // for scrolling during cursor dragging. + this.startOffset = this._startPoint.subtract(new L.Point(startBoundingRect.x, startBoundingRect.y)); L.DomEvent .on(document, L.Draggable.MOVE[e.type], this._onMove, this) diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 99a5199..16271d1 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -605,7 +605,11 @@ L.TileLayer = L.GridLayer.extend({ center = center.subtract(this._map.getSize().divideBy(2)); center.x = Math.round(center.x < 0 ? 0 : center.x); center.y = Math.round(center.y < 0 ? 0 : center.y); - this._map.fire('scrollto', {x: center.x, y: center.y}); + + if (!(this._selectionHandles.start && this._selectionHandles.start.isDragged) && + !(this._selectionHandles.end && this._selectionHandles.end.isDragged)) { + this._map.fire('scrollto', {x: center.x, y: center.y}); + } } if (this._permission === 'edit' && this._isCursorVisible && this._isCursorOverlayVisible @@ -657,16 +661,10 @@ L.TileLayer = L.GridLayer.extend({ var cursorPos = L.point(boundingrect.x - e.target._icon.offsetLeft, boundingrect.y - e.target._icon.offsetTop); - var expectedPos = L.point(e.originalEvent.pageX, e.originalEvent.pageY); + var expectedPos = L.point(e.originalEvent.pageX, e.originalEvent.pageY).subtract(e.target.dragging._draggable.startOffset); // If the map has been scrolled, but the cursor hasn't been updated yet, then // the current mouse position differs. - // In reality there should be a small offset between the top-left of the cursor, - // and where the mouse was when the cursor was selected - this is accounted - // for by the offset in Draggable, however that gets lost once the map - // starts scrolling. - // TODO: decide whether we really want to take account of the offset (this - // will be even messier, and probably require modifying Draggable too). if (!expectedPos.equals(cursorPos)) { var correction = expectedPos.subtract(cursorPos); @@ -676,10 +674,16 @@ L.TileLayer = L.GridLayer.extend({ e.target.dragging._draggable._updatePosition(); } + + var containerPos = new L.point(expectedPos.x - this._map._container.getBoundingClientRect().x, + expectedPos.y - this._map._container.getBoundingClientRect().y); + + this._map.fire('handleautoscroll', { pos: containerPos, map: this._map }); } if (e.type === 'dragend') { e.target.isDragged = false; this._textArea.focus(); + this._map.fire('scrollvelocity', {vx: 0, vy: 0}); } var aPos = this._latLngToTwips(e.target.getLatLng()); diff --git a/loleaflet/src/map/handler/Map.Mouse.js b/loleaflet/src/map/handler/Map.Mouse.js index c0345a4..b3f9eba 100644 --- a/loleaflet/src/map/handler/Map.Mouse.js +++ b/loleaflet/src/map/handler/Map.Mouse.js @@ -112,6 +112,8 @@ L.Map.Mouse = L.Handler.extend({ } } } + + this._map.fire('scrollvelocity', {vx: 0, vy: 0}); } else if (e.type === 'mousemove' && this._mouseDown) { if (this._holdMouseEvent) { @@ -132,12 +134,15 @@ L.Map.Mouse = L.Handler.extend({ if (!this._map.dragging.enabled()) { mousePos = docLayer._latLngToTwips(e.latlng); docLayer._postMouseEvent('move', mousePos.x, mousePos.y, 1, buttons, modifier); + for (key in docLayer._selectionHandles) { handle = docLayer._selectionHandles[key]; if (handle._icon) { L.DomUtil.addClass(handle._icon, 'leaflet-not-clickable'); } } + + this._map.fire('handleautoscroll', { pos: e.containerPoint, map: this._map }); } } else if (e.type === 'dblclick') { commit c2493177437ac2596bb8b8fc6714afe4e9e0d60d Author: Andrzej Hunt <andrzej.h...@collabora.com> Date: Tue Oct 27 19:44:31 2015 +0100 Implement scrollvelocity This is needed for e.g. fdo#94610 diff --git a/loleaflet/src/control/Control.Scroll.js b/loleaflet/src/control/Control.Scroll.js index 7b4c4d2..8115292 100644 --- a/loleaflet/src/control/Control.Scroll.js +++ b/loleaflet/src/control/Control.Scroll.js @@ -11,6 +11,7 @@ L.Control.Scroll = L.Control.extend({ map.on('scrollto', this._onScrollTo, this); map.on('scrollby', this._onScrollBy, this); + map.on('scrollvelocity', this._onScrollVelocity, this); map.on('docsize', this._onUpdateSize, this); map.on('updatescrolloffset', this._onUpdateScrollOffset, this); @@ -77,6 +78,20 @@ L.Control.Scroll = L.Control.extend({ $('.scroll-container').mCustomScrollbar('scrollTo', [y, x]); }, + _onScrollVelocity: function (e) { + if (e.vx == 0 && e.vy == 0) { + clearInterval(this._autoScrollTimer); + this._autoScrollTimer = null; + this._map.isAutoScrolling = false; + } else { + clearInterval(this._autoScrollTimer); + this._map.isAutoScrolling = true; + this._autoScrollTimer = setInterval(L.bind(function() { + this._onScrollBy({x: e.vx, y: e.vy}); + }, this), 100); + } + }, + _onUpdateSize: function (e) { this._ignoreScroll = true; setTimeout(L.bind(function() {this._ignoreScroll = null;}, this), 200); commit c10713fac281aa65482143e66a025318c6fbead2 Author: Andrzej Hunt <andrzej.h...@collabora.com> Date: Tue Oct 27 19:44:17 2015 +0100 Make currently dragged cursor follow map scroll Previously the cursor would become offset from the mouse position if the window was scrolled during dragging. Related: fdo#94610 diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 34ef53e..99a5199 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -644,16 +644,46 @@ L.TileLayer = L.GridLayer.extend({ // Update dragged text selection. _onSelectionHandleDrag: function (e) { - var aPos = this._latLngToTwips(e.target.getLatLng()); - if (e.type === 'drag') { e.target.isDragged = true; + + // This is rather hacky, but it seems to be the only way to make the + // marker follow the mouse cursor if the document is autoscrolled under + // us. (This can happen when we're changing the selection if the cursor + // moves somewhere that is considered off screen.) + + // Onscreen position of the cursor, i.e. relative to the browser window + var boundingrect = e.target._icon.getBoundingClientRect(); + var cursorPos = L.point(boundingrect.x - e.target._icon.offsetLeft, + boundingrect.y - e.target._icon.offsetTop); + + var expectedPos = L.point(e.originalEvent.pageX, e.originalEvent.pageY); + + // If the map has been scrolled, but the cursor hasn't been updated yet, then + // the current mouse position differs. + // In reality there should be a small offset between the top-left of the cursor, + // and where the mouse was when the cursor was selected - this is accounted + // for by the offset in Draggable, however that gets lost once the map + // starts scrolling. + // TODO: decide whether we really want to take account of the offset (this + // will be even messier, and probably require modifying Draggable too). + if (!expectedPos.equals(cursorPos)) { + var correction = expectedPos.subtract(cursorPos); + + e.target.dragging._draggable._startPoint = e.target.dragging._draggable._startPoint.add(correction); + e.target.dragging._draggable._startPos = e.target.dragging._draggable._startPos.add(correction); + e.target.dragging._draggable._newPos = e.target.dragging._draggable._newPos.add(correction); + + e.target.dragging._draggable._updatePosition(); + } } if (e.type === 'dragend') { e.target.isDragged = false; this._textArea.focus(); } + var aPos = this._latLngToTwips(e.target.getLatLng()); + if (this._selectionHandles.start === e.target) { this._postSelectTextEvent('start', aPos.x, aPos.y); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits