mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 10:12:45 +00:00 
			
		
		
		
	 f0560fd087
			
		
	
	
		f0560fd087
		
	
	
	
	
		
			
			There are a couple of things that went into this: - We now calculate the intrinsic width/height and aspect ratio of <svg> elements based on the spec algorithm instead of our previous ad-hoc guesswork solution. - Replaced elements with automatic size and intrinsic aspect ratio but no intrinsic dimensions are now sized with the stretch-fit width formula. - We take care to assign both used width and used height to <svg> elements before running their SVG formatting contexts. This ensures that the inside SVG content is laid out with knowledge of its viewport geometry. - We avoid infinite recursion in tentative_height_for_replaced_element() by using the already-calculated used width instead of calling the function that calculates the used width (since that may call us right back again).
		
			
				
	
	
		
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <LibWeb/Layout/ReplacedBox.h>
 | |
| #include <LibWeb/SVG/SVGSVGElement.h>
 | |
| 
 | |
| namespace Web::Layout {
 | |
| 
 | |
| class SVGSVGBox final : public ReplacedBox {
 | |
|     JS_CELL(SVGSVGBox, ReplacedBox);
 | |
| 
 | |
| public:
 | |
|     SVGSVGBox(DOM::Document&, SVG::SVGSVGElement&, NonnullRefPtr<CSS::StyleProperties>);
 | |
|     virtual ~SVGSVGBox() override = default;
 | |
| 
 | |
|     SVG::SVGSVGElement& dom_node() { return verify_cast<SVG::SVGSVGElement>(ReplacedBox::dom_node()); }
 | |
|     SVG::SVGSVGElement const& dom_node() const { return verify_cast<SVG::SVGSVGElement>(ReplacedBox::dom_node()); }
 | |
| 
 | |
|     virtual bool can_have_children() const override { return true; }
 | |
| 
 | |
|     virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;
 | |
| 
 | |
|     virtual void prepare_for_replaced_layout() override;
 | |
| 
 | |
| private:
 | |
|     virtual bool is_svg_svg_box() const final { return true; }
 | |
| 
 | |
|     [[nodiscard]] Optional<float> calculate_intrinsic_aspect_ratio() const;
 | |
| };
 | |
| 
 | |
| template<>
 | |
| inline bool Node::fast_is<SVGSVGBox>() const { return is_svg_svg_box(); }
 | |
| 
 | |
| }
 |