dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / svg / svg_length.lucb
#==============================================================================================
#
# svg_length - SVG::SVGLength: a length value of the SVG DOM
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGLength.cpp (lines 1-91) with the inline members of SVGLength.h:
# creation (also from a CSS LengthPercentage), the value and unit accessors and the
# value setter of https://svgwg.org/svg2-draft/types.html#InterfaceSVGLength.
#
#==============================================================================================
## Ported from Libraries/LibWeb/SVG/SVGLength.cpp:17 Web::SVG::SVGLength::create.
pub func svg_length_create(realm: Realm*, unit_type: u8, value: f32, read_only: SvgLengthReadOnly) -> SvgLength*:
return realm_create_svg_length(realm, realm, unit_type, value, read_only)
## from_length_percentage's lambda: the SVGLength unit type of a CSS length unit.
func svg_length_unit_type_for(length_unit: css_data.LengthUnit) -> u16:
match length_unit:
.em: return svg_length_svg_lengthtype_ems
.ex: return svg_length_svg_lengthtype_exs
.px: return svg_length_svg_lengthtype_px
.cm: return svg_length_svg_lengthtype_cm
.mm: return svg_length_svg_lengthtype_mm
.in_: return svg_length_svg_lengthtype_in
.pt: return svg_length_svg_lengthtype_pt
.pc: return svg_length_svg_lengthtype_pc
_: return svg_length_svg_lengthtype_unknown
## Ported from Libraries/LibWeb/SVG/SVGLength.cpp:22 Web::SVG::SVGLength::from_length_percentage.
pub func svg_length_from_length_percentage(realm: Realm*, length_percentage: CssLengthPercentage, read_only: SvgLengthReadOnly) -> SvgLength*:
# FIXME: We can't tell if a CSS::LengthPercentage was a unitless length.
if css_percentage_or_is_percentage(&length_percentage.percentage_or):
let percentage = css_percentage_or_percentage(&length_percentage.percentage_or)
return svg_length_create(realm, (u8)svg_length_svg_lengthtype_percentage, (f32)css_percentage_value(&percentage), read_only)
if css_length_percentage_is_length(&length_percentage):
let length = css_length_percentage_length(&length_percentage)
return svg_length_create(realm, (u8)svg_length_unit_type_for(css_length_unit(&length)), (f32)css_length_raw_value(&length), read_only)
return svg_length_create(realm, (u8)svg_length_svg_lengthtype_unknown, 0.0, read_only)
## Ported from Libraries/LibWeb/SVG/SVGLength.cpp:57 Web::SVG::SVGLength::SVGLength.
pub func svg_length_construct(this: SvgLength*, realm: Realm*, unit_type: u8, value: f32, read_only: SvgLengthReadOnly):
bind_platform_object_construct_realm(this.bind_platform_object(), realm)
this.m_value = value
this.m_unit_type = unit_type
this.m_read_only = read_only
## Ported from Libraries/LibWeb/SVG/SVGLength.cpp:65 Web::SVG::SVGLength::initialize (override).
pub func svg_length_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_length)
js_cell_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/SVG/SVGLength.h:41 Web::SVG::SVGLength::value.
pub func svg_length_value(this: SvgLength*) -> f32:
return this.m_value
## Ported from Libraries/LibWeb/SVG/SVGLength.cpp:74 Web::SVG::SVGLength::set_value.
# https://svgwg.org/svg2-draft/types.html#__svg__SVGLength__value
pub func svg_length_set_value(this: SvgLength*, value: f32) -> !:
# 1. If the SVGLength object is read only, then throw a NoModificationAllowedError.
if this.m_read_only == SvgLengthReadOnly.yes:
return try idl_throw(.idl_dom_exception(idl_no_modification_allowed_error_create(bind_platform_object_realm(this.bind_platform_object()),
ak.utf16_string_from_str("Cannot modify value of read-only SVGLength"))))
# 2. Let value be the value being assigned to value.
# 3. Set the SVGLength's value to a <number> whose value is value.
this.m_value = value
this.m_unit_type = (u8)svg_length_svg_lengthtype_number
# FIXME: 4. If the SVGLength reflects the base value of a reflected attribute, reflects a presentation attribute, or
# reflects an element of the base value of a reflected attribute, then reserialize the reflected attribute.
return
## Ported from Libraries/LibWeb/SVG/SVGLength.h:44 Web::SVG::SVGLength::unit_type.
pub func svg_length_unit_type(this: SvgLength*) -> u8:
return this.m_unit_type
## Ported from Libraries/LibWeb/SVG/SVGLength.h:45 Web::SVG::SVGLength::read_only.
pub func svg_length_read_only(this: SvgLength*) -> SvgLengthReadOnly:
return this.m_read_only