dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / svg / svg_element.lucb
#==============================================================================================
#
# svg_element - SVG::SVGElement: the base of every SVG element
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGElement.cpp (lines 1-359) with the inline members of
# SVGElement.h: construction (which moves the mixin tables to SVGElement's, as C++'s
# vptrs move), the presentation attributes
# (https://svgwg.org/svg2-draft/styling.html#PresentationAttributes), the accessibility
# rules of SVG-AAM, the DOM steps shared with HTMLOrSVGElement, the <use> element
# bookkeeping, forcing position:static, and className, ownerSVGElement and
# viewportElement.
#
# attribute_style_properties' static Array is a module global made once in the C heap
# (DESIGN.md §3.3 rule 7).
#
#==============================================================================================
# mark: Construction =============================================================================
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:29 Web::SVG::SVGElement::SVGElement.
pub func svg_element_construct(this: SvgElement*, document: DomDocument*, qualified_name: DomQualifiedName):
dom_element_construct(this.dom_element(), document, qualified_name)
# The bases after Element: GlobalEventHandlers (no state) and HTMLOrSVGElement<SVGElement>
# (its two fields start null and empty). The vptrs of every mixin base are SVGElement's (a
# subclass moves them on, DESIGN.md §2.5).
this.element.slottable_mixin.vtable = &svg_element_slottable_mixin_vtable
this.element.aria_mixin.vtable = &svg_element_aria_mixin_vtable
this.element.animatable.vtable = &svg_element_animatable_vtable
this.global_event_handlers.vtable = &svg_element_global_event_handlers_vtable
this.global_event_handlers.class_id = this.cell().class_id
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:34 Web::SVG::SVGElement::initialize (override).
pub func svg_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_element)
dom_element_initialize_impl(base, realm)
# mark: Presentation attributes ==================================================================
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:41 Web::SVG::NamedPropertyID::NamedPropertyID.
pub func svg_named_property_id_construct_fly_string(this: SvgNamedPropertyId*, property_id: css_data.PropertyId, name: ak.FlyString, supported_elements: ak.Vector[ak.FlyString]):
*this = SvgNamedPropertyId(id = property_id, name = name, supported_elements = supported_elements)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:47 Web::SVG::NamedPropertyID::NamedPropertyID.
pub func svg_named_property_id_construct_vector(this: SvgNamedPropertyId*, property_id: css_data.PropertyId, supported_elements: ak.Vector[ak.FlyString]):
svg_named_property_id_construct_fly_string(this, property_id, css_data.string_from_property_id(property_id), supported_elements)
## The `static Array const properties` of attribute_style_properties, made on first use.
var svg_attribute_style_properties_storage: ak.Vector[SvgNamedPropertyId]
var svg_attribute_style_properties_initialized: bool
## `{ SVG::TagNames::... }`: the supported elements of a presentation attribute.
func svg_tag_list(names: (const ak.FlyString[])?) -> ak.Vector[ak.FlyString]:
var list = ak.Vector[ak.FlyString]()
if let given = names:
for name in given:
ak.vector_append_t(&list, name)
return list
## `NamedPropertyID(property_id, supported_elements)` appended to the table.
func svg_add_property(properties: ak.Vector[SvgNamedPropertyId]*, property_id: css_data.PropertyId, supported_elements: (const ak.FlyString[])? = none):
var property: SvgNamedPropertyId = ---
svg_named_property_id_construct_vector(&property, property_id, svg_tag_list(supported_elements))
ak.vector_append_t(properties, property)
## `NamedPropertyID(property_id, name, supported_elements)` appended to the table.
func svg_add_named_property(properties: ak.Vector[SvgNamedPropertyId]*, property_id: css_data.PropertyId, name: ak.FlyString,
supported_elements: (const ak.FlyString[])? = none):
var property: SvgNamedPropertyId = ---
svg_named_property_id_construct_fly_string(&property, property_id, name, svg_tag_list(supported_elements))
ak.vector_append_t(properties, property)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:57 Web::SVG::attribute_style_properties (static).
func svg_attribute_style_properties() -> const SvgNamedPropertyId[]:
if svg_attribute_style_properties_initialized:
return ak.vector_span_const(&svg_attribute_style_properties_storage)
# The table outlives every VM: it is made in the C heap (DESIGN.md §3.3 rule 7).
let saved_atomic_allocator = ak.atomic_allocator
ak.atomic_allocator = none
defer ak.atomic_allocator = saved_atomic_allocator
with memory.heap:
let p = &svg_attribute_style_properties_storage
let dimensioned: ak.FlyString[6] = [svg_tag_names_foreign_object, svg_tag_names_image, svg_tag_names_rect, svg_tag_names_svg, svg_tag_names_symbol,
svg_tag_names_use]
# https://svgwg.org/svg2-draft/styling.html#PresentationAttributes
# FIXME: The `fill` attribute and CSS `fill` property are not the same! But our support is limited enough that they are equivalent for now.
svg_add_property(p, css_data.PropertyId.fill)
# FIXME: The `stroke` attribute and CSS `stroke` property are not the same! But our support is limited enough that they are equivalent for now.
svg_add_property(p, css_data.PropertyId.clip_path)
svg_add_property(p, css_data.PropertyId.clip_rule)
svg_add_property(p, css_data.PropertyId.color)
svg_add_property(p, css_data.PropertyId.color_interpolation)
svg_add_property(p, css_data.PropertyId.cursor)
svg_add_property(p, css_data.PropertyId.cx, [svg_tag_names_circle, svg_tag_names_ellipse])
svg_add_property(p, css_data.PropertyId.cy, [svg_tag_names_circle, svg_tag_names_ellipse])
svg_add_property(p, css_data.PropertyId.direction)
svg_add_property(p, css_data.PropertyId.display)
svg_add_property(p, css_data.PropertyId.dominant_baseline)
svg_add_property(p, css_data.PropertyId.fill_opacity)
svg_add_property(p, css_data.PropertyId.fill_rule)
svg_add_property(p, css_data.PropertyId.filter)
svg_add_property(p, css_data.PropertyId.flood_color)
svg_add_property(p, css_data.PropertyId.flood_opacity)
svg_add_property(p, css_data.PropertyId.font_family)
svg_add_property(p, css_data.PropertyId.font_size)
svg_add_property(p, css_data.PropertyId.font_style)
svg_add_property(p, css_data.PropertyId.font_variant)
svg_add_property(p, css_data.PropertyId.font_weight)
svg_add_named_property(p, css_data.PropertyId.font_width, ak.fly_string_from_str("font-stretch"))
svg_add_property(p, css_data.PropertyId.height, dimensioned)
svg_add_property(p, css_data.PropertyId.image_rendering)
svg_add_property(p, css_data.PropertyId.letter_spacing)
svg_add_property(p, css_data.PropertyId.mask)
svg_add_property(p, css_data.PropertyId.mask_type)
svg_add_property(p, css_data.PropertyId.opacity)
svg_add_property(p, css_data.PropertyId.overflow)
svg_add_property(p, css_data.PropertyId.paint_order)
svg_add_property(p, css_data.PropertyId.pointer_events)
# donor quirk: `NamedPropertyID(CSS::PropertyID::R, { SVG::TagNames::circle })` picks the (id, name)
# constructor (a one-element braced list converts to a FlyString): the attribute named "circle" maps to
# `r` on every element, and the `r` attribute is left to SVGCircleElement's own hints.
svg_add_named_property(p, css_data.PropertyId.r, svg_tag_names_circle)
svg_add_property(p, css_data.PropertyId.rx, [svg_tag_names_ellipse, svg_tag_names_rect])
svg_add_property(p, css_data.PropertyId.ry, [svg_tag_names_ellipse, svg_tag_names_rect])
svg_add_property(p, css_data.PropertyId.shape_rendering)
svg_add_property(p, css_data.PropertyId.stop_color)
svg_add_property(p, css_data.PropertyId.stop_opacity)
svg_add_property(p, css_data.PropertyId.stroke)
svg_add_property(p, css_data.PropertyId.stroke_dasharray)
svg_add_property(p, css_data.PropertyId.stroke_dashoffset)
svg_add_property(p, css_data.PropertyId.stroke_linecap)
svg_add_property(p, css_data.PropertyId.stroke_linejoin)
svg_add_property(p, css_data.PropertyId.stroke_miterlimit)
svg_add_property(p, css_data.PropertyId.stroke_opacity)
svg_add_property(p, css_data.PropertyId.stroke_width)
svg_add_property(p, css_data.PropertyId.text_anchor)
svg_add_property(p, css_data.PropertyId.text_decoration)
svg_add_property(p, css_data.PropertyId.text_rendering)
svg_add_property(p, css_data.PropertyId.text_overflow)
svg_add_named_property(p, css_data.PropertyId.transform, svg_attribute_names_gradient_transform, [svg_tag_names_linear_gradient, svg_tag_names_radial_gradient])
svg_add_named_property(p, css_data.PropertyId.transform, svg_attribute_names_pattern_transform, [svg_tag_names_pattern])
svg_add_property(p, css_data.PropertyId.transform_origin)
svg_add_property(p, css_data.PropertyId.unicode_bidi)
svg_add_property(p, css_data.PropertyId.visibility)
svg_add_property(p, css_data.PropertyId.white_space)
svg_add_property(p, css_data.PropertyId.width, dimensioned)
svg_add_property(p, css_data.PropertyId.word_spacing)
svg_add_property(p, css_data.PropertyId.writing_mode)
svg_add_property(p, css_data.PropertyId.x, dimensioned)
svg_add_property(p, css_data.PropertyId.y, dimensioned)
svg_attribute_style_properties_initialized = true
return ak.vector_span_const(&svg_attribute_style_properties_storage)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:127 Web::SVG::SVGElement::is_presentational_hint (override).
pub func svg_element_is_presentational_hint_impl(base: DomElement*, name: ak.FlyString) -> bool:
if dom_element_is_presentational_hint_impl(base, name):
return true
for property in svg_attribute_style_properties():
if ak.fly_string_equals_ignoring_ascii_case_fly_string(&name, &property.name):
return true
return false
## `property.supported_elements.contains_slow(name)` of FlyStrings.
func svg_fly_strings_contain(names: const ak.Vector[ak.FlyString]*, name: ak.FlyString) -> bool:
for candidate in ak.vector_span_const(names):
if ak.fly_string_eq_fly_string(&candidate, &name):
return true
return false
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:135 Web::SVG::SVGElement::apply_presentational_hints (override).
pub func svg_element_apply_presentational_hints_impl(base: DomElement*, properties: ak.Vector[CssStyleProperty]*):
dom_element_apply_presentational_hints_impl(base, properties)
var parsing_context: CssParsingParams = ---
css_parsing_params_construct_dom_document(&parsing_context, dom_node_document(base.dom_node()), CssParsingMode.svg_presentation_attribute)
# for_each_attribute([&](auto& name, auto& value) { ... })
let attributes = base.m_attributes else return
for i in 0..<dom_named_node_map_length(attributes):
let attribute = dom_named_node_map_item(attributes, (u32)i) else trap("NamedNodeMap::item in range")
let name = dom_attr_name(attribute)
let value = dom_attr_value(attribute)
for property in svg_attribute_style_properties():
if not ak.fly_string_equals_ignoring_ascii_case_fly_string(&name, &property.name):
continue
if not ak.vector_is_empty(&property.supported_elements) and not svg_fly_strings_contain(&property.supported_elements, dom_element_local_name(base)):
continue
if property.id == css_data.PropertyId.mask:
if let style_value = parse_css_value(parsing_context, ak.string_bytes_as_string_view(&value), css_data.PropertyId.mask):
html_append_presentational_hint(properties, css_data.PropertyId.mask, style_value)
else:
if let style_value = parse_css_value(parsing_context, ak.string_bytes_as_string_view(&value), property.id):
html_append_presentational_hint(properties, property.id, style_value)
break
# mark: Accessibility ============================================================================
## Whether a child's text content, trimmed of ASCII whitespace, is not empty.
func svg_element_has_text_content(node: DomNode*) -> bool:
let text = dom_node_text_content(node) else trap("VERIFY: text_content() of an element")
let view = ak.utf16_string_base_utf16_view(&text.utf16_string_base)
let trimmed = ak.utf16_view_trim_ascii_whitespace(&view)
return not ak.utf16_view_is_empty(&trimmed)
## Whether an optional ARIA string attribute is present and not only whitespace.
func svg_aria_string_is_not_blank(value: ak.String?) -> bool:
let string = value else return false
let view = ak.string_bytes_as_string_view(&string)
let trimmed = ak.string_view_trim_whitespace(&view)
return not ak.string_view_is_empty(&trimmed)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:157 Web::SVG::SVGElement::should_include_in_accessibility_tree.
pub func svg_element_should_include_in_accessibility_tree(this: SvgElement*) -> bool:
var has_title_or_desc = false
let role = aria_mixin_role_from_role_attribute_value(&this.element.aria_mixin)
# for_each_child_of_type<SVGElement>(...)
for child in dom_node_children(this.dom_node()):
if not is_svg_element(child):
continue
if (is_svg_title_element(child) or is_svg_desc_element(child)) and svg_element_has_text_content(child):
has_title_or_desc = true
break
# https://w3c.github.io/svg-aam/#include_elements
# TODO: Add support for the SVG tabindex attribute, and include a check for it here.
let aria = &this.element.aria_mixin
if has_title_or_desc:
return true
if svg_aria_string_is_not_blank(aria_mixin_aria_label(aria)):
return true
if svg_aria_string_is_not_blank(aria_mixin_aria_labelled_by(aria)):
return true
if svg_aria_string_is_not_blank(aria_mixin_aria_described_by(aria)):
return true
if let used_role = role:
return aria_is_abstract_role(used_role) and used_role != AriaRole.none_ and used_role != AriaRole.presentation
return false
## `local_name() == name` of an element.
func svg_element_local_name_is(this: SvgElement*, name: ak.FlyString) -> bool:
let local_name = dom_element_local_name(this.dom_element())
return ak.fly_string_eq_fly_string(&local_name, &name)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:177 Web::SVG::SVGElement::default_role (override).
pub func svg_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
let this = (SvgElement*)dom_element_from_aria_mixin(base)
let element = this.dom_element()
# https://w3c.github.io/svg-aam/#mapping_role_table
if svg_element_local_name_is(this, svg_tag_names_a) and (dom_element_has_attribute(element, svg_attribute_names_href) or dom_element_has_attribute(element, svg_attribute_names_xlink_href)):
return AriaRole.link
if (svg_element_local_name_is(this, svg_tag_names_foreign_object) or svg_element_local_name_is(this, svg_tag_names_g)) and svg_element_should_include_in_accessibility_tree(this):
return AriaRole.group
if svg_element_local_name_is(this, svg_tag_names_image) and svg_element_should_include_in_accessibility_tree(this):
return AriaRole.image
if svg_element_local_name_is(this, svg_tag_names_circle) and svg_element_should_include_in_accessibility_tree(this):
return AriaRole.graphicssymbol
if (svg_element_local_name_is(this, svg_tag_names_ellipse) or svg_element_local_name_is(this, svg_tag_names_path) or svg_element_local_name_is(this, svg_tag_names_polygon) or svg_element_local_name_is(this, svg_tag_names_polyline)) and svg_element_should_include_in_accessibility_tree(this):
return AriaRole.graphicssymbol
return AriaRole.generic
# mark: DOM steps ===============================================================================
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:195 Web::SVG::SVGElement::visit_edges (override).
pub func svg_element_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (SvgElement*)base
dom_element_visit_edges_impl(base, visitor)
html_or_svg_element_visit_edges(&this.html_or_svg_element, visitor)
gc.cell_visitor_visit_t(visitor, this.m_class_name_animated_string)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:202 Web::SVG::SVGElement::attribute_changed (override).
pub func svg_element_attribute_changed_impl(base: DomElement*, local_name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
let this = (SvgElement*)base
dom_element_attribute_changed_impl(base, local_name, old_value, value, namespace_)
html_or_svg_element_attribute_changed(&this.html_or_svg_element, local_name, old_value, value, namespace_)
svg_element_update_use_elements_that_reference_this(this)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:210 Web::SVG::SVGElement::cloned (override).
pub func svg_element_cloned_impl(base: DomNode*, copy: DomNode*, clone_children: bool) -> !:
let this = (SvgElement*)base
try dom_node_cloned_impl(base, copy, clone_children)
try html_or_svg_element_cloned(&this.html_or_svg_element, copy, clone_children)
return
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:217 Web::SVG::SVGElement::inserted (override).
pub func svg_element_inserted_impl(base: DomNode*):
let this = (SvgElement*)base
dom_element_inserted_impl(base)
html_or_svg_element_inserted(&this.html_or_svg_element)
svg_element_update_use_elements_that_reference_this(this)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:225 Web::SVG::SVGElement::children_changed (override).
pub func svg_element_children_changed_impl(base: DomNode*, metadata: DomNodeChildrenChangedMetadata):
let this = (SvgElement*)base
dom_element_children_changed_impl(base, metadata)
svg_element_update_use_elements_that_reference_this(this)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:232 Web::SVG::SVGElement::update_use_elements_that_reference_this.
func svg_element_update_use_elements_that_reference_this(this: SvgElement*):
let node = this.dom_node()
let document = dom_node_document(node)
if (is_svg_use_element(node) or is_dom_shadow_root(tree_node_root(node)) or dom_element_id(this.dom_element()) == none or not dom_node_is_connected(node) or not dom_document_is_completely_loaded(document)):
# If this element is in a shadow root, it already represents a clone and is not itself referenced.
# If this does not have an id it cannot be referenced, no point in searching the entire DOM tree.
# An unconnected node cannot have valid references.
# This also prevents searches for elements that are in the process of being constructed - as clones.
# Each use element already listens for the completely_loaded event and then clones its reference,
# we do not have to also clone it in the process of initial DOM building.
return
# document().for_each_in_subtree_of_type<SVGUseElement>(...)
for descendant in dom_node_subtree(document.dom_node()):
if let use_element = as_if_svg_use_element(descendant):
svg_use_element_svg_element_changed(use_element, this)
## removed_from's is_use_element_shadow_root lambda.
func svg_is_use_element_shadow_root(node: DomNode*) -> bool:
let shadow_root = as_if_dom_shadow_root(node) else return false
let host = dom_document_fragment_host(shadow_root.dom_document_fragment()) else return false
return is_svg_use_element(host)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:255 Web::SVG::SVGElement::removed_from (override).
pub func svg_element_removed_from_impl(base: DomNode*, is_subtree_root: DomNodeIsSubtreeRoot, old_ancestor: DomNode*?, old_root: DomNode*):
let this = (SvgElement*)base
dom_element_removed_from_impl(base, is_subtree_root, old_ancestor, old_root)
# If this element is in a shadow root hosted by a use element,
# it already represents a clone and is not itself referenced.
# NB: We check both old_root (for when the element is removed from the shadow tree directly)
# and root() (for when the use element host is removed from the document).
if svg_is_use_element_shadow_root(old_root) or svg_is_use_element_shadow_root(tree_node_root(base)):
return
svg_element_remove_from_use_element_that_reference_this(this)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:274 Web::SVG::SVGElement::remove_from_use_element_that_reference_this.
func svg_element_remove_from_use_element_that_reference_this(this: SvgElement*):
if is_svg_use_element(this) or dom_element_id(this.dom_element()) == none:
return
let document = dom_node_document(this.dom_node())
# document().for_each_in_subtree_of_type<SVGUseElement>(...)
for descendant in dom_node_subtree(document.dom_node()):
if let use_element = as_if_svg_use_element(descendant):
svg_use_element_svg_element_removed(use_element, this)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:286 Web::SVG::SVGElement::adjust_computed_style (override).
pub func svg_element_adjust_computed_style_impl(base: DomElement*, computed_properties: CssComputedProperties*):
let this = (SvgElement*)base
dom_element_adjust_computed_style_impl(base, computed_properties)
# The outermost <svg> element (no ancestor <svg>) participates in CSS box layout
# and may be positioned. All other SVG elements, including nested <svg> elements,
# use SVG's coordinate system and must be forced to position:static.
if is_svg_svgsvg_element(this) and svg_element_owner_svg_element(this) == none:
return
css_computed_properties_set_property(computed_properties, css_data.PropertyId.position, css_keyword_style_value_create(css_data.Keyword.static_).css_style_value())
# mark: IDL attributes ===========================================================================
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:300 Web::SVG::SVGElement::class_name.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__classNames
pub func svg_element_class_name(this: SvgElement*) -> SvgAnimatedString*:
# The className IDL attribute reflects the ‘class’ attribute.
if this.m_class_name_animated_string == none:
var qualified_name: DomQualifiedName = ---
dom_qualified_name_construct(&qualified_name, svg_attribute_names_class, none, none)
this.m_class_name_animated_string = svg_animated_string_create(dom_element_realm(this.dom_element()), this, qualified_name)
return this.m_class_name_animated_string else trap("VERIFY: m_class_name_animated_string")
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:310 Web::SVG::SVGElement::owner_svg_element.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__ownerSVGElement
pub func svg_element_owner_svg_element(this: SvgElement*) -> SvgSvgsvgElement*?:
# The ownerSVGElement IDL attribute represents the nearest ancestor ‘svg’ element.
# On getting ownerSVGElement, the nearest ancestor ‘svg’ element is returned;
# if the current element is the outermost svg element, then null is returned.
let ancestor = dom_node_first_flat_tree_ancestor_of_type(this.dom_node(), &svg_svgsvg_element_class) else return none
return (SvgSvgsvgElement*)ancestor
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:319 Web::SVG::SVGElement::viewport_element.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGElement__viewportElement
pub func svg_element_viewport_element(this: SvgElement*) -> SvgElement*?:
var node = tree_node_parent(this.dom_node())
while let current = node:
# https://svgwg.org/svg2-draft/coords.html#EstablishingANewSVGViewport
# The following elements establish new SVG viewports:
# - The ‘svg’ element
# - A ‘symbol’ element that is instanced by a ‘use’ element.
if is_svg_svgsvg_element(current) or is_svg_symbol_element(current):
return (SvgElement*)current
node = dom_node_parent_or_shadow_host_node(current)
return none
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:333 Web::SVG::SVGElement::fake_animated_length_fixme.
pub func svg_element_fake_animated_length_fixme(this: SvgElement*) -> SvgAnimatedLength*:
let realm = dom_element_realm(this.dom_element())
# FIXME: All callers of this method must implement their animated length correctly.
let base_length = svg_length_create(realm, 0, 0.0, SvgLengthReadOnly.no)
let anim_length = svg_length_create(realm, 0, 0.0, SvgLengthReadOnly.yes)
return svg_animated_length_create(realm, base_length, anim_length)
## svg_animated_length_for_property's make_length lambda.
func svg_element_make_length(this: SvgElement*, property: css_data.PropertyId, read_only: SvgLengthReadOnly) -> SvgLength*:
let realm = dom_element_realm(this.dom_element())
if let computed_properties = dom_element_computed_properties(this.dom_element()):
let style_value = css_computed_properties_property(computed_properties, property)
if not css_style_value_has_auto(style_value):
return svg_length_from_length_percentage(realm, css_length_percentage_from_style_value(style_value), read_only)
return svg_length_create(realm, 0, 0.0, read_only)
## Ported from Libraries/LibWeb/SVG/SVGElement.cpp:341 Web::SVG::SVGElement::svg_animated_length_for_property.
pub func svg_element_svg_animated_length_for_property(this: SvgElement*, property: css_data.PropertyId) -> SvgAnimatedLength*:
# FIXME: Create a proper animated value when animations are supported.
return svg_animated_length_create(dom_element_realm(this.dom_element()), svg_element_make_length(this, property, SvgLengthReadOnly.no),
svg_element_make_length(this, property, SvgLengthReadOnly.yes))
# mark: SVGElement.h =============================================================================
## Ported from Libraries/LibWeb/SVG/SVGElement.h:25 Web::SVG::SVGElement::requires_svg_container (override).
pub func svg_element_requires_svg_container_impl(base: DomNode*) -> bool:
return true
## Ported from Libraries/LibWeb/SVG/SVGElement.h:58 Web::SVG::SVGElement::global_event_handlers_to_event_target (override).
pub func svg_element_global_event_handlers_to_event_target_impl(base: HtmlGlobalEventHandlers*, arg0: ak.FlyString) -> DomEventTarget*?:
return (DomEventTarget*)((u8*)base - memory.offset_of(SvgElement, global_event_handlers))
## Ported from Libraries/LibWeb/SVG/SVGElement.h:60 Web::SVG::SVGElement::is_svg_element (override).
pub func svg_element_is_svg_element_impl(base: DomNode*) -> bool:
return true