| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Error.h>
 | 
					
						
							|  |  |  | #include <AK/OwnPtr.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Size.h>
 | 
					
						
							|  |  |  | #include <LibJS/Heap/Handle.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  | #include <LibURL/URL.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | #include <LibWeb/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2023-06-14 12:45:56 +02:00
										 |  |  | #include <LibWeb/HTML/SharedImageRequest.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/images.html#image-request
 | 
					
						
							| 
									
										
										
										
											2023-08-18 12:56:21 +02:00
										 |  |  | class ImageRequest final : public JS::Cell { | 
					
						
							|  |  |  |     JS_CELL(ImageRequest, JS::Cell); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(ImageRequest); | 
					
						
							| 
									
										
										
										
											2023-08-18 12:56:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-12-03 15:29:11 +13:00
										 |  |  |     [[nodiscard]] static JS::NonnullGCPtr<ImageRequest> create(JS::Realm&, JS::NonnullGCPtr<Page>); | 
					
						
							| 
									
										
										
										
											2023-08-18 12:56:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  |     ~ImageRequest(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/images.html#img-req-state
 | 
					
						
							|  |  |  |     enum class State { | 
					
						
							|  |  |  |         Unavailable, | 
					
						
							|  |  |  |         PartiallyAvailable, | 
					
						
							|  |  |  |         CompletelyAvailable, | 
					
						
							|  |  |  |         Broken, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool is_available() const; | 
					
						
							| 
									
										
										
										
											2023-06-14 12:45:56 +02:00
										 |  |  |     bool is_fetching() const; | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     State state() const; | 
					
						
							|  |  |  |     void set_state(State); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     URL::URL const& current_url() const; | 
					
						
							|  |  |  |     void set_current_url(JS::Realm&, URL::URL); | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  |     [[nodiscard]] JS::GCPtr<DecodedImageData> image_data() const; | 
					
						
							|  |  |  |     void set_image_data(JS::GCPtr<DecodedImageData>); | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [[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<Gfx::FloatSize> const& preferred_density_corrected_dimensions() const { return m_preferred_density_corrected_dimensions; } | 
					
						
							|  |  |  |     void set_preferred_density_corrected_dimensions(Optional<Gfx::FloatSize> 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&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 14:46:54 +02:00
										 |  |  |     void fetch_image(JS::Realm&, JS::NonnullGCPtr<Fetch::Infrastructure::Request>); | 
					
						
							| 
									
										
										
										
											2023-09-25 14:27:11 +02:00
										 |  |  |     void add_callbacks(Function<void()> on_finish, Function<void()> on_fail); | 
					
						
							| 
									
										
										
										
											2023-06-11 14:46:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 12:45:56 +02:00
										 |  |  |     SharedImageRequest const* shared_image_request() const { return m_shared_image_request; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-18 14:11:55 +02:00
										 |  |  |     virtual void visit_edges(JS::Cell::Visitor&) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-12-03 15:29:11 +13:00
										 |  |  |     explicit ImageRequest(JS::NonnullGCPtr<Page>); | 
					
						
							| 
									
										
										
										
											2023-06-11 14:46:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-03 15:29:11 +13:00
										 |  |  |     JS::NonnullGCPtr<Page> m_page; | 
					
						
							| 
									
										
										
										
											2023-06-11 14:46:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  |     // 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.
 | 
					
						
							| 
									
										
										
										
											2024-03-18 16:22:27 +13:00
										 |  |  |     URL::URL m_current_url; | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/images.html#img-req-data
 | 
					
						
							| 
									
										
										
										
											2023-12-12 20:07:19 +01:00
										 |  |  |     JS::GCPtr<DecodedImageData> m_image_data; | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // 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<Gfx::FloatSize> m_preferred_density_corrected_dimensions; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-18 14:11:55 +02:00
										 |  |  |     JS::GCPtr<SharedImageRequest> m_shared_image_request; | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-11 06:53:40 +02:00
										 |  |  | // https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request
 | 
					
						
							|  |  |  | void abort_the_image_request(JS::Realm&, ImageRequest*); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-10 19:36:43 +02:00
										 |  |  | } |