diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
index 1ffedb29990..be327ed21d2 100644
--- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp
@@ -2128,13 +2128,15 @@ RefPtr Navigable::record_display_list(PaintConfig config)
viewport_paintable.paint_all_phases(context);
- Vector scroll_offsets_by_frame_id;
- scroll_offsets_by_frame_id.resize(viewport_paintable.scroll_state.size());
- for (auto [_, scrollable_frame] : viewport_paintable.scroll_state) {
- auto scroll_offset = context.rounded_device_point(scrollable_frame->cumulative_offset).to_type();
- scroll_offsets_by_frame_id[scrollable_frame->id] = scroll_offset;
+ display_list->set_device_pixels_per_css_pixel(page.client().device_pixels_per_css_pixel());
+
+ Vector> scroll_state;
+ scroll_state.resize(viewport_paintable.scroll_state.size());
+ for (auto& [_, scrollable_frame] : viewport_paintable.scroll_state) {
+ scroll_state[scrollable_frame->id] = scrollable_frame;
}
- display_list_recorder.display_list().apply_scroll_offsets(scroll_offsets_by_frame_id);
+
+ display_list->set_scroll_state(move(scroll_state));
m_needs_repaint = false;
diff --git a/Userland/Libraries/LibWeb/Painting/DisplayList.cpp b/Userland/Libraries/LibWeb/Painting/DisplayList.cpp
index 50744a700a4..2146d3c88c9 100644
--- a/Userland/Libraries/LibWeb/Painting/DisplayList.cpp
+++ b/Userland/Libraries/LibWeb/Painting/DisplayList.cpp
@@ -24,28 +24,26 @@ static Optional command_bounding_rectangle(Command const& command)
});
}
-void DisplayList::apply_scroll_offsets(Vector const& offsets_by_frame_id)
-{
- for (auto& command_with_scroll_id : m_commands) {
- if (command_with_scroll_id.scroll_frame_id.has_value()) {
- auto const& scroll_frame_id = command_with_scroll_id.scroll_frame_id.value();
- auto const& scroll_offset = offsets_by_frame_id[scroll_frame_id];
- command_with_scroll_id.command.visit(
- [&](auto& command) {
- if constexpr (requires { command.translate_by(scroll_offset); })
- command.translate_by(scroll_offset);
- });
- }
- }
-}
-
void DisplayListPlayer::execute(DisplayList& display_list)
{
auto const& commands = display_list.commands();
+ auto const& scroll_state = display_list.scroll_state();
+ auto device_pixels_per_css_pixel = display_list.device_pixels_per_css_pixel();
size_t next_command_index = 0;
while (next_command_index < commands.size()) {
- auto const& command = commands[next_command_index++].command;
+ auto scroll_frame_id = commands[next_command_index].scroll_frame_id;
+ auto command = commands[next_command_index++].command;
+ if (scroll_frame_id.has_value()) {
+ auto const& scroll_offset = scroll_state[scroll_frame_id.value()]->cumulative_offset.to_type().scaled(device_pixels_per_css_pixel).to_type();
+ command.visit(
+ [&](auto& command) {
+ if constexpr (requires { command.translate_by(scroll_offset); }) {
+ command.translate_by(scroll_offset);
+ }
+ });
+ }
+
auto bounding_rect = command_bounding_rectangle(command);
if (bounding_rect.has_value() && (bounding_rect->is_empty() || would_be_fully_clipped_by_painter(*bounding_rect))) {
continue;
diff --git a/Userland/Libraries/LibWeb/Painting/DisplayList.h b/Userland/Libraries/LibWeb/Painting/DisplayList.h
index c286b5e00c1..60ec3c4832e 100644
--- a/Userland/Libraries/LibWeb/Painting/DisplayList.h
+++ b/Userland/Libraries/LibWeb/Painting/DisplayList.h
@@ -29,6 +29,7 @@
#include
#include
#include
+#include
namespace Web::Painting {
@@ -83,8 +84,6 @@ public:
void append(Command&& command, Optional scroll_frame_id);
- void apply_scroll_offsets(Vector const& offsets_by_frame_id);
-
struct CommandListItem {
Optional scroll_frame_id;
Command command;
@@ -92,10 +91,19 @@ public:
AK::SegmentedVector const& commands() const { return m_commands; }
+ void set_scroll_state(Vector> scroll_state) { m_scroll_state = move(scroll_state); }
+
+ Vector> const& scroll_state() const { return m_scroll_state; }
+
+ void set_device_pixels_per_css_pixel(double device_pixels_per_css_pixel) { m_device_pixels_per_css_pixel = device_pixels_per_css_pixel; }
+ double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; }
+
private:
DisplayList() = default;
AK::SegmentedVector m_commands;
+ Vector> m_scroll_state;
+ double m_device_pixels_per_css_pixel;
};
}