aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/WebViewStackSpec.cpp244
-rw-r--r--spec/testUtils.h36
-rw-r--r--src/WindowActionRouter.cpp44
-rw-r--r--src/WindowActionRouter.hpp15
-rw-r--r--src/widgets/BrowserWindow.cpp2
-rw-r--r--src/widgets/WebViewStack.cpp32
6 files changed, 166 insertions, 207 deletions
diff --git a/spec/WebViewStackSpec.cpp b/spec/WebViewStackSpec.cpp
index 06443ad..0559b43 100644
--- a/spec/WebViewStackSpec.cpp
+++ b/spec/WebViewStackSpec.cpp
@@ -3,6 +3,7 @@
#include <vector>
#include "Configuration.hpp"
+#include "LuaRuntime.hpp"
#include "testUtils.h"
#include "widgets/WebView.hpp"
#include "widgets/WebViewStack.hpp"
@@ -13,178 +14,118 @@ class WebViewStackSpec : public QObject {
class FakeNewWindowRequest : public QWebEngineNewWindowRequest {
public:
- FakeNewWindowRequest(DestinationType t, const QRect &r, const QUrl &u,
- bool b)
+ FakeNewWindowRequest(DestinationType t, const QRect &r, const QUrl &u, bool b)
: QWebEngineNewWindowRequest(t, r, u, b, nullptr) {}
};
private slots:
+ void beforeTestCase() { LuaRuntime::instance().start_event_loop(); }
+ void cleanupTestCase() { LuaRuntime::instance().stop_event_loop(); }
+
void test_initial_state() {
context("when initialized");
- it("opens a single tab") {
+ it("opens an empty stack maintaining current url") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- QCOMPARE(webview_stack.count(), 1);
+ QCOMPARE(webview_stack.count(), 0);
QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
- webview_stack.deleteLater();
}
}
void test_open_url() {
- context("when openUrl is called without an open type");
- it("replaces current tab url with newtab url") {
+ context("when openUrl is called with an empty stack");
+ it("opens a new webview") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- webview_stack.open_url(QUrl("http://a.com"), OpenType::OpenUrl);
+ QCOMPARE(webview_stack.count(), 0);
- webview_stack.open_url(QUrl(configuration.new_tab_url));
+ webview_stack.open_url(QUrl("http://a.com"));
QCOMPARE(webview_stack.count(), 1);
- std::vector<QUrl> urls = {QUrl(configuration.new_tab_url)};
- QCOMPARE(webview_stack.urls(), urls);
+ QCOMPARE(webview_stack.urls(), (std::vector<QUrl>{QUrl("http://a.com")}));
QCOMPARE(webview_stack.current_webview_index(), 0);
- QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
+ QCOMPARE(webview_stack.current_url(), QUrl("http://a.com"));
}
- context("when creating a new webview with a url and focus is false");
+ context("when openUrl is called with webviews open");
+ it("replaces current tab url with newtab url") {
+ Configuration configuration;
+ WebViewStack webview_stack(&configuration);
+ webview_stack.open_url(QUrl("http://a.com"));
+ webview_stack.open_url(QUrl("http://b.com"), OpenType::OpenUrlInTab);
+ QCOMPARE(webview_stack.count(), 2);
+ QCOMPARE(webview_stack.current_webview_index(), 1);
+
+ webview_stack.open_url(QUrl("http://new-b.com"));
+
+ QCOMPARE(webview_stack.count(), 2);
+ QCOMPARE(webview_stack.urls(), (std::vector<QUrl>{
+ QUrl("http://a.com"),
+ QUrl("http://new-b.com"),
+ }));
+ QCOMPARE(webview_stack.current_webview_index(), 1);
+ QCOMPARE(webview_stack.current_url(), QUrl("http://new-b.com"));
+ }
+
+ context("when openurl is called with OpenUrlInBgTab");
it("opens the given url in background") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
+ webview_stack.open_url(QUrl("http://a.com"));
- webview_stack.open_url(QUrl("https://duckduckgo.com"),
- OpenType::OpenUrlInBgTab);
+ webview_stack.open_url(QUrl("https://duckduckgo.com"), OpenType::OpenUrlInBgTab);
QCOMPARE(webview_stack.count(), 2);
- std::vector<QUrl> urls = {QUrl(configuration.new_tab_url),
- QUrl("https://duckduckgo.com")};
- QCOMPARE(webview_stack.urls(), urls);
+ QCOMPARE(webview_stack.urls(),
+ (std::vector<QUrl>{QUrl("http://a.com"), QUrl("https://duckduckgo.com")}));
QCOMPARE(webview_stack.current_webview_index(), 0);
- QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
+ QCOMPARE(webview_stack.current_url(), QUrl("http://a.com"));
}
- context("when creating a new webview with a url and focus is true");
+ context("when openurl is called with OpenUrlInTab");
it("opens the given url as current view") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
+ webview_stack.open_url(QUrl("http://a.com"));
- webview_stack.open_url(QUrl("https://duckduckgo.com"),
- OpenType::OpenUrlInTab);
+ webview_stack.open_url(QUrl("https://duckduckgo.com"), OpenType::OpenUrlInTab);
QCOMPARE(webview_stack.count(), 2);
- std::vector<QUrl> urls = {QUrl(configuration.new_tab_url),
- QUrl("https://duckduckgo.com")};
- QCOMPARE(webview_stack.urls(), urls);
+ QCOMPARE(webview_stack.urls(),
+ (std::vector<QUrl>{QUrl("http://a.com"), QUrl("https://duckduckgo.com")}));
QCOMPARE(webview_stack.current_webview_index(), 1);
QCOMPARE(webview_stack.current_url(), QUrl("https://duckduckgo.com"));
}
- }
- // void test_next_navigation() {
- // context("when nextWebView is called");
- // context("- and there is only 1 tab");
- // it("does nothing") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- //
- // webview_stack.next();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 0);
- // QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
- // }
- //
- // context("when nextWebView is called");
- // context("- and there are tabs after the current tab");
- // it("goes to the next tab") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- // webview_stack.open_url(QUrl("http://a1.com"),
- // OpenType::OpenUrlInBgTab);
- // webview_stack.open_url(QUrl("http://a2.com"),
- // OpenType::OpenUrlInBgTab);
- //
- // webview_stack.next();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 1);
- // QCOMPARE(webview_stack.current_url(), QUrl("http://a1.com"));
- // }
- //
- // context("when nextWebView is called");
- // context("- and current tab is the last tab");
- // it("jumps to the first tab") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- // webview_stack.open_url(QUrl("http://a1.com"),
- // OpenType::OpenUrlInBgTab);
- // webview_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInTab);
- // QCOMPARE(webview_stack.current_webview_index(), 2);
- //
- // webview_stack.next();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 0);
- // QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
- // }
- // }
- //
- // void test_previous_navigation() {
- // context("when previousWebView is called");
- // context("- and there is only 1 tab");
- // it("does nothing") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- //
- // webview_stack.previous();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 0);
- // QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
- // }
- //
- // context("when previousWebView is called");
- // context("- and there are tabs before the current tab");
- // it("goes to the next tab") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- // webview_stack.open_url(QUrl("http://a1.com"),
- // OpenType::OpenUrlInBgTab);
- // webview_stack.open_url(QUrl("http://a2.com"), OpenType::OpenUrlInTab);
- // QCOMPARE(webview_stack.current_webview_index(), 2);
- //
- // webview_stack.previous();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 1);
- // QCOMPARE(webview_stack.current_url(), QUrl("http://a1.com"));
- // }
- //
- // context("when previousWebView is called");
- // context("- and current tab is the last tab");
- // it("jumps to the last tab") {
- // Configuration configuration;
- // WebViewStack webview_stack(&configuration);
- // webview_stack.open_url(QUrl("http://a1.com"),
- // OpenType::OpenUrlInBgTab);
- // webview_stack.open_url(QUrl("http://a2.com"),
- // OpenType::OpenUrlInBgTab);
- //
- // webview_stack.previous();
- //
- // QCOMPARE(webview_stack.current_webview_index(), 2);
- // QCOMPARE(webview_stack.current_url(), QUrl("http://a2.com"));
- // }
- // }
+ context("when openurl is called with OpenUrlInWindow");
+ it("requests a new window") {
+ Configuration configuration;
+ WebViewStack webview_stack(&configuration);
+ QSignalSpy new_window_requested_spy(&webview_stack, &WebViewStack::new_window_requested);
+ webview_stack.open_url(QUrl("http://a.com"));
+
+ webview_stack.open_url(QUrl("https://duckduckgo.com"), OpenType::OpenUrlInWindow);
+ new_window_requested_spy.wait(100);
+
+ QCOMPARE(new_window_requested_spy.count(), 1);
+ QCOMPARE(new_window_requested_spy.takeFirst().at(0), QUrl("https://duckduckgo.com"));
+ QCOMPARE(webview_stack.count(), 1);
+ }
+ }
void test_close() {
context("when close is called");
context("- with invalid id");
- xit("does nothing") {
+ it("does nothing") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- webview_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl);
+ webview_stack.open_url(QUrl("https://a.com"));
webview_stack.close(99);
QCOMPARE(webview_stack.count(), 1);
- QCOMPARE(webview_stack.urls(),
- (std::vector<QUrl>{QUrl("https://a.com")}));
+ QCOMPARE(webview_stack.urls(), (std::vector<QUrl>{QUrl("https://a.com")}));
QCOMPARE(webview_stack.current_webview_index(), 0);
QCOMPARE(webview_stack.current_url(), QUrl("https://a.com"));
}
@@ -194,14 +135,13 @@ private slots:
it("closes the tab and opens empty tab in its place") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- webview_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl);
+ webview_stack.open_url(QUrl("https://a.com"));
QCOMPARE(webview_stack.count(), 1);
webview_stack.close(webview_stack.current_webview_id());
QCOMPARE(webview_stack.count(), 1);
- QCOMPARE(webview_stack.urls(),
- (std::vector<QUrl>{configuration.new_tab_url}));
+ QCOMPARE(webview_stack.urls(), (std::vector<QUrl>{configuration.new_tab_url}));
QCOMPARE(webview_stack.current_webview_index(), 0);
QCOMPARE(webview_stack.current_url(), configuration.new_tab_url);
}
@@ -212,6 +152,7 @@ private slots:
it("closes the tab and focuses the next tab") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
+ webview_stack.open_url(QUrl("https://a0.com"));
webview_stack.open_url(QUrl("https://a1.com"), OpenType::OpenUrlInTab);
webview_stack.open_url(QUrl("https://a2.com"), OpenType::OpenUrlInBgTab);
QCOMPARE(webview_stack.count(), 3);
@@ -221,8 +162,7 @@ private slots:
QCOMPARE(webview_stack.count(), 2);
QCOMPARE(webview_stack.urls(),
- (std::vector<QUrl>{configuration.new_tab_url,
- QUrl("https://a2.com")}));
+ (std::vector<QUrl>{QUrl("https://a0.com"), QUrl("https://a2.com")}));
QCOMPARE(webview_stack.current_webview_index(), 1);
QCOMPARE(webview_stack.current_url(), QUrl("https://a2.com"));
}
@@ -233,6 +173,7 @@ private slots:
it("closes the tab and focuses previous tab") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
+ webview_stack.open_url(QUrl("https://a0.com"));
webview_stack.open_url(QUrl("https://a1.com"), OpenType::OpenUrlInBgTab);
webview_stack.open_url(QUrl("https://a2.com"), OpenType::OpenUrlInTab);
QCOMPARE(webview_stack.count(), 3);
@@ -242,8 +183,7 @@ private slots:
QCOMPARE(webview_stack.count(), 2);
QCOMPARE(webview_stack.urls(),
- (std::vector<QUrl>{configuration.new_tab_url,
- QUrl("https://a1.com")}));
+ (std::vector<QUrl>{QUrl("https://a0.com"), QUrl("https://a1.com")}));
QCOMPARE(webview_stack.current_webview_index(), 1);
QCOMPARE(webview_stack.current_url(), QUrl("https://a1.com"));
}
@@ -252,46 +192,62 @@ private slots:
void test_new_window_request_signal() {
context("when webview emits a newWindowRequested signal");
context("- of type new tab");
- xit("opens a new web view and focusses it") {
+ it("opens a new web view and focuses it") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- webview_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl);
+ webview_stack.open_url(QUrl("https://a.com"));
auto *webview = webview_stack.findChild<WebView *>();
QCOMPARE(webview_stack.count(), 1);
- FakeNewWindowRequest window_request(
- FakeNewWindowRequest::DestinationType::InNewTab, QRect(0, 0, 0, 0),
- QUrl("https://new.com"), true);
+ FakeNewWindowRequest window_request(FakeNewWindowRequest::DestinationType::InNewTab,
+ QRect(0, 0, 0, 0), QUrl("https://new.com"), true);
emit webview->page()->newWindowRequested(window_request);
QCOMPARE(webview_stack.count(), 2);
- QCOMPARE(
- webview_stack.urls(),
- (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")}));
+ QCOMPARE(webview_stack.urls(),
+ (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")}));
QCOMPARE(webview_stack.current_webview_index(), 1);
QCOMPARE(webview_stack.current_url(), QUrl("https://new.com"));
}
context("when webview emits a newWindowRequested signal");
context("- of type new background tab");
- xit("opens a new web view in the background") {
+ it("opens a new web view in the background") {
Configuration configuration;
WebViewStack webview_stack(&configuration);
- webview_stack.open_url(QUrl("https://a.com"), OpenType::OpenUrl);
+ webview_stack.open_url(QUrl("https://a.com"));
auto *webview = webview_stack.findChild<WebView *>();
- FakeNewWindowRequest window_request(
- FakeNewWindowRequest::DestinationType::InNewBackgroundTab,
- QRect(0, 0, 0, 0), QUrl("https://new.com"), true);
+ FakeNewWindowRequest window_request(FakeNewWindowRequest::DestinationType::InNewBackgroundTab,
+ QRect(0, 0, 0, 0), QUrl("https://new.com"), true);
emit webview->page()->newWindowRequested(window_request);
QCOMPARE(webview_stack.count(), 2);
- QCOMPARE(
- webview_stack.urls(),
- (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")}));
+ QCOMPARE(webview_stack.urls(),
+ (std::vector<QUrl>{QUrl("https://a.com"), QUrl("https://new.com")}));
QCOMPARE(webview_stack.current_webview_index(), 0);
QCOMPARE(webview_stack.current_url(), QUrl("https://a.com"));
}
+
+ context("when webview emits a newWindowRequested signal");
+ context("- of type new window");
+ it("requests a new window") {
+ Configuration configuration;
+ WebViewStack webview_stack(&configuration);
+ QSignalSpy new_window_requested_spy(&webview_stack, &WebViewStack::new_window_requested);
+ webview_stack.open_url(QUrl("https://a.com"));
+ QCOMPARE(webview_stack.count(), 1);
+ auto *webview = webview_stack.findChild<WebView *>();
+
+ FakeNewWindowRequest window_request(FakeNewWindowRequest::DestinationType::InNewWindow,
+ QRect(0, 0, 0, 0), QUrl("https://new.com"), true);
+ emit webview->page()->newWindowRequested(window_request);
+ new_window_requested_spy.wait(100);
+
+ QCOMPARE(new_window_requested_spy.count(), 1);
+ QCOMPARE(new_window_requested_spy.takeFirst().at(0), QUrl("https://new.com"));
+ QCOMPARE(webview_stack.count(), 1);
+ }
}
};
diff --git a/spec/testUtils.h b/spec/testUtils.h
index 0ba2e9a..37bc9f9 100644
--- a/spec/testUtils.h
+++ b/spec/testUtils.h
@@ -12,16 +12,18 @@
#define COLOR_SKIP "\x1b[33m" ANSI_BOLD
#define ANSI_RESET "\x1b[0m"
-#define context(msg) printf("⚪" COLOR_CONTEXT "%s" ANSI_RESET "\n", msg);
+#define context(msg) \
+ printf("⚪" COLOR_CONTEXT "%s" ANSI_RESET "\n", msg); \
+ fflush(stdout);
-#define it(msg) \
- printf(" ⚪" ANSI_BOLD COLOR_IT "it " ANSI_RESET COLOR_IT "%s" ANSI_RESET \
- "\n", \
- msg); \
+#define it(msg) \
+ printf(" ⚪" ANSI_BOLD COLOR_IT "it " ANSI_RESET COLOR_IT "%s" ANSI_RESET "\n", msg); \
+ fflush(stdout); \
if (1)
-#define xit(msg) \
- printf(" ⚪" COLOR_SKIP "SKIPPED it %s" ANSI_RESET "\n", msg); \
+#define xit(msg) \
+ printf(" ⚪" COLOR_SKIP "SKIPPED it %s" ANSI_RESET "\n", msg); \
+ fflush(stdout); \
if (0)
#define STRINGIFY(x) #x
@@ -29,16 +31,16 @@
std::vector<std::function<QObject *()>> &get_qtest_registry();
int run_all_tests();
-#define QTEST_REGISTER(klass) \
- namespace { \
- const bool registered__##klass = []() { \
- get_qtest_registry().push_back([]() { \
- auto test = new (klass); \
- test->setObjectName(#klass); \
- return test; \
- }); \
- return true; \
- }(); \
+#define QTEST_REGISTER(klass) \
+ namespace { \
+ const bool registered__##klass = []() { \
+ get_qtest_registry().push_back([]() { \
+ auto test = new (klass); \
+ test->setObjectName(#klass); \
+ return test; \
+ }); \
+ return true; \
+ }(); \
};
bool wait_for_lua_to_be_true(QString lua_code);
diff --git a/src/WindowActionRouter.cpp b/src/WindowActionRouter.cpp
index 8c80290..c1051ad 100644
--- a/src/WindowActionRouter.cpp
+++ b/src/WindowActionRouter.cpp
@@ -12,21 +12,18 @@
void WindowActionRouter::initialize() {
auto &runtime = LuaRuntime::instance();
- connect(&runtime, &LuaRuntime::keymap_added, this,
- &WindowActionRouter::add_keymap);
+ connect(&runtime, &LuaRuntime::keymap_added, this, &WindowActionRouter::add_keymap);
connect(&runtime, &LuaRuntime::history_back_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
WITH_WEBVIEW_WINDOW(webview_id, window, {
- emit window->mediator()->history_back_requested(webview_id,
- history_index);
+ emit window->mediator()->history_back_requested(webview_id, history_index);
});
});
connect(&runtime, &LuaRuntime::history_forward_requested, this,
[this](WebViewId webview_id, qsizetype history_index) {
WITH_WEBVIEW_WINDOW(webview_id, window, {
- emit window->mediator()->history_forward_requested(webview_id,
- history_index);
+ emit window->mediator()->history_forward_requested(webview_id, history_index);
});
});
connect(&runtime, &LuaRuntime::url_opened, this,
@@ -35,18 +32,14 @@ void WindowActionRouter::initialize() {
emit window->mediator()->url_opened(url, open_type, webview_id);
});
});
- connect(&runtime, &LuaRuntime::webview_closed, this,
- [this](WebViewId webview_id) {
- WITH_WEBVIEW_WINDOW(webview_id, window, {
- emit window->mediator()->webview_closed(webview_id);
- });
- });
- connect(&runtime, &LuaRuntime::webview_selected, this,
- [this](WebViewId webview_id) {
- WITH_WEBVIEW_WINDOW(webview_id, window, {
- emit window->mediator()->webview_selected(webview_id);
- });
- });
+ connect(&runtime, &LuaRuntime::webview_closed, this, [this](WebViewId webview_id) {
+ WITH_WEBVIEW_WINDOW(webview_id, window,
+ { emit window->mediator()->webview_closed(webview_id); });
+ });
+ connect(&runtime, &LuaRuntime::webview_selected, this, [this](WebViewId webview_id) {
+ WITH_WEBVIEW_WINDOW(webview_id, window,
+ { emit window->mediator()->webview_selected(webview_id); });
+ });
}
void WindowActionRouter::add_window(BrowserWindow *window) {
@@ -55,16 +48,14 @@ void WindowActionRouter::add_window(BrowserWindow *window) {
window_map.insert({win_id, window});
window->set_id(win_id);
- connect(window, &BrowserWindow::closed, this,
- [this, win_id]() { window_map.erase(win_id); });
+ connect(window, &BrowserWindow::closed, this, [this, win_id]() { window_map.erase(win_id); });
connect(window->mediator(), &WindowMediator::new_window_requested, this,
&WindowActionRouter::new_window_requested);
}
const WindowMap &WindowActionRouter::windows() { return window_map; }
-void WindowActionRouter::add_keymap(const QString &mode_string,
- const QString &keyseq,
+void WindowActionRouter::add_keymap(const QString &mode_string, const QString &keyseq,
std::function<void()> action) {
auto &keymap_evaluator = KeymapEvaluator::instance();
const KeyMode mode = keymap_evaluator.mode_from_string(mode_string);
@@ -74,8 +65,7 @@ void WindowActionRouter::add_keymap(const QString &mode_string,
WebViewId WindowActionRouter::fetch_current_tab_id(WindowId win_id) {
for (auto &pair : window_map) {
auto *win = pair.second;
- auto is_current_window =
- win_id == win->get_id() || (win_id == 0 && win->isActiveWindow());
+ auto is_current_window = win_id == win->get_id() || (win_id == 0 && win->isActiveWindow());
if (is_current_window) {
return win->mediator()->current_webview_id();
}
@@ -83,12 +73,10 @@ WebViewId WindowActionRouter::fetch_current_tab_id(WindowId win_id) {
return 0;
}
-QList<WebViewData>
-WindowActionRouter::fetch_webview_data_list(WindowId win_id) {
+QList<WebViewData> WindowActionRouter::fetch_webview_data_list(WindowId win_id) {
for (auto &pair : window_map) {
auto *win = pair.second;
- auto is_current_window =
- win_id == win->get_id() || (win_id == 0 && win->isActiveWindow());
+ auto is_current_window = win_id == win->get_id() || (win_id == 0 && win->isActiveWindow());
if (is_current_window) {
return win->mediator()->get_webview_list();
}
diff --git a/src/WindowActionRouter.hpp b/src/WindowActionRouter.hpp
index b72734c..c72aaaf 100644
--- a/src/WindowActionRouter.hpp
+++ b/src/WindowActionRouter.hpp
@@ -9,12 +9,12 @@
#include "widgets/BrowserWindow.hpp"
#include "widgets/WebViewStack.hpp"
-#define WITH_WEBVIEW_WINDOW(WEBVIEW_ID, IDENT, BLOCK) \
- for (auto &win_match : window_map) { \
- auto *IDENT = win_match.second; \
- if (IDENT->mediator()->has_webview(WEBVIEW_ID)) { \
- BLOCK; \
- } \
+#define WITH_WEBVIEW_WINDOW(WEBVIEW_ID, IDENT, BLOCK) \
+ for (auto &win_match : window_map) { \
+ auto *IDENT = win_match.second; \
+ if (IDENT->mediator()->has_webview(WEBVIEW_ID)) { \
+ BLOCK; \
+ } \
}
class WindowActionRouter : public QWidget {
@@ -40,8 +40,7 @@ public:
protected:
WindowActionRouter() = default;
- void add_keymap(const QString &mode_string, const QString &keyseq,
- std::function<void()> action);
+ void add_keymap(const QString &mode_string, const QString &keyseq, std::function<void()> action);
signals:
void new_window_requested(const QUrl &url);
diff --git a/src/widgets/BrowserWindow.cpp b/src/widgets/BrowserWindow.cpp
index 2867379..aad551d 100644
--- a/src/widgets/BrowserWindow.cpp
+++ b/src/widgets/BrowserWindow.cpp
@@ -26,7 +26,7 @@ BrowserWindow::BrowserWindow(const Configuration &configuration, const QStringLi
// Open webviews for given urls
if (urls.isEmpty()) {
- webview_stack->open_url(configuration.new_tab_url.toString(), OpenType::OpenUrlInTab);
+ webview_stack->open_url(configuration.new_tab_url.toString());
} else {
for (const auto &url : urls) {
webview_stack->open_url(url, OpenType::OpenUrlInTab);
diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp
index f5e9765..ae95ea6 100644
--- a/src/widgets/WebViewStack.cpp
+++ b/src/widgets/WebViewStack.cpp
@@ -35,7 +35,7 @@ void WebViewStack::open_url(const QUrl &url, OpenType open_type, WebViewId webvi
create_new_webview(url, false);
break;
case OpenType::OpenUrlInWindow:
- create_new_webview(url, true);
+ emit new_window_requested(url);
break;
}
}
@@ -68,20 +68,23 @@ WebView *WebViewStack::create_new_webview(const QUrl &url, bool focus) {
QList<WebViewData> WebViewStack::get_webview_list() {
QList<WebViewData> urls;
- for (auto &view : webview_list)
- urls.append(
- WebViewData{.id = view->get_id(), .url = view->url().toString(), .title = view->title()});
+ for (auto &view : webview_list) {
+ urls.append(WebViewData{
+ .id = view->get_id(),
+ .url = view->url().toString(),
+ .title = view->title(),
+ });
+ }
return urls;
}
void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &request) {
- qDebug() << request.destination();
switch (request.destination()) {
case QWebEngineNewWindowRequest::InNewTab:
- create_new_webview(request.requestedUrl(), true);
+ open_url(request.requestedUrl(), OpenType::OpenUrlInTab);
break;
case QWebEngineNewWindowRequest::InNewBackgroundTab:
- create_new_webview(request.requestedUrl(), false);
+ open_url(request.requestedUrl(), OpenType::OpenUrlInBgTab);
break;
case QWebEngineNewWindowRequest::InNewWindow:
case QWebEngineNewWindowRequest::InNewDialog:
@@ -202,13 +205,18 @@ QUrl WebViewStack::current_url() {
auto *webview = current_webview();
if (webview == nullptr) {
qDebug() << "No current webview";
- return QUrl{};
+ return configuration->new_tab_url;
}
return webview->url();
}
void WebViewStack::set_current_url(const QUrl &url) {
+ if (count() == 0) {
+ create_new_webview(url, true);
+ return;
+ }
+
auto *webview = current_webview();
if (webview == nullptr) {
qDebug() << "No current webview";
@@ -217,10 +225,16 @@ void WebViewStack::set_current_url(const QUrl &url) {
webview->setUrl(url);
}
+
void WebViewStack::set_webview_url(const QUrl &url, WebViewId webview_id) {
+ if (webview_id == 0) {
+ set_current_url(url);
+ return;
+ }
+
auto *webview = get_webview(webview_id);
if (webview == nullptr) {
- qDebug() << "No current webview";
+ qDebug() << "Webview does not exist";
return;
}