| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, MacDue <macdue@dueutil.tech> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/Intrinsics.h>
 | 
					
						
							| 
									
										
										
										
											2024-04-27 12:09:58 +12:00
										 |  |  | #include <LibWeb/Bindings/SVGTransformListPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | #include <LibWeb/SVG/SVGTransformList.h>
 | 
					
						
							|  |  |  | #include <LibWeb/WebIDL/ExceptionOr.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::SVG { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC_DEFINE_ALLOCATOR(SVGTransformList); | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC::Ref<SVGTransformList> SVGTransformList::create(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2024-11-14 05:50:17 +13:00
										 |  |  |     return realm.create<SVGTransformList>(realm); | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SVGTransformList::~SVGTransformList() = default; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SVGTransformList::SVGTransformList(JS::Realm& realm) | 
					
						
							| 
									
										
										
										
											2024-10-12 20:56:21 +02:00
										 |  |  |     : PlatformObject(realm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-02 12:46:15 +01:00
										 |  |  | // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__length
 | 
					
						
							|  |  |  | WebIDL::UnsignedLong SVGTransformList::length() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // The length and numberOfItems IDL attributes represents the length of the list, and on getting simply return the length of the list.
 | 
					
						
							|  |  |  |     return m_transforms.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-02 12:48:35 +01:00
										 |  |  | // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__numberOfItems
 | 
					
						
							|  |  |  | WebIDL::UnsignedLong SVGTransformList::number_of_items() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     // The length and numberOfItems IDL attributes represents the length of the list, and on getting simply return the length of the list.
 | 
					
						
							|  |  |  |     return m_transforms.size(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__getItem
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | WebIDL::ExceptionOr<GC::Ref<SVGTransform>> SVGTransformList::get_item(WebIDL::UnsignedLong index) | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // 1. If index is greater than or equal to the length of the list, then throw an IndexSizeError.
 | 
					
						
							|  |  |  |     if (index >= m_transforms.size()) | 
					
						
							| 
									
										
										
										
											2024-10-12 20:56:21 +02:00
										 |  |  |         return WebIDL::IndexSizeError::create(realm(), "SVGTransformList index out of bounds"_string); | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  |     // 2. Return the element in the list at position index.
 | 
					
						
							|  |  |  |     return m_transforms.at(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__appendItem
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  | GC::Ref<SVGTransform> SVGTransformList::append_item(GC::Ref<SVGTransform> new_item) | 
					
						
							| 
									
										
										
										
											2024-03-31 14:54:00 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // FIXME: This does not implement the steps from the specification.
 | 
					
						
							|  |  |  |     m_transforms.append(new_item); | 
					
						
							|  |  |  |     return new_item; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SVGTransformList::initialize(JS::Realm& realm) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::initialize(realm); | 
					
						
							|  |  |  |     WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTransformList); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SVGTransformList::visit_edges(Cell::Visitor& visitor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Base::visit_edges(visitor); | 
					
						
							|  |  |  |     for (auto transform : m_transforms) | 
					
						
							|  |  |  |         transform->visit_edges(visitor); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |