Unified · Split
| @@ -91,6 +91,7 @@ · 90 unmodified lines | |||
| 91 | #include "scripting/MenuScriptingInterface.h" | 91 | #include "scripting/MenuScriptingInterface.h" |
| 92 | #include "scripting/SettingsScriptingInterface.h" | 92 | #include "scripting/SettingsScriptingInterface.h" |
| 93 | #include "scripting/WindowScriptingInterface.h" | 93 | #include "scripting/WindowScriptingInterface.h" |
| 94 | #include "scripting/WebWindow.h" | ||
| 94 | 95 | ||
| 95 | #include "ui/DataWebDialog.h" | 96 | #include "ui/DataWebDialog.h" |
| 96 | #include "ui/InfoView.h" | 97 | #include "ui/InfoView.h" |
| @@ -3871,6 +3872,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 3774 unmodified lines | |||
| 3871 | // register `location` on the global object. | 3872 | // register `location` on the global object. |
| 3872 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, | 3873 | scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, |
| 3873 | LocationScriptingInterface::locationSetter); | 3874 | LocationScriptingInterface::locationSetter); |
| 3875 | |||
| 3876 | scriptEngine->registerFunction("WebWindow", WebWindow::constructor, 1); | ||
| 3874 | 3877 | ||
| 3875 | scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); | 3878 | scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); |
| 3876 | scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); | 3879 | scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); |
| @@ -0,0 +1,68 @@ | |||
| 1 | // | ||
| 2 | // WebWindow.cpp | ||
| 3 | // interface/src/scripting | ||
| 4 | // | ||
| 5 | // Created by Ryan Huffman on 11/06/14. | ||
| 6 | // Copyright 2014 High Fidelity, Inc. | ||
| 7 | // | ||
| 8 | // Distributed under the Apache License, Version 2.0. | ||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 10 | // | ||
| 11 | |||
| 12 | #include <QVBoxLayout> | ||
| 13 | #include <QApplication> | ||
| 14 | #include <QWebFrame> | ||
| 15 | #include <QWebView> | ||
| 16 | |||
| 17 | #include "WindowScriptingInterface.h" | ||
| 18 | #include "WebWindow.h" | ||
| 19 | |||
| 20 | ScriptEventBridge::ScriptEventBridge(QObject* parent) : QObject(parent) { | ||
| 21 | } | ||
| 22 | |||
| 23 | void ScriptEventBridge::emitWebEvent(const QString& data) { | ||
| 24 | emit webEventReceived(data); | ||
| 25 | } | ||
| 26 | |||
| 27 | void ScriptEventBridge::emitScriptEvent(const QString& data) { | ||
| 28 | emit scriptEventReceived(data); | ||
| 29 | } | ||
| 30 | |||
| 31 | WebWindow::WebWindow(const QString& url, int width, int height) | ||
| 32 | : QObject(NULL), | ||
| 33 | _window(new QWidget(NULL, Qt::Tool)), | ||
| 34 | _eventBridge(new ScriptEventBridge(this)) { | ||
| 35 | |||
| 36 | QWebView* webView = new QWebView(_window); | ||
| 37 | webView->page()->mainFrame()->addToJavaScriptWindowObject("EventBridge", _eventBridge); | ||
| 38 | webView->setUrl(url); | ||
| 39 | QVBoxLayout* layout = new QVBoxLayout(_window); | ||
| 40 | _window->setLayout(layout); | ||
| 41 | layout->addWidget(webView); | ||
| 42 | layout->setSpacing(0); | ||
| 43 | layout->setContentsMargins(0, 0, 0, 0); | ||
| 44 | _window->setGeometry(0, 0, width, height); | ||
| 45 | |||
| 46 | connect(this, &WebWindow::destroyed, _window, &QWidget::deleteLater); | ||
| 47 | } | ||
| 48 | |||
| 49 | WebWindow::~WebWindow() { | ||
| 50 | } | ||
| 51 | |||
| 52 | void WebWindow::setVisible(bool visible) { | ||
| 53 | QMetaObject::invokeMethod(_window, "setVisible", Qt::BlockingQueuedConnection, Q_ARG(bool, visible)); | ||
| 54 | } | ||
| 55 | |||
| 56 | QScriptValue WebWindow::constructor(QScriptContext* context, QScriptEngine* engine) { | ||
| 57 | WebWindow* retVal; | ||
| 58 | QString file = context->argument(0).toString(); | ||
| 59 | QMetaObject::invokeMethod(WindowScriptingInterface::getInstance(), "doCreateWebWindow", Qt::BlockingQueuedConnection, | ||
| 60 | Q_RETURN_ARG(WebWindow*, retVal), | ||
| 61 | Q_ARG(const QString&, file), | ||
| 62 | Q_ARG(int, context->argument(1).toInteger()), | ||
| 63 | Q_ARG(int, context->argument(2).toInteger())); | ||
| 64 | |||
| 65 | connect(engine, &QScriptEngine::destroyed, retVal, &WebWindow::deleteLater); | ||
| 66 | |||
| 67 | return engine->newQObject(retVal);//, QScriptEngine::ScriptOwnership); | ||
| 68 | } | ||
| @@ -0,0 +1,53 @@ | |||
| 1 | // | ||
| 2 | // WebWindow.h | ||
| 3 | // interface/src/scripting | ||
| 4 | // | ||
| 5 | // Created by Ryan Huffman on 11/06/14. | ||
| 6 | // Copyright 2014 High Fidelity, Inc. | ||
| 7 | // | ||
| 8 | // Distributed under the Apache License, Version 2.0. | ||
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | ||
| 10 | // | ||
| 11 | |||
| 12 | #ifndef hifi_WebWindow_h | ||
| 13 | #define hifi_WebWindow_h | ||
| 14 | |||
| 15 | #include <QScriptContext> | ||
| 16 | #include <QScriptEngine> | ||
| 17 | |||
| 18 | // #include "ScriptWebView.h" | ||
| 19 | |||
| 20 | class ScriptEventBridge : public QObject { | ||
| 21 | Q_OBJECT | ||
| 22 | public: | ||
| 23 | ScriptEventBridge(QObject* parent = NULL); | ||
| 24 | |||
| 25 | public slots: | ||
| 26 | void emitWebEvent(const QString& data); | ||
| 27 | void emitScriptEvent(const QString& data); | ||
| 28 | |||
| 29 | signals: | ||
| 30 | void webEventReceived(const QString& data); | ||
| 31 | void scriptEventReceived(const QString& data); | ||
| 32 | |||
| 33 | }; | ||
| 34 | |||
| 35 | class WebWindow : public QObject { | ||
| 36 | Q_OBJECT | ||
| 37 | Q_PROPERTY(QObject* eventBridge READ getEventBridge) | ||
| 38 | public: | ||
| 39 | WebWindow(const QString& url, int width, int height); | ||
| 40 | ~WebWindow(); | ||
| 41 | |||
| 42 | static QScriptValue constructor(QScriptContext* context, QScriptEngine* engine); | ||
| 43 | |||
| 44 | public slots: | ||
| 45 | void setVisible(bool visible); | ||
| 46 | ScriptEventBridge* getEventBridge() const { return _eventBridge; } | ||
| 47 | |||
| 48 | private: | ||
| 49 | QWidget* _window; | ||
| 50 | ScriptEventBridge* _eventBridge; | ||
| 51 | }; | ||
| 52 | |||
| 53 | #endif | ||