[Libreoffice-commits] online.git: loleaflet/src

Henry Castro (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 4 21:45:10 UTC 2020


 loleaflet/src/map/Map.js               |   12 +++++++-----
 loleaflet/src/map/handler/Map.Mouse.js |   18 ++++++++++++------
 2 files changed, 19 insertions(+), 11 deletions(-)

New commits:
commit 38324b3e29331aee893a989b0765a810ad24d189
Author:     Henry Castro <hcastro at collabora.com>
AuthorDate: Tue Feb 4 09:20:22 2020 -0400
Commit:     Henry Castro <hcastro at collabora.com>
CommitDate: Tue Feb 4 22:44:51 2020 +0100

    loleaflet: mobile: avoid creating an "iframe" element resize detector
    
    Creating an "iframe" element inside a container the browser usually creates
    another sandbox window object. This is not required in mobile browser also
     we can reduce complexity operations.
    
    Change-Id: I75c57479af1cbf51beb1eaa812293432aeaf221c
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/87974
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Reviewed-by: Henry Castro <hcastro at collabora.com>
    Tested-by: Henry Castro <hcastro at collabora.com>

diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index afd66ef8b..3ffc476ae 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -961,13 +961,15 @@ L.Map = L.Evented.extend({
 			throw new Error('Map container is already initialized.');
 		}
 
-		this._resizeDetector = L.DomUtil.create('iframe', 'resize-detector', container);
+		if (!L.Browser.mobile) {
+			this._resizeDetector = L.DomUtil.create('iframe', 'resize-detector', container);
+			this._resizeDetector.contentWindow.addEventListener('touchstart', L.DomEvent.preventDefault, {passive: false});
+			L.DomEvent.on(this._resizeDetector.contentWindow, 'contextmenu', L.DomEvent.preventDefault);
+		}
+
 		this._fileDownloader = L.DomUtil.create('iframe', '', container);
 		L.DomUtil.setStyle(this._fileDownloader, 'display', 'none');
 
-		this._resizeDetector.contentWindow.addEventListener('touchstart', L.DomEvent.preventDefault, {passive: false});
-
-		L.DomEvent.on(this._resizeDetector.contentWindow, 'contextmenu', L.DomEvent.preventDefault);
 		L.DomEvent.on(this._fileDownloader.contentWindow, 'contextmenu', L.DomEvent.preventDefault);
 		L.DomEvent.addListener(container, 'scroll', this._onScroll, this);
 		container._leaflet = true;
@@ -1095,7 +1097,7 @@ L.Map = L.Evented.extend({
 
 		this._mainEvents(onOff);
 
-		if (this.options.trackResize && this._resizeDetector.contentWindow) {
+		if (this.options.trackResize && this._resizeDetector && this._resizeDetector.contentWindow) {
 			L.DomEvent[onOff](this._resizeDetector.contentWindow, 'resize', this._onResize, this);
 		}
 
diff --git a/loleaflet/src/map/handler/Map.Mouse.js b/loleaflet/src/map/handler/Map.Mouse.js
index 21b884366..cb5b4d91c 100644
--- a/loleaflet/src/map/handler/Map.Mouse.js
+++ b/loleaflet/src/map/handler/Map.Mouse.js
@@ -92,8 +92,10 @@ L.Map.Mouse = L.Handler.extend({
 		if (mouseEnteringLeavingMap && e.type === 'mouseover' && this._mouseDown) {
 			L.DomEvent.off(document, 'mousemove', this._onMouseMoveOutside, this);
 			L.DomEvent.off(document, 'mouseup', this._onMouseUpOutside, this);
-			L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
-			L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+			if (this._map._resizeDetector) {
+				L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
+				L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+			}
 		}
 		else if (e.type === 'mousedown') {
 			docLayer._resetPreFetching();
@@ -211,8 +213,10 @@ L.Map.Mouse = L.Handler.extend({
 			docLayer._postMouseEvent('buttonup', mousePos.x, mousePos.y, count, buttons, modifier);
 		}
 		else if (mouseEnteringLeavingMap && e.type === 'mouseout' && this._mouseDown) {
-			L.DomEvent.on(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
-			L.DomEvent.on(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+			if (this._map._resizeDetector) {
+				L.DomEvent.on(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
+				L.DomEvent.on(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+			}
 			L.DomEvent.on(document, 'mousemove', this._onMouseMoveOutside, this);
 			L.DomEvent.on(document, 'mouseup', this._onMouseUpOutside, this);
 		}
@@ -237,8 +241,10 @@ L.Map.Mouse = L.Handler.extend({
 		this._mouseDown = false;
 		L.DomEvent.off(document, 'mousemove', this._onMouseMoveOutside, this);
 		L.DomEvent.off(document, 'mouseup', this._onMouseUpOutside, this);
-		L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
-		L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+		if (this._map._resizeDetector) {
+			L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mousemove', this._onMouseMoveOutside, this);
+			L.DomEvent.off(this._map._resizeDetector.contentWindow, 'mouseup', this._onMouseUpOutside, this);
+		}
 
 		this._map._handleDOMEvent(e);
 		if (this._map.dragging.enabled()) {


More information about the Libreoffice-commits mailing list