mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 08:14:48 +02:00
Merge pull request #14028 from ElderOrb/FB12459
Improve keyboard raising logic for web views
This commit is contained in:
commit
1611525220
5 changed files with 41 additions and 4 deletions
|
@ -18,6 +18,11 @@
|
|||
window.isKeyboardRaised = false;
|
||||
window.isNumericKeyboard = false;
|
||||
window.isPasswordField = false;
|
||||
window.lastActiveElement = null;
|
||||
|
||||
function getActiveElement() {
|
||||
return document.activeElement;
|
||||
}
|
||||
|
||||
function shouldSetPasswordField() {
|
||||
var nodeType = document.activeElement.type;
|
||||
|
@ -65,10 +70,11 @@
|
|||
var keyboardRaised = shouldRaiseKeyboard();
|
||||
var numericKeyboard = shouldSetNumeric();
|
||||
var passwordField = shouldSetPasswordField();
|
||||
var activeElement = getActiveElement();
|
||||
|
||||
if (isWindowFocused &&
|
||||
(keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard
|
||||
|| passwordField !== window.isPasswordField)) {
|
||||
|| passwordField !== window.isPasswordField || activeElement !== window.lastActiveElement)) {
|
||||
|
||||
if (typeof EventBridge !== "undefined" && EventBridge !== null) {
|
||||
EventBridge.emitWebEvent(
|
||||
|
@ -90,6 +96,7 @@
|
|||
window.isKeyboardRaised = keyboardRaised;
|
||||
window.isNumericKeyboard = numericKeyboard;
|
||||
window.isPasswordField = passwordField;
|
||||
window.lastActiveElement = activeElement;
|
||||
}
|
||||
}, POLL_FREQUENCY);
|
||||
|
||||
|
|
|
@ -34,10 +34,34 @@ Item {
|
|||
webViewCore.stop();
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: delayedUnfocuser
|
||||
repeat: false
|
||||
interval: 200
|
||||
onTriggered: {
|
||||
|
||||
// The idea behind this is to delay unfocusing, so that fast lower/raise will not result actual unfocusing.
|
||||
// Fast lower/raise happens every time keyboard is being re-raised (see the code below in OffscreenQmlSurface::setKeyboardRaised)
|
||||
//
|
||||
// if (raised) {
|
||||
// item->setProperty("keyboardRaised", QVariant(!raised));
|
||||
// }
|
||||
//
|
||||
// item->setProperty("keyboardRaised", QVariant(raised));
|
||||
//
|
||||
|
||||
webViewCore.runJavaScript("if (document.activeElement) document.activeElement.blur();", function(result) {
|
||||
console.log('unfocus completed: ', result);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function unfocus() {
|
||||
webViewCore.runJavaScript("if (document.activeElement) document.activeElement.blur();", function(result) {
|
||||
console.log('unfocus completed: ', result);
|
||||
});
|
||||
delayedUnfocuser.start();
|
||||
}
|
||||
|
||||
function stopUnfocus() {
|
||||
delayedUnfocuser.stop();
|
||||
}
|
||||
|
||||
function onLoadingChanged(loadRequest) {
|
||||
|
|
|
@ -13,6 +13,8 @@ Item {
|
|||
onKeyboardRaisedChanged: {
|
||||
if(!keyboardRaised) {
|
||||
webroot.unfocus();
|
||||
} else {
|
||||
webroot.stopUnfocus();
|
||||
}
|
||||
}
|
||||
property bool punctuationMode: false
|
||||
|
|
|
@ -17,6 +17,8 @@ Item {
|
|||
onKeyboardRaisedChanged: {
|
||||
if(!keyboardRaised) {
|
||||
webroot.unfocus();
|
||||
} else {
|
||||
webroot.stopUnfocus();
|
||||
}
|
||||
}
|
||||
property bool punctuationMode: false
|
||||
|
|
|
@ -15,6 +15,8 @@ Item {
|
|||
onKeyboardRaisedChanged: {
|
||||
if(!keyboardRaised) {
|
||||
webroot.unfocus();
|
||||
} else {
|
||||
webroot.stopUnfocus();
|
||||
}
|
||||
}
|
||||
property bool punctuationMode: false
|
||||
|
|
Loading…
Reference in a new issue