SVGDecodedImageData.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/DOM/Document.h>
  8. #include <LibWeb/HTML/DecodedImageData.h>
  9. namespace Web::SVG {
  10. class SVGDecodedImageData final : public HTML::DecodedImageData {
  11. public:
  12. static ErrorOr<NonnullRefPtr<SVGDecodedImageData>> create(Page&, AK::URL const&, ByteBuffer encoded_svg);
  13. virtual ~SVGDecodedImageData() override;
  14. virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index, Gfx::IntSize) const override;
  15. virtual Optional<CSSPixels> intrinsic_width() const override;
  16. virtual Optional<CSSPixels> intrinsic_height() const override;
  17. virtual Optional<float> intrinsic_aspect_ratio() const override;
  18. // FIXME: Support SVG animations. :^)
  19. virtual int frame_duration(size_t) const override { return 0; }
  20. virtual size_t frame_count() const override { return 1; }
  21. virtual size_t loop_count() const override { return 0; }
  22. virtual bool is_animated() const override { return false; }
  23. DOM::Document const& svg_document() const { return *m_document; }
  24. private:
  25. class SVGPageClient;
  26. SVGDecodedImageData(NonnullOwnPtr<Page>, NonnullOwnPtr<SVGPageClient>, JS::Handle<DOM::Document>, JS::Handle<SVG::SVGSVGElement>);
  27. void render(Gfx::IntSize) const;
  28. mutable RefPtr<Gfx::Bitmap> m_bitmap;
  29. NonnullOwnPtr<Page> m_page;
  30. NonnullOwnPtr<SVGPageClient> m_page_client;
  31. JS::Handle<DOM::Document> m_document;
  32. JS::Handle<SVG::SVGSVGElement> m_root_element;
  33. };
  34. }