aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-05-01 20:43:12 +0530
committerAkshay Nair <phenax5@gmail.com>2025-05-02 16:20:09 +0530
commitfab5f4d2fd80eb288265c64ba390460ac974ee81 (patch)
treeaced5984fceced0e621a885c8a38e8ddf88cd203
parent4afe7914a4d4f59703d14f9ba8470ed87831ddcb (diff)
downloadnull-browser-fab5f4d2fd80eb288265c64ba390460ac974ee81.tar.gz
null-browser-fab5f4d2fd80eb288265c64ba390460ac974ee81.zip
Make window requests open a tab instead
-rw-r--r--TODO.org6
-rw-r--r--spec/WebViewStackSpec.cpp10
-rw-r--r--src/widgets/WebViewStack.cpp7
-rw-r--r--src/widgets/WebViewStack.hpp3
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<WebView *>();
@@ -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>{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<WebViewData> 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 <QStackedLayout>
#include <QWebEngineProfile>
#include <cstdint>
+#include <functional>
#include <qwebengineprofile.h>
#include <vector>
@@ -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;