mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:02:43 +00:00 
			
		
		
		
	 4d401bf796
			
		
	
	
		4d401bf796
		
	
	
	
	
		
			
			This simplifies the ownership model between DOM/layout/paint nodes immensely by deferring to the garbage collector for figuring out what's live and what's not.
		
			
				
	
	
		
			54 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
 | |
|  * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include <LibWeb/Layout/SVGGeometryBox.h>
 | |
| #include <LibWeb/Painting/SVGGeometryPaintable.h>
 | |
| #include <LibWeb/SVG/SVGPathElement.h>
 | |
| #include <LibWeb/SVG/SVGSVGElement.h>
 | |
| 
 | |
| namespace Web::Layout {
 | |
| 
 | |
| SVGGeometryBox::SVGGeometryBox(DOM::Document& document, SVG::SVGGeometryElement& element, NonnullRefPtr<CSS::StyleProperties> properties)
 | |
|     : SVGGraphicsBox(document, element, properties)
 | |
| {
 | |
| }
 | |
| 
 | |
| float SVGGeometryBox::viewbox_scaling() const
 | |
| {
 | |
|     auto* svg_box = dom_node().first_ancestor_of_type<SVG::SVGSVGElement>();
 | |
| 
 | |
|     if (!svg_box || !svg_box->view_box().has_value())
 | |
|         return 1;
 | |
| 
 | |
|     auto view_box = svg_box->view_box().value();
 | |
| 
 | |
|     bool has_specified_width = svg_box->has_attribute(HTML::AttributeNames::width);
 | |
|     auto specified_width = paint_box()->content_width().value();
 | |
| 
 | |
|     bool has_specified_height = svg_box->has_attribute(HTML::AttributeNames::height);
 | |
|     auto specified_height = paint_box()->content_height().value();
 | |
| 
 | |
|     auto scale_width = has_specified_width ? specified_width / view_box.width : 1;
 | |
|     auto scale_height = has_specified_height ? specified_height / view_box.height : 1;
 | |
| 
 | |
|     return min(scale_width, scale_height);
 | |
| }
 | |
| 
 | |
| CSSPixelPoint SVGGeometryBox::viewbox_origin() const
 | |
| {
 | |
|     auto* svg_box = dom_node().first_ancestor_of_type<SVG::SVGSVGElement>();
 | |
|     if (!svg_box || !svg_box->view_box().has_value())
 | |
|         return { 0, 0 };
 | |
|     return { svg_box->view_box().value().min_x, svg_box->view_box().value().min_y };
 | |
| }
 | |
| 
 | |
| JS::GCPtr<Painting::Paintable> SVGGeometryBox::create_paintable() const
 | |
| {
 | |
|     return Painting::SVGGeometryPaintable::create(*this);
 | |
| }
 | |
| 
 | |
| }
 |