/src/serenity/Userland/Libraries/LibWeb/Painting/PaintContext.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org> |
3 | | * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> |
4 | | * |
5 | | * SPDX-License-Identifier: BSD-2-Clause |
6 | | */ |
7 | | |
8 | | #pragma once |
9 | | |
10 | | #include <AK/Vector.h> |
11 | | #include <LibGfx/Forward.h> |
12 | | #include <LibGfx/Palette.h> |
13 | | #include <LibGfx/Rect.h> |
14 | | #include <LibWeb/Painting/DisplayListRecorder.h> |
15 | | #include <LibWeb/PixelUnits.h> |
16 | | |
17 | | namespace Web { |
18 | | |
19 | | class PaintContext { |
20 | | public: |
21 | | PaintContext(Painting::DisplayListRecorder& painter, Palette const& palette, double device_pixels_per_css_pixel); |
22 | | |
23 | 0 | Painting::DisplayListRecorder& display_list_recorder() const { return m_display_list_recorder; } |
24 | 0 | Palette const& palette() const { return m_palette; } |
25 | | |
26 | 0 | bool should_show_line_box_borders() const { return m_should_show_line_box_borders; } |
27 | 0 | void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; } |
28 | | |
29 | 0 | bool should_paint_overlay() const { return m_should_paint_overlay; } |
30 | 0 | void set_should_paint_overlay(bool should_paint_overlay) { m_should_paint_overlay = should_paint_overlay; } |
31 | | |
32 | 0 | DevicePixelRect device_viewport_rect() const { return m_device_viewport_rect; } |
33 | 0 | void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; } |
34 | | CSSPixelRect css_viewport_rect() const; |
35 | | |
36 | 0 | bool has_focus() const { return m_focus; } |
37 | 0 | void set_has_focus(bool focus) { m_focus = focus; } |
38 | | |
39 | | void set_svg_transform(Gfx::AffineTransform transform) |
40 | 0 | { |
41 | 0 | m_svg_transform = transform; |
42 | 0 | } |
43 | | |
44 | | Gfx::AffineTransform const& svg_transform() const |
45 | 0 | { |
46 | 0 | return m_svg_transform; |
47 | 0 | } |
48 | | |
49 | | bool draw_svg_geometry_for_clip_path() const |
50 | 0 | { |
51 | 0 | return m_draw_svg_geometry_for_clip_path; |
52 | 0 | } |
53 | | |
54 | | void set_draw_svg_geometry_for_clip_path(bool draw_svg_geometry_for_clip_path) |
55 | 0 | { |
56 | 0 | m_draw_svg_geometry_for_clip_path = draw_svg_geometry_for_clip_path; |
57 | 0 | } |
58 | | |
59 | | DevicePixels enclosing_device_pixels(CSSPixels css_pixels) const; |
60 | | DevicePixels floored_device_pixels(CSSPixels css_pixels) const; |
61 | | DevicePixels rounded_device_pixels(CSSPixels css_pixels) const; |
62 | | DevicePixelPoint rounded_device_point(CSSPixelPoint) const; |
63 | | DevicePixelPoint floored_device_point(CSSPixelPoint) const; |
64 | | DevicePixelRect enclosing_device_rect(CSSPixelRect) const; |
65 | | DevicePixelRect rounded_device_rect(CSSPixelRect) const; |
66 | | DevicePixelSize enclosing_device_size(CSSPixelSize) const; |
67 | | DevicePixelSize rounded_device_size(CSSPixelSize) const; |
68 | | CSSPixels scale_to_css_pixels(DevicePixels) const; |
69 | | CSSPixelPoint scale_to_css_point(DevicePixelPoint) const; |
70 | | CSSPixelSize scale_to_css_size(DevicePixelSize) const; |
71 | | CSSPixelRect scale_to_css_rect(DevicePixelRect) const; |
72 | | |
73 | | PaintContext clone(Painting::DisplayListRecorder& painter) const |
74 | 0 | { |
75 | 0 | auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel); |
76 | 0 | clone.m_device_viewport_rect = m_device_viewport_rect; |
77 | 0 | clone.m_should_show_line_box_borders = m_should_show_line_box_borders; |
78 | 0 | clone.m_should_paint_overlay = m_should_paint_overlay; |
79 | 0 | clone.m_focus = m_focus; |
80 | 0 | return clone; |
81 | 0 | } |
82 | | |
83 | 0 | double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; } |
84 | | |
85 | 0 | u32 allocate_corner_clipper_id() { return m_next_corner_clipper_id++; } |
86 | | |
87 | 0 | u64 paint_generation_id() const { return m_paint_generation_id; } |
88 | | |
89 | | private: |
90 | | Painting::DisplayListRecorder& m_display_list_recorder; |
91 | | Palette m_palette; |
92 | | double m_device_pixels_per_css_pixel { 0 }; |
93 | | DevicePixelRect m_device_viewport_rect; |
94 | | bool m_should_show_line_box_borders { false }; |
95 | | bool m_should_paint_overlay { true }; |
96 | | bool m_focus { false }; |
97 | | bool m_draw_svg_geometry_for_clip_path { false }; |
98 | | Gfx::AffineTransform m_svg_transform; |
99 | | u32 m_next_corner_clipper_id { 0 }; |
100 | | u64 m_paint_generation_id { 0 }; |
101 | | }; |
102 | | |
103 | | } |