SVGGraphicsElement.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
  3. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <LibGfx/PaintStyle.h>
  9. #include <LibGfx/Path.h>
  10. #include <LibWeb/DOM/Node.h>
  11. #include <LibWeb/SVG/AttributeParser.h>
  12. #include <LibWeb/SVG/SVGElement.h>
  13. #include <LibWeb/SVG/SVGGradientElement.h>
  14. #include <LibWeb/SVG/TagNames.h>
  15. #include <LibWeb/SVG/ViewBox.h>
  16. namespace Web::SVG {
  17. class SVGGraphicsElement : public SVGElement {
  18. WEB_PLATFORM_OBJECT(SVGGraphicsElement, SVGElement);
  19. public:
  20. virtual void apply_presentational_hints(CSS::StyleProperties&) const override;
  21. virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
  22. Optional<Gfx::Color> fill_color() const;
  23. Optional<FillRule> fill_rule() const;
  24. Optional<Gfx::Color> stroke_color() const;
  25. Optional<float> stroke_width() const;
  26. Optional<float> fill_opacity() const;
  27. Optional<float> stroke_opacity() const;
  28. float visible_stroke_width() const
  29. {
  30. if (auto color = stroke_color(); color.has_value() && color->alpha() > 0)
  31. return stroke_width().value_or(0);
  32. return 0;
  33. }
  34. Gfx::AffineTransform get_transform() const;
  35. Optional<Gfx::PaintStyle const&> fill_paint_style(SVGPaintContext const&) const;
  36. Optional<Gfx::PaintStyle const&> stroke_paint_style(SVGPaintContext const&) const;
  37. JS::GCPtr<SVG::SVGMaskElement const> mask() const;
  38. protected:
  39. SVGGraphicsElement(DOM::Document&, DOM::QualifiedName);
  40. virtual void initialize(JS::Realm&) override;
  41. virtual Gfx::AffineTransform element_transform() const
  42. {
  43. return m_transform;
  44. }
  45. Optional<Gfx::PaintStyle const&> svg_paint_computed_value_to_gfx_paint_style(SVGPaintContext const& paint_context, Optional<CSS::SVGPaint> const& paint_value) const;
  46. Gfx::AffineTransform m_transform = {};
  47. template<typename T>
  48. JS::GCPtr<T> try_resolve_url_to(URL const& url) const
  49. {
  50. if (!url.fragment().has_value())
  51. return {};
  52. auto node = document().get_element_by_id(*url.fragment());
  53. if (!node)
  54. return {};
  55. if (is<T>(*node))
  56. return static_cast<T&>(*node);
  57. return {};
  58. }
  59. private:
  60. virtual bool is_svg_graphics_element() const final { return true; }
  61. };
  62. Gfx::AffineTransform transform_from_transform_list(ReadonlySpan<Transform> transform_list);
  63. }
  64. namespace Web::DOM {
  65. template<>
  66. inline bool Node::fast_is<SVG::SVGGraphicsElement>() const { return is_svg_graphics_element(); }
  67. }