From 8f85c7650b88a7e5e91a90f66f4b09d35fa25b02 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Mon, 13 Nov 2017 14:16:04 -0800 Subject: [PATCH] Make sure loaded components get the right parent context --- interface/resources/qml/hifi/tablet/WindowRoot.qml | 7 +------ libraries/ui/src/ui/OffscreenQmlSurface.cpp | 9 ++++++--- libraries/ui/src/ui/OffscreenQmlSurface.h | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/WindowRoot.qml b/interface/resources/qml/hifi/tablet/WindowRoot.qml index 0b631326f4..9c027308b8 100644 --- a/interface/resources/qml/hifi/tablet/WindowRoot.qml +++ b/interface/resources/qml/hifi/tablet/WindowRoot.qml @@ -64,8 +64,8 @@ Windows.ScrollingWindow { function loadWebContent(source, url, injectJavaScriptUrl) { loader.load(source, function() { - loader.item.url = url loader.item.scriptURL = injectJavaScriptUrl; + loader.item.url = url; if (loader.item.hasOwnProperty("closeButtonVisible")) { loader.item.closeButtonVisible = false; } @@ -146,11 +146,6 @@ Windows.ScrollingWindow { } function load(newSource, callback) { - if (loader.source == newSource) { - loader.loaded(); - return; - } - if (loader.item) { loader.item.destroy(); loader.item = null; diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index aab89ccd4d..a0c6790b93 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -697,13 +697,16 @@ QQuickItem* OffscreenQmlSurface::getRootItem() { return _rootItem; } -QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, bool forceNewContext) { +QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, QQuickItem* parent, bool forceNewContext) { // Get any whitelist functionality QList callbacks = getQmlWhitelist()->getCallbacksForUrl(qmlSource); // If we have whitelisted content, we must load a new context forceNewContext |= !callbacks.empty(); - QQmlContext* targetContext = _qmlContext; + QQmlContext* targetContext = parent ? QQmlEngine::contextForObject(parent) : _qmlContext; + if (!targetContext) { + targetContext = _qmlContext; + } if (_rootItem && forceNewContext) { targetContext = new QQmlContext(targetContext); } @@ -737,7 +740,7 @@ void OffscreenQmlSurface::loadInternal(const QUrl& qmlSource, bool createNewCont finalQmlSource = _qmlContext->resolvedUrl(qmlSource); } - auto targetContext = contextForUrl(finalQmlSource, createNewContext); + auto targetContext = contextForUrl(finalQmlSource, parent, createNewContext); auto qmlComponent = new QQmlComponent(_qmlContext->engine(), finalQmlSource, QQmlComponent::PreferSynchronous); if (qmlComponent->isLoading()) { connect(qmlComponent, &QQmlComponent::statusChanged, this, [=](QQmlComponent::Status) { diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.h b/libraries/ui/src/ui/OffscreenQmlSurface.h index 2d2eb0811b..62754efe14 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.h +++ b/libraries/ui/src/ui/OffscreenQmlSurface.h @@ -130,7 +130,7 @@ protected: private: static QOpenGLContext* getSharedContext(); - QQmlContext* contextForUrl(const QUrl& url, bool forceNewContext = false); + QQmlContext* contextForUrl(const QUrl& url, QQuickItem* parent, bool forceNewContext = false); void loadInternal(const QUrl& qmlSource, bool createNewContext, QQuickItem* parent, const QmlContextObjectCallback& onQmlLoadedCallback); void finishQmlLoad(QQmlComponent* qmlComponent, QQmlContext* qmlContext, QQuickItem* parent, const QmlContextObjectCallback& onQmlLoadedCallback); QPointF mapWindowToUi(const QPointF& sourcePosition, QObject* sourceObject);