From fa7892e5c68d756231058b60845f4dfca87fab5e Mon Sep 17 00:00:00 2001 From: beholder Date: Fri, 13 Oct 2017 19:51:30 +0300 Subject: [PATCH 1/2] 8217 Search in tablet doesn't update --- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 43 ++++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 01026ae5ff..62ef25f47e 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -1018,17 +1018,8 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key, QObject* targetOverrid } } -static void forEachKeyboard(QQuickItem* item, std::function function) { - QObject* itemObject = item; - while (itemObject) { - if (itemObject->parent()) { - itemObject = itemObject->parent(); - } else { - break; - } - } - - auto keyboards = itemObject->findChildren("keyboard"); +static void forEachKeyboard(QQuickItem* parent, std::function function) { + auto keyboards = parent->findChildren("keyboard"); for (auto keyboardObject : keyboards) { auto keyboard = qobject_cast(keyboardObject); @@ -1044,6 +1035,19 @@ static void forEachKeyboard(QQuickItem* item, std::function f static const int TEXTINPUT_PASSWORD = 2; +static QQuickItem* getTopmostParent(QQuickItem* item) { + QObject* itemObject = item; + while (itemObject) { + if (itemObject->parent()) { + itemObject = itemObject->parent(); + } else { + break; + } + } + + return qobject_cast (itemObject); +} + void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool numeric) { #if Q_OS_ANDROID return; @@ -1066,10 +1070,14 @@ void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool n // we need to somehow pass 'isPasswordField' to visible keyboard so it will change its 'mirror text' to asterixes // the issue in some cases there might be more than one keyboard in object tree and it is hard to understand which one is being used at the moment // unfortunately attempts to check for visibility failed becuase visibility is not updated yet. So... I don't see other way than just update properties for all the keyboards - forEachKeyboard(item, [&](QQuickItem* keyboard) { - keyboard->setProperty("mirroredText", QVariant::fromValue(QString(""))); - keyboard->setProperty("password", isPasswordField); - }); + + auto topmostParent = getTopmostParent(item); + if (topmostParent) { + forEachKeyboard(topmostParent, [&](QQuickItem* keyboard) { + keyboard->setProperty("mirroredText", QVariant::fromValue(QString(""))); + keyboard->setProperty("password", isPasswordField); + }); + } // for future probably makes sense to consider one of the following: // 1. make keyboard a singleton, which will be dynamically re-parented before showing @@ -1081,6 +1089,11 @@ void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised, bool n numeric = numeric || QString(item->metaObject()->className()).left(7) == "SpinBox"; if (item->property("keyboardRaised").isValid()) { + forEachKeyboard(item, [&](QQuickItem* keyboard) { + keyboard->setProperty("mirroredText", QVariant::fromValue(QString(""))); + keyboard->setProperty("password", isPasswordField); + }); + // FIXME - HMD only: Possibly set value of "keyboardEnabled" per isHMDMode() for use in WebView.qml. if (item->property("punctuationMode").isValid()) { item->setProperty("punctuationMode", QVariant(numeric)); From e8589d53dd32e19644a4e257d707349ea84bbda5 Mon Sep 17 00:00:00 2001 From: beholder Date: Wed, 18 Oct 2017 03:45:50 +0300 Subject: [PATCH 2/2] updated code based on code review --- libraries/ui/src/ui/OffscreenQmlSurface.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index 62ef25f47e..eb42c95c66 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -1019,15 +1019,15 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key, QObject* targetOverrid } static void forEachKeyboard(QQuickItem* parent, std::function function) { + if (!function) { + return; + } + auto keyboards = parent->findChildren("keyboard"); for (auto keyboardObject : keyboards) { auto keyboard = qobject_cast(keyboardObject); - if (keyboard == nullptr) { - continue; - } - - if (function) { + if (keyboard) { function(keyboard); } }