dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / svg / svg_animated_integer.lucb
#==============================================================================================
#
# svg_animated_integer - SVG::SVGAnimatedInteger: a reflected integer attribute
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGAnimatedInteger.cpp (lines 1-166): an SVGAnimatedInteger reflects
# a integer (or a integer-optional-integer) content attribute of its element
# (https://svgwg.org/svg2-draft/types.html#InterfaceSVGAnimatedInteger).
#
#==============================================================================================
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:18 Web::SVG::SVGAnimatedInteger::create.
pub func svg_animated_integer_create(realm: Realm*, element: SvgElement*, reflected_attribute: DomQualifiedName, initial_value: i32, supports_second_value: SvgAnimatedIntegerSupportsSecondValue = SvgAnimatedIntegerSupportsSecondValue.no, value_represented: SvgAnimatedIntegerValueRepresented = SvgAnimatedIntegerValueRepresented.first) -> SvgAnimatedInteger*:
return realm_create_svg_animated_integer(realm, realm, element, reflected_attribute, initial_value, supports_second_value, value_represented)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:30 Web::SVG::SVGAnimatedInteger::SVGAnimatedInteger.
pub func svg_animated_integer_construct(this: SvgAnimatedInteger*, realm: Realm*, element: SvgElement*, reflected_attribute: DomQualifiedName, initial_value: i32, supports_second_value: SvgAnimatedIntegerSupportsSecondValue, value_represented: SvgAnimatedIntegerValueRepresented):
bind_platform_object_construct_realm(this.bind_platform_object(), realm)
this.m_element = element
this.m_reflected_attribute = reflected_attribute
this.m_initial_value = initial_value
this.m_supports_second_value = supports_second_value
this.m_value_represented = value_represented
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:49 Web::SVG::SVGAnimatedInteger::base_val.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedInteger__baseVal
pub func svg_animated_integer_base_val(this: SvgAnimatedInteger*) -> i32:
# On getting baseVal or animVal, the following steps are run:
return svg_animated_integer_get_base_or_anim_value(this)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:56 Web::SVG::SVGAnimatedInteger::set_base_val.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedInteger__baseVal
pub func svg_animated_integer_set_base_val(this: SvgAnimatedInteger*, new_value: i32):
# 1. Let value be the value being assigned to baseVal.
let value = new_value
# 2. Let new be a list of integers.
var new_ = ak.Vector[i32]()
# 3. If the reflected attribute is defined to take an integer followed by an optional second integer, then:
if this.m_supports_second_value == SvgAnimatedIntegerSupportsSecondValue.yes:
# 1. Let current be the value of the reflected attribute (using the attribute's initial value if it is not
# present or invalid).
let current = dom_element_get_attribute_value(this.m_element.dom_element(), dom_qualified_name_local_name(&this.m_reflected_attribute),
dom_qualified_name_namespace(&this.m_reflected_attribute))
let current_values = ak.string_split(¤t, 0x20) else trap("MUST: String::split")
# 2. Let first be the first integer in current.
var first = this.m_initial_value
if ak.vector_size(¤t_values) > 0:
first = svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(ak.vector_at_const(¤t_values, 0)))
# 3. Let second be the second integer in current if it has been explicitly specified, and if not, the implicit
# value as described in the definition of the attribute.
# NB: All known usages of <number-optional-number> specify that a missing second number defaults to the value
# of the first number.
var second = first
if ak.vector_size(¤t_values) > 1 and not ak.string_is_empty(ak.vector_at_const(¤t_values, 1)):
second = svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(ak.vector_at_const(¤t_values, 1)))
# 4. If this SVGAnimatedInteger object reflects the first integer, then set first to value. Otherwise, set second
# to value.
if this.m_value_represented == SvgAnimatedIntegerValueRepresented.first:
first = value
else:
second = value
# 5. Append first to new.
ak.vector_append_t(&new_, first)
# 6. Append second to new.
ak.vector_append_t(&new_, second)
else:
# 4. Otherwise, the reflected attribute is defined to take a single integer value. Append value to new.
ak.vector_append_t(&new_, value)
# 5. Set the content attribute to a string consisting of each integer in new serialized to an implementation
# specific string that, if parsed as an <number> using CSS syntax, would return that integer,
# joined and separated by a single U+0020 SPACE character.
var builder = ak.string_builder_new()
var first_item = true
for item in ak.vector_span_const(&new_):
if not first_item:
ak.string_builder_append_u8(&builder, ' ')
first_item = false
ak.format_i64(&builder, item)
let new_attribute_value = ak.string_builder_to_string_without_validation(&builder)
dom_element_set_attribute_value(this.m_element.dom_element(), dom_qualified_name_local_name(&this.m_reflected_attribute), new_attribute_value,
dom_qualified_name_prefix(&this.m_reflected_attribute), dom_qualified_name_namespace(&this.m_reflected_attribute))
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:109 Web::SVG::SVGAnimatedInteger::anim_val.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedInteger__animVal
pub func svg_animated_integer_anim_val(this: SvgAnimatedInteger*) -> i32:
# On getting baseVal or animVal, the following steps are run:
return svg_animated_integer_get_base_or_anim_value(this)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:115 Web::SVG::SVGAnimatedInteger::parse_value_or_initial.
func svg_animated_integer_parse_value_or_initial(this: SvgAnimatedInteger*, number_value: ak.StringView) -> i32:
let value = svg_attribute_parser_parse_integer_string_view(number_value) else return this.m_initial_value
return value
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:124 Web::SVG::SVGAnimatedInteger::get_base_or_anim_value.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGAnimatedInteger__baseVal
func svg_animated_integer_get_base_or_anim_value(this: SvgAnimatedInteger*) -> i32:
# 1. Let value be the value of the reflected attribute (using the attribute's initial value if it is not present or
# invalid).
let value = dom_element_get_attribute_value(this.m_element.dom_element(), dom_qualified_name_local_name(&this.m_reflected_attribute),
dom_qualified_name_namespace(&this.m_reflected_attribute))
# 2. If the reflected attribute is defined to take an integer followed by an optional second integer, then:
if this.m_supports_second_value == SvgAnimatedIntegerSupportsSecondValue.yes:
# 1. If this SVGAnimatedInteger object reflects the first integer, then return the first value in value.
let values = ak.string_split(&value, 0x20) else trap("MUST: String::split")
if ak.vector_is_empty(&values):
return this.m_initial_value
if this.m_value_represented == SvgAnimatedIntegerValueRepresented.first:
return svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(ak.vector_at_const(&values, 0)))
# 2. Otherwise, this SVGAnimatedInteger object reflects the second integer. Return the second value in value if
# it has been explicitly specified, and if not, return the implicit value as described in the definition of
# the attribute.
# NB: All known usages of <number-optional-number> specify that a missing second number defaults to the value
# of the first number.
assert(this.m_value_represented == SvgAnimatedIntegerValueRepresented.second)
if ak.vector_size(&values) > 1 and not ak.string_is_empty(ak.vector_at_const(&values, 1)):
return svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(ak.vector_at_const(&values, 1)))
return svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(ak.vector_at_const(&values, 0)))
# 3. Otherwise, the reflected attribute is defined to take a single integer value. Return value.
return svg_animated_integer_parse_value_or_initial(this, ak.string_bytes_as_string_view(&value))
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:154 Web::SVG::SVGAnimatedInteger::initialize (override).
pub func svg_animated_integer_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_animated_integer)
js_cell_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/SVG/SVGAnimatedInteger.cpp:160 Web::SVG::SVGAnimatedInteger::visit_edges (override).
pub func svg_animated_integer_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (SvgAnimatedInteger*)base
bind_platform_object_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_t_2(visitor, this.m_element)