Truly independent web browser
UI/Qt: Show the tab performance monitor in a row of its own
Andreas Kling072ee4f7b2a0
diff --git a/Documentation/TabPerformanceMonitor.md b/Documentation/TabPerformanceMonitor.mdindex 43aeb62d035..95b4f5ef2e8 100644--- a/Documentation/TabPerformanceMonitor.md+++ b/Documentation/TabPerformanceMonitor.md@@ -6,7 +6,7 @@Enable **Show Tab Performance Monitor** in the **Debug** menu, which **ShowDebug menu** in **Settings → Advanced** turns on, or set`debug.ui.show_tab_performance_monitor` to `true`. It defaults to `false`.-The UI's toolbars display the current tab's statistics inline.+A row of its own below the page displays the current tab's statistics.Each tab retains its own CPU history while monitoring is enabled.`LibWebView::TabPerformanceMonitor` resolves browser ownership and suppliesdiff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cppindex 47d293c3247..550865853bf 100644--- a/UI/Qt/TabBar.cpp+++ b/UI/Qt/TabBar.cpp@@ -4698,12 +4698,14 @@ void TabWidget::rebuild_page_column()add_page_to_page_column();}-// The bookmarks bar heads the page, unless it only shows over the page while the pointer is near the toolbar.+// The bookmarks bar heads the page, unless it only shows over the page while the pointer is near the toolbar. The tab+// performance monitor's row ends the column.void TabWidget::add_page_to_page_column(){if (!m_bookmarks_bar->shows_over_page())m_page_column_layout->addWidget(m_bookmarks_bar);m_page_column_layout->addWidget(m_stacked_widget, 1);+ m_page_column_layout->addWidget(&m_toolbar->performance_monitor_row());}void TabWidget::update_bookmarks_bar_visibility()diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cppindex e6bb1f10ae7..ddafa60d4dc 100644--- a/UI/Qt/WindowToolbar.cpp+++ b/UI/Qt/WindowToolbar.cpp@@ -630,6 +630,7 @@ static constexpr int SIDEBAR_FIELD_BOTTOM_MARGIN = 8;static constexpr int SIDEBAR_FOOTER_HEIGHT = 40;// NB: The container draws the line under the toolbar along its bottom edge, below the toolbar's full height.static constexpr int TOOLBAR_BOTTOM_LINE_HEIGHT = 1;+static constexpr int PERFORMANCE_MONITOR_ROW_MARGIN = 2;// The address field and its suggestions are one surface. While it lists suggestions, the field grows downward into it,// as wide as the field in a toolbar row, but no narrower than the minimum, and this wide over the page in the sidebar. It// stays this far from the window's edge.@@ -1230,9 +1231,17 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)m_location_edit_layout = new QHBoxLayout(m_location_edit_container);m_location_edit_layout->setSpacing(0);- m_performance_monitor = new PerformanceMonitorWidget(m_toolbar);+ m_performance_monitor_row = new QWidget(this);+ m_performance_monitor_row->setAutoFillBackground(true);+ // NB: The monitor is wider than a narrow window, which it shouldn't hold open.+ m_performance_monitor_row->setMinimumWidth(1);+ auto* performance_monitor_row_layout = new QHBoxLayout(m_performance_monitor_row);+ performance_monitor_row_layout->setContentsMargins(TOOLBAR_HORIZONTAL_MARGIN, PERFORMANCE_MONITOR_ROW_MARGIN, TOOLBAR_HORIZONTAL_MARGIN, PERFORMANCE_MONITOR_ROW_MARGIN);+ m_performance_monitor = new PerformanceMonitorWidget(m_performance_monitor_row);+ performance_monitor_row_layout->addWidget(m_performance_monitor);+ performance_monitor_row_layout->addStretch(1);(void)WebView::TabPerformanceMonitor::the();- m_performance_monitor->setVisible(WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowTabPerformanceMonitor));+ update_performance_monitor_row();m_sidebar_slot = new QWidget(m_toolbar);m_sidebar_slot->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);@@ -1298,7 +1307,6 @@ void WindowToolbar::lay_out_as_row()toolbar_layout->addWidget(m_downloads_button, 0, Qt::AlignVCenter);if (m_feedback_button)toolbar_layout->addWidget(m_feedback_button, 0, Qt::AlignVCenter);- toolbar_layout->addWidget(m_performance_monitor, 0, Qt::AlignVCenter);if constexpr (!use_native_macos_window_controls()) {toolbar_layout->addWidget(m_window_controls_separator, 0, Qt::AlignVCenter);toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);@@ -1340,7 +1348,6 @@ void WindowToolbar::lay_out_in_sidebar()footer_layout->addWidget(m_downloads_button, 0, Qt::AlignVCenter);if (m_feedback_button)footer_layout->addWidget(m_feedback_button, 0, Qt::AlignVCenter);- footer_layout->addWidget(m_performance_monitor, 0, Qt::AlignVCenter);footer_layout->setContentsMargins(m_sidebar_inset, 0, m_sidebar_inset, 0);layout()->setContentsMargins(0, 0, 0, 0);@@ -1814,6 +1821,10 @@ bool WindowToolbar::event(QEvent* event)recreate_icons();}+ // NB: The monitor's row lies outside the toolbar, and leaves with it, as in full screen.+ if (event->type() == QEvent::Show || event->type() == QEvent::Hide)+ update_performance_monitor_row();+return QWidget::event(event);}@@ -1831,7 +1842,13 @@ void WindowToolbar::config_variable_changed(WebView::ConfigVariableID variable)m_feedback_button->setVisible(show_button);}if (variable == WebView::ConfigVariableID::ShowTabPerformanceMonitor)- m_performance_monitor->setVisible(WebView::Application::settings().config_variable_as_bool(variable));+ update_performance_monitor_row();+}++void WindowToolbar::update_performance_monitor_row()+{+ auto enabled = WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowTabPerformanceMonitor);+ m_performance_monitor_row->setVisible(enabled && isVisible());}void WindowToolbar::update_chrome_style()@@ -1843,6 +1860,11 @@ void WindowToolbar::update_chrome_style()setStyleSheet(style_sheet);// NB: The sidebar's footer lies outside the toolbar while the sidebar holds it, so it takes the style sheet itself.m_sidebar_footer->setStyleSheet(style_sheet);+ auto const& colors = Theme::chrome(Theme::chrome_palette(*this));+ auto row_palette = m_performance_monitor_row->palette();+ row_palette.setColor(QPalette::Window, colors.toolbar);+ row_palette.setColor(QPalette::WindowText, colors.text);+ m_performance_monitor_row->setPalette(row_palette);if (m_field_panel) {m_field_panel->setStyleSheet(style_sheet);m_field_panel->round_corners();diff --git a/UI/Qt/WindowToolbar.h b/UI/Qt/WindowToolbar.hindex 458d931e73e..2b157b82387 100644--- a/UI/Qt/WindowToolbar.h+++ b/UI/Qt/WindowToolbar.h@@ -76,6 +76,8 @@ public:// The sidebar's own margin plus the given inset keeps the toolbar's contents clear of the sidebar's edges.void set_arrangement(ToolbarArrangement, int sidebar_inset = 0);QWidget& sidebar_footer() { return *m_sidebar_footer; }+ // The row of its own that the tab performance monitor shows in, which ends the page column in every layout.+ QWidget& performance_monitor_row() { return *m_performance_monitor_row; }// The toolbar's height in either arrangement, whichever it is in now.int height_in_row() const;int height_in_sidebar() const;@@ -121,6 +123,7 @@ private:void update_field_panel();void raise_field_panel();void apply_contents_opacity();+ void update_performance_monitor_row();WebView::IsPrivate m_is_private { WebView::IsPrivate::No };QPointer<Tab> m_tab;@@ -143,6 +146,7 @@ private:// NB: The fields of the tabs shown so far share this layout, which leaves room around them for the focus ring.QHBoxLayout* m_location_edit_layout { nullptr };QPointer<LocationEdit> m_location_edit;+ QWidget* m_performance_monitor_row { nullptr };PerformanceMonitorWidget* m_performance_monitor { nullptr };QWidget* m_window_controls_separator { nullptr };QWidget* m_sidebar_slot { nullptr };