mirror of
https://github.com/RGBCube/serenity
synced 2025-05-17 15:35:06 +00:00

With this change, instead of applying scroll offsets during the recording of the painting command list, we do the following: 1. Collect all boxes with scrollable overflow into a PaintContext, each with an id and the total amount of scrolling offset accumulated from ancestor scrollable boxes. 2. During the recording phase assign a corresponding scroll_frame_id to each command that paints content within a scrollable box. 3. Before executing the recorded commands, translate each command that has a scroll_frame_id by the accumulated scroll offset. This approach has following advantages: - Implementing nested scrollables becomes much simpler, as the recording phase only requires the correct assignment of the nearest scrollable's scroll_frame_id, while the accumulated offset from ancestors is applied subsequently. - The recording of painting commands is not tied to a specific offset within scrollable boxes, which means in the future, it will be possible to update the scrolling offset and repaint without the need to re-record painting commands.
96 lines
3.6 KiB
C++
96 lines
3.6 KiB
C++
/*
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Vector.h>
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibGfx/Palette.h>
|
|
#include <LibGfx/Rect.h>
|
|
#include <LibWeb/Painting/RecordingPainter.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web {
|
|
|
|
class PaintContext {
|
|
public:
|
|
PaintContext(Painting::RecordingPainter& painter, Palette const& palette, double device_pixels_per_css_pixel);
|
|
|
|
Painting::RecordingPainter& recording_painter() const { return m_recording_painter; }
|
|
Palette const& palette() const { return m_palette; }
|
|
|
|
bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
|
|
void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
|
|
|
|
bool should_paint_overlay() const { return m_should_paint_overlay; }
|
|
void set_should_paint_overlay(bool should_paint_overlay) { m_should_paint_overlay = should_paint_overlay; }
|
|
|
|
DevicePixelRect device_viewport_rect() const { return m_device_viewport_rect; }
|
|
void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; }
|
|
CSSPixelRect css_viewport_rect() const;
|
|
|
|
bool has_focus() const { return m_focus; }
|
|
void set_has_focus(bool focus) { m_focus = focus; }
|
|
|
|
void set_svg_transform(Gfx::AffineTransform transform)
|
|
{
|
|
m_svg_transform = transform;
|
|
}
|
|
|
|
Gfx::AffineTransform const& svg_transform() const
|
|
{
|
|
return m_svg_transform;
|
|
}
|
|
|
|
DevicePixels enclosing_device_pixels(CSSPixels css_pixels) const;
|
|
DevicePixels floored_device_pixels(CSSPixels css_pixels) const;
|
|
DevicePixels rounded_device_pixels(CSSPixels css_pixels) const;
|
|
DevicePixelPoint rounded_device_point(CSSPixelPoint) const;
|
|
DevicePixelPoint floored_device_point(CSSPixelPoint) const;
|
|
DevicePixelRect enclosing_device_rect(CSSPixelRect) const;
|
|
DevicePixelRect rounded_device_rect(CSSPixelRect) const;
|
|
DevicePixelSize enclosing_device_size(CSSPixelSize) const;
|
|
DevicePixelSize rounded_device_size(CSSPixelSize) const;
|
|
CSSPixels scale_to_css_pixels(DevicePixels) const;
|
|
CSSPixelPoint scale_to_css_point(DevicePixelPoint) const;
|
|
CSSPixelSize scale_to_css_size(DevicePixelSize) const;
|
|
CSSPixelRect scale_to_css_rect(DevicePixelRect) const;
|
|
|
|
PaintContext clone(Painting::RecordingPainter& painter) const
|
|
{
|
|
auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel);
|
|
clone.m_device_viewport_rect = m_device_viewport_rect;
|
|
clone.m_should_show_line_box_borders = m_should_show_line_box_borders;
|
|
clone.m_should_paint_overlay = m_should_paint_overlay;
|
|
clone.m_focus = m_focus;
|
|
return clone;
|
|
}
|
|
|
|
double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; }
|
|
|
|
u32 allocate_corner_clipper_id() { return m_next_corner_clipper_id++; }
|
|
|
|
struct ScrollFrame {
|
|
i32 id { -1 };
|
|
CSSPixelPoint offset;
|
|
};
|
|
HashMap<Painting::PaintableBox const*, ScrollFrame>& scroll_frames() { return m_scroll_frames; }
|
|
|
|
private:
|
|
Painting::RecordingPainter& m_recording_painter;
|
|
Palette m_palette;
|
|
double m_device_pixels_per_css_pixel { 0 };
|
|
DevicePixelRect m_device_viewport_rect;
|
|
bool m_should_show_line_box_borders { false };
|
|
bool m_should_paint_overlay { true };
|
|
bool m_focus { false };
|
|
Gfx::AffineTransform m_svg_transform;
|
|
u32 m_next_corner_clipper_id { 0 };
|
|
HashMap<Painting::PaintableBox const*, ScrollFrame> m_scroll_frames;
|
|
};
|
|
|
|
}
|