[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - loleaflet/src

Pranav Kant pranavk at collabora.co.uk
Sat Dec 17 19:54:23 UTC 2016


 loleaflet/src/core/Browser.js          |  109 ++++++++++++++++++++++++++++++---
 loleaflet/src/layer/tile/TileLayer.js  |    3 
 loleaflet/src/map/handler/Map.Print.js |    6 +
 3 files changed, 105 insertions(+), 13 deletions(-)

New commits:
commit affe96b64a28e287ca8bec3172f6290cfd26c477
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Dec 14 18:14:28 2016 +0530

    loleaflet: fix printing on MS Edge
    
    This is a combination of 7 commits.
    Revert "loleaflet: print dialog: it seems that this magic hack is no more needed"
    
    This reverts commit 8c522c44d101c0c5e3e1c51b59249266cef4e9d3.
    
    We need to remove the iframe otherwise it will leak.
    
    (cherry picked from commit 9d039cbd5a65945b0fbb758f2841d725e4bd2a99)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    loleaflet: bump timeout for closing print iframe to 5 minutes
    
    Change-Id: If58a28ef5c856b4ab5e497028fbcabf7b954b282
    (cherry picked from commit e255fe64d22ebc1a1f8c015114b2684b27f9d1ca)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    loleaflet: Pass print frame as argument to close function
    
    Removing this._printIframe may still cause leakage here as
    this._printIframe is overwritten everytime user issues a print
    command.
    
    Change-Id: I06f45604940380b809bc262f07b9b6a8aa7d9a87
    (cherry picked from commit 7ed38a20117210a4cca9ec23adbe1f4ab028aeec)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    Pick changes from upstream Leaflet
    
    Only the changes made to src/core/Browser.js
    
    Change-Id: I96f95e59a50fabea7dad1a8836e78aebac9112c8
    (cherry picked from commit a0036f24bac8fdfd67055935aa756c873db30fe7)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    loleaflet: Fix L.Browser.pointer
    
    window.PointerEvent is available even on non-touch devices in
    chrome and Edge (and maybe others too, firefox doesn't have it).
    
    So it results in L.Browser.pointer resulting in true on Chrome,
    Edge while false in firefox which leads to click event not
    working on these browsers.
    
    Fallout from a0036f24bac8fdfd67055935aa756c873db30fe7
    
    Change-Id: I73b5824882e1cc1f87cdfbc9e7e31f22320367b1
    (cherry picked from commit 6f212ee49db21cf468a3afeb1aadc00e2043b27d)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    loleaflet: Reuse L.Browser instead of our own logic
    
    Change-Id: I479d6aa3de657ba032e3bb7e5039d5744a859163
    (cherry picked from commit 1bfbd6990cbc289734d06776326ca1ecefb1ce90)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>
    
    loleaflet: Print dialog for MS edge too
    
    MS Edge seems to be very problematic when one tries to load the
    pdf blob into the print iframe and issue a print command to it.
    
    Lets fallback to print prompt as we have in firefox
    
    Change-Id: I97fc394d0053030231c524efb6bf808d32a9aa07
    (cherry picked from commit 7c6d4719dabbaf479c4e7f7bb56c26970a7e6371)
    Signed-off-by: Andras Timar <andras.timar at collabora.com>

diff --git a/loleaflet/src/core/Browser.js b/loleaflet/src/core/Browser.js
index 1a71e4a..38640b9 100644
--- a/loleaflet/src/core/Browser.js
+++ b/loleaflet/src/core/Browser.js
@@ -1,5 +1,16 @@
 /*
- * L.Browser handles different browser and feature detections for internal Leaflet use.
+ * @namespace Browser
+ * @aka L.Browser
+ *
+ * A namespace with static properties for browser/feature detection used by Leaflet internally.
+ *
+ * @example
+ *
+ * ```js
+ * if (L.Browser.ielt9) {
+ *   alert('Upgrade your browser, dude!');
+ * }
+ * ```
  */
 
 (function () {
@@ -13,44 +24,124 @@
 	    phantomjs = ua.indexOf('phantom') !== -1,
 	    android23 = ua.search('android [23]') !== -1,
 	    chrome    = ua.indexOf('chrome') !== -1,
+	    gecko     = ua.indexOf('gecko') !== -1  && !webkit && !window.opera && !ie,
 
-	    mobile = typeof orientation !== 'undefined',
-	    msPointer = navigator.msPointerEnabled && navigator.msMaxTouchPoints && !window.PointerEvent,
-	    pointer = (window.PointerEvent && navigator.pointerEnabled && navigator.maxTouchPoints) || msPointer,
+	    win = navigator.platform.indexOf('Win') === 0,
+
+	    mobile = typeof orientation !== 'undefined' || ua.indexOf('mobile') !== -1,
+	    msPointer = !window.PointerEvent && window.MSPointerEvent,
+	    pointer = (window.PointerEvent && navigator.maxTouchPoints) || msPointer,
 
 	    ie3d = ie && ('transition' in doc.style),
 	    webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()) && !android23,
 	    gecko3d = 'MozPerspective' in doc.style,
-	    opera3d = 'OTransition' in doc.style;
+	    opera12 = 'OTransition' in doc.style;
+
 
-	var touch = !window.L_NO_TOUCH && !phantomjs && (pointer || 'ontouchstart' in window ||
+	var touch = !window.L_NO_TOUCH && (pointer || 'ontouchstart' in window ||
 			(window.DocumentTouch && document instanceof window.DocumentTouch));
 
 	L.Browser = {
+
+		// @property ie: Boolean
+		// `true` for all Internet Explorer versions (not Edge).
 		ie: ie,
+
+		// @property ielt9: Boolean
+		// `true` for Internet Explorer versions less than 9.
 		ielt9: ie && !document.addEventListener,
+
+		// @property edge: Boolean
+		// `true` for the Edge web browser.
+		edge: 'msLaunchUri' in navigator && !('documentMode' in document),
+
+		// @property webkit: Boolean
+		// `true` for webkit-based browsers like Chrome and Safari (including mobile versions).
 		webkit: webkit,
-		gecko: (ua.indexOf('gecko') !== -1) && !webkit && !window.opera && !ie,
+
+		// @property gecko: Boolean
+		// `true` for gecko-based browsers like Firefox.
+		gecko: gecko,
+
+		// @property android: Boolean
+		// `true` for any browser running on an Android platform.
 		android: ua.indexOf('android') !== -1,
+
+		// @property android23: Boolean
+		// `true` for browsers running on Android 2 or Android 3.
 		android23: android23,
+
+		// @property chrome: Boolean
+		// `true` for the Chrome browser.
 		chrome: chrome,
+
+		// @property safari: Boolean
+		// `true` for the Safari browser.
 		safari: !chrome && ua.indexOf('safari') !== -1,
 
+
+		// @property win: Boolean
+		// `true` when the browser is running in a Windows platform
+		win: win,
+
+
+		// @property ie3d: Boolean
+		// `true` for all Internet Explorer versions supporting CSS transforms.
 		ie3d: ie3d,
+
+		// @property webkit3d: Boolean
+		// `true` for webkit-based browsers supporting CSS transforms.
 		webkit3d: webkit3d,
+
+		// @property gecko3d: Boolean
+		// `true` for gecko-based browsers supporting CSS transforms.
 		gecko3d: gecko3d,
-		opera3d: opera3d,
-		any3d: !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d || opera3d) && !phantomjs,
 
+		// @property opera12: Boolean
+		// `true` for the Opera browser supporting CSS transforms (version 12 or later).
+		opera12: opera12,
+
+		// @property any3d: Boolean
+		// `true` for all browsers supporting CSS transforms.
+		any3d: !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d) && !opera12 && !phantomjs,
+
+
+		// @property mobile: Boolean
+		// `true` for all browsers running in a mobile device.
 		mobile: mobile,
+
+		// @property mobileWebkit: Boolean
+		// `true` for all webkit-based browsers in a mobile device.
 		mobileWebkit: mobile && webkit,
+
+		// @property mobileWebkit3d: Boolean
+		// `true` for all webkit-based browsers in a mobile device supporting CSS transforms.
 		mobileWebkit3d: mobile && webkit3d,
+
+		// @property mobileOpera: Boolean
+		// `true` for the Opera browser in a mobile device.
 		mobileOpera: mobile && window.opera,
 
+		// @property mobileGecko: Boolean
+		// `true` for gecko-based browsers running in a mobile device.
+		mobileGecko: mobile && gecko,
+
+
+		// @property touch: Boolean
+		// `true` for all browsers supporting [touch events](https://developer.mozilla.org/docs/Web/API/Touch_events).
 		touch: !!touch,
+
+		// @property msPointer: Boolean
+		// `true` for browsers implementing the Microsoft touch events model (notably IE10).
 		msPointer: !!msPointer,
+
+		// @property pointer: Boolean
+		// `true` for all browsers supporting [pointer events](https://msdn.microsoft.com/en-us/library/dn433244%28v=vs.85%29.aspx).
 		pointer: !!pointer,
 
+
+		// @property retina: Boolean
+		// `true` for browsers on a high-resolution "retina" screen.
 		retina: (window.devicePixelRatio || (window.screen.deviceXDPI / window.screen.logicalXDPI)) > 1
 	};
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 07b4b09..ba57b74 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -465,8 +465,7 @@ L.TileLayer = L.GridLayer.extend({
 
 		this._map.hideBusy();
 		if (command.id === 'print') {
-			var isFirefox = typeof InstallTrigger !== 'undefined' || navigator.userAgent.search('Firefox') >= 0;
-			if (isFirefox || this._map.options.print === false) {
+			if (L.Browser.gecko || L.Browser.edge || this._map.options.print === false) {
 				// the print dialog doesn't work well on firefox
 				this._map.fire('print', {url: url});
 			}
diff --git a/loleaflet/src/map/handler/Map.Print.js b/loleaflet/src/map/handler/Map.Print.js
index c2f8265..8f32fb6 100644
--- a/loleaflet/src/map/handler/Map.Print.js
+++ b/loleaflet/src/map/handler/Map.Print.js
@@ -49,10 +49,12 @@ L.Map.Print = L.Handler.extend({
 	_onIframeLoaded: function () {
 		this._printIframe.contentWindow.focus(); // Required for IE
 		this._printIframe.contentWindow.print();
+		// couldn't find another way to remove it
+		setTimeout(L.bind(this._closePrintIframe, this, this._printIframe), 300 * 1000);
 	},
 
-	_closePrintDialog: function () {
-		L.DomUtil.remove(this._printIframe);
+	_closePrintIframe: function (printIframe) {
+		L.DomUtil.remove(printIframe);
 		this._map.focus();
 	}
 });


More information about the Libreoffice-commits mailing list