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

Pranav Kant pranavk at collabora.co.uk
Tue Jan 2 13:18:20 UTC 2018


 loleaflet/src/control/Control.LokDialog.js |   41 ++---------------------------
 loleaflet/src/layer/tile/TileLayer.js      |   14 ---------
 loleaflet/src/map/handler/Map.Keyboard.js  |   24 +++++++++-------
 3 files changed, 17 insertions(+), 62 deletions(-)

New commits:
commit e59ef72e19bf3001fe4dd361531cbc8715609a73
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Sat Dec 23 18:36:28 2017 +0530

    loleaflet: Unify dialog key handling logic with document's
    
    Change-Id: I422e813d76df9b52a860a05d09a89362dfb0b616
    Reviewed-on: https://gerrit.libreoffice.org/47070
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js
index 4abf350b..82f69130 100644
--- a/loleaflet/src/control/Control.LokDialog.js
+++ b/loleaflet/src/control/Control.LokDialog.js
@@ -222,7 +222,9 @@ L.Control.LokDialog = L.Control.extend({
 			this._postWindowMouseEvent(lokEventType, this._toRawDlgId(strDlgId), e.offsetX, e.offsetY, 1, buttons, 0);
 		}, this);
 		L.DomEvent.on(dialogCanvas, 'keyup keypress keydown', function(e) {
-			this._handleDialogKeyEvent(e, this._toRawDlgId(strDlgId));
+			// _onKeyDown fn below requires this kind of structure but leaflet DomEvent.on doesn't pass it
+			e.originalEvent = e;
+			map['keyboard']._onKeyDown(e, L.bind(this._postWindowKeyboardEvent, this, this._toRawDlgId(strDlgId)));
 		}, this);
 		L.DomEvent.on(dialogCanvas, 'contextmenu', function() {
 			return false;
@@ -242,43 +244,6 @@ L.Control.LokDialog = L.Control.extend({
 		                              ' char=' + charcode + ' key=' + keycode);
 	},
 
-	_handleDialogKeyEvent: function(e, winid) {
-		var docLayer = this._map._docLayer;
-		this.modifier = 0;
-		var shift = e.shiftKey ? this._map['keyboard'].keyModifier.shift : 0;
-		var ctrl = e.ctrlKey ? this._map['keyboard'].keyModifier.ctrl : 0;
-		var alt = e.altKey ? this._map['keyboard'].keyModifier.alt : 0;
-		var cmd = e.metaKey ? this._map['keyboard'].keyModifier.ctrl : 0;
-		var location = e.location;
-		this.modifier = shift | ctrl | alt | cmd;
-
-		var charCode = e.charCode;
-		var keyCode = e.keyCode;
-		var unoKeyCode = this._map['keyboard']._toUNOKeyCode(keyCode);
-
-		if (this.modifier) {
-			unoKeyCode |= this.modifier;
-			if (e.type !== 'keyup') {
-				this._postWindowKeyboardEvent(winid, 'input', charCode, unoKeyCode);
-				return;
-			}
-		}
-
-		if (e.type === 'keydown' && this._map['keyboard'].handleOnKeyDownKeys[keyCode]) {
-			this._postWindowKeyboardEvent(winid, 'input', charCode, unoKeyCode);
-		}
-		else if (e.type === 'keypress' && (!this._map['keyboard'].handleOnKeyDownKeys[keyCode] || charCode !== 0)) {
-			if (charCode === keyCode && charCode !== 13) {
-				keyCode = 0;
-				unoKeyCode = this._map['keyboard']._toUNOKeyCode(keyCode);
-			}
-			this._postWindowKeyboardEvent(winid, 'input', charCode, unoKeyCode);
-		}
-		else if (e.type === 'keyup') {
-			this._postWindowKeyboardEvent(winid, 'up', charCode, unoKeyCode);
-		}
-	},
-
 	_onDialogClose: function(dialogId, notifyBackend) {
 		if (notifyBackend)
 			this._sendCloseWindow(dialogId);
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index de0091b5..16ac17b3 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1334,20 +1334,6 @@ L.TileLayer = L.GridLayer.extend({
 		}
 	},
 
-	_postKeyboardEvents: function(type, charcodes, keycodes) {
-		// Both are arrays
-		if (typeof(charcodes.length) !== 'number' && typeof(keycodes.length) !== 'number')
-			return;
-
-		// both have same length
-		if (charcodes.length !== keycodes.length)
-			return;
-
-		for (var i = 0; i < charcodes.length; i++) {
-			this._postKeyboardEvent(type, charcodes[i], keycodes[i]);
-		}
-	},
-
 	_postKeyboardEvent: function(type, charcode, keycode) {
 		if (this._docType === 'spreadsheet' && this._prevCellCursor && type === 'input') {
 			if (keycode === 1030) { // PgUp
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 1109b35f..23c55f21 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -237,11 +237,15 @@ L.Map.Keyboard = L.Handler.extend({
 		return this.keymap[keyCode] || keyCode;
 	},
 
-	_onKeyDown: function (e) {
+	_onKeyDown: function (e, postEventFn) {
 		if (this._map.slideShow && this._map.slideShow.fullscreen) {
 			return;
 		}
 		var docLayer = this._map._docLayer;
+		if (!postEventFn) {
+			// default is to post keyboard events on the document
+			postEventFn = docLayer._postKeyboardEvent;
+		}
 		this.modifier = 0;
 		var shift = e.originalEvent.shiftKey ? this.keyModifier.shift : 0;
 		var ctrl = e.originalEvent.ctrlKey ? this.keyModifier.ctrl : 0;
@@ -311,7 +315,7 @@ L.Map.Keyboard = L.Handler.extend({
 		if (this.modifier) {
 			unoKeyCode |= this.modifier;
 			if (e.type !== 'keyup' && (this.modifier !== shift || (keyCode === 32 && !docLayer._isCursorVisible))) {
-				docLayer._postKeyboardEvent('input', charCode, unoKeyCode);
+				postEventFn.call(this, 'input', charCode, unoKeyCode);
 				e.originalEvent.preventDefault();
 				return;
 			}
@@ -325,7 +329,7 @@ L.Map.Keyboard = L.Handler.extend({
 				this._bufferedTextInputEvent = null;
 
 				if (this._handleOnKeyDown(keyCode, this.modifier) && charCode === 0) {
-					docLayer._postKeyboardEvent('input', charCode, unoKeyCode);
+					postEventFn.call(this, 'input', charCode, unoKeyCode);
 				}
 			}
 			else if ((e.type === 'keypress' || e.type === 'compositionend') &&
@@ -342,9 +346,11 @@ L.Map.Keyboard = L.Handler.extend({
 				}
 				if (e.type === 'compositionend') {
 					// Set all keycodes to zero
-					docLayer._postKeyboardEvents('input', compCharCodes, Array.apply(null, Array(compCharCodes.length)).map(Number.prototype.valueOf, 0));
+					for (var i = 0; i < compCharCodes.length; ++i) {
+						postEventFn.call(this, 'input', compCharCodes[i], 0);
+					}
 				} else {
-					docLayer._postKeyboardEvent('input', charCode, unoKeyCode);
+					postEventFn.call(this, 'input', charCode, unoKeyCode);
 				}
 
 				this._keyHandled = true;
@@ -373,13 +379,11 @@ L.Map.Keyboard = L.Handler.extend({
 				if (!this._keyHandled && this._bufferedTextInputEvent) {
 					var textInputData = this._bufferedTextInputEvent.originalEvent.data;
 					charCode = e.originalEvent.keyCode;
-					var compCharCodes = [];
 					for (var i = 0; i < textInputData.length; i++) {
-						compCharCodes.push(textInputData[i].charCodeAt());
+						postEventFn.call(this, 'input', textInputData[i].charCodeAt(), 0);
 					}
-					docLayer._postKeyboardEvents('input', compCharCodes, Array.apply(null, Array(compCharCodes.length)).map(Number.prototype.valueOf, 0));
 				}
-				docLayer._postKeyboardEvent('up', charCode, unoKeyCode);
+				postEventFn.call(this, 'up', charCode, unoKeyCode);
 
 				this._keyHandled = true;
 				this._bufferedTextInputEvent = null;
@@ -405,7 +409,7 @@ L.Map.Keyboard = L.Handler.extend({
 			else if (key in this._panKeys && e.originalEvent.shiftKey &&
 					docLayer._selections.getLayers().length !== 0) {
 				// if there is a selection and the user wants to modify it
-				docLayer._postKeyboardEvent('input', charCode, unoKeyCode);
+				postEventFn.call(this, 'input', charCode, unoKeyCode);
 			}
 			else if (key in this._zoomKeys) {
 				map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);


More information about the Libreoffice-commits mailing list