From 0345c67e149015f2071576f39b4816b81f6c5fdd Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 7 Nov 2024 12:46:45 -0500 Subject: [PATCH] UI/Qt: Do not place the WebView inside a scroll view Now that scrolling and rendering scrollbars is handled entirely in the WebContent process, there's no reason to place the WebView inside scroll views. --- Ladybird/Qt/FindInPageWidget.cpp | 2 ++ Ladybird/Qt/WebContentView.cpp | 32 +++++++++++++------------------- Ladybird/Qt/WebContentView.h | 4 ++-- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Ladybird/Qt/FindInPageWidget.cpp b/Ladybird/Qt/FindInPageWidget.cpp index fb06a11a27f..0c38f2babc6 100644 --- a/Ladybird/Qt/FindInPageWidget.cpp +++ b/Ladybird/Qt/FindInPageWidget.cpp @@ -18,9 +18,11 @@ FindInPageWidget::FindInPageWidget(Tab* tab, WebContentView* content_view) , m_content_view(content_view) { setFocusPolicy(Qt::FocusPolicy::StrongFocus); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); auto* layout = new QHBoxLayout(this); setLayout(layout); + layout->setContentsMargins(5, 5, 5, 5); layout->setAlignment(Qt::AlignmentFlag::AlignLeft); diff --git a/Ladybird/Qt/WebContentView.cpp b/Ladybird/Qt/WebContentView.cpp index 891fdb7ef65..03e5d220073 100644 --- a/Ladybird/Qt/WebContentView.cpp +++ b/Ladybird/Qt/WebContentView.cpp @@ -49,11 +49,8 @@ namespace Ladybird { bool is_using_dark_system_theme(QWidget&); WebContentView::WebContentView(QWidget* window, RefPtr parent_client, size_t page_index) - : QAbstractScrollArea(window) + : QWidget(window) { - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - m_client_state.client = parent_client; m_client_state.page_index = page_index; @@ -65,9 +62,6 @@ WebContentView::WebContentView(QWidget* window, RefPtrsetSingleStep(24); - horizontalScrollBar()->setSingleStep(24); - QObject::connect(qGuiApp, &QGuiApplication::screenRemoved, [this](QScreen*) { update_screen_rects(); }); @@ -89,7 +83,7 @@ WebContentView::WebContentView(QWidget* window, RefPtrupdate(); + update(); }; on_cursor_change = [this](auto cursor) { @@ -491,7 +485,7 @@ void WebContentView::focusOutEvent(QFocusEvent*) void WebContentView::paintEvent(QPaintEvent*) { - QPainter painter(viewport()); + QPainter painter(this); painter.scale(1 / m_device_pixel_ratio, 1 / m_device_pixel_ratio); Gfx::Bitmap const* bitmap = nullptr; @@ -525,7 +519,7 @@ void WebContentView::paintEvent(QPaintEvent*) void WebContentView::resizeEvent(QResizeEvent* event) { - QAbstractScrollArea::resizeEvent(event); + QWidget::resizeEvent(event); update_viewport_size(); handle_resize(); } @@ -546,8 +540,8 @@ void WebContentView::set_device_pixel_ratio(double device_pixel_ratio) void WebContentView::update_viewport_size() { - auto scaled_width = int(viewport()->width() * m_device_pixel_ratio); - auto scaled_height = int(viewport()->height() * m_device_pixel_ratio); + auto scaled_width = int(width() * m_device_pixel_ratio); + auto scaled_height = int(height() * m_device_pixel_ratio); Gfx::IntRect rect(0, 0, scaled_width, scaled_height); set_viewport_rect(rect); @@ -561,13 +555,13 @@ void WebContentView::update_zoom() void WebContentView::showEvent(QShowEvent* event) { - QAbstractScrollArea::showEvent(event); + QWidget::showEvent(event); client().async_set_system_visibility_state(m_client_state.page_index, true); } void WebContentView::hideEvent(QHideEvent* event) { - QAbstractScrollArea::hideEvent(event); + QWidget::hideEvent(event); client().async_set_system_visibility_state(m_client_state.page_index, false); } @@ -767,7 +761,7 @@ bool WebContentView::event(QEvent* event) if (event->type() == QEvent::PaletteChange) { update_palette(); - return QAbstractScrollArea::event(event); + return QWidget::event(event); } if (event->type() == QEvent::ShortcutOverride) { @@ -775,7 +769,7 @@ bool WebContentView::event(QEvent* event) return true; } - return QAbstractScrollArea::event(event); + return QWidget::event(event); } void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePointEvent const& event) @@ -807,9 +801,9 @@ void WebContentView::enqueue_native_event(Web::MouseEvent::Type type, QSinglePoi float delta_x = -static_cast(angle_delta.x()) / 120.0f; float delta_y = static_cast(angle_delta.y()) / 120.0f; + static constexpr float scroll_step_size = 24; auto step_x = delta_x * static_cast(QApplication::wheelScrollLines()) * m_device_pixel_ratio; auto step_y = delta_y * static_cast(QApplication::wheelScrollLines()) * m_device_pixel_ratio; - auto scroll_step_size = static_cast(verticalScrollBar()->singleStep()); wheel_delta_x = static_cast(step_x * scroll_step_size); wheel_delta_y = static_cast(step_y * scroll_step_size); @@ -910,10 +904,10 @@ void WebContentView::finish_handling_key_event(Web::KeyEvent const& key_event) switch (key_event.type) { case Web::KeyEvent::Type::KeyDown: - QAbstractScrollArea::keyPressEvent(&event); + QWidget::keyPressEvent(&event); break; case Web::KeyEvent::Type::KeyUp: - QAbstractScrollArea::keyReleaseEvent(&event); + QWidget::keyReleaseEvent(&event); break; } diff --git a/Ladybird/Qt/WebContentView.h b/Ladybird/Qt/WebContentView.h index f2d6d844d65..229247b26e1 100644 --- a/Ladybird/Qt/WebContentView.h +++ b/Ladybird/Qt/WebContentView.h @@ -21,10 +21,10 @@ #include #include #include -#include #include #include #include +#include class QKeyEvent; class QLineEdit; @@ -42,7 +42,7 @@ namespace Ladybird { class Tab; class WebContentView final - : public QAbstractScrollArea + : public QWidget , public WebView::ViewImplementation { Q_OBJECT public: