mirror of
https://github.com/overte-org/overte.git
synced 2025-06-18 21:20:38 +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.isKeyboardRaised = false;
|
||||||
window.isNumericKeyboard = false;
|
window.isNumericKeyboard = false;
|
||||||
window.isPasswordField = false;
|
window.isPasswordField = false;
|
||||||
|
window.lastActiveElement = null;
|
||||||
|
|
||||||
|
function getActiveElement() {
|
||||||
|
return document.activeElement;
|
||||||
|
}
|
||||||
|
|
||||||
function shouldSetPasswordField() {
|
function shouldSetPasswordField() {
|
||||||
var nodeType = document.activeElement.type;
|
var nodeType = document.activeElement.type;
|
||||||
|
@ -65,10 +70,11 @@
|
||||||
var keyboardRaised = shouldRaiseKeyboard();
|
var keyboardRaised = shouldRaiseKeyboard();
|
||||||
var numericKeyboard = shouldSetNumeric();
|
var numericKeyboard = shouldSetNumeric();
|
||||||
var passwordField = shouldSetPasswordField();
|
var passwordField = shouldSetPasswordField();
|
||||||
|
var activeElement = getActiveElement();
|
||||||
|
|
||||||
if (isWindowFocused &&
|
if (isWindowFocused &&
|
||||||
(keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard
|
(keyboardRaised !== window.isKeyboardRaised || numericKeyboard !== window.isNumericKeyboard
|
||||||
|| passwordField !== window.isPasswordField)) {
|
|| passwordField !== window.isPasswordField || activeElement !== window.lastActiveElement)) {
|
||||||
|
|
||||||
if (typeof EventBridge !== "undefined" && EventBridge !== null) {
|
if (typeof EventBridge !== "undefined" && EventBridge !== null) {
|
||||||
EventBridge.emitWebEvent(
|
EventBridge.emitWebEvent(
|
||||||
|
@ -90,6 +96,7 @@
|
||||||
window.isKeyboardRaised = keyboardRaised;
|
window.isKeyboardRaised = keyboardRaised;
|
||||||
window.isNumericKeyboard = numericKeyboard;
|
window.isNumericKeyboard = numericKeyboard;
|
||||||
window.isPasswordField = passwordField;
|
window.isPasswordField = passwordField;
|
||||||
|
window.lastActiveElement = activeElement;
|
||||||
}
|
}
|
||||||
}, POLL_FREQUENCY);
|
}, POLL_FREQUENCY);
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,35 @@ Item {
|
||||||
webViewCore.stop();
|
webViewCore.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
function unfocus() {
|
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) {
|
webViewCore.runJavaScript("if (document.activeElement) document.activeElement.blur();", function(result) {
|
||||||
console.log('unfocus completed: ', result);
|
console.log('unfocus completed: ', result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function unfocus() {
|
||||||
|
delayedUnfocuser.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopUnfocus() {
|
||||||
|
delayedUnfocuser.stop();
|
||||||
|
}
|
||||||
|
|
||||||
function onLoadingChanged(loadRequest) {
|
function onLoadingChanged(loadRequest) {
|
||||||
if (WebEngineView.LoadStartedStatus === loadRequest.status) {
|
if (WebEngineView.LoadStartedStatus === loadRequest.status) {
|
||||||
|
|
|
@ -13,6 +13,8 @@ Item {
|
||||||
onKeyboardRaisedChanged: {
|
onKeyboardRaisedChanged: {
|
||||||
if(!keyboardRaised) {
|
if(!keyboardRaised) {
|
||||||
webroot.unfocus();
|
webroot.unfocus();
|
||||||
|
} else {
|
||||||
|
webroot.stopUnfocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property bool punctuationMode: false
|
property bool punctuationMode: false
|
||||||
|
|
|
@ -17,6 +17,8 @@ Item {
|
||||||
onKeyboardRaisedChanged: {
|
onKeyboardRaisedChanged: {
|
||||||
if(!keyboardRaised) {
|
if(!keyboardRaised) {
|
||||||
webroot.unfocus();
|
webroot.unfocus();
|
||||||
|
} else {
|
||||||
|
webroot.stopUnfocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property bool punctuationMode: false
|
property bool punctuationMode: false
|
||||||
|
|
|
@ -15,6 +15,8 @@ Item {
|
||||||
onKeyboardRaisedChanged: {
|
onKeyboardRaisedChanged: {
|
||||||
if(!keyboardRaised) {
|
if(!keyboardRaised) {
|
||||||
webroot.unfocus();
|
webroot.unfocus();
|
||||||
|
} else {
|
||||||
|
webroot.stopUnfocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property bool punctuationMode: false
|
property bool punctuationMode: false
|
||||||
|
|
Loading…
Reference in a new issue