dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / svg / svg_animated_string.lucb
#==============================================================================================
#
# svg_animated_string - SVG::SVGAnimatedString: a reflected string attribute
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGAnimatedString.cpp (lines 1-88): an SVGAnimatedString reflects a
# content attribute, optionally also a deprecated one such as xlink:href
# (https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedString).
#
#==============================================================================================
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:18 Web::SVG::SVGAnimatedString::create.
pub func svg_animated_string_create(realm: Realm*, element: SvgElement*, reflected_attribute: DomQualifiedName, deprecated_reflected_attribute: DomQualifiedName? = none, initial_value: ak.FlyString? = none) -> SvgAnimatedString*:
return realm_create_svg_animated_string(realm, realm, element, reflected_attribute, deprecated_reflected_attribute, initial_value)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:23 Web::SVG::SVGAnimatedString::SVGAnimatedString.
pub func svg_animated_string_construct(this: SvgAnimatedString*, realm: Realm*, element: SvgElement*, reflected_attribute: DomQualifiedName, deprecated_reflected_attribute: DomQualifiedName?, initial_value: ak.FlyString?):
bind_platform_object_construct_realm(this.bind_platform_object(), realm)
this.m_element = element
this.m_reflected_attribute = reflected_attribute
this.m_deprecated_reflected_attribute = deprecated_reflected_attribute
this.m_initial_value = initial_value
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:34 Web::SVG::SVGAnimatedString::initialize (override).
pub func svg_animated_string_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_animated_string)
js_cell_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:40 Web::SVG::SVGAnimatedString::visit_edges (override).
pub func svg_animated_string_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (SvgAnimatedString*)base
bind_platform_object_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_t_2(visitor, this.m_element)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:47 Web::SVG::SVGAnimatedString::base_val.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedString__baseVal
pub func svg_animated_string_base_val(this: SvgAnimatedString*) -> ak.String:
let element = this.m_element.dom_element()
let reflected = &this.m_reflected_attribute
# On getting baseVal or animVal, the following steps are run:
# 1. If the reflected attribute is not present, then:
if not dom_element_has_attribute_ns(element, dom_qualified_name_namespace(reflected), dom_qualified_name_local_name(reflected)):
# 1. If the SVGAnimatedString object is defined to additionally reflect a second, deprecated attribute,
# and that attribute is present, then return its value.
if let deprecated = this.m_deprecated_reflected_attribute:
if let attribute = dom_element_get_attribute_ns(element, dom_qualified_name_namespace(&deprecated), dom_qualified_name_local_name(&deprecated)):
return attribute
# 2. Otherwise, if the reflected attribute has an initial value, then return it.
if let initial_value = this.m_initial_value:
return ak.fly_string_to_string_const(&initial_value)
# 3. Otherwise, return the empty string.
return ak.String()
# 2. Otherwise, the reflected attribute is present. Return its value.
return dom_element_get_attribute_ns(element, dom_qualified_name_namespace(reflected), dom_qualified_name_local_name(reflected)) else trap("VERIFY: Optional::value")
## Ported from Libraries/LibWeb/SVG/SVGAnimatedString.cpp:72 Web::SVG::SVGAnimatedString::set_base_val.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedString__baseVal
pub func svg_animated_string_set_base_val(this: SvgAnimatedString*, base_val: ak.String):
let element = this.m_element.dom_element()
let reflected = &this.m_reflected_attribute
# 1. If the reflected attribute is not present, the SVGAnimatedString object is defined to additionally reflect
# a second, deprecated attribute, and that deprecated attribute is present, then set that deprecated attribute
# to the specified value.
if not dom_element_has_attribute_ns(element, dom_qualified_name_namespace(reflected), dom_qualified_name_local_name(reflected)):
if let deprecated = this.m_deprecated_reflected_attribute:
if dom_element_has_attribute_ns(element, dom_qualified_name_namespace(&deprecated), dom_qualified_name_local_name(&deprecated)):
dom_element_set_attribute_value(element, dom_qualified_name_local_name(&deprecated), base_val, dom_qualified_name_prefix(&deprecated),
dom_qualified_name_namespace(&deprecated))
return
# 2. Otherwise, set the reflected attribute to the specified value.
dom_element_set_attribute_value(element, dom_qualified_name_local_name(reflected), base_val, dom_qualified_name_prefix(reflected),
dom_qualified_name_namespace(reflected))