| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2023, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  |  * Copyright (c) 2023, MacDue <macdue@dueutil.tech> | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/SVGMaskElementPrototype.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/Document.h>
 | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  | #include <LibWeb/SVG/AttributeNames.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | #include <LibWeb/SVG/SVGMaskElement.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  | JS_DEFINE_ALLOCATOR(SVGMaskElement); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | SVGMaskElement::SVGMaskElement(DOM::Document& document, DOM::QualifiedName tag_name) | 
					
						
							|  |  |  |     : SVGGraphicsElement(document, move(tag_name)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SVGMaskElement::~SVGMaskElement() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SVGMaskElement::initialize(JS::Realm& realm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::initialize(realm); | 
					
						
							| 
									
										
										
										
											2023-11-22 12:55:21 +13:00
										 |  |  |     set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGMaskElementPrototype>(realm, "SVGMaskElement"_fly_string)); | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 18:26:58 +00:00
										 |  |  | JS::GCPtr<Layout::Node> SVGMaskElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties>) | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-03-11 18:26:58 +00:00
										 |  |  |     // Masks are handled as a special case in the TreeBuilder.
 | 
					
						
							|  |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  | void SVGMaskElement::attribute_changed(FlyString const& name, Optional<String> const& value) | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     SVGGraphicsElement::attribute_changed(name, value); | 
					
						
							|  |  |  |     if (name == AttributeNames::maskUnits) { | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  |         m_mask_units = AttributeParser::parse_units(value.value_or(String {})); | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  |     } else if (name == AttributeNames::maskContentUnits) { | 
					
						
							| 
									
										
										
										
											2023-11-19 18:10:36 +13:00
										 |  |  |         m_mask_content_units = AttributeParser::parse_units(value.value_or(String {})); | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MaskContentUnits SVGMaskElement::mask_content_units() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_mask_content_units.value_or(MaskContentUnits::UserSpaceOnUse); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MaskUnits SVGMaskElement::mask_units() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_mask_units.value_or(MaskUnits::ObjectBoundingBox); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CSSPixelRect SVGMaskElement::resolve_masking_area(CSSPixelRect const& mask_target) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // TODO: Resolve this based on the x, y, width, and height of the mask.
 | 
					
						
							|  |  |  |     return mask_target.inflated(mask_target.size().scaled(CSSPixels(2) / 10)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | } |