Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / svg / svg_fit_to_view_box.lucb

#==============================================================================================
#
#   svg_fit_to_view_box - SVG::SVGFitToViewBox: the viewBox and preserveAspectRatio mixin
#
#   DESCRIPTION:
#       Port of LibWeb/SVG/SVGFitToViewBox.cpp (lines 1-46) with the inline members of
#       SVGFitToViewBox.h: the mixin of <svg> and <view> that parses viewBox and
#       preserveAspectRatio and reflects the viewBox as an SVGAnimatedRect. Its owner calls
#       initialize, visit_edges and attribute_changed with `&this.svg_fit_to_view_box`.
#
#==============================================================================================

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.h:19 Web::SVG::SVGFitToViewBox::view_box_for_bindings.
pub func svg_fit_to_view_box_view_box_for_bindings(this: SvgFitToViewBox*) -> SvgAnimatedRect*:
    return this.m_view_box_for_bindings else trap("VERIFY: m_view_box_for_bindings")

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.h:20 Web::SVG::SVGFitToViewBox::view_box.
pub func svg_fit_to_view_box_view_box(this: SvgFitToViewBox*) -> SvgViewBox?:
    return this.m_view_box

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.h:21 Web::SVG::SVGFitToViewBox::preserve_aspect_ratio.
pub func svg_fit_to_view_box_preserve_aspect_ratio(this: SvgFitToViewBox*) -> SvgPreserveAspectRatio?:
    return this.m_preserve_aspect_ratio

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.cpp:16 Web::SVG::SVGFitToViewBox::initialize.
pub func svg_fit_to_view_box_initialize(this: SvgFitToViewBox*, realm: Realm*):
    this.m_view_box_for_bindings = realm_create_svg_animated_rect(realm, realm)

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.cpp:21 Web::SVG::SVGFitToViewBox::visit_edges.
pub func svg_fit_to_view_box_visit_edges(this: SvgFitToViewBox*, visitor: gc.CellVisitor*):
    gc.cell_visitor_visit_t(visitor, this.m_view_box_for_bindings)

## Ported from Libraries/LibWeb/SVG/SVGFitToViewBox.cpp:26 Web::SVG::SVGFitToViewBox::attribute_changed.
pub func svg_fit_to_view_box_attribute_changed(this: SvgFitToViewBox*, element: DomElement*, name: ak.FlyString, value: ak.String?):
    if ak.fly_string_equals_ignoring_ascii_case_fly_string(&name, &svg_attribute_names_view_box):
        let view_box_for_bindings = this.m_view_box_for_bindings else trap("VERIFY: m_view_box_for_bindings")
        if value == none:
            svg_animated_rect_set_nulled(view_box_for_bindings, true)
        else:
            let text = value else ak.String()
            this.m_view_box = svg_attribute_parser_parse_viewbox(ak.string_bytes_as_string_view(&text))
            svg_animated_rect_set_nulled(view_box_for_bindings, this.m_view_box == none)
            if let view_box = this.m_view_box:
                let rect = GeometryDoubleRect(m_x = view_box.min_x, m_y = view_box.min_y, m_width = view_box.width, m_height = view_box.height)
                svg_animated_rect_set_base_val(view_box_for_bindings, rect)
                svg_animated_rect_set_anim_val(view_box_for_bindings, rect)
        dom_node_set_needs_layout_update(element.dom_node(), DomSetNeedsLayoutReason.svg_view_box_change)
    elif ak.fly_string_equals_ignoring_ascii_case_fly_string(&name, &svg_attribute_names_preserve_aspect_ratio):
        let text = value else ak.String()
        this.m_preserve_aspect_ratio = svg_attribute_parser_parse_preserve_aspect_ratio(ak.string_bytes_as_string_view(&text))
        dom_node_set_needs_layout_update(element.dom_node(), DomSetNeedsLayoutReason.svg_view_box_change)