From fab5f4d2fd80eb288265c64ba390460ac974ee81 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 1 May 2025 20:43:12 +0530 Subject: Make window requests open a tab instead --- TODO.org | 6 +++--- spec/WebViewStackSpec.cpp | 10 +++++----- src/widgets/WebViewStack.cpp | 7 +++++-- src/widgets/WebViewStack.hpp | 3 ++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/TODO.org b/TODO.org index 29f3759..61d7cef 100644 --- a/TODO.org +++ b/TODO.org @@ -8,12 +8,12 @@ - [X] Searchengines - [X] Scroll api (for j/k/h/l/gg/G) - [X] table extend/merge +- [X] window.opener controls (use tab for now?) - [ ] Tests for api -- [ ] Fullscreen -- [ ] Zoom in/out - [ ] Permission requests handling/persisting - [ ] Notifications -- [ ] window.opener controls (use createWindow api directly?) +- [ ] Fullscreen +- [ ] Zoom in/out ** Bugs - [ ] INVESTIGATE: segfault on api module error diff --git a/spec/WebViewStackSpec.cpp b/spec/WebViewStackSpec.cpp index a63eca6..8391dbe 100644 --- a/spec/WebViewStackSpec.cpp +++ b/spec/WebViewStackSpec.cpp @@ -241,7 +241,6 @@ private slots: 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(); @@ -249,11 +248,12 @@ private slots: 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); + QCOMPARE(webview_stack.count(), 2); + QCOMPARE(webview_stack.urls(), + (std::vector{QUrl("https://a.com"), QUrl("https://new.com")})); + QCOMPARE(webview_stack.current_webview_index(), 1); + QCOMPARE(webview_stack.current_url(), QUrl("https://new.com")); } } }; diff --git a/src/widgets/WebViewStack.cpp b/src/widgets/WebViewStack.cpp index 53224c5..c48a363 100644 --- a/src/widgets/WebViewStack.cpp +++ b/src/widgets/WebViewStack.cpp @@ -80,7 +80,7 @@ QList WebViewStack::get_webview_list() { return urls; } -void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &request) { +void WebViewStack::on_new_webview_request(QWebEngineNewWindowRequest &request) { switch (request.destination()) { case QWebEngineNewWindowRequest::InNewTab: open_url(request.requestedUrl(), OpenType::OpenUrlInView); @@ -90,7 +90,10 @@ void WebViewStack::on_new_webview_request(const QWebEngineNewWindowRequest &requ break; case QWebEngineNewWindowRequest::InNewWindow: case QWebEngineNewWindowRequest::InNewDialog: - emit new_window_requested(request.requestedUrl()); + // NOTE: Using tabs for now instead of windows + auto *webview = create_new_webview(request.requestedUrl(), true); + request.openIn(webview->page()); + // emit new_window_requested(request.requestedUrl()); break; } } diff --git a/src/widgets/WebViewStack.hpp b/src/widgets/WebViewStack.hpp index 6e17753..1b8b288 100644 --- a/src/widgets/WebViewStack.hpp +++ b/src/widgets/WebViewStack.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -72,7 +73,7 @@ public slots: void scroll_to_bottom(WebViewId webview_id); protected slots: - void on_new_webview_request(const QWebEngineNewWindowRequest &request); + void on_new_webview_request(QWebEngineNewWindowRequest &request); private: const Configuration *configuration; -- cgit v1.3.1