SVGGradientElement.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2023, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/IterationDecision.h>
  8. #include <LibGfx/PaintStyle.h>
  9. #include <LibWeb/SVG/AttributeParser.h>
  10. #include <LibWeb/SVG/SVGElement.h>
  11. #include <LibWeb/SVG/SVGStopElement.h>
  12. namespace Web::SVG {
  13. struct SVGPaintContext {
  14. Gfx::FloatRect viewport;
  15. Gfx::FloatRect path_bounding_box;
  16. Gfx::AffineTransform transform;
  17. };
  18. class SVGGradientElement : public SVGElement {
  19. WEB_PLATFORM_OBJECT(SVGGradientElement, SVGElement);
  20. public:
  21. virtual ~SVGGradientElement() override = default;
  22. virtual void parse_attribute(DeprecatedFlyString const& name, DeprecatedString const& value) override;
  23. virtual Optional<Gfx::PaintStyle const&> to_gfx_paint_style(SVGPaintContext const&) const = 0;
  24. GradientUnits gradient_units() const;
  25. Optional<Gfx::AffineTransform> gradient_transform() const;
  26. protected:
  27. SVGGradientElement(DOM::Document&, DOM::QualifiedName);
  28. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  29. JS::GCPtr<SVGGradientElement const> xlink_href() const;
  30. template<VoidFunction<SVGStopElement> Callback>
  31. void for_each_color_stop(Callback const& callback) const
  32. {
  33. for_each_child_of_type<SVG::SVGStopElement>([&](auto& stop) {
  34. callback(stop);
  35. });
  36. if (auto href = xlink_href())
  37. href->for_each_color_stop(callback);
  38. }
  39. private:
  40. Optional<GradientUnits> m_gradient_units = {};
  41. Optional<Gfx::AffineTransform> m_gradient_transform = {};
  42. };
  43. }