diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/BrowserWindow.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/BrowserWindow.hpp | 1 | ||||
| -rw-r--r-- | src/widgets/Decorations.cpp | 7 | ||||
| -rw-r--r-- | src/widgets/Decorations.hpp | 4 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.cpp | 12 | ||||
| -rw-r--r-- | src/widgets/EdgeDecoration.hpp | 1 | ||||
| -rw-r--r-- | src/widgets/IWebViewMediator.hpp | 4 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/WebViewStack.hpp | 2 |
9 files changed, 36 insertions, 5 deletions
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp index f97f397..1fcf0c0 100644 --- a/src/widgets/BrowserWindow.cpp +++ b/src/widgets/BrowserWindow.cpp @@ -97,3 +97,8 @@ void BrowserWindow::open_url(const QUrl &url, OpenType open_type, WebViewId webv void BrowserWindow::set_html(const QString &html, WebViewId webview_id) { get_webview_mediator(webview_id)->set_html(html, webview_id); } + +void BrowserWindow::expose_rpc_function(const QString &name, const RpcFunc &action, + WebViewId webview_id) { + get_webview_mediator(webview_id)->expose_rpc_function(name, action, webview_id); +} diff --git a/src/widgets/BrowserWindow.hpp b/src/widgets/BrowserWindow.hpp index e434521..3dc9e69 100644 --- a/src/widgets/BrowserWindow.hpp +++ b/src/widgets/BrowserWindow.hpp @@ -38,6 +38,7 @@ public: bool has_webview(WebViewId webview_id); void open_url(const QUrl &url, OpenType open_type, WebViewId webview_id); void set_html(const QString &html, WebViewId webview_id); + void expose_rpc_function(const QString &name, const RpcFunc &action, WebViewId webview_id); bool on_window_key_event(QKeyEvent *event); diff --git a/src/widgets/Decorations.cpp b/src/widgets/Decorations.cpp index 223e19a..7886442 100644 --- a/src/widgets/Decorations.cpp +++ b/src/widgets/Decorations.cpp @@ -88,3 +88,10 @@ std::optional<WebViewId> Decorations::get_view_id(DecorationType type) { auto decoration = get_decoration_widget_type(type); return decoration.has_value() ? decoration.value()->get_view_id() : std::nullopt; } + +void Decorations::expose_rpc_function(const QString &name, const RpcFunc &action, + WebViewId view_id) { + auto decoration = get_decoration_widget_by_view_id(view_id); + if (decoration.has_value()) + decoration.value()->expose_rpc_function(name, action); +} diff --git a/src/widgets/Decorations.hpp b/src/widgets/Decorations.hpp index ef81c19..9788359 100644 --- a/src/widgets/Decorations.hpp +++ b/src/widgets/Decorations.hpp @@ -27,8 +27,10 @@ public: std::optional<WebViewId> get_view_id(DecorationType type); bool has_webview(WebViewId view_id) override; - void open_url(const QUrl &url, OpenType /*unused*/, WebViewId view_id) override; + void open_url(const QUrl &url, OpenType open_type, WebViewId view_id) override; void set_html(const QString &html, WebViewId view_id) override; + void expose_rpc_function(const QString &name, const RpcFunc &action, + WebViewId webview_id) override; private: EdgeDecoration *decoration_top; diff --git a/src/widgets/EdgeDecoration.cpp b/src/widgets/EdgeDecoration.cpp index 5277e6c..ed48857 100644 --- a/src/widgets/EdgeDecoration.cpp +++ b/src/widgets/EdgeDecoration.cpp @@ -66,9 +66,9 @@ void EdgeDecoration::setup_webview() { webview = new WebView(WebViewStack::next_webview_id++, profile, this); layout()->addWidget(webview.value()); webview.value()->enable_rpc_api(); - webview.value()->expose_rpc_function("tab_select", [](RpcArgs args) { - LuaRuntime::instance().webview_selected(args.at("view").toInt()); - }); + // expose_rpc_function("tab_select", [](RpcArgs args) { + // LuaRuntime::instance().webview_selected(args.at("view").toInt()); + // }); } webview.value()->setHtml(QString(default_html_layout).replace("{{body}}", html_content), @@ -95,3 +95,9 @@ void EdgeDecoration::set_url(const QUrl &url) { std::optional<WebViewId> EdgeDecoration::get_view_id() { return webview.has_value() ? std::make_optional(webview.value()->get_id()) : std::nullopt; } + +void EdgeDecoration::expose_rpc_function(const QString &name, const RpcFunc &action) { + if (!webview.has_value()) + return; + webview.value()->expose_rpc_function(name, action); +} diff --git a/src/widgets/EdgeDecoration.hpp b/src/widgets/EdgeDecoration.hpp index 0a977df..2af567c 100644 --- a/src/widgets/EdgeDecoration.hpp +++ b/src/widgets/EdgeDecoration.hpp @@ -22,6 +22,7 @@ public: void set_enabled(bool enabled_value); void set_url(const QUrl &url); std::optional<WebViewId> get_view_id(); + void expose_rpc_function(const QString &name, const RpcFunc &action); DEFINE_GETTER(is_enabled, enabled) diff --git a/src/widgets/IWebViewMediator.hpp b/src/widgets/IWebViewMediator.hpp index d20836a..b9af36f 100644 --- a/src/widgets/IWebViewMediator.hpp +++ b/src/widgets/IWebViewMediator.hpp @@ -1,13 +1,15 @@ #pragma once #include "WebViewData.hpp" +#include "widgets/WebView.hpp" class IWebViewMediator { public: IWebViewMediator() = default; virtual bool has_webview(WebViewId webview_id) = 0; - virtual void open_url(const QUrl &url, OpenType open_type, WebViewId webview_id) = 0; virtual void set_html(const QString &html, WebViewId webview_id) = 0; + virtual void expose_rpc_function(const QString &name, const RpcFunc &action, + WebViewId webview_id) = 0; }; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 698cb88..9ec8570 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -328,3 +328,8 @@ void WebViewStack::set_html(const QString &html, WebViewId webview_id) { webview->setHtml(html); } + +void WebViewStack::expose_rpc_function(const QString &name, const RpcFunc & /* unused */, + WebViewId /* unused */) { + qDebug() << "expose_rpc_function: NOT IMPLEMENTED" << name; +} diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 2096f25..27a1181 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -62,6 +62,8 @@ public slots: void scroll_to_top(WebViewId webview_id); void scroll_to_bottom(WebViewId webview_id); void set_html(const QString &html, WebViewId webview_id = 0) override; + void expose_rpc_function(const QString &name, const RpcFunc &action, + WebViewId webview_id) override; protected slots: void on_new_webview_request(QWebEngineNewWindowRequest &request); |
