1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 12:27:34 +00:00

LibWeb: Refactor int types in WebContentServer to DevicePixels

This commit is contained in:
Bastiaan van der Plaat 2023-12-14 07:17:00 +01:00 committed by Alexander Kalenik
parent 8730e56f62
commit c069ab1ca0
18 changed files with 169 additions and 69 deletions

View file

@ -85,11 +85,11 @@ struct HideCursor {
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
auto* screens = [NSScreen screens];
Vector<Gfx::IntRect> screen_rects;
Vector<Web::DevicePixelRect> screen_rects;
screen_rects.ensure_capacity([screens count]);
for (id screen in screens) {
auto screen_rect = Ladybird::ns_rect_to_gfx_rect([screen frame]);
auto screen_rect = Ladybird::ns_rect_to_gfx_rect([screen frame]).to_type<Web::DevicePixels>();
screen_rects.unchecked_append(screen_rect);
}

View file

@ -23,12 +23,12 @@ static T scale_for_device(T size, float device_pixel_ratio)
return size.template to_type<float>().scaled(device_pixel_ratio).template to_type<int>();
}
ErrorOr<NonnullOwnPtr<WebViewBridge>> WebViewBridge::create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
ErrorOr<NonnullOwnPtr<WebViewBridge>> WebViewBridge::create(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
{
return adopt_nonnull_own_or_enomem(new (nothrow) WebViewBridge(move(screen_rects), device_pixel_ratio, web_content_options, move(webdriver_content_ipc_path), preferred_color_scheme));
}
WebViewBridge::WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
WebViewBridge::WebViewBridge(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, WebContentOptions const& web_content_options, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme preferred_color_scheme)
: m_screen_rects(move(screen_rects))
, m_web_content_options(web_content_options)
, m_webdriver_content_ipc_path(move(webdriver_content_ipc_path))
@ -89,7 +89,7 @@ void WebViewBridge::set_viewport_rect(Gfx::IntRect viewport_rect, ForResize for_
viewport_rect.set_size(scale_for_device(viewport_rect.size(), m_device_pixel_ratio));
m_viewport_rect = viewport_rect;
client().async_set_viewport_rect(m_viewport_rect);
client().async_set_viewport_rect(m_viewport_rect.to_type<Web::DevicePixels>());
request_repaint();
if (for_resize == ForResize::Yes) {
@ -151,10 +151,10 @@ Optional<WebViewBridge::Paintable> WebViewBridge::paintable()
if (m_client_state.has_usable_bitmap) {
bitmap = m_client_state.front_bitmap.bitmap.ptr();
bitmap_size = m_client_state.front_bitmap.last_painted_size;
bitmap_size = m_client_state.front_bitmap.last_painted_size.to_type<int>();
} else {
bitmap = m_backup_bitmap.ptr();
bitmap_size = m_backup_bitmap_size;
bitmap_size = m_backup_bitmap_size.to_type<int>();
}
if (!bitmap)
@ -170,9 +170,9 @@ void WebViewBridge::update_zoom()
on_zoom_level_changed();
}
Gfx::IntRect WebViewBridge::viewport_rect() const
Web::DevicePixelRect WebViewBridge::viewport_rect() const
{
return m_viewport_rect;
return m_viewport_rect.to_type<Web::DevicePixels>();
}
Gfx::IntPoint WebViewBridge::to_content_position(Gfx::IntPoint widget_position) const

View file

@ -23,7 +23,7 @@ namespace Ladybird {
class WebViewBridge final : public WebView::ViewImplementation {
public:
static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
static ErrorOr<NonnullOwnPtr<WebViewBridge>> create(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
virtual ~WebViewBridge() override;
float device_pixel_ratio() const { return m_device_pixel_ratio; }
@ -60,16 +60,16 @@ public:
Function<void(Gfx::IntPoint)> on_scroll;
private:
WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
WebViewBridge(Vector<Web::DevicePixelRect> screen_rects, float device_pixel_ratio, WebContentOptions const&, Optional<StringView> webdriver_content_ipc_path, Web::CSS::PreferredColorScheme);
virtual void update_zoom() override;
virtual Gfx::IntRect viewport_rect() const override;
virtual Web::DevicePixelRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
virtual void create_client() override;
Vector<Gfx::IntRect> m_screen_rects;
Vector<Web::DevicePixelRect> m_screen_rects;
Gfx::IntRect m_viewport_rect;
WebContentOptions m_web_content_options;

View file

@ -704,7 +704,7 @@ void BrowserWindow::resizeEvent(QResizeEvent* event)
QWidget::resizeEvent(event);
for_each_tab([&](auto& tab) {
tab.view().set_window_size({ frameSize().width(), frameSize().height() });
tab.view().set_window_size({ frameSize().width() * m_device_pixel_ratio, frameSize().height() * m_device_pixel_ratio });
});
}
@ -713,7 +713,7 @@ void BrowserWindow::moveEvent(QMoveEvent* event)
QWidget::moveEvent(event);
for_each_tab([&](auto& tab) {
tab.view().set_window_position({ event->pos().x(), event->pos().y() });
tab.view().set_window_position({ event->pos().x() * m_device_pixel_ratio, event->pos().y() * m_device_pixel_ratio });
});
}

View file

@ -484,11 +484,11 @@ void WebContentView::paintEvent(QPaintEvent*)
if (m_client_state.has_usable_bitmap) {
bitmap = m_client_state.front_bitmap.bitmap.ptr();
bitmap_size = m_client_state.front_bitmap.last_painted_size;
bitmap_size = m_client_state.front_bitmap.last_painted_size.to_type<int>();
} else {
bitmap = m_backup_bitmap.ptr();
bitmap_size = m_backup_bitmap_size;
bitmap_size = m_backup_bitmap_size.to_type<int>();
}
if (bitmap) {
@ -518,17 +518,17 @@ void WebContentView::resizeEvent(QResizeEvent* event)
void WebContentView::set_viewport_rect(Gfx::IntRect rect)
{
m_viewport_rect = rect;
client().async_set_viewport_rect(rect);
client().async_set_viewport_rect(rect.to_type<Web::DevicePixels>());
}
void WebContentView::set_window_size(Gfx::IntSize size)
{
client().async_set_window_size(size);
client().async_set_window_size(size.to_type<Web::DevicePixels>());
}
void WebContentView::set_window_position(Gfx::IntPoint position)
{
client().async_set_window_position(position);
client().async_set_window_position(position.to_type<Web::DevicePixels>());
}
void WebContentView::set_device_pixel_ratio(double device_pixel_ratio)
@ -631,12 +631,10 @@ void WebContentView::create_client()
auto screens = QGuiApplication::screens();
if (!screens.empty()) {
Vector<Gfx::IntRect> screen_rects;
Vector<Web::DevicePixelRect> screen_rects;
for (auto const& screen : screens) {
auto geometry = screen->geometry();
screen_rects.append(Gfx::IntRect(geometry.x(), geometry.y(), geometry.width(), geometry.height()));
screen_rects.append(Web::DevicePixelRect(geometry.x(), geometry.y(), geometry.width(), geometry.height()));
}
// FIXME: Update the screens again when QGuiApplication::screenAdded/Removed signals are emitted
@ -714,9 +712,9 @@ void WebContentView::update_cursor(Gfx::StandardCursor cursor)
}
}
Gfx::IntRect WebContentView::viewport_rect() const
Web::DevicePixelRect WebContentView::viewport_rect() const
{
return m_viewport_rect;
return m_viewport_rect.to_type<Web::DevicePixels>();
}
Gfx::IntPoint WebContentView::to_content_position(Gfx::IntPoint widget_position) const

View file

@ -84,7 +84,7 @@ private:
// ^WebView::ViewImplementation
virtual void create_client() override;
virtual void update_zoom() override;
virtual Gfx::IntRect viewport_rect() const override;
virtual Web::DevicePixelRect viewport_rect() const override;
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;