Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / svg / svg_ellipse_element.lucb

#==============================================================================================
#
#   svg_ellipse_element - SVG::SVGEllipseElement: <ellipse>
#
#   DESCRIPTION:
#       Port of LibWeb/SVG/SVGEllipseElement.cpp (lines 1-119): the cx, cy, rx and ry
#       attributes, the ellipse's path (https://svgwg.org/svg2-draft/shapes.html#EllipseElement)
#       and the SVGAnimatedLength accessors.
#
#==============================================================================================

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:18 Web::SVG::SVGEllipseElement::SVGEllipseElement.
pub func svg_ellipse_element_construct(this: SvgEllipseElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    svg_geometry_element_construct(this.svg_geometry_element(), document, qualified_name)
    # The vptrs of the mixin bases move to SVGEllipseElement's tables.
    let element = this.svg_element()
    element.element.slottable_mixin.vtable = &svg_ellipse_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &svg_ellipse_element_aria_mixin_vtable
    element.element.animatable.vtable = &svg_ellipse_element_animatable_vtable
    element.global_event_handlers.vtable = &svg_ellipse_element_global_event_handlers_vtable

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:23 Web::SVG::SVGEllipseElement::initialize (override).
pub func svg_ellipse_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_ellipse_element)
    svg_geometry_element_initialize_impl(base, realm)

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:29 Web::SVG::SVGEllipseElement::attribute_changed (override).
pub func svg_ellipse_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    let this = (SvgEllipseElement*)base
    svg_graphics_element_attribute_changed_impl(base, name, old_value, value, namespace_)
    let value_text = value else ak.String()  # value.value_or(String {})

    if ak.fly_string_eq_fly_string(&name, &svg_attribute_names_cx):
        this.m_center_x = svg_attribute_parser_parse_coordinate_string_view(ak.string_bytes_as_string_view(&value_text))
    elif ak.fly_string_eq_fly_string(&name, &svg_attribute_names_cy):
        this.m_center_y = svg_attribute_parser_parse_coordinate_string_view(ak.string_bytes_as_string_view(&value_text))
    elif ak.fly_string_eq_fly_string(&name, &svg_attribute_names_rx):
        this.m_radius_x = svg_attribute_parser_parse_positive_length(ak.string_bytes_as_string_view(&value_text))
    elif ak.fly_string_eq_fly_string(&name, &svg_attribute_names_ry):
        this.m_radius_y = svg_attribute_parser_parse_positive_length(ak.string_bytes_as_string_view(&value_text))

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:44 Web::SVG::SVGEllipseElement::get_path (override).
pub func svg_ellipse_element_get_path_impl(base: SvgGeometryElement*, viewport_size: gfx.CssPixelSize) -> gfx.Path:
    let this = (SvgEllipseElement*)base
    let rx = this.m_radius_x else 0.0
    let ry = this.m_radius_y else 0.0
    let cx = this.m_center_x else 0.0
    let cy = this.m_center_y else 0.0
    var path: gfx.Path

    # A computed value of zero for either dimension, or a computed value of auto for both dimensions, disables rendering of the element.
    if rx == 0.0 or ry == 0.0:
        return path

    let radii = gfx.FloatSize(m_width = rx, m_height = ry)
    let x_axis_rotation: f64 = 0.0
    let large_arc = false
    let sweep = true  # Note: Spec says it should be false, but it's wrong. https://github.com/w3c/svgwg/issues/765

    # 1. A move-to command to the point cx+rx,cy;
    gfx.path_move_to(&path, gfx.FloatPoint(m_x = cx + rx, m_y = cy))

    # 2. arc to cx,cy+ry;
    gfx.path_elliptical_arc_to(&path, gfx.FloatPoint(m_x = cx, m_y = cy + ry), radii, (f32)x_axis_rotation, large_arc, sweep)

    # 3. arc to cx-rx,cy;
    gfx.path_elliptical_arc_to(&path, gfx.FloatPoint(m_x = cx - rx, m_y = cy), radii, (f32)x_axis_rotation, large_arc, sweep)

    # 4. arc to cx,cy-ry;
    gfx.path_elliptical_arc_to(&path, gfx.FloatPoint(m_x = cx, m_y = cy - ry), radii, (f32)x_axis_rotation, large_arc, sweep)

    # 5. arc with a segment-completing close path operation.
    gfx.path_elliptical_arc_to(&path, gfx.FloatPoint(m_x = cx + rx, m_y = cy), radii, (f32)x_axis_rotation, large_arc, sweep)

    return path

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:80 Web::SVG::SVGEllipseElement::cx.
# https://www.w3.org/TR/SVG11/shapes.html#EllipseElementCXAttribute
pub func svg_ellipse_element_cx(this: SvgEllipseElement*) -> SvgAnimatedLength*:
    let realm = dom_element_realm(this.dom_element())
    # FIXME: Populate the unit type when it is parsed (0 here is "unknown").
    # FIXME: Create a proper animated value when animations are supported.
    let base_length = svg_length_create(realm, 0, (this.m_center_x else 0.0), SvgLengthReadOnly.no)
    let anim_length = svg_length_create(realm, 0, (this.m_center_x else 0.0), SvgLengthReadOnly.yes)
    return svg_animated_length_create(realm, base_length, anim_length)

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:90 Web::SVG::SVGEllipseElement::cy.
# https://www.w3.org/TR/SVG11/shapes.html#EllipseElementCYAttribute
pub func svg_ellipse_element_cy(this: SvgEllipseElement*) -> SvgAnimatedLength*:
    let realm = dom_element_realm(this.dom_element())
    # FIXME: Populate the unit type when it is parsed (0 here is "unknown").
    # FIXME: Create a proper animated value when animations are supported.
    let base_length = svg_length_create(realm, 0, (this.m_center_y else 0.0), SvgLengthReadOnly.no)
    let anim_length = svg_length_create(realm, 0, (this.m_center_y else 0.0), SvgLengthReadOnly.yes)
    return svg_animated_length_create(realm, base_length, anim_length)

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:100 Web::SVG::SVGEllipseElement::rx.
# https://www.w3.org/TR/SVG11/shapes.html#EllipseElementRXAttribute
pub func svg_ellipse_element_rx(this: SvgEllipseElement*) -> SvgAnimatedLength*:
    let realm = dom_element_realm(this.dom_element())
    # FIXME: Populate the unit type when it is parsed (0 here is "unknown").
    # FIXME: Create a proper animated value when animations are supported.
    let base_length = svg_length_create(realm, 0, (this.m_radius_x else 0.0), SvgLengthReadOnly.no)
    let anim_length = svg_length_create(realm, 0, (this.m_radius_x else 0.0), SvgLengthReadOnly.yes)
    return svg_animated_length_create(realm, base_length, anim_length)

## Ported from Libraries/LibWeb/SVG/SVGEllipseElement.cpp:110 Web::SVG::SVGEllipseElement::ry.
# https://www.w3.org/TR/SVG11/shapes.html#EllipseElementRYAttribute
pub func svg_ellipse_element_ry(this: SvgEllipseElement*) -> SvgAnimatedLength*:
    let realm = dom_element_realm(this.dom_element())
    # FIXME: Populate the unit type when it is parsed (0 here is "unknown").
    # FIXME: Create a proper animated value when animations are supported.
    let base_length = svg_length_create(realm, 0, (this.m_radius_y else 0.0), SvgLengthReadOnly.no)
    let anim_length = svg_length_create(realm, 0, (this.m_radius_y else 0.0), SvgLengthReadOnly.yes)
    return svg_animated_length_create(realm, base_length, anim_length)