| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/URL.h>
 | 
					
						
							|  |  |  | #include <AK/Variant.h>
 | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  | #include <LibWeb/CSS/CalculatedOr.h>
 | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::HTML { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/images.html#image-source
 | 
					
						
							|  |  |  | struct ImageSource { | 
					
						
							|  |  |  |     struct PixelDensityDescriptorValue { | 
					
						
							| 
									
										
										
										
											2023-05-24 10:50:57 +02:00
										 |  |  |         double value { 0 }; | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct WidthDescriptorValue { | 
					
						
							|  |  |  |         CSSPixels value { 0 }; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     String url; | 
					
						
							|  |  |  |     Variant<Empty, PixelDensityDescriptorValue, WidthDescriptorValue> descriptor; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ImageSourceAndPixelDensity { | 
					
						
							|  |  |  |     ImageSource source; | 
					
						
							| 
									
										
										
										
											2023-05-24 10:50:57 +02:00
										 |  |  |     double pixel_density { 1.0f }; | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://html.spec.whatwg.org/multipage/images.html#source-set
 | 
					
						
							|  |  |  | struct SourceSet { | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  |     static SourceSet create(DOM::Element const&, String default_source, String srcset, String sizes); | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] bool is_empty() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/images.html#select-an-image-source-from-a-source-set
 | 
					
						
							|  |  |  |     [[nodiscard]] ImageSourceAndPixelDensity select_an_image_source(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // https://html.spec.whatwg.org/multipage/images.html#normalise-the-source-densities
 | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  |     void normalize_source_densities(DOM::Element const&); | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     SourceSet(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Vector<ImageSource> m_sources; | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  |     CSS::LengthOrCalculated m_source_size; | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SourceSet parse_a_srcset_attribute(StringView); | 
					
						
							| 
									
										
										
										
											2023-07-28 15:52:06 +02:00
										 |  |  | [[nodiscard]] CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Document const&, StringView); | 
					
						
							| 
									
										
										
										
											2023-05-11 16:56:01 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |