kit/ChildSession.cpp | 12 +++++++----- loleaflet/src/control/Control.LokDialog.js | 21 ++++++++++++++++----- loleaflet/src/layer/tile/TileLayer.js | 5 +++++ loleaflet/src/map/handler/Map.Keyboard.js | 28 +++++++++++++++------------- 4 files changed, 43 insertions(+), 23 deletions(-)
New commits: commit 9a063c72613c2d5448e457c2ded9e0e82266fcd4 Author: Pranav Kant <pran...@collabora.co.uk> Date: Tue Feb 13 23:05:54 2018 +0530 Adapt to IME API changes; better reuse of Map's key handler Change-Id: I670243ea155ac698c694531d3fc16a574f418bf4 (cherry picked from commit 6d4f02ac2aff539132e66bce237ed4b6c20cc43f) Reviewed-on: https://gerrit.libreoffice.org/49777 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Andras Timar <andras.ti...@collabora.com> diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 655eae1e..c98bbe48 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -771,13 +771,15 @@ bool ChildSession::insertFile(const char* /*buffer*/, int /*length*/, const std: bool ChildSession::extTextInputEvent(const char* /*buffer*/, int /*length*/, const std::vector<std::string>& tokens) { - int type; + int id, type; std::string text; - if (tokens.size() < 3 || - !getTokenKeyword(tokens[1], "type", + if (tokens.size() < 4 || + !getTokenInteger(tokens[1], "id", id) || id < 0 || + !getTokenKeyword(tokens[2], "type", {{"input", LOK_EXT_TEXTINPUT}, {"end", LOK_EXT_TEXTINPUT_END}}, type) || - !getTokenString(tokens[2], "text", text)) + !getTokenString(tokens[3], "text", text)) + { sendTextFrame("error: cmd=" + std::string(tokens[0]) + " kind=syntax"); return false; @@ -785,7 +787,7 @@ bool ChildSession::extTextInputEvent(const char* /*buffer*/, int /*length*/, std::unique_lock<std::mutex> lock(_docManager.getDocumentMutex()); getLOKitDocument()->setView(_viewId); - getLOKitDocument()->postExtTextInputEvent(type, text.c_str()); + getLOKitDocument()->postExtTextInputEvent(id, type, text.c_str()); return true; } diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js index ae9b712c..d30e2411 100644 --- a/loleaflet/src/control/Control.LokDialog.js +++ b/loleaflet/src/control/Control.LokDialog.js @@ -231,11 +231,18 @@ L.Control.LokDialog = L.Control.extend({ var lokEventType = e.type.replace('mouse', 'button'); this._postWindowMouseEvent(lokEventType, this._toRawDlgId(strDlgId), e.offsetX, e.offsetY, 1, buttons, 0); }, this); - L.DomEvent.on(dialogCanvas, 'keyup keypress keydown', function(e) { - // _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, + 'keyup keypress keydown compositionstart compositionupdate compositionend', + function(e) { + e.originalEvent = e; // _onKeyDown fn below requires real event in e.originalEvent + var fn = this._postWindowKeyboardEvent; + if (e.type.startsWith('composition')) { + fn = this._postWindowCompositionEvent; + } + map['keyboard']._onKeyDown(e, L.bind(fn, + this, + this._toRawDlgId(strDlgId))); + }, this); L.DomEvent.on(dialogCanvas, 'contextmenu', function() { return false; }); @@ -243,6 +250,10 @@ L.Control.LokDialog = L.Control.extend({ this._launchDialogCursor(strDlgId); }, + _postWindowCompositionEvent: function(winid, type, text) { + this._map._docLayer._postCompositionEvent(winid, type, text); + }, + _postWindowMouseEvent: function(type, winid, x, y, count, buttons, modifier) { this._map._socket.sendMessage('windowmouse id=' + winid + ' type=' + type + ' x=' + x + ' y=' + y + ' count=' + count + diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 7072a848..8e36d7ab 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1372,6 +1372,11 @@ L.TileLayer = L.GridLayer.extend({ ' char=' + charcode + ' key=' + keycode); }, + // if winId=0, then event is posted on the document + _postCompositionEvent: function(winId, type, text) { + this._map._socket.sendMessage('textinput id=' + winId + ' type=' + type + ' text=' + text); + }, + _postSelectGraphicEvent: function(type, x, y) { this._map._socket.sendMessage('selectgraphic type=' + type + ' x=' + x + ' y=' + y); diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js index af3917eb..b1e25a2d 100644 --- a/loleaflet/src/map/handler/Map.Keyboard.js +++ b/loleaflet/src/map/handler/Map.Keyboard.js @@ -237,16 +237,18 @@ L.Map.Keyboard = L.Handler.extend({ return this.keymap[keyCode] || keyCode; }, - _onKeyDown: function (e, postEventFn) { + _onKeyDown: function (e, keyEventFn, compEventFn) { if (this._map.slideShow && this._map.slideShow.fullscreen) { return; } var docLayer = this._map._docLayer; - var eventObject; - if (!postEventFn) { + if (!keyEventFn) { // default is to post keyboard events on the document - postEventFn = docLayer._postKeyboardEvent; - eventObject = docLayer; + keyEventFn = L.bind(docLayer._postKeyboardEvent, docLayer); + } + if (!compEventFn) { + // document has winid=0 + compEventFn = L.bind(docLayer._postCompositionEvent, docLayer, 0 /* winid */); } this.modifier = 0; var shift = e.originalEvent.shiftKey ? this.keyModifier.shift : 0; @@ -297,7 +299,7 @@ L.Map.Keyboard = L.Handler.extend({ txt += e.originalEvent.data[i]; } if (txt) { - this._map._socket.sendMessage('textinput type=input text=' + txt); + compEventFn('input', txt); } } @@ -320,7 +322,7 @@ L.Map.Keyboard = L.Handler.extend({ if (this.modifier) { unoKeyCode |= this.modifier; if (e.type !== 'keyup' && (this.modifier !== shift || (keyCode === 32 && !docLayer._isCursorVisible))) { - postEventFn.call(eventObject, 'input', charCode, unoKeyCode); + keyEventFn('input', charCode, unoKeyCode); e.originalEvent.preventDefault(); return; } @@ -334,7 +336,7 @@ L.Map.Keyboard = L.Handler.extend({ this._bufferedTextInputEvent = null; if (this._handleOnKeyDown(keyCode, this.modifier) && charCode === 0) { - postEventFn.call(eventObject, 'input', charCode, unoKeyCode); + keyEventFn('input', charCode, unoKeyCode); } } else if ((e.type === 'keypress' || e.type === 'compositionend') && @@ -351,9 +353,9 @@ L.Map.Keyboard = L.Handler.extend({ } if (e.type === 'compositionend') { // Set all keycodes to zero - this._map._socket.sendMessage('textinput type=end text=void'); + compEventFn('end', ''); } else { - postEventFn.call(eventObject, 'input', charCode, unoKeyCode); + keyEventFn('input', charCode, unoKeyCode); } this._keyHandled = true; @@ -383,10 +385,10 @@ L.Map.Keyboard = L.Handler.extend({ var textInputData = this._bufferedTextInputEvent.originalEvent.data; charCode = e.originalEvent.keyCode; for (var i = 0; i < textInputData.length; i++) { - postEventFn.call(eventObject, 'input', textInputData[i].charCodeAt(), 0); + keyEventFn('input', textInputData[i].charCodeAt(), 0); } } - postEventFn.call(eventObject, 'up', charCode, unoKeyCode); + keyEventFn('up', charCode, unoKeyCode); this._keyHandled = true; this._bufferedTextInputEvent = null; @@ -412,7 +414,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 - postEventFn.call(eventObject, 'input', charCode, unoKeyCode); + keyEventFn('input', charCode, unoKeyCode); } else if (key in this._zoomKeys) { map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits