mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 00:42:44 +00:00 
			
		
		
		
	 95097e47a7
			
		
	
	
		95097e47a7
		
	
	
	
	
		
			
			Note that we currently can't resolve calc() values without a layout node, so when normalizing an image's source set, we'll flush any pending layout updates and hope that gives us an up-to-date layout node. I've left a FIXME about implementing this in a more elegant and less layout-thrashy way, as that will require more architectural work.
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/URL.h>
 | |
| #include <AK/Variant.h>
 | |
| #include <LibWeb/CSS/CalculatedOr.h>
 | |
| 
 | |
| namespace Web::HTML {
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/images.html#image-source
 | |
| struct ImageSource {
 | |
|     struct PixelDensityDescriptorValue {
 | |
|         double value { 0 };
 | |
|     };
 | |
| 
 | |
|     struct WidthDescriptorValue {
 | |
|         CSSPixels value { 0 };
 | |
|     };
 | |
| 
 | |
|     String url;
 | |
|     Variant<Empty, PixelDensityDescriptorValue, WidthDescriptorValue> descriptor;
 | |
| };
 | |
| 
 | |
| struct ImageSourceAndPixelDensity {
 | |
|     ImageSource source;
 | |
|     double pixel_density { 1.0f };
 | |
| };
 | |
| 
 | |
| // https://html.spec.whatwg.org/multipage/images.html#source-set
 | |
| struct SourceSet {
 | |
|     static SourceSet create(DOM::Element const&, String default_source, String srcset, String sizes);
 | |
| 
 | |
|     [[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
 | |
|     void normalize_source_densities(DOM::Element const&);
 | |
| 
 | |
|     SourceSet();
 | |
| 
 | |
|     Vector<ImageSource> m_sources;
 | |
|     CSS::LengthOrCalculated m_source_size;
 | |
| };
 | |
| 
 | |
| SourceSet parse_a_srcset_attribute(StringView);
 | |
| [[nodiscard]] CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Document const&, StringView);
 | |
| 
 | |
| }
 |