loleaflet/src/layer/tile/TileLayer.js | 132 ----------------- loleaflet/src/map/handler/Map.Keyboard.js | 226 ++++++++++++++++-------------- 2 files changed, 122 insertions(+), 236 deletions(-)
New commits: commit 11063ea843869226fb94ae739cd098edc7df2061 Author: Mihai Varga <mihai.va...@collabora.com> Date: Thu Jul 16 15:23:42 2015 +0300 loleaflet: moved keyboard handler from TileLayer.js -> Map.Keyboard.js diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index b5c9e64..e7af468 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -27,91 +27,6 @@ L.TileLayer = L.GridLayer.extend({ crossOrigin: false }, - keymap: { - 8 : 1283, // backspace : BACKSPACE - 9 : 1282, // tab : TAB - 13 : 1280, // enter : RETURN - 16 : null, // shift : UNKOWN - 17 : null, // ctrl : UNKOWN - 18 : null, // alt : UNKOWN - 19 : null, // pause/break : UNKOWN - 20 : null, // caps lock : UNKOWN - 27 : 1281, // escape : ESCAPE - 32 : 1284, // space : SPACE - 33 : 1030, // page up : PAGEUP - 34 : 1031, // page down : PAGEDOWN - 35 : 1029, // end : END - 36 : 1028, // home : HOME - 37 : 1026, // left arrow : LEFT - 38 : 1025, // up arrow : UP - 39 : 1027, // right arrow : RIGHT - 40 : 1024, // down arrow : DOWN - 45 : 1285, // insert : INSERT - 46 : 1286, // delete : DELETE - 91 : null, // left window key : UNKOWN - 92 : null, // right window key : UNKOWN - 93 : null, // select key : UNKOWN - 96 : 256, // numpad 0 : NUM0 - 97 : 257, // numpad 1 : NUM1 - 98 : 258, // numpad 2 : NUM2 - 99 : 259, // numpad 3 : NUM3 - 100 : 260, // numpad 4 : NUM4 - 101 : 261, // numpad 5 : NUM5 - 102 : 262, // numpad 6 : NUM6 - 103 : 263, // numpad 7 : NUM7 - 104 : 264, // numpad 8 : NUM8 - 105 : 265, // numpad 9 : NUM9 - 106 : 1289, // multiply : MULTIPLY - 107 : 1287, // add : ADD - 109 : 1288, // subtract : SUBTRACT - 110 : 1309, // decimal point : DECIMAL - 111 : 1290, // divide : DIVIDE - 112 : 768, // f1 : F1 - 113 : 769, // f2 : F2 - 114 : 770, // f3 : F3 - 115 : 771, // f4 : F4 - 116 : 772, // f5 : F5 - 117 : 773, // f6 : F6 - 118 : 774, // f7 : F7 - 119 : 775, // f8 : F8 - 120 : 776, // f9 : F9 - 121 : 777, // f10 : F10 - 122 : 778, // f11 : F11 - 144 : 1313, // num lock : NUMLOCK - 145 : 1314, // scroll lock : SCROLLLOCK - 186 : 1317, // semi-colon : SEMICOLON - 187 : 1295, // equal sign : EQUAL - 188 : 1292, // comma : COMMA - 189 : 5, // dash : DASH - 190 : null, // period : UNKOWN - 191 : null, // forward slash : UNKOWN - 192 : null, // grave accent : UNKOWN - 219 : null, // open bracket : UNKOWN - 220 : null, // back slash : UNKOWN - 221 : null, // close bracket : UNKOWN - 222 : null // single quote : UNKOWN - }, - - handleOnKeyDown: { - // these keys need to be handled on keydown in order for them - // to work on chrome - 8 : true, // backspace - 9 : true, // tab - 19 : true, // pause/break - 20 : true, // caps lock - 27 : true, // escape - 33 : true, // page up - 34 : true, // page down - 35 : true, // end - 36 : true, // home - 37 : true, // left arrow - 38 : true, // up arrow - 39 : true, // right arrow - 40 : true, // down arrow - 45 : true, // insert - 46 : true // delete - }, - initialize: function (url, options) { this._url = url; @@ -211,10 +126,7 @@ L.TileLayer = L.GridLayer.extend({ var events = { viewreset: this._viewReset, movestart: this._moveStart, - moveend: this._move, - keydown: this._signalKey, - keypress: this._signalKey, - keyup: this._signalKey + moveend: this._move }; if (!this.options.updateWhenIdle) { @@ -875,48 +787,6 @@ L.TileLayer = L.GridLayer.extend({ this._mouseEventsQueue = []; }, - // Convert javascript key codes to UNO key codes. - _toUNOKeyCode: function (keyCode) { - return this.keymap[keyCode] || keyCode; - }, - - // Receives a key press or release event. - _signalKey: function (e) { - if (e.originalEvent.ctrlKey) { - // we prepare for a copy event - this._textArea.value = 'dummy text'; - this._textArea.focus(); - this._textArea.select(); - return; - } - - if (this._permission !== 'edit') { - return; - } - - var charCode = e.originalEvent.charCode; - var keyCode = e.originalEvent.keyCode; - if (e.type === 'keydown' && this.handleOnKeyDown[keyCode] && charCode === 0) { - this._postKeyboardEvent('input', charCode, this._toUNOKeyCode(keyCode)); - } - else if (e.type === 'keypress' && - (!this.handleOnKeyDown[keyCode] || charCode !== 0)) { - if (charCode === keyCode && charCode !== 13) { - // Chrome sets keyCode = charCode for printable keys - // while LO requires it to be 0 - keyCode = 0; - } - this._postKeyboardEvent('input', charCode, this._toUNOKeyCode(keyCode)); - } - else if (e.type === 'keyup') { - this._postKeyboardEvent('up', charCode, this._toUNOKeyCode(keyCode)); - } - if (keyCode === 9) { - // tab would change focus to other DOM elements - e.originalEvent.preventDefault(); - } - }, - // Is rRectangle empty? _isEmptyRectangle: function (aBounds) { return aBounds.getSouthWest().equals(new L.LatLng(0, 0)) && aBounds.getNorthEast().equals(new L.LatLng(0, 0)); diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js index e524ce8..084fc03 100644 --- a/loleaflet/src/map/handler/Map.Keyboard.js +++ b/loleaflet/src/map/handler/Map.Keyboard.js @@ -4,26 +4,97 @@ L.Map.mergeOptions({ keyboard: true, - keyboardPanOffset: 80, - keyboardZoomOffset: 1 }); L.Map.Keyboard = L.Handler.extend({ - keyCodes: { - left: [37], - right: [39], - down: [40], - up: [38], - zoomIn: [187, 107, 61, 171], - zoomOut: [189, 109, 173] + keymap: { + 8 : 1283, // backspace : BACKSPACE + 9 : 1282, // tab : TAB + 13 : 1280, // enter : RETURN + 16 : null, // shift : UNKOWN + 17 : null, // ctrl : UNKOWN + 18 : null, // alt : UNKOWN + 19 : null, // pause/break : UNKOWN + 20 : null, // caps lock : UNKOWN + 27 : 1281, // escape : ESCAPE + 32 : 1284, // space : SPACE + 33 : 1030, // page up : PAGEUP + 34 : 1031, // page down : PAGEDOWN + 35 : 1029, // end : END + 36 : 1028, // home : HOME + 37 : 1026, // left arrow : LEFT + 38 : 1025, // up arrow : UP + 39 : 1027, // right arrow : RIGHT + 40 : 1024, // down arrow : DOWN + 45 : 1285, // insert : INSERT + 46 : 1286, // delete : DELETE + 91 : null, // left window key : UNKOWN + 92 : null, // right window key : UNKOWN + 93 : null, // select key : UNKOWN + 96 : 256, // numpad 0 : NUM0 + 97 : 257, // numpad 1 : NUM1 + 98 : 258, // numpad 2 : NUM2 + 99 : 259, // numpad 3 : NUM3 + 100 : 260, // numpad 4 : NUM4 + 101 : 261, // numpad 5 : NUM5 + 102 : 262, // numpad 6 : NUM6 + 103 : 263, // numpad 7 : NUM7 + 104 : 264, // numpad 8 : NUM8 + 105 : 265, // numpad 9 : NUM9 + 106 : 1289, // multiply : MULTIPLY + 107 : 1287, // add : ADD + 109 : 1288, // subtract : SUBTRACT + 110 : 1309, // decimal point : DECIMAL + 111 : 1290, // divide : DIVIDE + 112 : 768, // f1 : F1 + 113 : 769, // f2 : F2 + 114 : 770, // f3 : F3 + 115 : 771, // f4 : F4 + 116 : 772, // f5 : F5 + 117 : 773, // f6 : F6 + 118 : 774, // f7 : F7 + 119 : 775, // f8 : F8 + 120 : 776, // f9 : F9 + 121 : 777, // f10 : F10 + 122 : 778, // f11 : F11 + 144 : 1313, // num lock : NUMLOCK + 145 : 1314, // scroll lock : SCROLLLOCK + 186 : 1317, // semi-colon : SEMICOLON + 187 : 1295, // equal sign : EQUAL + 188 : 1292, // comma : COMMA + 189 : 5, // dash : DASH + 190 : null, // period : UNKOWN + 191 : null, // forward slash : UNKOWN + 192 : null, // grave accent : UNKOWN + 219 : null, // open bracket : UNKOWN + 220 : null, // back slash : UNKOWN + 221 : null, // close bracket : UNKOWN + 222 : null // single quote : UNKOWN + }, + + handleOnKeyDown: { + // these keys need to be handled on keydown in order for them + // to work on chrome + 8 : true, // backspace + 9 : true, // tab + 19 : true, // pause/break + 20 : true, // caps lock + 27 : true, // escape + 33 : true, // page up + 34 : true, // page down + 35 : true, // end + 36 : true, // home + 37 : true, // left arrow + 38 : true, // up arrow + 39 : true, // right arrow + 40 : true, // down arrow + 45 : true, // insert + 46 : true // delete }, initialize: function (map) { this._map = map; - - this._setPanOffset(map.options.keyboardPanOffset); - this._setZoomOffset(map.options.keyboardZoomOffset); }, addHooks: function () { @@ -34,113 +105,58 @@ L.Map.Keyboard = L.Handler.extend({ container.tabIndex = '0'; } - L.DomEvent.on(container, { - focus: this._onFocus, - blur: this._onBlur, - mousedown: this._onMouseDown - }, this); - - this._map.on({ - focus: this._addHooks, - blur: this._removeHooks - }, this); - }, - - removeHooks: function () { - this._removeHooks(); - - L.DomEvent.off(this._map._container, { - focus: this._onFocus, - blur: this._onBlur, - mousedown: this._onMouseDown - }, this); - - this._map.off({ - focus: this._addHooks, - blur: this._removeHooks - }, this); + this._map.on('mousedown', this._onMouseDown, this); + this._map.on('keydown keyup keypress', this._onKeyDown, this); }, _onMouseDown: function () { - if (this._focused) { return; } - - var body = document.body, - docEl = document.documentElement, - top = body.scrollTop || docEl.scrollTop, - left = body.scrollLeft || docEl.scrollLeft; - + if (this._map._docLayer._permission === 'edit') { + return; + } this._map._container.focus(); - - window.scrollTo(left, top); - }, - - _onFocus: function () { - this._focused = true; - this._map.fire('focus'); }, - _onBlur: function () { - this._focused = false; - this._map.fire('blur'); + // Convert javascript key codes to UNO key codes. + _toUNOKeyCode: function (keyCode) { + return this.keymap[keyCode] || keyCode; }, - _setPanOffset: function (pan) { - var keys = {}, - codes = this.keyCodes, - i, len; - - for (i = 0, len = codes.left.length; i < len; i++) { - keys[codes.left[i]] = [-1 * pan, 0]; - } - for (i = 0, len = codes.right.length; i < len; i++) { - keys[codes.right[i]] = [pan, 0]; - } - for (i = 0, len = codes.down.length; i < len; i++) { - keys[codes.down[i]] = [0, pan]; - } - for (i = 0, len = codes.up.length; i < len; i++) { - keys[codes.up[i]] = [0, -1 * pan]; + _onKeyDown: function (e) { + var docLayer = this._map._docLayer; + if (e.originalEvent.ctrlKey) { + // we prepare for a copy event + docLayer._textArea.value = 'dummy text'; + docLayer._textArea.focus(); + docLayer._textArea.select(); + return; } - }, - _setZoomOffset: function (zoom) { - var keys = this._zoomKeys = {}, - codes = this.keyCodes, - i, len; + if (docLayer._permission !== 'edit') { + return; + } - for (i = 0, len = codes.zoomIn.length; i < len; i++) { - keys[codes.zoomIn[i]] = zoom; + var charCode = e.originalEvent.charCode; + var keyCode = e.originalEvent.keyCode; + if (e.type === 'keydown' && this.handleOnKeyDown[keyCode] && charCode === 0) { + docLayer._postKeyboardEvent('input', charCode, this._toUNOKeyCode(keyCode)); } - for (i = 0, len = codes.zoomOut.length; i < len; i++) { - keys[codes.zoomOut[i]] = -zoom; + else if (e.type === 'keypress' && + (!this.handleOnKeyDown[keyCode] || charCode !== 0)) { + if (charCode === keyCode && charCode !== 13) { + // Chrome sets keyCode = charCode for printable keys + // while LO requires it to be 0 + keyCode = 0; + } + docLayer._postKeyboardEvent('input', charCode, this._toUNOKeyCode(keyCode)); } - }, - - _addHooks: function () { - L.DomEvent.on(document, 'keydown', this._onKeyDown, this); - }, - - _removeHooks: function () { - L.DomEvent.off(document, 'keydown', this._onKeyDown, this); - }, - - _onKeyDown: function (e) { - if (this._map._bDisableKeyboard || e.altKey || e.ctrlKey || e.metaKey) { return; } - - var key = e.keyCode, - map = this._map; - - if (key in this._zoomKeys) { - map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]); - - } else if (key === 27) { - map.closePopup(); - - } else { - return; + else if (e.type === 'keyup') { + docLayer._postKeyboardEvent('up', charCode, this._toUNOKeyCode(keyCode)); } - - L.DomEvent.stop(e); + if (keyCode === 9) { + // tab would change focus to other DOM elements + e.originalEvent.preventDefault(); + } + L.DomEvent.stopPropagation(e.originalEvent); } }); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits