SVGMaskElement.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/SVG/AttributeParser.h>
  8. #include <LibWeb/SVG/SVGGraphicsElement.h>
  9. #include <LibWeb/SVG/SVGViewport.h>
  10. namespace Web::SVG {
  11. class SVGMaskElement final : public SVGGraphicsElement
  12. , public SVGViewport {
  13. WEB_PLATFORM_OBJECT(SVGMaskElement, SVGGraphicsElement);
  14. JS_DECLARE_ALLOCATOR(SVGMaskElement);
  15. public:
  16. virtual ~SVGMaskElement() override;
  17. virtual Optional<ViewBox> view_box() const override
  18. {
  19. // maskContentUnits = objectBoundingBox acts like the mask is sized to the bounding box
  20. // of the target element, with a viewBox of "0 0 1 1".
  21. if (mask_content_units() == MaskContentUnits::ObjectBoundingBox)
  22. return ViewBox { 0, 0, 1, 1 };
  23. return {};
  24. }
  25. virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const override
  26. {
  27. // preserveAspectRatio = none (allow mask to be scaled in both x and y to match target size)
  28. return PreserveAspectRatio { PreserveAspectRatio::Align::None, {} };
  29. }
  30. virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
  31. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  32. CSSPixelRect resolve_masking_area(CSSPixelRect const& mask_target) const;
  33. MaskContentUnits mask_content_units() const;
  34. MaskUnits mask_units() const;
  35. private:
  36. SVGMaskElement(DOM::Document&, DOM::QualifiedName);
  37. virtual void initialize(JS::Realm&) override;
  38. Optional<MaskContentUnits> m_mask_content_units = {};
  39. Optional<MaskUnits> m_mask_units = {};
  40. };
  41. }