mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 02:05:07 +02:00
Add ElementResizeAction to Page (maybe there's a better place). It's just a mousemove delegate that updates styles on the target element. Add ChromeMetrics for zoom-invariant chrome like scrollbar thumb thickness, resize gripper size, paddings, etc. It's not user-stylable but separates basic concerns in a way that a visually gifted designer unlike myself can adjust to taste. These values are pre-divided by zoom factor so that PaintableBox can continue using device_pixels_per_css_pixel calls as normal. The adjusted metrics are computed on demand from Page multiple times per paint cycle, which is not ideal but avoids lifetime management and atomics. Maybe someone with more surety about the painting flow control can improve this, but it won't be a huge win. If profiling shows this slowing paints, then Ladybird is in good shape. Update PaintableBox to draw the resize gripper and deconflict the scrollbars. Set apropriate cursors for scrollbars and gripper in mousemove. We override EventHandler's cursor handling because nothing should ever come between a man and his resize gripper. Chrome metrics use the CSSPixels class. This is good because it's broadly compatible but bad because they're actually different units when zoom is not 1.0. If that's a problem, we could make a new type or just use double.
100 lines
4.0 KiB
C++
100 lines
4.0 KiB
C++
/*
|
|
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGfx/Forward.h>
|
|
#include <LibGfx/Palette.h>
|
|
#include <LibGfx/Rect.h>
|
|
#include <LibWeb/Export.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/Painting/ChromeMetrics.h>
|
|
#include <LibWeb/Painting/DevicePixelConverter.h>
|
|
#include <LibWeb/PixelUnits.h>
|
|
|
|
namespace Web {
|
|
|
|
class WEB_API DisplayListRecordingContext {
|
|
public:
|
|
DisplayListRecordingContext(Painting::DisplayListRecorder& painter, Palette const& palette, double device_pixels_per_css_pixel, ChromeMetrics const& chrome_metrics);
|
|
|
|
Painting::DisplayListRecorder& display_list_recorder() const { return m_display_list_recorder; }
|
|
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;
|
|
|
|
void set_svg_transform(Gfx::AffineTransform transform)
|
|
{
|
|
m_svg_transform = transform;
|
|
}
|
|
|
|
Gfx::AffineTransform const& svg_transform() const
|
|
{
|
|
return m_svg_transform;
|
|
}
|
|
|
|
bool draw_svg_geometry_for_clip_path() const
|
|
{
|
|
return m_draw_svg_geometry_for_clip_path;
|
|
}
|
|
|
|
void set_draw_svg_geometry_for_clip_path(bool draw_svg_geometry_for_clip_path)
|
|
{
|
|
m_draw_svg_geometry_for_clip_path = draw_svg_geometry_for_clip_path;
|
|
}
|
|
|
|
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;
|
|
|
|
DisplayListRecordingContext clone(Painting::DisplayListRecorder& painter) const
|
|
{
|
|
auto clone = DisplayListRecordingContext(painter, m_palette, m_device_pixel_converter.device_pixels_per_css_pixel(), m_chrome_metrics);
|
|
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;
|
|
return clone;
|
|
}
|
|
|
|
Painting::DevicePixelConverter const& device_pixel_converter() const { return m_device_pixel_converter; }
|
|
double device_pixels_per_css_pixel() const { return m_device_pixel_converter.device_pixels_per_css_pixel(); }
|
|
ChromeMetrics const& chrome_metrics() const { return m_chrome_metrics; }
|
|
u64 paint_generation_id() const { return m_paint_generation_id; }
|
|
|
|
private:
|
|
Painting::DisplayListRecorder& m_display_list_recorder;
|
|
Palette m_palette;
|
|
Painting::DevicePixelConverter m_device_pixel_converter;
|
|
ChromeMetrics m_chrome_metrics;
|
|
DevicePixelRect m_device_viewport_rect;
|
|
bool m_should_show_line_box_borders { false };
|
|
bool m_should_paint_overlay { true };
|
|
bool m_draw_svg_geometry_for_clip_path { false };
|
|
Gfx::AffineTransform m_svg_transform;
|
|
u64 m_paint_generation_id { 0 };
|
|
};
|
|
|
|
}
|