Truly independent web browser
UI/Qt: Add a review for web compatibility reports
Jelle Raaijmakers92a90308df6b
diff --git a/Tests/UI/Qt/CMakeLists.txt b/Tests/UI/Qt/CMakeLists.txtindex f39fcfa32e3..8396f61659d 100644--- a/Tests/UI/Qt/CMakeLists.txt+++ b/Tests/UI/Qt/CMakeLists.txt@@ -98,6 +98,19 @@ target_sources(TestScreenshotViewer PRIVATE)deploy_qt_offscreen_platform_plugin(TestScreenshotViewer)+ladybird_test("TestWebCompatReportReview.cpp" UI/Qt+ CUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>"+ LIBS LibURL LibWebView Qt::Core Qt::Gui Qt::Widgets+)+target_sources(TestWebCompatReportReview PRIVATE+ "${LADYBIRD_SOURCE_DIR}/UI/Qt/ChromeStyle.cpp"+ "${LADYBIRD_SOURCE_DIR}/UI/Qt/Icon.cpp"+ "${LADYBIRD_SOURCE_DIR}/UI/Qt/ReportReview.cpp"+ "${LADYBIRD_SOURCE_DIR}/UI/Qt/StringUtils.cpp"+ "${LADYBIRD_SOURCE_DIR}/UI/Qt/WebCompatReportReview.cpp"+)+deploy_qt_offscreen_platform_plugin(TestWebCompatReportReview)+ladybird_test("TestHiddenPageSizing.cpp" UI/QtCUSTOM_MAIN "$<TARGET_OBJECTS:QtTestMain>"LIBS Qt::Core Qt::Gui Qt::Widgetsdiff --git a/Tests/UI/Qt/TestWebCompatReportReview.cpp b/Tests/UI/Qt/TestWebCompatReportReview.cppnew file mode 100644index 00000000000..81f1d94d27a--- /dev/null+++ b/Tests/UI/Qt/TestWebCompatReportReview.cpp@@ -0,0 +1,229 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/Vector.h>+#include <LibTest/TestCase.h>+#include <LibURL/Parser.h>+#include <UI/Qt/WebCompatReportReview.h>++#include <QAbstractButton>+#include <QCheckBox>+#include <QLabel>+#include <QPlainTextEdit>+#include <QPushButton>++using Ladybird::WebCompatReportReview;+using WebView::ReportSubmission;+using WebView::WebCompatReport;++static WebCompatReport::Page test_page()+{+ return {+ .url = URL::Parser::basic_parse("https://example.com/broken"sv).release_value(),+ .user_agent = "Mozilla/5.0 Ladybird/1.0"_string,+ .viewport_size = { 1280, 720 },+ .device_pixel_ratio = 2,+ .zoom_level = 1,+ };+}++static QImage test_screenshot()+{+ QImage image(400, 200, QImage::Format_RGB32);+ image.fill(Qt::red);+ return image;+}++template<typename T>+static T& child(QWidget& widget, char const* name)+{+ auto* child = widget.findChild<T*>(name);+ VERIFY(child);+ return *child;+}++TEST_CASE(the_review_shows_the_website_and_the_selected_screenshot)+{+ WebCompatReportReview review { test_page(), test_screenshot(), nullptr };+ review.show();++ EXPECT_EQ(child<QLabel>(review, "WebCompatReportWebsite").text(), "https://example.com/broken");+ EXPECT(child<QWidget>(review, "WebCompatReportScreenshot").isVisible());+ EXPECT_EQ(child<QPushButton>(review, "WebCompatReportSelectScreenshotButton").text(), "Retake screenshot");+ EXPECT(child<QPushButton>(review, "WebCompatReportRemoveScreenshotButton").isVisible());+}++TEST_CASE(the_screenshot_opens_in_full)+{+ WebCompatReportReview review { test_page(), test_screenshot(), nullptr };+ Optional<QImage> viewed;+ review.on_view_screenshot = [&](QImage const& screenshot) { viewed = screenshot; };+ review.show();++ EXPECT(!child<QLabel>(review, "WebCompatReportNoScreenshotNote").isVisible());+ child<QAbstractButton>(review, "WebCompatReportScreenshot").click();+ EXPECT(viewed.has_value());+ EXPECT_EQ(viewed->size(), QSize(400, 200));+}++TEST_CASE(a_screenshot_can_be_removed_and_taken_again)+{+ WebCompatReportReview review { test_page(), test_screenshot(), nullptr };+ review.show();++ auto& remove_button = child<QPushButton>(review, "WebCompatReportRemoveScreenshotButton");+ remove_button.click();+ EXPECT(!child<QWidget>(review, "WebCompatReportScreenshot").isVisible());+ EXPECT(!remove_button.isVisible());+ EXPECT(child<QLabel>(review, "WebCompatReportNoScreenshotNote").isVisible());+ EXPECT_EQ(child<QPushButton>(review, "WebCompatReportSelectScreenshotButton").text(), "Take a screenshot");+}++TEST_CASE(a_report_without_a_screenshot_offers_to_take_one)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ auto selections = 0;+ review.on_select_screenshot = [&] { ++selections; };+ review.show();++ EXPECT(!child<QWidget>(review, "WebCompatReportScreenshot").isVisible());+ EXPECT(!child<QPushButton>(review, "WebCompatReportRemoveScreenshotButton").isVisible());+ auto& select_button = child<QPushButton>(review, "WebCompatReportSelectScreenshotButton");+ EXPECT_EQ(select_button.text(), "Take a screenshot");+ select_button.click();+ EXPECT_EQ(selections, 1);++ review.set_screenshot(test_screenshot());+ EXPECT(child<QWidget>(review, "WebCompatReportScreenshot").isVisible());+ EXPECT_EQ(select_button.text(), "Retake screenshot");+}++TEST_CASE(page_dumps_can_be_included_once_they_have_arrived)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ review.show();++ auto& include_page_dumps = child<QCheckBox>(review, "WebCompatReportIncludePageDumps");+ EXPECT(!include_page_dumps.isEnabled());+ EXPECT(!include_page_dumps.isChecked());+ review.set_page_dumps("Layout tree:\nViewport\n"_string);+ EXPECT(include_page_dumps.isEnabled());+ EXPECT(!include_page_dumps.isChecked());+}++TEST_CASE(the_full_report_is_shown_in_place_of_the_review)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ Vector<bool> text_visibility;+ review.on_report_text_visibility_change = [&](bool visible) { text_visibility.append(visible); };+ review.show();+ review.set_page_dumps("Layout tree:\nBlockContainer <html>\n"_string);++ auto& send = child<QPushButton>(review, "WebCompatReportSendButton");+ auto& show_report = child<QPushButton>(review, "WebCompatReportShowReportButton");+ auto& text = child<QPlainTextEdit>(review, "ReportText");+ show_report.click();+ EXPECT(text.isVisible());+ EXPECT(!send.isVisible());+ EXPECT(text.toPlainText().contains("https://example.com/broken"));+ EXPECT(!text.toPlainText().contains("BlockContainer <html>"));++ child<QPushButton>(review, "ReportTextBackButton").click();+ EXPECT(!text.isVisible());+ EXPECT(send.isVisible());+ EXPECT_EQ(text_visibility, (Vector<bool> { true, false }));++ child<QCheckBox>(review, "WebCompatReportIncludePageDumps").setChecked(true);+ show_report.click();+ EXPECT(text.toPlainText().contains("BlockContainer <html>"));+}++TEST_CASE(a_report_needs_a_description)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ review.show();++ child<QPushButton>(review, "WebCompatReportSendButton").click();+ auto& validation = child<QLabel>(review, "WebCompatReportValidation");+ EXPECT(validation.isVisible());+ EXPECT_EQ(validation.text(), "Describe what is wrong with this website.");+ EXPECT(!child<QLabel>(review, "WebCompatReportStatusTitle").isVisible());+}++TEST_CASE(leaving_the_review_closes_its_tab)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ auto exits = 0;+ review.on_exit = [&] { ++exits; };+ review.show();++ auto& review_close = child<QPushButton>(review, "WebCompatReportReviewCloseButton");+ EXPECT_EQ(review_close.text(), "Close tab");+ review_close.click();+ EXPECT_EQ(exits, 1);++ review.show_sent();+ auto& close = child<QPushButton>(review, "WebCompatReportCloseButton");+ EXPECT_EQ(close.text(), "Close tab");+ close.click();+ EXPECT_EQ(exits, 2);+}++TEST_CASE(sending_can_be_canceled_until_the_report_is_sent)+{+ WebCompatReportReview review { test_page(), {}, nullptr };+ review.show();++ auto& description = child<QPlainTextEdit>(review, "WebCompatReportDescription");+ description.setPlainText("The menu does not open");+ review.show_progress(ReportSubmission::Stage::SolvingProof);+ auto& title = child<QLabel>(review, "WebCompatReportStatusTitle");+ auto& retry = child<QPushButton>(review, "WebCompatReportRetryButton");+ auto& cancel = child<QPushButton>(review, "WebCompatReportCancelButton");+ auto& close = child<QPushButton>(review, "WebCompatReportCloseButton");+ EXPECT_EQ(title.text(), "Sending report");+ EXPECT(!retry.isVisible());+ EXPECT(cancel.isVisible());+ EXPECT(!cancel.isDefault());+ EXPECT(!close.isVisible());++ review.show_failure(ReportSubmission::Failure::Sending, "Network error while contacting the report server."_string);+ EXPECT_EQ(title.text(), "Couldn’t send report");+ EXPECT(retry.isVisible());+ EXPECT(retry.isDefault());+ EXPECT(cancel.isVisible());+ EXPECT(!close.isVisible());++ cancel.click();+ EXPECT(child<QPushButton>(review, "WebCompatReportSendButton").isVisible());+ EXPECT_EQ(description.toPlainText(), "The menu does not open");++ review.show_sent();+ EXPECT_EQ(title.text(), "Report sent");+ EXPECT(!retry.isVisible());+ EXPECT(!cancel.isVisible());+ EXPECT(close.isVisible());+ EXPECT(close.isDefault());+}++TEST_CASE(a_screenshot_is_shrunk_to_fit_a_report)+{+ EXPECT(!WebCompatReportReview::encode_screenshot({}).has_value());++ auto small = WebCompatReportReview::encode_screenshot(test_screenshot());+ EXPECT(small.has_value());+ auto decoded_small = QImage::fromData(small->bytes().data(), small->size(), "PNG");+ EXPECT_EQ(decoded_small.size(), QSize(400, 200));++ QImage large(4000, 3000, QImage::Format_RGB32);+ large.fill(Qt::blue);+ auto encoded = WebCompatReportReview::encode_screenshot(large);+ EXPECT(encoded.has_value());+ EXPECT(encoded->size() <= WebCompatReport::maximum_screenshot_bytes);+ auto decoded = QImage::fromData(encoded->bytes().data(), encoded->size(), "PNG");+ EXPECT(static_cast<size_t>(decoded.width()) * decoded.height() <= WebCompatReport::maximum_screenshot_pixels);+ EXPECT(decoded.width() > 3000);+}diff --git a/UI/Qt/CMakeLists.txt b/UI/Qt/CMakeLists.txtindex dde74eef6ab..0e3c42aa0f1 100644--- a/UI/Qt/CMakeLists.txt+++ b/UI/Qt/CMakeLists.txt@@ -56,6 +56,7 @@ target_sources(ladybird PRIVATEStringUtils.cppTab.cppTabBar.cpp+ WebCompatReportReview.cppWebContentView.cppWindowCloseCoordinator.cppWindowControlButton.cppdiff --git a/UI/Qt/Icon.cpp b/UI/Qt/Icon.cppindex bd44221715f..0a37f013066 100644--- a/UI/Qt/Icon.cpp+++ b/UI/Qt/Icon.cpp@@ -243,7 +243,7 @@ static QPixmap create_transparent_icon_pixmap(QSize logical_size, qreal device_preturn pixmap;}-static QPixmap create_chrome_icon_pixmap(ChromeIcon icon, QColor color, qreal device_pixel_ratio)+QPixmap create_chrome_icon_pixmap(ChromeIcon icon, QColor color, qreal device_pixel_ratio){auto pixmap = create_transparent_icon_pixmap({ 20, 20 }, device_pixel_ratio);diff --git a/UI/Qt/Icon.h b/UI/Qt/Icon.hindex 6e5ef138c17..54d2ec58804 100644--- a/UI/Qt/Icon.h+++ b/UI/Qt/Icon.h@@ -10,7 +10,9 @@#include <AK/Span.h>#include <AK/StringView.h>+#include <QColor>#include <QIcon>+#include <QPixmap>#include <QSize>class QPalette;@@ -53,6 +55,7 @@ constexpr inline auto ICON_DEVICE_PIXEL_RATIOS = to_array({ 1, 2, 3 });QIcon load_icon_from_uri(StringView);QIcon icon_from_png(ReadonlyBytes, int logical_size);QIcon create_chrome_icon(ChromeIcon, QPalette const&);+QPixmap create_chrome_icon_pixmap(ChromeIcon, QColor, qreal device_pixel_ratio);QIcon loading_spinner_icon(QPalette const& palette, int frame);QSize physical_size_for_device_pixel_ratio(QSize size, qreal device_pixel_ratio);diff --git a/UI/Qt/WebCompatReportReview.cpp b/UI/Qt/WebCompatReportReview.cppnew file mode 100644index 00000000000..1b17e5d94bb--- /dev/null+++ b/UI/Qt/WebCompatReportReview.cpp@@ -0,0 +1,470 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/Math.h>+#include <UI/Qt/Icon.h>+#include <UI/Qt/ReportReview.h>+#include <UI/Qt/StringUtils.h>+#include <UI/Qt/WebCompatReportReview.h>++#include <QAbstractButton>+#include <QBuffer>+#include <QCheckBox>+#include <QEvent>+#include <QFormLayout>+#include <QFrame>+#include <QHBoxLayout>+#include <QLabel>+#include <QPainter>+#include <QPainterPath>+#include <QPixmap>+#include <QPlainTextEdit>+#include <QProgressBar>+#include <QPushButton>+#include <QVBoxLayout>++namespace Ladybird {++using namespace ReportReview;++static constexpr QSize SCREENSHOT_PREVIEW_SIZE { 480, 270 };+static constexpr qreal SCREENSHOT_PREVIEW_RADIUS = 8;+static constexpr qreal SCREENSHOT_BADGE_SIZE = 44;+static constexpr qreal SCREENSHOT_SIZE_MARGIN = 0.9;+static constexpr int MAXIMUM_SCREENSHOT_ENCODINGS = 4;++// The screenshot as a card that opens it in full, and says so while it is hovered or focused.+class ScreenshotThumbnail final : public QAbstractButton {+public:+ AK_ALLOC_WITH_KMALLOC;++ explicit ScreenshotThumbnail(QWidget* parent)+ : QAbstractButton(parent)+ {+ setCursor(Qt::PointingHandCursor);+ setFocusPolicy(Qt::StrongFocus);+ setAttribute(Qt::WA_Hover);+ setToolTip(tr("View the screenshot in full"));+ }++ void set_screenshot(QImage const& screenshot)+ {+ if (screenshot.isNull()) {+ m_pixmap = {};+ return;+ }+ auto size = (QSizeF(screenshot.size()) / devicePixelRatioF()).toSize();+ if (size.width() > SCREENSHOT_PREVIEW_SIZE.width() || size.height() > SCREENSHOT_PREVIEW_SIZE.height())+ size = size.scaled(SCREENSHOT_PREVIEW_SIZE, Qt::KeepAspectRatio);+ m_pixmap = QPixmap::fromImage(screenshot.scaled(size * devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation));+ m_pixmap.setDevicePixelRatio(devicePixelRatioF());+ setFixedSize(size);+ update();+ }++protected:+ virtual void paintEvent(QPaintEvent*) override+ {+ QPainter painter(this);+ painter.setRenderHint(QPainter::Antialiasing);+ QRectF bounds = rect();++ QPainterPath corners;+ corners.addRoundedRect(bounds, SCREENSHOT_PREVIEW_RADIUS, SCREENSHOT_PREVIEW_RADIUS);+ painter.setClipPath(corners);+ painter.drawPixmap(0, 0, m_pixmap);++ // A dark badge keeps the magnifying glass legible whatever the screenshot shows behind it.+ if (underMouse() || hasFocus()) {+ painter.fillRect(bounds, QColor(0, 0, 0, 40));++ QRectF badge { 0, 0, SCREENSHOT_BADGE_SIZE, SCREENSHOT_BADGE_SIZE };+ badge.moveCenter(bounds.center());+ painter.setPen(QPen(QColor(255, 255, 255, 72), 1));+ painter.setBrush(QColor(0, 0, 0, 160));+ painter.drawEllipse(badge);++ auto magnifier = create_chrome_icon_pixmap(ChromeIcon::Search, Qt::white, devicePixelRatioF());+ auto magnifier_size = QSizeF(magnifier.size()) / magnifier.devicePixelRatio();+ painter.drawPixmap(badge.center() - QPointF(magnifier_size.width() / 2, magnifier_size.height() / 2), magnifier);+ }+ painter.setClipping(false);++ auto border = palette().color(QPalette::WindowText);+ border.setAlpha(40);+ auto pen = hasFocus() ? QPen(palette().color(QPalette::Highlight), 2) : QPen(border, 1);+ auto inset = pen.widthF() / 2;+ painter.setPen(pen);+ painter.setBrush(Qt::NoBrush);+ painter.drawRoundedRect(bounds.adjusted(inset, inset, -inset, -inset), SCREENSHOT_PREVIEW_RADIUS, SCREENSHOT_PREVIEW_RADIUS);+ }++private:+ QPixmap m_pixmap;+};++// A screenshot is shrunk until it fits within the pixels and bytes a report may carry.+Optional<ByteBuffer> WebCompatReportReview::encode_screenshot(QImage const& screenshot)+{+ if (screenshot.isNull())+ return {};++ auto image = screenshot;+ auto pixels = static_cast<qreal>(image.width()) * image.height();+ if (pixels > WebView::WebCompatReport::maximum_screenshot_pixels) {+ auto scale = AK::sqrt(WebView::WebCompatReport::maximum_screenshot_pixels / pixels);+ image = image.scaled(image.size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);+ }++ for (int encoding = 0; encoding < MAXIMUM_SCREENSHOT_ENCODINGS && !image.isNull(); ++encoding) {+ QByteArray png;+ QBuffer buffer(&png);+ buffer.open(QIODevice::WriteOnly);+ if (!image.save(&buffer, "PNG"))+ return {};+ if (static_cast<size_t>(png.size()) <= WebView::WebCompatReport::maximum_screenshot_bytes)+ return MUST(ByteBuffer::copy(png.constData(), png.size()));++ // A PNG grows about as much as its pixels do, so the next one is scaled to fit, with a little room to spare.+ auto scale = AK::sqrt(static_cast<double>(WebView::WebCompatReport::maximum_screenshot_bytes) / png.size()) * SCREENSHOT_SIZE_MARGIN;+ image = image.scaled(image.size() * scale, Qt::KeepAspectRatio, Qt::SmoothTransformation);+ }+ return {};+}++WebCompatReportReview::WebCompatReportReview(WebView::WebCompatReport::Page page, QImage screenshot, QWidget* parent)+ : QWidget(parent)+ , m_report(AK::move(page))+{+ setObjectName("LadybirdReportReview");++ auto* layout = new QVBoxLayout(this);+ layout->setContentsMargins(0, 0, 0, 0);++ m_review_page = new QWidget(this);+ auto* review_layout = new QVBoxLayout(m_review_page);+ review_layout->setContentsMargins(0, 0, 0, 0);+ review_layout->setSpacing(group_spacing);++ auto* heading = new QWidget(m_review_page);+ auto* heading_layout = create_group_layout(heading);+ heading_layout->addWidget(create_title(tr("Report a website issue"), heading));+ auto* website = create_label(qstring_from_ak_string(m_report.page().url.serialize()), heading);+ website->setObjectName("WebCompatReportWebsite");+ website->setForegroundRole(QPalette::PlaceholderText);+ heading_layout->addWidget(website);+ review_layout->addWidget(heading);++ auto* description = new QWidget(m_review_page);+ auto* description_layout = create_group_layout(description);+ description_layout->addWidget(create_label(tr("What is wrong with this website?"), description));+ m_description_edit = new QPlainTextEdit(description);+ m_description_edit->setObjectName("WebCompatReportDescription");+ m_description_edit->setPlaceholderText(tr("Describe what you expected to see or do, and what happened instead."));+ m_description_edit->setTabChangesFocus(true);+ m_description_edit->setFixedHeight(m_description_edit->fontMetrics().lineSpacing() * 5);+ description_layout->addWidget(m_description_edit);+ review_layout->addWidget(description);++ auto* screenshot_group = new QWidget(m_review_page);+ auto* screenshot_layout = create_group_layout(screenshot_group);+ screenshot_layout->addWidget(create_label(tr("Screenshot"), screenshot_group));+ m_screenshot_preview = new ScreenshotThumbnail(screenshot_group);+ m_screenshot_preview->setObjectName("WebCompatReportScreenshot");+ QObject::connect(m_screenshot_preview, &QAbstractButton::clicked, this, [this] {+ if (on_view_screenshot)+ on_view_screenshot(m_screenshot);+ });+ screenshot_layout->addWidget(m_screenshot_preview, 0, Qt::AlignLeft);+ m_no_screenshot_note = create_label(tr("The report will not include a screenshot."), screenshot_group);+ m_no_screenshot_note->setObjectName("WebCompatReportNoScreenshotNote");+ m_no_screenshot_note->setForegroundRole(QPalette::PlaceholderText);+ screenshot_layout->addWidget(m_no_screenshot_note);+ m_select_screenshot_button = new QPushButton(screenshot_group);+ m_select_screenshot_button->setObjectName("WebCompatReportSelectScreenshotButton");+ m_select_screenshot_button->setAutoDefault(false);+ m_remove_screenshot_button = new QPushButton(tr("Remove screenshot"), screenshot_group);+ m_remove_screenshot_button->setObjectName("WebCompatReportRemoveScreenshotButton");+ m_remove_screenshot_button->setAutoDefault(false);+ auto* screenshot_buttons = new QHBoxLayout;+ screenshot_buttons->setSpacing(button_spacing);+ screenshot_buttons->addWidget(m_select_screenshot_button);+ screenshot_buttons->addWidget(m_remove_screenshot_button);+ screenshot_buttons->addStretch();+ screenshot_layout->addLayout(screenshot_buttons);+ review_layout->addWidget(screenshot_group);++ auto* page_dumps = new QWidget(m_review_page);+ auto* page_dumps_layout = create_group_layout(page_dumps);+ m_include_page_dumps = new QCheckBox(tr("Include layout and painting information"), page_dumps);+ m_include_page_dumps->setObjectName("WebCompatReportIncludePageDumps");+ m_include_page_dumps->setEnabled(false);+ page_dumps_layout->addWidget(m_include_page_dumps);+ auto* page_dumps_note = create_label(tr("This can contain personal information, such as text on the page."), page_dumps);+ page_dumps_note->setForegroundRole(QPalette::PlaceholderText);+ page_dumps_layout->addWidget(page_dumps_note);+ review_layout->addWidget(page_dumps);++ auto* contents = new QWidget(m_review_page);+ auto* contents_layout = create_group_layout(contents);+ auto* contents_summary = create_label(tr("Includes the website URL, your Ladybird version, platform, user agent, window size and zoom level."), contents);+ contents_summary->setForegroundRole(QPalette::PlaceholderText);+ contents_layout->addWidget(contents_summary);+ auto* details = create_details_panel(contents);+ auto* details_layout = static_cast<QVBoxLayout*>(details->layout());+ auto* details_form = create_details_form();+ set_details(*details_form, m_report.details(), details);+ details_layout->addLayout(details_form);+ details_layout->addSpacing(item_spacing);+ m_show_report_button = new QPushButton(tr("View full report"), details);+ m_show_report_button->setObjectName("WebCompatReportShowReportButton");+ m_show_report_button->setAutoDefault(false);+ QObject::connect(m_show_report_button, &QPushButton::clicked, this, [this] { show_report_text(); });+ details_layout->addWidget(m_show_report_button, 0, Qt::AlignLeft);+ auto* details_toggle = create_disclosure(tr("Report details"), details, contents);+ // The toggle comes before what it shows, although it is created after it.+ QWidget::setTabOrder(details_toggle, m_show_report_button);+ contents_layout->addWidget(details_toggle);+ contents_layout->addWidget(details);+ review_layout->addWidget(contents);++ m_validation = create_label({}, m_review_page);+ m_validation->setObjectName("WebCompatReportValidation");+ m_validation->hide();+ review_layout->addWidget(m_validation);++ auto* send_button = new QPushButton(tr("Send report"), m_review_page);+ send_button->setObjectName("WebCompatReportSendButton");+ send_button->setDefault(true);+ auto* review_close_button = new QPushButton(tr("Close tab"), m_review_page);+ review_close_button->setObjectName("WebCompatReportReviewCloseButton");+ review_close_button->setAutoDefault(false);+ auto* review_buttons = new QHBoxLayout;+ review_buttons->setSpacing(button_spacing);+ review_buttons->addStretch();+ review_buttons->addWidget(review_close_button);+ review_buttons->addWidget(send_button);+ review_layout->addLayout(review_buttons);+ layout->addWidget(m_review_page);++ m_status_page = new QWidget(this);+ auto* status_layout = new QVBoxLayout(m_status_page);+ status_layout->setContentsMargins(0, 0, 0, 0);+ status_layout->setSpacing(group_spacing);+ auto* outcome = new QWidget(m_status_page);+ auto* outcome_layout = create_group_layout(outcome);+ m_status_title = create_title({}, outcome);+ m_status_title->setObjectName("WebCompatReportStatusTitle");+ outcome_layout->addWidget(m_status_title);+ m_progress = new QProgressBar(outcome);+ m_progress->setObjectName("WebCompatReportProgress");+ m_progress->setRange(0, 100);+ m_progress->setTextVisible(false);+ outcome_layout->addWidget(m_progress);+ m_status_message = create_label({}, outcome);+ m_status_message->setObjectName("WebCompatReportStatusMessage");+ m_status_message->setForegroundRole(QPalette::PlaceholderText);+ outcome_layout->addWidget(m_status_message);+ status_layout->addWidget(outcome);++ m_retry_button = new QPushButton(tr("Try sending again"), m_status_page);+ m_retry_button->setObjectName("WebCompatReportRetryButton");+ m_cancel_button = new QPushButton(tr("Cancel"), m_status_page);+ m_cancel_button->setObjectName("WebCompatReportCancelButton");+ m_close_button = new QPushButton(tr("Close tab"), m_status_page);+ m_close_button->setObjectName("WebCompatReportCloseButton");+ auto* status_buttons = new QHBoxLayout;+ status_buttons->setSpacing(button_spacing);+ status_buttons->addStretch();+ status_buttons->addWidget(m_retry_button);+ status_buttons->addWidget(m_cancel_button);+ status_buttons->addWidget(m_close_button);+ status_layout->addLayout(status_buttons);+ status_layout->addStretch();+ m_status_page->hide();+ layout->addWidget(m_status_page);++ auto report_text_page = create_report_text_page(this);+ m_report_text_page = report_text_page.page;+ m_report_text = report_text_page.text;+ QObject::connect(report_text_page.back_button, &QPushButton::clicked, this, [this] {+ show_page(*m_review_page);+ m_show_report_button->setFocus(Qt::OtherFocusReason);+ });+ layout->addWidget(m_report_text_page);++ QObject::connect(m_select_screenshot_button, &QPushButton::clicked, this, [this] {+ if (on_select_screenshot)+ on_select_screenshot();+ });+ QObject::connect(m_remove_screenshot_button, &QPushButton::clicked, this, [this] {+ set_screenshot({});+ m_select_screenshot_button->setFocus(Qt::OtherFocusReason);+ });+ QObject::connect(send_button, &QPushButton::clicked, this, [this] { send(); });+ QObject::connect(review_close_button, &QPushButton::clicked, this, [this] { exit(); });+ QObject::connect(m_retry_button, &QPushButton::clicked, this, [this] {+ show_progress(WebView::ReportSubmission::Stage::Preparing);+ m_report.retry();+ });+ QObject::connect(m_cancel_button, &QPushButton::clicked, this, [this] {+ m_report.cancel_sending();+ show_page(*m_review_page);+ m_description_edit->setFocus(Qt::OtherFocusReason);+ });+ QObject::connect(m_close_button, &QPushButton::clicked, this, [this] { exit(); });++ m_report.on_progress = [this](auto stage) { show_progress(stage); };+ m_report.on_retry = [this](String const& reason, u32 retry_number, u32 maximum_retries, u32 delay_seconds) {+ show_retry(reason, retry_number, maximum_retries, delay_seconds);+ };+ m_report.on_sent = [this] { show_sent(); };+ m_report.on_failed = [this](auto failure, String const& reason) { show_failure(failure, reason); };++ set_screenshot(AK::move(screenshot));+ update_chrome_style();+ setFocusProxy(m_description_edit);+}++void WebCompatReportReview::set_screenshot(QImage screenshot)+{+ m_screenshot = AK::move(screenshot);++ auto has_screenshot = !m_screenshot.isNull();+ m_screenshot_preview->set_screenshot(m_screenshot);+ m_screenshot_preview->setVisible(has_screenshot);+ m_remove_screenshot_button->setVisible(has_screenshot);+ m_select_screenshot_button->setText(has_screenshot ? tr("Retake screenshot") : tr("Take a screenshot"));+ m_no_screenshot_note->setVisible(!has_screenshot);+}++void WebCompatReportReview::set_page_dumps(String page_dumps)+{+ m_report.set_page_dumps(AK::move(page_dumps));+ m_include_page_dumps->setEnabled(true);+}++WebView::WebCompatReport::IncludePageDumps WebCompatReportReview::include_page_dumps() const+{+ return m_include_page_dumps->isChecked() ? WebView::WebCompatReport::IncludePageDumps::Yes : WebView::WebCompatReport::IncludePageDumps::No;+}++void WebCompatReportReview::send()+{+ auto description = ak_string_from_qstring(m_description_edit->toPlainText());+ if (auto error = WebView::WebCompatReport::validate(description); error.has_value()) {+ m_validation->setText(qstring_from_ak_string(*error));+ m_validation->show();+ m_description_edit->setFocus(Qt::OtherFocusReason);+ return;+ }++ Optional<ByteBuffer> screenshot;+ if (!m_screenshot.isNull()) {+ screenshot = encode_screenshot(m_screenshot);+ if (!screenshot.has_value()) {+ m_validation->setText(tr("This screenshot could not be included. Remove it or retake it."));+ m_validation->show();+ return;+ }+ }++ m_validation->hide();+ show_progress(WebView::ReportSubmission::Stage::Preparing);+ if (auto error = m_report.send(description, AK::move(screenshot), include_page_dumps()); error.has_value()) {+ m_validation->setText(qstring_from_ak_string(*error));+ m_validation->show();+ show_page(*m_review_page);+ }+}++void WebCompatReportReview::exit()+{+ if (on_exit)+ on_exit();+}++// The report is shown with the choices made so far, such as whether it includes layout and painting information.+void WebCompatReportReview::show_report_text()+{+ m_report_text->setPlainText(qstring_from_ak_string(String::from_utf8_with_replacement_character(m_report.diagnostics(include_page_dumps()))));+ show_page(*m_report_text_page);+ m_report_text->setFocus(Qt::OtherFocusReason);+}++void WebCompatReportReview::show_page(QWidget& page)+{+ m_review_page->setVisible(&page == m_review_page);+ m_status_page->setVisible(&page == m_status_page);+ m_report_text_page->setVisible(&page == m_report_text_page);+ if (on_report_text_visibility_change)+ on_report_text_visibility_change(&page == m_report_text_page);+}++void WebCompatReportReview::show_status(QString const& title, QString const& message, Vector<QPushButton*> const& actions,+ QPushButton* primary)+{+ m_status_title->setText(title);+ m_status_message->setText(message);+ show_page(*m_status_page);+ QPushButton* all_actions[] = { m_retry_button, m_cancel_button, m_close_button };+ show_actions(all_actions, actions, primary);+}++void WebCompatReportReview::show_progress(WebView::ReportSubmission::Stage stage)+{+ // Until the report is sent, the user can stop sending it and return to the review.+ auto is_sending = stage == WebView::ReportSubmission::Stage::Sending;+ show_status(tr("Sending report"), is_sending ? tr("Sending report…") : tr("Preparing report…"), { m_cancel_button });+ m_progress->setValue(progress_percent(stage));+ m_progress->show();+}++void WebCompatReportReview::show_retry(String const& reason, u32 retry_number, u32 maximum_retries, u32 delay_seconds)+{+ m_status_message->setText(retry_message(reason, retry_number, maximum_retries, delay_seconds));+}++void WebCompatReportReview::show_sent()+{+ m_progress->setValue(100);+ show_status(tr("Report sent"), tr("Thank you for helping Ladybird."), { m_close_button }, m_close_button);+}++void WebCompatReportReview::show_failure(WebView::ReportSubmission::Failure, String const& reason)+{+ m_progress->hide();+ show_status(tr("Couldn’t send report"), qstring_from_ak_string(reason), { m_retry_button, m_cancel_button }, m_retry_button);+}++bool WebCompatReportReview::focusNextPrevChild(bool next)+{+ if (focus_next_control(*this, next))+ return true;+ return QWidget::focusNextPrevChild(next);+}++bool WebCompatReportReview::event(QEvent* event)+{+ if (event->type() == QEvent::PaletteChange)+ update_chrome_style();+ return QWidget::event(event);+}++void WebCompatReportReview::update_chrome_style()+{+ // Restyling changes the palette, which would bring us back here.+ if (m_is_updating_chrome_style)+ return;+ m_is_updating_chrome_style = true;++ QWidget* fields[] = { m_description_edit, m_report_text };+ apply_style(*this, fields);++ m_is_updating_chrome_style = false;+}++}diff --git a/UI/Qt/WebCompatReportReview.h b/UI/Qt/WebCompatReportReview.hnew file mode 100644index 00000000000..5229c4377cc--- /dev/null+++ b/UI/Qt/WebCompatReportReview.h@@ -0,0 +1,94 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#pragma once++#include <AK/ByteBuffer.h>+#include <AK/Function.h>+#include <AK/Optional.h>+#include <AK/String.h>+#include <AK/Vector.h>+#include <AK/kmalloc.h>+#include <LibWebView/ReportSubmission.h>+#include <LibWebView/WebCompatReport.h>++#include <QImage>+#include <QWidget>++class QCheckBox;+class QLabel;+class QPlainTextEdit;+class QProgressBar;+class QPushButton;++namespace Ladybird {++class ScreenshotThumbnail;++class WebCompatReportReview final : public QWidget {+public:+ AK_ALLOC_WITH_KMALLOC;++ static Optional<ByteBuffer> encode_screenshot(QImage const&);++ WebCompatReportReview(WebView::WebCompatReport::Page, QImage screenshot, QWidget* parent);++ void set_screenshot(QImage);+ void set_page_dumps(String);++ void show_progress(WebView::ReportSubmission::Stage);+ void show_retry(String const& reason, u32 retry_number, u32 maximum_retries, u32 delay_seconds);+ void show_sent();+ void show_failure(WebView::ReportSubmission::Failure, String const& reason);++ Function<void()> on_select_screenshot;+ Function<void(QImage const&)> on_view_screenshot;+ Function<void()> on_exit;+ Function<void(bool)> on_report_text_visibility_change;++protected:+ virtual bool event(QEvent*) override;+ virtual bool focusNextPrevChild(bool next) override;++private:+ void send();+ void exit();+ void show_report_text();+ void show_page(QWidget&);+ void show_status(QString const& title, QString const& message, Vector<QPushButton*> const& actions,+ QPushButton* primary = nullptr);+ void update_chrome_style();++ WebView::WebCompatReport::IncludePageDumps include_page_dumps() const;++ WebView::WebCompatReport m_report;+ QImage m_screenshot;++ QWidget* m_review_page { nullptr };+ QWidget* m_status_page { nullptr };+ QWidget* m_report_text_page { nullptr };++ QPlainTextEdit* m_description_edit { nullptr };+ ScreenshotThumbnail* m_screenshot_preview { nullptr };+ QLabel* m_no_screenshot_note { nullptr };+ QPushButton* m_select_screenshot_button { nullptr };+ QPushButton* m_remove_screenshot_button { nullptr };+ QCheckBox* m_include_page_dumps { nullptr };+ QPushButton* m_show_report_button { nullptr };+ QPlainTextEdit* m_report_text { nullptr };+ QLabel* m_validation { nullptr };++ QLabel* m_status_title { nullptr };+ QProgressBar* m_progress { nullptr };+ QLabel* m_status_message { nullptr };+ QPushButton* m_retry_button { nullptr };+ QPushButton* m_cancel_button { nullptr };+ QPushButton* m_close_button { nullptr };++ bool m_is_updating_chrome_style { false };+};++}