PaintContext.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Vector.h>
  8. #include <LibGfx/Forward.h>
  9. #include <LibGfx/Palette.h>
  10. #include <LibGfx/Rect.h>
  11. #include <LibWeb/SVG/SVGContext.h>
  12. namespace Web {
  13. class PaintContext {
  14. public:
  15. PaintContext(Gfx::Painter& painter, Palette const& palette, Gfx::IntPoint const& scroll_offset);
  16. Gfx::Painter& painter() const { return m_painter; }
  17. Palette const& palette() const { return m_palette; }
  18. bool has_svg_context() const { return m_svg_context.has_value(); }
  19. SVGContext& svg_context();
  20. void set_svg_context(SVGContext);
  21. void clear_svg_context();
  22. bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
  23. void set_should_show_line_box_borders(bool value) { m_should_show_line_box_borders = value; }
  24. Gfx::IntRect viewport_rect() const { return m_viewport_rect; }
  25. void set_viewport_rect(Gfx::IntRect const& rect) { m_viewport_rect = rect; }
  26. Gfx::IntPoint scroll_offset() const { return m_scroll_offset; }
  27. bool has_focus() const { return m_focus; }
  28. void set_has_focus(bool focus) { m_focus = focus; }
  29. PaintContext clone(Gfx::Painter& painter) const
  30. {
  31. auto clone = PaintContext(painter, m_palette, m_scroll_offset);
  32. clone.m_viewport_rect = m_viewport_rect;
  33. clone.m_should_show_line_box_borders = m_should_show_line_box_borders;
  34. clone.m_focus = m_focus;
  35. clone.m_svg_context = m_svg_context;
  36. return clone;
  37. }
  38. private:
  39. Gfx::Painter& m_painter;
  40. Palette m_palette;
  41. Optional<SVGContext> m_svg_context;
  42. Gfx::IntRect m_viewport_rect;
  43. Gfx::IntPoint m_scroll_offset;
  44. bool m_should_show_line_box_borders { false };
  45. bool m_focus { false };
  46. };
  47. }