Skip to content

Truly independent web browser

UI/Qt: Size a hidden tab only until it has had a real size

Andreas Kling56a68f0cfd20
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index 58a82896556..015b01e7e43 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -1620,6 +1620,8 @@ void Tab::paintEvent(QPaintEvent*)
void Tab::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
+ if (isVisible())
+ did_get_real_size();
if (m_hover_label->isVisible())
update_hover_label();
}
diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h
index ed36aea6951..8c702b60026 100644
--- a/UI/Qt/Tab.h
+++ b/UI/Qt/Tab.h
@@ -86,6 +86,11 @@ public:
WebContentView& view() { return *m_view; }
WebContentView const& view() const { return *m_view; }
+ // A page that has never had a real size must be sized while hidden, so that it doesn't load into Qt's placeholder
+ // geometry. Once it has had one, it keeps its size while hidden and takes the window's when it is shown again.
+ bool has_had_real_size() const { return m_has_had_real_size; }
+ void did_get_real_size() { m_has_had_real_size = true; }
+
void navigate(URL::URL const&);
void load_html(StringView);
@@ -229,6 +234,7 @@ private:
QIcon m_favicon;
QTimer* m_loading_animation_timer { nullptr };
bool m_is_loading { false };
+ bool m_has_had_real_size { false };
bool m_is_updating_chrome_style { false };
bool m_vertical_tabs_enabled { false };
WebView::VerticalTabsPosition m_vertical_tabs_position { WebView::VerticalTabsPosition::Left };
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index 387f07b32d4..eb4ee2e14f9 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -9,6 +9,7 @@
#include <AK/ScopeGuard.h>
#include <AK/StdLibExtras.h>
#include <AK/kmalloc.h>
+#include <LibCore/EventLoop.h>
#include <UI/Qt/Application.h>
#include <UI/Qt/BrowserWindow.h>
#include <UI/Qt/ChromeLayout.h>
@@ -2070,10 +2071,23 @@ void TabWidget::add_tab(Tab* widget, QString const& label)
// Sizing the hidden page's view alone doesn't hold: The page itself still has its placeholder geometry, and the next
// pass of the page's own layout pulls the view back to it. So, give the whole page the current page's geometry, laid
// out now — and only then push the view's viewport.
+// NB: A page that already had a real size is left alone. Sizing it would have it lay out anew, and wake its WebContent,
+// at every step of a window resize, for a size it would never show. It takes the window's size when it is shown.
static void size_page_like(Tab& page, Tab const& current)
{
+ if (page.has_had_real_size())
+ return;
size_hidden_page_like(page, current);
page.view().push_viewport_size();
+
+ // NB: The current view takes several sizes in one turn of the event loop as the chrome around it settles, so the
+ // page has its real size only once the turn is over.
+ if (current.isVisible()) {
+ Core::deferred_invoke([page = QPointer<Tab>(&page)] {
+ if (page)
+ page->did_get_real_size();
+ });
+ }
}
void TabWidget::insert_tab(int index, Tab* widget, QString const& label)
@@ -2410,7 +2424,7 @@ void TabWidget::resizeEvent(QResizeEvent* event)
// The stacked layout sizes only the current page, so the tabs behind it keep stale geometry: Qt's default 100x30 for
// a tab that was created before the window was first shown — which is every tab but the first on a command line, and
// every restored one. Their pages may already be loading. So, whenever the current page's view gets its size, then size
-// every hidden page's view the same (Chrome keeps its background tabs at the window's size the same way).
+// every hidden page's view the same, until it has had a real size.
// NB: This hangs off the view's own resize event, not this widget's: At the window's first show, this widget is laid
// out before the current page's child layout has run. So at that point the current view still has its placeholder size.
void TabWidget::size_hidden_pages_like_the_current_one()