From bd88a68a0fb14e9c8ae1b0e4761441110c0d52f7 Mon Sep 17 00:00:00 2001 From: amerhifi Date: Fri, 24 May 2019 10:58:13 -0700 Subject: [PATCH] testing context passing to dockWidget via whitelisting. --- interface/src/ui/InteractiveWindow.cpp | 8 ++++++++ libraries/ui/src/ui/OffscreenQmlSurface.cpp | 12 ++++++++++++ libraries/ui/src/ui/OffscreenQmlSurface.h | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index 657b6b3ac5..3f97fe4dc2 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -111,6 +111,14 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap auto quickView = _dockWidget->getQuickView(); Application::setupQmlSurface(quickView->rootContext(), true); + auto offscreenUi = DependencyManager::get(); + // Build the event bridge and wrapper on the main thread + auto context = offscreenUi->widgetContextForUrl(sourceUrl); + + + if(context!=nullptr){ + _dockWidget->getQuickView()->rootContext()->setContextObject(context); + } /**jsdoc * Configures how a NATIVE window is displayed. * @typedef {object} InteractiveWindow.PresentationWindowInfo diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.cpp b/libraries/ui/src/ui/OffscreenQmlSurface.cpp index ec0a011bd0..175ad1fedf 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.cpp +++ b/libraries/ui/src/ui/OffscreenQmlSurface.cpp @@ -307,6 +307,18 @@ void OffscreenQmlSurface::onRootContextCreated(QQmlContext* qmlContext) { #endif } +QQmlContext* OffscreenQmlSurface::widgetContextForUrl(const QUrl& url) { + + // Get any whitelist functionality + QList callbacks = getQmlWhitelist()->getCallbacksForUrl(url); + // If we have whitelisted content, we must load a new context + if(callbacks.empty()){ + return nullptr; + } + + return contextForUrl(url,nullptr, false); +} + QQmlContext* OffscreenQmlSurface::contextForUrl(const QUrl& qmlSource, QQuickItem* parent, bool forceNewContext) { // Get any whitelist functionality QList callbacks = getQmlWhitelist()->getCallbacksForUrl(qmlSource); diff --git a/libraries/ui/src/ui/OffscreenQmlSurface.h b/libraries/ui/src/ui/OffscreenQmlSurface.h index b8c6808afa..6d2141eebc 100644 --- a/libraries/ui/src/ui/OffscreenQmlSurface.h +++ b/libraries/ui/src/ui/OffscreenQmlSurface.h @@ -36,7 +36,8 @@ public: Q_INVOKABLE void lowerKeyboard(); PointerEvent::EventType choosePointerEventType(QEvent::Type type); Q_INVOKABLE unsigned int deviceIdByTouchPoint(qreal x, qreal y); - + QQmlContext* widgetContextForUrl(const QUrl& url); + signals: void focusObjectChanged(QObject* newFocus); void focusTextChanged(bool focusText);