SVGUseElement.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2023, Preston Taylor <95388976+PrestonLTaylor@users.noreply.github.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <LibGfx/Path.h>
  9. #include <LibWeb/DOM/DocumentObserver.h>
  10. #include <LibWeb/SVG/SVGAnimatedLength.h>
  11. #include <LibWeb/SVG/SVGGraphicsElement.h>
  12. #include <LibWeb/SVG/SVGURIReference.h>
  13. namespace Web::SVG {
  14. class SVGUseElement final
  15. : public SVGGraphicsElement
  16. , public SVGURIReferenceMixin<SupportsXLinkHref::Yes> {
  17. WEB_PLATFORM_OBJECT(SVGUseElement, SVGGraphicsElement);
  18. JS_DECLARE_ALLOCATOR(SVGUseElement);
  19. public:
  20. virtual ~SVGUseElement() override = default;
  21. virtual void attribute_changed(FlyString const& name, Optional<String> const& value) override;
  22. virtual void inserted() override;
  23. void svg_element_changed(SVGElement&);
  24. void svg_element_removed(SVGElement&);
  25. JS::NonnullGCPtr<SVGAnimatedLength> x() const;
  26. JS::NonnullGCPtr<SVGAnimatedLength> y() const;
  27. JS::NonnullGCPtr<SVGAnimatedLength> width() const;
  28. JS::NonnullGCPtr<SVGAnimatedLength> height() const;
  29. JS::GCPtr<SVGElement> instance_root() const;
  30. JS::GCPtr<SVGElement> animated_instance_root() const;
  31. virtual Gfx::AffineTransform element_transform() const override;
  32. private:
  33. SVGUseElement(DOM::Document&, DOM::QualifiedName);
  34. virtual void initialize(JS::Realm&) override;
  35. virtual void visit_edges(Cell::Visitor&) override;
  36. virtual bool is_svg_use_element() const override { return true; }
  37. virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
  38. static Optional<FlyString> parse_id_from_href(StringView);
  39. JS::GCPtr<DOM::Element> referenced_element();
  40. void clone_element_tree_as_our_shadow_tree(Element* to_clone) const;
  41. bool is_valid_reference_element(Element* reference_element) const;
  42. Optional<float> m_x;
  43. Optional<float> m_y;
  44. Optional<FlyString> m_referenced_id;
  45. JS::GCPtr<DOM::DocumentObserver> m_document_observer;
  46. };
  47. }
  48. namespace Web::DOM {
  49. template<>
  50. inline bool Node::fast_is<SVG::SVGUseElement>() const { return is_svg_use_element(); }
  51. }