/* * Copyright (c) 2024, Tim Ledbetter * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::SVG { class SVGImageElement : public SVGGraphicsElement , public SVGURIReferenceMixin , public Layout::ImageProvider { WEB_PLATFORM_OBJECT(SVGImageElement, SVGGraphicsElement); public: virtual void attribute_changed(FlyString const& name, Optional const& old_value, Optional const& value) override; JS::NonnullGCPtr x(); JS::NonnullGCPtr y(); JS::NonnullGCPtr width(); JS::NonnullGCPtr height(); Gfx::Rect bounding_box() const; // FIXME: This is a hack for images used as CanvasImageSource. Do something more elegant. RefPtr bitmap() const { auto bitmap = current_image_bitmap(); if (!bitmap) return nullptr; return bitmap->bitmap(); } // ^Layout::ImageProvider virtual bool is_image_available() const override; virtual Optional intrinsic_width() const override; virtual Optional intrinsic_height() const override; virtual Optional intrinsic_aspect_ratio() const override; virtual RefPtr current_image_bitmap(Gfx::IntSize = {}) const override; virtual void set_visible_in_viewport(bool) override { } virtual JS::NonnullGCPtr to_html_element() const override { return *this; } protected: SVGImageElement(DOM::Document&, DOM::QualifiedName); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; void process_the_url(Optional const& href); void fetch_the_document(URL::URL const& url); private: virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; void animate(); JS::GCPtr m_x; JS::GCPtr m_y; JS::GCPtr m_width; JS::GCPtr m_height; RefPtr m_animation_timer; size_t m_current_frame_index { 0 }; size_t m_loops_completed { 0 }; URL::URL m_href; JS::GCPtr m_resource_request; Optional m_load_event_delayer; }; }