PaintContext.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #pragma once
  8. #include <AK/Vector.h>
  9. #include <LibGfx/Forward.h>
  10. #include <LibGfx/Palette.h>
  11. #include <LibGfx/Rect.h>
  12. #include <LibWeb/Painting/RecordingPainter.h>
  13. #include <LibWeb/PixelUnits.h>
  14. namespace Web {
  15. class PaintContext {
  16. public:
  17. PaintContext(Painting::RecordingPainter& painter, Palette const& palette, double device_pixels_per_css_pixel);
  18. Painting::RecordingPainter& recording_painter() const { return m_recording_painter; }
  19. Palette const& palette() const { return m_palette; }
  20. bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
  21. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  22. bool should_paint_overlay() const { return m_should_paint_overlay; }
  23. void set_should_paint_overlay(bool should_paint_overlay) { m_should_paint_overlay = should_paint_overlay; }
  24. DevicePixelRect device_viewport_rect() const { return m_device_viewport_rect; }
  25. void set_device_viewport_rect(DevicePixelRect const& rect) { m_device_viewport_rect = rect; }
  26. CSSPixelRect css_viewport_rect() const;
  27. bool has_focus() const { return m_focus; }
  28. void set_has_focus(bool focus) { m_focus = focus; }
  29. void set_svg_transform(Gfx::AffineTransform transform)
  30. {
  31. m_svg_transform = transform;
  32. }
  33. Gfx::AffineTransform const& svg_transform() const
  34. {
  35. return m_svg_transform;
  36. }
  37. DevicePixels enclosing_device_pixels(CSSPixels css_pixels) const;
  38. DevicePixels floored_device_pixels(CSSPixels css_pixels) const;
  39. DevicePixels rounded_device_pixels(CSSPixels css_pixels) const;
  40. DevicePixelPoint rounded_device_point(CSSPixelPoint) const;
  41. DevicePixelPoint floored_device_point(CSSPixelPoint) const;
  42. DevicePixelRect enclosing_device_rect(CSSPixelRect) const;
  43. DevicePixelRect rounded_device_rect(CSSPixelRect) const;
  44. DevicePixelSize enclosing_device_size(CSSPixelSize) const;
  45. DevicePixelSize rounded_device_size(CSSPixelSize) const;
  46. CSSPixels scale_to_css_pixels(DevicePixels) const;
  47. CSSPixelPoint scale_to_css_point(DevicePixelPoint) const;
  48. CSSPixelSize scale_to_css_size(DevicePixelSize) const;
  49. CSSPixelRect scale_to_css_rect(DevicePixelRect) const;
  50. PaintContext clone(Painting::RecordingPainter& painter) const
  51. {
  52. auto clone = PaintContext(painter, m_palette, m_device_pixels_per_css_pixel);
  53. clone.m_device_viewport_rect = m_device_viewport_rect;
  54. clone.m_should_show_line_box_borders = m_should_show_line_box_borders;
  55. clone.m_should_paint_overlay = m_should_paint_overlay;
  56. clone.m_focus = m_focus;
  57. return clone;
  58. }
  59. double device_pixels_per_css_pixel() const { return m_device_pixels_per_css_pixel; }
  60. u32 allocate_corner_clipper_id() { return m_next_corner_clipper_id++; }
  61. private:
  62. Painting::RecordingPainter& m_recording_painter;
  63. Palette m_palette;
  64. double m_device_pixels_per_css_pixel { 0 };
  65. DevicePixelRect m_device_viewport_rect;
  66. bool m_should_show_line_box_borders { false };
  67. bool m_should_paint_overlay { true };
  68. bool m_focus { false };
  69. Gfx::AffineTransform m_svg_transform;
  70. u32 m_next_corner_clipper_id { 0 };
  71. };
  72. }