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

Tor Lillqvist (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 27 19:13:51 UTC 2020


 loleaflet/src/layer/marker/TextInput.js |   87 +++++++++++++++++++++++++++++++-
 1 file changed, 86 insertions(+), 1 deletion(-)

New commits:
commit e2e0727be7b546d81f2f12bd84de06f72bad6cca
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Aug 19 11:19:35 2020 +0300
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Thu Aug 27 21:13:32 2020 +0200

    Use CollaboraOnlineWebViewKeyboardManager if available
    
    If loleaflet is embedded in an iOS app that uses
    CollaboraOnlineWebViewKeyboardManager, then we can use that to
    reliably display and hide the on-screen keyboard. (Such iOS apps are
    Collabora Office or Nextcloud.)
    
    This is optional as we can't be sure whether the version of the iOS
    app we are embedded in uses CollaboraOnlineWebViewKeyboardManager or
    not. If not, work as before. I.e. hope that calling the focus()/blur()
    methods of a textarea object will show/hide the on-screen keyboard.
    
    Change-Id: Idddedcb4a83588c622067cdbeadb02ecdbd4fc72
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100980
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/101441
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/loleaflet/src/layer/marker/TextInput.js b/loleaflet/src/layer/marker/TextInput.js
index 9fe093ce7..418ffd7d1 100644
--- a/loleaflet/src/layer/marker/TextInput.js
+++ b/loleaflet/src/layer/marker/TextInput.js
@@ -1,4 +1,4 @@
-/* -*- js-indent-level: 8 -*- */
+/* -*- js-indent-level: 8; fill-column: 100 -*- */
 /*
  * L.TextInput is the hidden textarea, which handles text input events
  *
@@ -171,6 +171,81 @@ L.TextInput = L.Layer.extend({
 			return;
 		}
 
+		// Are we running in a WebView under an iOS app that uses
+		// CollaboraOnlineWebViewKeyboardManager?
+		if (window.webkit &&
+		    window.webkit.messageHandlers &&
+		    window.webkit.messageHandlers.CollaboraOnlineWebViewKeyboardManager) {
+
+			if (!acceptInput) {
+				window.webkit.messageHandlers.CollaboraOnlineWebViewKeyboardManager.postMessage({command: 'hide'});
+				return;
+			}
+
+			// Define the function that CollaboraOnlineWebViewKeyboardManager will call.
+			// This is a hardcoded name that CollaboraOnlineWebViewKeyboardManager
+			// knows. This is not a problem as we can keep both codebases in sync.
+
+			var that = this;
+			window.COKbdMgrCallback = function(message) {
+				var errorMessage;
+				if (typeof message !== 'object') {
+					errorMessage = 'COKbdMgrCallback called with non-object of type ' + typeof message;
+					console.log(errorMessage);
+					throw errorMessage;
+				}
+
+				if (message.id !== 'COKbdMgr') {
+					errorMessage = 'COKbdMgrCallback called with object with unknown id: ' + message.id;
+					console.log(errorMessage);
+					throw errorMessage;
+				}
+
+				if (message.command === undefined || typeof message.command !== 'string') {
+					errorMessage = 'COKbdMgrCallback called without command';
+					console.log(errorMessage);
+					throw errorMessage;
+				}
+
+				if (message.command === 'replaceText') {
+					if (message.text === undefined || typeof message.text !== 'string') {
+						errorMessage = 'COKbdMgrCallback called for replaceText without text';
+						console.log(errorMessage);
+						throw errorMessage;
+					}
+
+					if (message.location === undefined || typeof message.location !== 'number') {
+						errorMessage = 'COKbdMgrCallback called for replaceText without location';
+						console.log(errorMessage);
+						throw errorMessage;
+					}
+
+					if (message.length === undefined || typeof message.length !== 'number') {
+						errorMessage = 'COKbdMgrCallback called for replaceText without length';
+						console.log(errorMessage);
+						throw errorMessage;
+					}
+
+					if (that._textArea.value.length == 2 && message.length == 0 && message.text.length == 0) {
+						that._removeTextContent(1, 0);
+					} else {
+						that._textArea.value = that._textArea.value.slice(0, message.location + 1) + message.text + that._textArea.value.slice(message.location + 1 + message.length);
+						that._onInput({});
+					}
+				} else {
+					errorMessage = 'COKbdMgrCallback called with unknown command ' + message.command;
+					console.log(errorMessage);
+					throw errorMessage;
+				}
+			};
+
+			// We don't know the seed text to feed CollaboraOnlineWebViewKeyboardManager
+			window.webkit.messageHandlers.CollaboraOnlineWebViewKeyboardManager.postMessage({command: 'display'});
+			this._onFocusBlur({type: 'focus'});
+
+			return;
+		}
+
 		// Trick to avoid showing the software keyboard: Set the textarea
 		// read-only before focus() and reset it again after the blur()
 		if (navigator.platform !== 'iPhone') {
@@ -216,6 +291,16 @@ L.TextInput = L.Layer.extend({
 	},
 
 	blur: function() {
+		// Are we running in a WebView under an iOS app that uses
+		// CollaboraOnlineWebViewKeyboardManager?
+		if (window.webkit &&
+		    window.webkit.messageHandlers &&
+		    window.webkit.messageHandlers.CollaboraOnlineWebViewKeyboardManager) {
+			window.webkit.messageHandlers.CollaboraOnlineWebViewKeyboardManager.postMessage({command: 'hide'});
+			this._onFocusBlur({type: 'blur'});
+			return;
+		}
+
 		this._setAcceptInput(false);
 		if (navigator.platform !== 'iPhone')
 			this._textArea.blur();


More information about the Libreoffice-commits mailing list