1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include <QWidget>
#include <QtCore>
#include "LuaRuntime.hpp"
#include "WindowActionRouter.hpp"
#include "widgets/WebViewStack.hpp"
WindowActionRouter::WindowActionRouter() {
auto *runtime = LuaRuntime::instance();
connect(runtime, &LuaRuntime::keymap_added, this,
[this](const QString &mode, const QString &keyseq,
const std::function<void()> &callback) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
emit mediator->keymap_added(mode, keyseq, callback);
}
});
connect(runtime, &LuaRuntime::history_back_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
if (mediator->has_webview(webview_id)) {
emit mediator->history_back_requested(webview_id,
history_index);
}
}
});
connect(runtime, &LuaRuntime::history_forward_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
if (mediator->has_webview(webview_id)) {
emit mediator->history_forward_requested(webview_id,
history_index);
}
}
});
connect(runtime, &LuaRuntime::url_opened, this,
[this](const QString &url, OpenType open_type, WebViewId webview_id) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
if (mediator->has_webview(webview_id)) {
emit mediator->url_opened(url, open_type, webview_id);
}
}
});
connect(runtime, &LuaRuntime::webview_closed, this,
[this](WebViewId webview_id) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
if (mediator->has_webview(webview_id)) {
emit mediator->webview_closed(webview_id);
}
}
});
connect(runtime, &LuaRuntime::webview_selected, this,
[this](WebViewId webview_id) {
for (auto &win : window_map) {
auto *mediator = win.second->mediator();
if (mediator->has_webview(webview_id)) {
emit mediator->webview_selected(webview_id);
}
}
});
}
void WindowActionRouter::add_window(BrowserWindow *window) {
window_map.insert({last_id, window});
last_id++;
}
const WindowMap &WindowActionRouter::windows() { return window_map; }
|