diff --git a/interface/resources/qml/AddressBarDialog.qml b/interface/resources/qml/AddressBarDialog.qml index 646c6bf2f0..e743031465 100644 --- a/interface/resources/qml/AddressBarDialog.qml +++ b/interface/resources/qml/AddressBarDialog.qml @@ -18,7 +18,7 @@ import "hifi/toolbars" import "controls-uit" as HifiControls Window { - property bool keyboardRaised: true + property bool keyboardRaised: false property bool punctuationMode: false id: root @@ -70,6 +70,7 @@ Window { AddressBarDialog { id: addressBarDialog + objectName: "AddressBarDialogDialog" implicitWidth: backgroundImage.width implicitHeight: backgroundImage.height + (keyboardRaised ? 200 : 0) // The buttons have their button state changed on hover, so we have to manually fix them up here @@ -126,6 +127,7 @@ Window { } Image { id: backgroundImage + objectName: "AddressBarDialogImage" source: "../images/address-bar.svg" width: 576 * root.scale height: 80 * root.scale @@ -175,6 +177,7 @@ Window { TextInput { id: addressLine focus: true + objectName: "AddressBarDialogTextInput" anchors { top: parent.top bottom: parent.bottom diff --git a/libraries/gl/src/gl/OffscreenQmlSurface.cpp b/libraries/gl/src/gl/OffscreenQmlSurface.cpp index fe25940198..4e7200c6c7 100644 --- a/libraries/gl/src/gl/OffscreenQmlSurface.cpp +++ b/libraries/gl/src/gl/OffscreenQmlSurface.cpp @@ -814,15 +814,29 @@ QVariant OffscreenQmlSurface::returnFromUiThread(std::function funct return function(); } +void OffscreenQmlSurface::focusDestroyed(QObject *obj) { + _currentFocusItem = nullptr; +} + void OffscreenQmlSurface::onFocusObjectChanged(QObject* object) { - if (!object) { + QQuickItem* item = dynamic_cast(object); + if (!item) { setFocusText(false); + _currentFocusItem = nullptr; return; } QInputMethodQueryEvent query(Qt::ImEnabled); qApp->sendEvent(object, &query); setFocusText(query.value(Qt::ImEnabled).toBool()); + + if (_currentFocusItem) { + disconnect(_currentFocusItem, &QObject::destroyed, this, 0); + setKeyboardRaised(_currentFocusItem, false); + } + setKeyboardRaised(item, item->hasActiveFocus()); + _currentFocusItem = item; + connect(_currentFocusItem, &QObject::destroyed, this, &OffscreenQmlSurface::focusDestroyed); } void OffscreenQmlSurface::setFocusText(bool newFocusText) { @@ -880,15 +894,25 @@ void OffscreenQmlSurface::synthesizeKeyPress(QString key) { QCoreApplication::postEvent(getEventHandler(), releaseEvent); } -void OffscreenQmlSurface::setKeyboardRaised(bool raised) { +void OffscreenQmlSurface::setKeyboardRaised(QObject* object, bool raised) { // raise the keyboard only while in HMD mode and it's being requested. // XXX // bool value = AbstractViewStateInterface::instance()->isHMDMode() && raised; // getRootItem()->setProperty("keyboardRaised", QVariant(value)); - getRootItem()->setProperty("keyboardRaised", QVariant(raised)); + if (!object) { + return; + } + QQuickItem* item = dynamic_cast(object); + while (item) { + if (item->property("keyboardRaised").isValid()) { + item->setProperty("keyboardRaised", QVariant(raised)); + return; + } + item = dynamic_cast(item->parentItem()); + } } void OffscreenQmlSurface::emitScriptEvent(const QVariant& message) { @@ -905,9 +929,9 @@ void OffscreenQmlSurface::emitWebEvent(const QVariant& message) { } else { // special case to handle raising and lowering the virtual keyboard if (message.type() == QVariant::String && message.toString() == "_RAISE_KEYBOARD") { - setKeyboardRaised(true); + setKeyboardRaised(getRootItem(), true); } else if (message.type() == QVariant::String && message.toString() == "_LOWER_KEYBOARD") { - setKeyboardRaised(false); + setKeyboardRaised(getRootItem(), false); } else { emit webEventReceived(message); } diff --git a/libraries/gl/src/gl/OffscreenQmlSurface.h b/libraries/gl/src/gl/OffscreenQmlSurface.h index ecdf3fbef5..bd83d4f41d 100644 --- a/libraries/gl/src/gl/OffscreenQmlSurface.h +++ b/libraries/gl/src/gl/OffscreenQmlSurface.h @@ -68,7 +68,7 @@ public: QPointF mapToVirtualScreen(const QPointF& originalPoint, QObject* originalWidget); bool eventFilter(QObject* originalDestination, QEvent* event) override; - Q_INVOKABLE void setKeyboardRaised(bool raised); + void setKeyboardRaised(QObject* object, bool raised); Q_INVOKABLE void synthesizeKeyPress(QString key); @@ -81,7 +81,7 @@ public slots: void requestUpdate(); void requestRender(); void onAboutToQuit(); - + void focusDestroyed(QObject *obj); // event bridge public slots: @@ -119,6 +119,8 @@ private: uint8_t _maxFps{ 60 }; MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p.toPoint(); } }; QWindow* _proxyWindow { nullptr }; + + QQuickItem* _currentFocusItem { nullptr }; }; #endif