loleaflet/src/control/Control.MobileInput.js | 52 +++++++++++++++++++++++++-- loleaflet/src/layer/tile/TileLayer.js | 2 + 2 files changed, 51 insertions(+), 3 deletions(-)
New commits: commit 7f1f9d1add17b6ddf3540b14d1c29865669f8593 Author: Tor Lillqvist <t...@collabora.com> AuthorDate: Fri May 17 17:06:08 2019 +0300 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Jun 13 13:22:39 2019 +0200 tdf#124906: Hack for dead keys in iOS app and iOS Safari against Online Handle key events fairly separately for the iOS app and Mobile Safari than for other mobile platforms. Use the key property of the keypress event and avoid looking at the keyCode property of keyboard events. There is still one problem left: After typing the dead key, it is not displayed temporarily "waiting" for the following letter, as it should. But that didn't work before either in the iOS app, as far as I see. Change-Id: I9df174ba294f855697df59dd016b39cd1b3d905b Reviewed-on: https://gerrit.libreoffice.org/73946 Reviewed-by: Tor Lillqvist <t...@collabora.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/loleaflet/src/control/Control.MobileInput.js b/loleaflet/src/control/Control.MobileInput.js index d1f65b240..ea3bccbb7 100644 --- a/loleaflet/src/control/Control.MobileInput.js +++ b/loleaflet/src/control/Control.MobileInput.js @@ -18,6 +18,9 @@ L.Control.MobileInput = L.Control.extend({ }); this._cursorHandler.on('dragend', this.onDragEnd, this); + this._currentKeysDown = {}; + this._ignoreKeypress = false; + this._isMobileSafariOriOSApp = window.ThisIsTheiOSApp || navigator.platform === 'iPad' || navigator.platform === 'iPhone'; }, onAdd: function () { @@ -101,11 +104,12 @@ L.Control.MobileInput = L.Control.extend({ this._textArea.setAttribute('spellcheck', 'false'); L.DomEvent.on(this._textArea, stopEvents, L.DomEvent.stopPropagation) .on(this._textArea, 'keydown keypress keyup', this.onKeyEvents, this) - .on(this._textArea, 'compositionstart compositionupdate compositionend', this.onCompEvents, this) .on(this._textArea, 'textInput', this.onTextInput, this) - .on(this._textArea, 'input', this.onInput, this) .on(this._textArea, 'focus', this.onGotFocus, this) .on(this._textArea, 'blur', this.onLostFocus, this); + if (!this._isMobileSafariOriOSApp) + L.DomEvent.on(this._textArea, 'compositionstart compositionupdate compositionend', this.onCompEvents, this) + .on(this._textArea, 'input', this.onInput, this); }, _getSurrogatePair: function(codePoint) { @@ -122,6 +126,7 @@ L.Control.MobileInput = L.Control.extend({ unoKeyCode = handler._toUNOKeyCode(keyCode); this._keyHandled = this._keyHandled || false; + // console.log('==> onKeyEvents: ' + e.type + ':' + e.key + ' keyCode=' + keyCode + ' charCode=' + charCode + ' unoKeyCode=' + unoKeyCode + ' _keyHandled=' + this._keyHandled + ' _isComposing=' + this._isComposing) if (this._isComposing) { if (keyCode === 229 && charCode === 0) { return; @@ -139,12 +144,42 @@ L.Control.MobileInput = L.Control.extend({ // key ignored } else if (e.type === 'keydown') { + if (this._isMobileSafariOriOSApp) { + if (!this._currentKeysDown[e.key]) + this._currentKeysDown[e.key] = 1; + else + this._currentKeysDown[e.key]++; + if (this._currentKeysDown[e.key] > 1) + this._ignoreKeypress = true; + } this._keyHandled = false; + // console.log(' _keyHandled := false'); if (handler.handleOnKeyDownKeys[keyCode] && charCode === 0) { docLayer._postKeyboardEvent('input', charCode, unoKeyCode); this._lastInput = unoKeyCode; } } + else if (this._isMobileSafariOriOSApp && + e.type === 'keypress') { + if (!this._ignoreKeypress) { + // e.key can be longer than one, for instance if you press a dead diacritic + // key followed by a letter that it can't combine with, like ¨ t => '¨t'. + // But e.key is longer than one also in the case of control keys where for + // instance e.key == 'Enter'. Detect the latter by comparing e.key against + // e.code. + if (e.key !== e.code) { + var i; + for (i = 0; i < e.key.length; ++i) { + docLayer._postKeyboardEvent('input', e.key[i].charCodeAt(), 0); + docLayer._postKeyboardEvent('up', e.key[i].charCodeAt(), 0); + } + } + else { + docLayer._postKeyboardEvent('input', charCode, unoKeyCode); + docLayer._postKeyboardEvent('up', charCode, unoKeyCode); + } + } + } else if ((e.type === 'keypress') && (!handler.handleOnKeyDownKeys[keyCode] || charCode !== 0)) { if (charCode === keyCode && charCode !== 13) { // Chrome sets keyCode = charCode for printable keys @@ -167,20 +202,29 @@ L.Control.MobileInput = L.Control.extend({ } this._lastInput = unoKeyCode; this._keyHandled = true; + // console.log(' _keyHandled := true'); } else if (e.type === 'keyup') { - if (charCode <= 0xFFFF) { + if (this._isMobileSafariOriOSApp) { + // Yes, forget all keys that are pressed at the same time as soon as one + // of them goes up. This seems to match what events the system sends. + this._currentKeysDown = {}; + } + else if (!this._ignoreKeypress && charCode <= 0xFFFF) { // For non-BMP characters we generated both 'input' and 'up' events // above already. docLayer._postKeyboardEvent('up', charCode, unoKeyCode); } + this._ignoreKeypress = false; this._lastInput = null; this._keyHandled = true; + // console.log(' _keyHandled := true'); } L.DomEvent.stopPropagation(e); }, onCompEvents: function (e) { + // console.log('==> onCompEvents: ' + e.type); var map = this._map; if (e.type === 'compositionstart' || e.type === 'compositionupdate') { @@ -197,6 +241,7 @@ L.Control.MobileInput = L.Control.extend({ }, onTextInput: function (e) { + // console.log('==> onTextInput: _keyHandled=' + this._keyHandled); if (!this._keyHandled) { this._textData = e.data; this._textArea.value = ''; @@ -206,6 +251,7 @@ L.Control.MobileInput = L.Control.extend({ }, onInput: function (e) { + // console.log('==> onInput: inputType=' + e.inputType); var backSpace = this._map.keyboard._toUNOKeyCode(8); var i; diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 661f4f82c..11f2995e7 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1545,6 +1545,7 @@ L.TileLayer = L.GridLayer.extend({ }, _postKeyboardEvent: function(type, charcode, keycode) { + // console.log('==> _postKeyboardEvent type=' + type + ' charcode=' + charcode + ' keycode=' + keycode); if (this._docType === 'spreadsheet' && this._prevCellCursor && type === 'input') { if (keycode === 1030) { // PgUp if (this._cellCursorOnPgUp) { @@ -1570,6 +1571,7 @@ L.TileLayer = L.GridLayer.extend({ // if winId=0, then event is posted on the document _postCompositionEvent: function(winId, type, text) { + // console.log('==> _postCompositionEvent type=' + type + ' text="' + text + '"'); this._map._socket.sendMessage('textinput id=' + winId + ' type=' + type + ' text=' + encodeURIComponent(text)); }, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits