2023-05-31 00:50:12 +01:00
/*
* Copyright ( c ) 2023 , Preston Taylor < 95388976 + PrestonLTaylor @ users . noreply . github . com >
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# include <LibWeb/Bindings/Intrinsics.h>
2024-04-27 12:09:58 +12:00
# include <LibWeb/Bindings/SVGSymbolElementPrototype.h>
2023-05-31 00:50:12 +01:00
# include <LibWeb/CSS/StyleProperties.h>
2024-08-14 11:46:56 +01:00
# include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
2023-05-31 00:50:12 +01:00
# include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
2023-09-20 16:32:11 +01:00
# include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
2023-05-31 00:50:12 +01:00
# include <LibWeb/DOM/ShadowRoot.h>
2024-03-10 14:41:00 +01:00
# include <LibWeb/Layout/SVGGraphicsBox.h>
2023-07-31 18:37:44 +02:00
# include <LibWeb/SVG/AttributeNames.h>
2024-07-20 18:32:53 +01:00
# include <LibWeb/SVG/SVGAnimatedRect.h>
2023-05-31 00:50:12 +01:00
# include <LibWeb/SVG/SVGSymbolElement.h>
# include <LibWeb/SVG/SVGUseElement.h>
namespace Web : : SVG {
2023-11-19 19:47:52 +01:00
JS_DEFINE_ALLOCATOR ( SVGSymbolElement ) ;
2023-05-31 00:50:12 +01:00
SVGSymbolElement : : SVGSymbolElement ( DOM : : Document & document , DOM : : QualifiedName qualified_name )
: SVGGraphicsElement ( document , qualified_name )
{
}
2023-08-07 08:41:28 +02:00
void SVGSymbolElement : : initialize ( JS : : Realm & realm )
2023-05-31 00:50:12 +01:00
{
2023-08-07 08:41:28 +02:00
Base : : initialize ( realm ) ;
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( SVGSymbolElement ) ;
2024-07-20 18:32:53 +01:00
m_view_box_for_bindings = heap ( ) . allocate < SVGAnimatedRect > ( realm , realm ) ;
}
void SVGSymbolElement : : visit_edges ( Cell : : Visitor & visitor )
{
Base : : visit_edges ( visitor ) ;
visitor . visit ( m_view_box_for_bindings ) ;
2023-05-31 00:50:12 +01:00
}
// https://svgwg.org/svg2-draft/struct.html#SymbolNotes
void SVGSymbolElement : : apply_presentational_hints ( CSS : : StyleProperties & style ) const
{
2023-08-20 00:17:42 +02:00
Base : : apply_presentational_hints ( style ) ;
2023-05-31 00:50:12 +01:00
if ( is_direct_child_of_use_shadow_tree ( ) ) {
// The generated instance of a ‘ symbol’ that is the direct referenced element of a ‘ use’ element must always have a computed value of inline for the display property.
2023-08-19 14:00:10 +01:00
style . set_property ( CSS : : PropertyID : : Display , CSS : : DisplayStyleValue : : create ( CSS : : Display : : from_short ( CSS : : Display : : Short : : Inline ) ) ) ;
2023-05-31 00:50:12 +01:00
}
2023-07-31 18:37:44 +02:00
}
2023-05-31 00:50:12 +01:00
2024-07-09 20:18:41 +01:00
void SVGSymbolElement : : attribute_changed ( FlyString const & name , Optional < String > const & old_value , Optional < String > const & value )
2023-07-31 18:37:44 +02:00
{
2024-07-09 20:18:41 +01:00
Base : : attribute_changed ( name , old_value , value ) ;
2024-07-20 18:32:53 +01:00
if ( name . equals_ignoring_ascii_case ( SVG : : AttributeNames : : viewBox ) ) {
2023-11-19 18:10:36 +13:00
m_view_box = try_parse_view_box ( value . value_or ( String { } ) ) ;
2024-07-20 18:32:53 +01:00
m_view_box_for_bindings - > set_nulled ( ! m_view_box . has_value ( ) ) ;
if ( m_view_box . has_value ( ) ) {
m_view_box_for_bindings - > set_base_val ( Gfx : : DoubleRect { m_view_box - > min_x , m_view_box - > min_y , m_view_box - > width , m_view_box - > height } ) ;
m_view_box_for_bindings - > set_anim_val ( Gfx : : DoubleRect { m_view_box - > min_x , m_view_box - > min_y , m_view_box - > width , m_view_box - > height } ) ;
}
}
2023-05-31 00:50:12 +01:00
}
bool SVGSymbolElement : : is_direct_child_of_use_shadow_tree ( ) const
{
auto maybe_shadow_root = parent ( ) ;
if ( ! is < DOM : : ShadowRoot > ( maybe_shadow_root ) ) {
return false ;
}
auto host = static_cast < const DOM : : ShadowRoot & > ( * maybe_shadow_root ) . host ( ) ;
return is < SVGUseElement > ( host ) ;
}
2023-08-19 19:42:31 +02:00
JS : : GCPtr < Layout : : Node > SVGSymbolElement : : create_layout_node ( NonnullRefPtr < CSS : : StyleProperties > style )
{
2024-03-10 14:41:00 +01:00
return heap ( ) . allocate_without_realm < Layout : : SVGGraphicsBox > ( document ( ) , * this , move ( style ) ) ;
2023-08-19 19:42:31 +02:00
}
2023-05-31 00:50:12 +01:00
}