Merge pull request #11476 from ElderOrb/case7925

7925 Create Mode: keyboard focused entry field is not visible
This commit is contained in:
Seth Alves 2017-09-28 10:03:28 -07:00 committed by GitHub
commit 912305fd4b

View file

@ -14,7 +14,6 @@
var isWindowFocused = true; var isWindowFocused = true;
var isKeyboardRaised = false; var isKeyboardRaised = false;
var isNumericKeyboard = false; var isNumericKeyboard = false;
var KEYBOARD_HEIGHT = 200;
function shouldRaiseKeyboard() { function shouldRaiseKeyboard() {
var nodeName = document.activeElement.nodeName; var nodeName = document.activeElement.nodeName;
@ -38,6 +37,19 @@
return document.activeElement.type === "number"; return document.activeElement.type === "number";
}; };
function scheduleBringToView(timeout) {
var timer = setTimeout(function () {
clearTimeout(timer);
var elementRect = document.activeElement.getBoundingClientRect();
var absoluteElementTop = elementRect.top + window.scrollY;
var middle = absoluteElementTop - (window.innerHeight / 2);
window.scrollTo(0, middle);
}, timeout);
}
setInterval(function () { setInterval(function () {
var keyboardRaised = shouldRaiseKeyboard(); var keyboardRaised = shouldRaiseKeyboard();
var numericKeyboard = shouldSetNumeric(); var numericKeyboard = shouldSetNumeric();
@ -56,13 +68,8 @@
} }
if (!isKeyboardRaised) { if (!isKeyboardRaised) {
var delta = document.activeElement.getBoundingClientRect().bottom + 10 scheduleBringToView(250); // Allow time for keyboard to be raised in QML.
- (document.body.clientHeight - KEYBOARD_HEIGHT); // 2DO: should it be rather done from 'client area height changed' event?
if (delta > 0) {
setTimeout(function () {
document.body.scrollTop += delta;
}, 500); // Allow time for keyboard to be raised in QML.
}
} }
isKeyboardRaised = keyboardRaised; isKeyboardRaised = keyboardRaised;
@ -70,6 +77,13 @@
} }
}, POLL_FREQUENCY); }, POLL_FREQUENCY);
window.addEventListener("click", function () {
var keyboardRaised = shouldRaiseKeyboard();
if(keyboardRaised && isKeyboardRaised) {
scheduleBringToView(150);
}
});
window.addEventListener("focus", function () { window.addEventListener("focus", function () {
isWindowFocused = true; isWindowFocused = true;
}); });