aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-04-05 20:46:53 +0530
committerAkshay Nair <phenax5@gmail.com>2025-04-05 20:46:53 +0530
commitb77a6444f94ce8d05962af9039c31851e224be5c (patch)
tree5a02fd175a8dbf706e509b4d6e7a8580b3944f2e /src/widgets
parent26504893e75fb33e9d3f01abdebf1d61f362f1b1 (diff)
downloadnull-browser-b77a6444f94ce8d05962af9039c31851e224be5c.tar.gz
null-browser-b77a6444f94ce8d05962af9039c31851e224be5c.zip
Fix new window handling + webviewstack tests
Diffstat (limited to '')
-rw-r--r--src/widgets/BrowserWindow.cpp2
-rw-r--r--src/widgets/WebViewStack.cpp32
2 files changed, 24 insertions, 10 deletions
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;
}