[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - loleaflet/src
Tomaž Vajngerl
tomaz.vajngerl at collabora.co.uk
Tue Dec 6 15:30:33 UTC 2016
loleaflet/src/layer/tile/TileLayer.js | 35 +++++++++++++++++++++++-----------
loleaflet/src/map/Map.js | 22 +++++++++++----------
2 files changed, 36 insertions(+), 21 deletions(-)
New commits:
commit 2770e606f745b8fc751424b4390dd83b44c5f904
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date: Mon Dec 5 21:58:07 2016 +0100
don't scroll to the cursor position after focus lose/get
Change-Id: Id017c5ea8c162a71a8b4d8ec47a6d9deb7357fca
Reviewed-on: https://gerrit.libreoffice.org/31656
Reviewed-by: Tor Lillqvist <tml at collabora.com>
Tested-by: Tor Lillqvist <tml at collabora.com>
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index aee3833..092d5dd 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1287,11 +1287,31 @@ L.TileLayer = L.GridLayer.extend({
}
}
- if (this._map._permission === 'edit' && this._isCursorVisible && this._isCursorOverlayVisible
- && !this._isEmptyRectangle(this._visibleCursor)) {
+ this._updateCursorAndOverlay();
+
+ this.eachView(this._viewCursors, function (item) {
+ var viewCursorMarker = item.marker;
+ if (viewCursorMarker) {
+ viewCursorMarker.setOpacity(this._map.hasLayer(this._cursorMarker) && this._cursorMarker.getLatLng().equals(viewCursorMarker.getLatLng()) ? 0 : 1);
+ }
+ }, this, true);
+ },
+
+ // enable or disable blinking cursor and the cursor overlay depending on
+ // the state of the document (if the falgs are set)
+ _updateCursorAndOverlay: function (update) {
+ if (this._map._permission === 'edit'
+ && this._isCursorVisible
+ && this._isCursorOverlayVisible
+ && !this._isEmptyRectangle(this._visibleCursor)) {
+
+ var pixBounds = L.bounds(this._map.latLngToLayerPoint(this._visibleCursor.getSouthWest()),
+ this._map.latLngToLayerPoint(this._visibleCursor.getNorthEast()));
+
+ var cursorPos = this._visibleCursor.getNorthWest();
+
if (!this._cursorMarker) {
- this._cursorMarker = L.cursor(cursorPos, pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())),
- {blink: true});
+ this._cursorMarker = L.cursor(cursorPos, pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())), {blink: true});
}
else {
this._cursorMarker.setLatLng(cursorPos, pixBounds.getSize().multiplyBy(this._map.getZoomScale(this._map.getZoom())));
@@ -1302,13 +1322,6 @@ L.TileLayer = L.GridLayer.extend({
this._map.removeLayer(this._cursorMarker);
this._isCursorOverlayVisible = false;
}
-
- this.eachView(this._viewCursors, function (item) {
- var viewCursorMarker = item.marker;
- if (viewCursorMarker) {
- viewCursorMarker.setOpacity(this._map.hasLayer(this._cursorMarker) && this._cursorMarker.getLatLng().equals(viewCursorMarker.getLatLng()) ? 0 : 1);
- }
- }, this, true);
},
// Update colored non-blinking view cursor
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 002f990..982664f 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -827,14 +827,16 @@ L.Map = L.Evented.extend({
if (!this._loaded) { return; }
var doclayer = this._docLayer;
- if (!doclayer) {
- return;
- }
- doclayer._isCursorVisibleOnLostFocus = doclayer._isCursorOverlayVisible;
+ if (!doclayer) { return; }
+
+ // save state of cursor (blinking marker) and the cursor overlay
+ doclayer._isCursorVisibleOnLostFocus = doclayer._isCursorVisible;
doclayer._isCursorOverlayVisibleOnLostFocus = doclayer._isCursorOverlayVisible;
+
+ // if the blinking cursor is visible, disable the overlay when we go out of focus
if (doclayer._isCursorVisible && doclayer._isCursorOverlayVisible) {
doclayer._isCursorOverlayVisible = false;
- doclayer._onUpdateCursor();
+ doclayer._updateCursorAndOverlay();
}
this._deactivate();
@@ -844,15 +846,15 @@ L.Map = L.Evented.extend({
if (!this._loaded) { return; }
var doclayer = this._docLayer;
- if (doclayer && doclayer._isCursorVisibleOnLostFocus && doclayer._isCursorOverlayVisibleOnLostFocus) {
+ if (doclayer) {
// we restore the old cursor position by a small delay, so that if the user clicks
// inside the document we skip to restore it, so that the user does not see the cursor
// jumping from the old position to the new one
setTimeout(function () {
- if (doclayer._isCursorOverlayVisible) { return; } // user has clicked inside the document
- doclayer._isCursorOverlayVisible = doclayer._isCursorVisible = true;
- doclayer._visibleCursor = doclayer._visibleCursorOnLostFocus;
- doclayer._onUpdateCursor();
+ // restore the state that was before focus was lost
+ doclayer._isCursorOverlayVisible = doclayer._isCursorOverlayVisibleOnLostFocus;
+ doclayer._isCursorVisible = doclayer._isCursorVisibleOnLostFocus;
+ doclayer._updateCursorAndOverlay();
}, 300);
}
More information about the Libreoffice-commits
mailing list