Skip to content

Truly independent web browser

UI/Qt: Keep background tabs in the order they were opened

Andreas Kling2dd83167ec22
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index ffb9cd552d5..b6597778fe9 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -897,7 +897,12 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, TabLocat
case TabLocation::Kind::End:
break;
case TabLocation::Kind::AfterCurrentTab:
- insertion_index = m_tabs_container->current_index() + 1;
+ insertion_index = constrain_insertion_index(m_tabs_container->current_index() + 1, false);
+ // Tabs opened in the background line up after the current tab in the order they were opened.
+ if (activate_tab == Web::HTML::ActivateTab::No) {
+ while (insertion_index < m_tabs_container->count() && m_background_tabs_from_current_tab.contains([&](auto const& background_tab) { return background_tab == m_tabs_container->tab(insertion_index); }))
+ ++insertion_index;
+ }
break;
case TabLocation::Kind::AfterTab:
if (auto* source_tab = location.tab(); source_tab) {
@@ -914,6 +919,8 @@ Tab& BrowserWindow::create_new_tab(Web::HTML::ActivateTab activate_tab, TabLocat
if (activate_tab == Web::HTML::ActivateTab::Yes)
m_tabs_container->set_current_tab(tab);
+ else if (location.kind() == TabLocation::Kind::AfterCurrentTab)
+ m_background_tabs_from_current_tab.append(tab);
initialize_tab(tab);
@@ -1124,6 +1131,7 @@ void BrowserWindow::set_current_tab(Tab* tab)
}
m_current_tab = tab;
+ m_background_tabs_from_current_tab.clear();
if (m_current_tab) {
m_current_tab->clear_attention();
@@ -2275,6 +2283,13 @@ void BrowserWindow::cancel_window_close_preflight()
});
}
+void BrowserWindow::on_tab_navigated_by_user(Tab& tab)
+{
+ // The user is moving on from the page that the background tabs were opened from.
+ if (&tab == m_current_tab)
+ m_background_tabs_from_current_tab.clear();
+}
+
void BrowserWindow::on_tab_load_start(Tab& tab)
{
if (!m_window_close_coordinator.is_running() && !m_window_close_approved)
diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.h
index b524a9bf481..6bd3f5e7594 100644
--- a/UI/Qt/BrowserWindow.h
+++ b/UI/Qt/BrowserWindow.h
@@ -197,6 +197,7 @@ public:
void report_activation_to_session_store();
void cancel_window_close_preflight();
void on_tab_load_start(Tab&);
+ void on_tab_navigated_by_user(Tab&);
FullscreenMode& fullscreen_mode();
LadybirdButton& ladybird_button() const { return m_tabs_container->ladybird_button(); }
@@ -327,6 +328,7 @@ private:
TabWidget* m_tabs_container { nullptr };
Tab* m_current_tab { nullptr };
+ Vector<QPointer<Tab>> m_background_tabs_from_current_tab;
DevToolsBanner* m_devtools_banner { nullptr };
QWidget* m_menu_bar_window_controls { nullptr };
diff --git a/UI/Qt/RemoteView.cpp b/UI/Qt/RemoteView.cpp
index ce3d8d9023f..866a3dba0dd 100644
--- a/UI/Qt/RemoteView.cpp
+++ b/UI/Qt/RemoteView.cpp
@@ -562,6 +562,9 @@ void RemoteView::did_make_link_to_highlight(Optional<URL::URL> url)
void RemoteView::load_from_user_input(URL::URL const& url)
{
+ if (on_load_from_user_input)
+ on_load_from_user_input();
+
if (!WebView::is_url_handled_internally(url)) {
open_external_url_from_user_input(url);
return;
@@ -576,6 +579,9 @@ void RemoteView::load_from_user_input(StringView input)
void RemoteView::load_from_user_input(StringView input, Optional<URL::URL> fallback_url)
{
+ if (on_load_from_user_input)
+ on_load_from_user_input();
+
auto classified_input = WebView::classify_user_input(input);
if (classified_input.classification != WebView::UserInputClassification::ExternalURL) {
diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.h
index c10e9d8d9b3..7f5c5451854 100644
--- a/UI/Qt/RemoteView.h
+++ b/UI/Qt/RemoteView.h
@@ -317,6 +317,7 @@ private:
public:
decltype(Hub::View::on_load_start) on_load_start;
decltype(Hub::View::on_load_finish) on_load_finish;
+ Function<void()> on_load_from_user_input;
decltype(Hub::View::on_ready_to_paint) on_ready_to_paint;
decltype(Hub::View::on_performance_stats) on_performance_stats;
Function<void(Web::HTML::ActivateTab, Web::HTML::WebViewHints, u64 view_id)> on_open_new_view;
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 05171517523..d7e2730caf9 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -348,6 +348,9 @@ void Tab::initialize(Optional<u64> hub_view_id)
view().on_load_start = [this] {
m_window->on_tab_load_start(*this);
};
+ view().on_load_from_user_input = [this] {
+ m_window->on_tab_navigated_by_user(*this);
+ };
set_loading(view().is_loading());
view().on_load_finish = [this](auto const&) {
@@ -1092,6 +1095,7 @@ void Tab::location_edit_return_pressed(String input, Optional<URL::URL> fallback
view().set_next_history_visit_transition(WebView::HistoryVisitTransition::Omnibox);
if (destination_kind == WebView::OmniboxDestinationKind::Search) {
+ m_window->on_tab_navigated_by_user(*this);
if (fallback_url.has_value())
view().load(*fallback_url);
else