| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-04 13:19:50 +02:00
										 |  |  |  * Copyright (c) 2023, Andreas Kling <andreas@ladybird.org> | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  | #include <LibWeb/SVG/AttributeParser.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | #include <LibWeb/SVG/SVGGraphicsElement.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-11 18:26:58 +00:00
										 |  |  | #include <LibWeb/SVG/SVGViewport.h>
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 18:26:58 +00:00
										 |  |  | class SVGMaskElement final : public SVGGraphicsElement | 
					
						
							|  |  |  |     , public SVGViewport { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  |     WEB_PLATFORM_OBJECT(SVGMaskElement, SVGGraphicsElement); | 
					
						
							| 
									
										
										
										
											2023-11-19 19:47:52 +01:00
										 |  |  |     JS_DECLARE_ALLOCATOR(SVGMaskElement); | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~SVGMaskElement() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 18:26:58 +00:00
										 |  |  |     virtual Optional<ViewBox> view_box() const override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // maskContentUnits = objectBoundingBox acts like the mask is sized to the bounding box
 | 
					
						
							|  |  |  |         // of the target element, with a viewBox of "0 0 1 1".
 | 
					
						
							|  |  |  |         if (mask_content_units() == MaskContentUnits::ObjectBoundingBox) | 
					
						
							|  |  |  |             return ViewBox { 0, 0, 1, 1 }; | 
					
						
							|  |  |  |         return {}; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual Optional<PreserveAspectRatio> preserve_aspect_ratio() const override | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         // preserveAspectRatio = none (allow mask to be scaled in both x and y to match target size)
 | 
					
						
							|  |  |  |         return PreserveAspectRatio { PreserveAspectRatio::Align::None, {} }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-09 20:18:41 +01:00
										 |  |  |     virtual void attribute_changed(FlyString const& name, Optional<String> const& old_value, Optional<String> const& value) override; | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-26 17:42:27 +02:00
										 |  |  |     virtual JS::GCPtr<Layout::Node> create_layout_node(CSS::StyleProperties) override; | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  |     CSSPixelRect resolve_masking_area(CSSPixelRect const& mask_target) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MaskContentUnits mask_content_units() const; | 
					
						
							|  |  |  |     MaskUnits mask_units() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | private: | 
					
						
							|  |  |  |     SVGMaskElement(DOM::Document&, DOM::QualifiedName); | 
					
						
							|  |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2023-09-10 14:00:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Optional<MaskContentUnits> m_mask_content_units = {}; | 
					
						
							|  |  |  |     Optional<MaskUnits> m_mask_units = {}; | 
					
						
							| 
									
										
										
										
											2023-08-10 09:55:15 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |