/* * Copyright (c) 2023, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::HTML { // https://html.spec.whatwg.org/multipage/images.html#image-request class ImageRequest : public RefCounted { public: static ErrorOr> create(Page&); ~ImageRequest(); // https://html.spec.whatwg.org/multipage/images.html#img-req-state enum class State { Unavailable, PartiallyAvailable, CompletelyAvailable, Broken, }; bool is_available() const; bool is_fetching() const; State state() const; void set_state(State); AK::URL const& current_url() const; void set_current_url(AK::URL); [[nodiscard]] RefPtr image_data() const; void set_image_data(RefPtr); [[nodiscard]] float current_pixel_density() const { return m_current_pixel_density; } void set_current_pixel_density(float density) { m_current_pixel_density = density; } [[nodiscard]] Optional const& preferred_density_corrected_dimensions() const { return m_preferred_density_corrected_dimensions; } void set_preferred_density_corrected_dimensions(Optional dimensions) { m_preferred_density_corrected_dimensions = move(dimensions); } // https://html.spec.whatwg.org/multipage/images.html#prepare-an-image-for-presentation void prepare_for_presentation(HTMLImageElement&); void fetch_image(JS::Realm&, JS::NonnullGCPtr); void add_callbacks(JS::SafeFunction on_finish, JS::SafeFunction on_fail); SharedImageRequest const* shared_image_request() const { return m_shared_image_request; } private: explicit ImageRequest(Page&); Page& m_page; // https://html.spec.whatwg.org/multipage/images.html#img-req-state // An image request's state is initially unavailable. State m_state { State::Unavailable }; // https://html.spec.whatwg.org/multipage/images.html#img-req-url // An image request's current URL is initially the empty string. AK::URL m_current_url; // https://html.spec.whatwg.org/multipage/images.html#img-req-data RefPtr m_image_data; // https://html.spec.whatwg.org/multipage/images.html#current-pixel-density // Each image request has a current pixel density, which must initially be 1. float m_current_pixel_density { 1 }; // https://html.spec.whatwg.org/multipage/images.html#preferred-density-corrected-dimensions // Each image request has preferred density-corrected dimensions, // which is either a struct consisting of a width and a height or is null. It must initially be null. Optional m_preferred_density_corrected_dimensions; RefPtr m_shared_image_request; }; // https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request void abort_the_image_request(JS::Realm&, ImageRequest*); }