Truly independent web browser
UI/Qt: Show report reviews in the interface theme’s colors
sideshowbarkered3e7ac1c5a5
diff --git a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp b/Tests/UI/Qt/TestCrashReportReviewWidget.cppindex 5a17287c63a..eef6405e74e 100644--- a/Tests/UI/Qt/TestCrashReportReviewWidget.cpp+++ b/Tests/UI/Qt/TestCrashReportReviewWidget.cpp@@ -12,12 +12,15 @@#include <LibCore/StandardPaths.h>#include <LibFileSystem/FileSystem.h>#include <LibTest/TestCase.h>+#include <LibWebView/Settings.h>#include <UI/Qt/CrashReportReviewWidget.h>#include <UI/Qt/StringUtils.h>+#include <UI/Qt/Theme.h>#include <QAbstractButton>#include <QApplication>#include <QCheckBox>+#include <QCoreApplication>#include <QKeyEvent>#include <QLabel>#include <QLineEdit>@@ -95,6 +98,57 @@ TEST_CASE(a_crash_screen_offers_the_website_without_including_it)EXPECT_EQ(status_title(widget), "Report not sent");}+// The offscreen platform keeps Qt's light palette whatever color scheme is asked for, as some platform themes do.+TEST_CASE(the_details_of_a_report_take_the_dark_interface_theme_where_qt_keeps_a_light_palette)+{+ cleanup();+ ScopeGuard guard = cleanup;+ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Dark);+ ScopeGuard restore_theme = [] { Ladybird::Theme::set_interface_theme(WebView::ThemePreference::System); };++ auto name = write_report("2026-10-01T12-00-00Z"sv);+ WebView::CrashReportStore store { test_directory() };+ CrashReportReviewWidget widget { QStringLiteral("Reload page"), nullptr, store };+ MUST(widget.open_report(name));+ widget.show();++ QLabel* process = nullptr;+ for (auto* label : widget.findChildren<QLabel*>()) {+ if (label->text() == QStringLiteral("WebContent"))+ process = label;+ }+ VERIFY(process);+ EXPECT(process->palette().color(process->foregroundRole()).lightness() > 128);+}++// A disclosure button has a style sheet of its own, which keeps Qt's cached palette for it through the review's restyle.+TEST_CASE(the_disclosure_follows_a_switch_to_the_dark_interface_theme)+{+ cleanup();+ ScopeGuard guard = cleanup;+ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Light);+ ScopeGuard restore_theme = [] { Ladybird::Theme::set_interface_theme(WebView::ThemePreference::System); };++ auto name = write_report("2026-10-01T12-00-00Z"sv);+ WebView::CrashReportStore store { test_directory() };+ CrashReportReviewWidget widget { QStringLiteral("Reload page"), nullptr, store };+ MUST(widget.open_report(name));+ widget.show();++ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Dark);+ QEvent palette_change(QEvent::PaletteChange);+ QCoreApplication::sendEvent(&widget, &palette_change);++ size_t disclosures = 0;+ for (auto* button : widget.findChildren<QPushButton*>()) {+ if (button->styleSheet().isEmpty())+ continue;+ ++disclosures;+ EXPECT(button->palette().color(QPalette::ButtonText).lightness() > 128);+ }+ EXPECT(disclosures > 0);+}+TEST_CASE(the_review_offers_to_exit_before_and_after_answering){cleanup();diff --git a/Tests/UI/Qt/TestWebCompatReportReview.cpp b/Tests/UI/Qt/TestWebCompatReportReview.cppindex 2efab16e8af..fe29c0b2003 100644--- a/Tests/UI/Qt/TestWebCompatReportReview.cpp+++ b/Tests/UI/Qt/TestWebCompatReportReview.cpp@@ -7,10 +7,13 @@#include <AK/Vector.h>#include <LibTest/TestCase.h>#include <LibURL/Parser.h>+#include <LibWebView/Settings.h>+#include <UI/Qt/Theme.h>#include <UI/Qt/WebCompatReportReview.h>#include <QAbstractButton>#include <QCheckBox>+#include <QCoreApplication>#include <QLabel>#include <QPlainTextEdit>#include <QPushButton>@@ -238,3 +241,39 @@ TEST_CASE(a_screenshot_is_shrunk_to_fit_a_report)EXPECT(static_cast<size_t>(decoded.width()) * decoded.height() <= WebCompatReport::maximum_screenshot_pixels);EXPECT(decoded.width() > 3000);}++// The offscreen platform keeps Qt's light palette whatever color scheme is asked for, as some platform themes do.+TEST_CASE(the_review_takes_the_dark_interface_theme_even_where_qt_keeps_a_light_palette)+{+ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Dark);+ WebCompatReportReview review { test_page(), test_screenshot(), nullptr };+ review.show();++ auto const& website = child<QLabel>(review, "WebCompatReportWebsite");+ EXPECT(review.palette().color(QPalette::Window).lightness() < 128);+ EXPECT(website.palette().color(website.foregroundRole()).lightness() > 128);++ // A switch of the interface theme restyles every widget, which takes the review back to Qt's palette.+ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Light);+ QEvent palette_change(QEvent::PaletteChange);+ QCoreApplication::sendEvent(&review, &palette_change);+ EXPECT(review.palette().color(QPalette::Window).lightness() > 128);+ EXPECT(website.palette().color(website.foregroundRole()).lightness() < 128);++ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::System);+}++// A review is shown over the page in an overlay that has the interface theme's colors already.+TEST_CASE(a_review_inside_a_dark_overlay_keeps_its_labels_light_where_qt_keeps_a_light_palette)+{+ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::Dark);+ QWidget overlay;+ overlay.setPalette(Ladybird::Theme::interface_palette(overlay.palette()));+ auto* review = new WebCompatReportReview { test_page(), test_screenshot(), &overlay };+ overlay.show();++ auto const& website = child<QLabel>(*review, "WebCompatReportWebsite");+ EXPECT(website.palette().color(website.foregroundRole()).lightness() > 128);++ Ladybird::Theme::set_interface_theme(WebView::ThemePreference::System);+}diff --git a/UI/Qt/ReportReview.cpp b/UI/Qt/ReportReview.cppindex fca0d6bf6de..73792a11c56 100644--- a/UI/Qt/ReportReview.cpp+++ b/UI/Qt/ReportReview.cpp@@ -8,6 +8,7 @@#include <UI/Qt/ChromeStyle.h>#include <UI/Qt/ReportReview.h>#include <UI/Qt/StringUtils.h>+#include <UI/Qt/Theme.h>#include <QApplication>#include <QFontDatabase>@@ -121,6 +122,11 @@ void set_details(QFormLayout& form, ReadonlySpan<WebView::ReportDetail> details,auto* value = create_label(qstring_from_ak_string(detail.value), parent);if (detail.is_code)value->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));+ // The review may be styled already, and its style sheet would hold these to the application's palette.+ if (parent) {+ label->setPalette(parent->palette());+ value->setPalette(parent->palette());+ }form.addRow(label, value);}}@@ -154,12 +160,33 @@ ReportTextPage create_report_text_page(QWidget* parent)// for its own.void apply_style(QWidget& review, ReadonlySpan<QWidget*> fields){+ // The review starts again from the palette it inherits, so it sees every switch between light and dark. Its style+ // sheet comes off first, as Qt puts back the palette a widget had when its style sheet was applied. And a widget+ // that a style sheet styles takes the application's palette rather than its parent's, so each one is given the+ // review's.+ review.setStyleSheet({});+ review.setPalette(QPalette {});+ // Every role is set explicitly, as a widget that a style sheet styles resolves the roles left unset against the+ // application's palette, which may have the other appearance.+ auto palette = Theme::interface_palette(review.palette());+ palette.setResolveMask(~QPalette::ResolveMask { 0 });+ review.setPalette(palette);+ for (auto* widget : review.findChildren<QWidget*>())+ widget->setPalette(palette);+for (auto* field : fields) {auto field_palette = field->palette();field_palette.setColor(QPalette::PlaceholderText, ChromeStyle::report_review_placeholder_text(review.palette()));field->setPalette(field_palette);}review.setStyleSheet(ChromeStyle::report_review_style_sheet(review.palette()));++ // A widget with a style sheet of its own, such as a disclosure, keeps the palette Qt saved for it when it was first+ // styled, and gets that back as the review's style sheet is applied.+ for (auto* widget : review.findChildren<QWidget*>()) {+ if (!widget->styleSheet().isEmpty())+ widget->setPalette(palette);+ }}// Tab moves through every control of the review and wraps around within it. The platform's own focus chain would skipdiff --git a/UI/Qt/Theme.cpp b/UI/Qt/Theme.cppindex 29350772c8c..78947e69780 100644--- a/UI/Qt/Theme.cpp+++ b/UI/Qt/Theme.cpp@@ -400,6 +400,26 @@ bool is_dark(QWidget const& widget)return is_dark(chrome_palette(widget));}+QPalette interface_palette(QPalette palette)+{+ auto palette_is_dark = palette.color(QPalette::Window).lightness() < 128;+ if (palette_is_dark == is_dark())+ return palette;++ auto const& colors = panel();+ palette.setColor(QPalette::Window, colors.surface);+ palette.setColor(QPalette::WindowText, colors.text);+ palette.setColor(QPalette::Base, colors.page);+ palette.setColor(QPalette::Text, colors.text);+ palette.setColor(QPalette::Button, colors.surface);+ palette.setColor(QPalette::ButtonText, colors.body);+ palette.setColor(QPalette::PlaceholderText, colors.muted);+ palette.setColor(QPalette::Link, colors.link);+ for (auto role : { QPalette::WindowText, QPalette::Text, QPalette::ButtonText })+ palette.setColor(QPalette::Disabled, role, colors.muted);+ return palette;+}+PanelColors const& panel(){return is_dark() ? s_dark_panel : s_light_panel;diff --git a/UI/Qt/Theme.h b/UI/Qt/Theme.hindex 5739457573c..a67d63b2d52 100644--- a/UI/Qt/Theme.h+++ b/UI/Qt/Theme.h@@ -93,6 +93,10 @@ bool is_dark(QPalette const&);bool is_dark(QWidget const&);PanelColors const& panel();+// The palette for widgets that take the interface theme's appearance, such as the reviews of reports. Some platform+// themes keep the system's palette whatever color scheme is asked for, and the panel colors then stand in for it.+QPalette interface_palette(QPalette);+// The accent color the desktop's settings portal reports, as Qt's palette does not follow it.void set_desktop_accent(Optional<QColor>);Optional<QColor> const& desktop_accent();diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex 5d873c2d1c0..a8f001ce172 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -1401,6 +1401,7 @@ public:setWidgetResizable(true);setBackgroundRole(QPalette::Window);viewport()->setBackgroundRole(QPalette::Window);+ apply_interface_palette();// Qt scrolls opaque content by moving the pixels it painted before, which leaves stale text behind the// translucent fields of a review inside this native view. Transparent content is repainted instead, on top of@@ -1429,6 +1430,13 @@ public:QWidget& content() { return *m_content; }QWidget& column() { return *m_column; }+ virtual bool event(QEvent* event) override+ {+ if (event->type() == QEvent::PaletteChange)+ apply_interface_palette();+ return QScrollArea::event(event);+ }+// The column reaches from the top of the tab to its bottom rather than being centered in it.void set_fills_height(){@@ -1447,10 +1455,23 @@ public:}private:+ // The overlay is in the interface theme's colors, like the review it holds, whichever appearance Qt's palette has.+ void apply_interface_palette()+ {+ // Setting the palette changes it, which would bring us back here.+ if (m_is_applying_interface_palette)+ return;+ m_is_applying_interface_palette = true;+ setPalette(QPalette {});+ setPalette(Theme::interface_palette(palette()));+ m_is_applying_interface_palette = false;+ }+QWidget* m_content { nullptr };QWidget* m_column { nullptr };QVBoxLayout* m_layout { nullptr };bool m_fills_height { false };+ bool m_is_applying_interface_palette { false };};class CrashOverlayUrlLabel final : public QLabel {