Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / htmlo_list_element.lucb

#==============================================================================================
#
#   htmlo_list_element - HTML::HTMLOListElement: <ol>
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLOListElement.cpp (lines 1-114) and HTMLOListElement.h: the
#       constructor (which moves the mixin tables to HTMLOListElement's, as C++'s vptrs move),
#       initialize, the reversed/start/type change steps, start and the starting value, and the
#       type attribute's presentational hint.
#
#==============================================================================================

## Ported from HTMLOListElement.cpp:21 Web::HTML::HTMLOListElement::HTMLOListElement.
pub func html_htmlo_list_element_construct(this: HtmlHtmloListElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLOListElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_htmlo_list_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_htmlo_list_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_htmlo_list_element_animatable_vtable
    element.global_event_handlers.vtable = &html_htmlo_list_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_htmlo_list_element_form_associated_element_vtable

## Ported from HTMLOListElement.cpp:28 Web::HTML::HTMLOListElement::initialize (override).
pub func html_htmlo_list_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.htmlo_list_element)
    html_element_initialize_impl(base, realm)

## Ported from HTMLOListElement.cpp:34 Web::HTML::HTMLOListElement::attribute_changed (override).
pub func html_htmlo_list_element_attribute_changed_impl(base: DomElement*, local_name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    html_element_attribute_changed_impl(base, local_name, old_value, value, namespace_)

    if ak.fly_string_eq_fly_string(&local_name, &html_attribute_names_reversed) or ak.fly_string_eq_fly_string(&local_name, &html_attribute_names_start) or ak.fly_string_eq_fly_string(&local_name, &html_attribute_names_type):
        dom_node_set_needs_layout_tree_update(base.dom_node(), true, DomSetNeedsLayoutTreeUpdateReason.htmlo_list_element_ordinal_values)
        if let first_child_element = tree_node_first_child_of_type(base.dom_node(), &dom_element_class):
            dom_element_maybe_invalidate_ordinals_for_list_owner((DomElement*)first_child_element)

## Ported from HTMLOListElement.cpp:46 Web::HTML::HTMLOListElement::start.
# https://html.spec.whatwg.org/multipage/grouping-content.html#dom-ol-start
pub func html_htmlo_list_element_start(this: HtmlHtmloListElement*) -> i32:
    # The start IDL attribute must reflect the content attribute of the same name, with a default value of 1.
    let content_attribute_value = dom_element_get_attribute(this.dom_element(), html_attribute_names_start) else ak.string_from_str("1")
    if let maybe_number = html_parse_integer(ak.string_bytes_as_string_view(&content_attribute_value)):
        return maybe_number
    return 1

## Ported from HTMLOListElement.cpp:55 Web::HTML::HTMLOListElement::set_start.
pub func html_htmlo_list_element_set_start(this: HtmlHtmloListElement*, start: i32):
    dom_element_set_attribute_value(this.dom_element(), html_attribute_names_start, ak.string_number_i64(start))

## Ported from HTMLOListElement.cpp:61 Web::HTML::HTMLOListElement::starting_value.
# https://html.spec.whatwg.org/multipage/grouping-content.html#concept-ol-start
pub func html_htmlo_list_element_starting_value(this: HtmlHtmloListElement*) -> ak.Checked[i32]:
    # 1. If the ol element has a start attribute, then:
    if let start = dom_element_get_attribute(this.dom_element(), html_attribute_names_start):
        # 1. Let parsed be the result of parsing the value of the attribute as an integer.
        # 2. If parsed is not an error, then return parsed.
        if let parsed = html_parse_integer(ak.string_bytes_as_string_view(&start)):
            return ak.Checked[i32](m_value = parsed, m_overflow = false)
    # 2. If the ol element has a reversed attribute, then return the number of owned li elements.
    if dom_element_has_attribute(this.dom_element(), html_attribute_names_reversed):
        let reverse_list_starting_value = dom_element_number_of_owned_list_items(this.dom_element())
        assert(reverse_list_starting_value <= ak.i32_max)
        return ak.Checked[i32](m_value = reverse_list_starting_value, m_overflow = false)

    # 3. Return 1.
    return ak.Checked[i32](m_value = 1, m_overflow = false)

## Ported from HTMLOListElement.cpp:84 Web::HTML::HTMLOListElement::is_presentational_hint (override).
pub func html_htmlo_list_element_is_presentational_hint_impl(base: DomElement*, name: ak.FlyString) -> bool:
    if dom_element_is_presentational_hint_impl(base, name):
        return true

    return ak.fly_string_eq_fly_string(&name, &html_attribute_names_type)

## Ported from HTMLOListElement.cpp:92 Web::HTML::HTMLOListElement::apply_presentational_hints (override).
pub func html_htmlo_list_element_apply_presentational_hints_impl(base: DomElement*, properties: ak.Vector[CssStyleProperty]*):
    dom_element_apply_presentational_hints_impl(base, properties)

    # https://html.spec.whatwg.org/multipage/rendering.html#lists
    for attribute in dom_element_attribute_span(base):
        let name = dom_attr_name(attribute)
        let value = dom_attr_value(attribute)
        if ak.fly_string_eq_fly_string(&name, &html_attribute_names_type):
            if ak.string_eq_string_view(&value, ak.sv("1")):
                ak.vector_append_t(properties, html_list_style_type_counter_style("decimal"))
            elif ak.string_eq_string_view(&value, ak.sv("a")):
                ak.vector_append_t(properties, html_list_style_type_counter_style("lower-alpha"))
            elif ak.string_eq_string_view(&value, ak.sv("A")):
                ak.vector_append_t(properties, html_list_style_type_counter_style("upper-alpha"))
            elif ak.string_eq_string_view(&value, ak.sv("i")):
                ak.vector_append_t(properties, html_list_style_type_counter_style("lower-roman"))
            elif ak.string_eq_string_view(&value, ak.sv("I")):
                ak.vector_append_t(properties, html_list_style_type_counter_style("upper-roman"))

## Ported from HTMLOListElement.h:24 Web::HTML::HTMLOListElement::default_role (override).
pub func html_htmlo_list_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
    return AriaRole.list

## Ported from HTMLOListElement.h:31 Web::HTML::HTMLOListElement::is_html_olist_element (override).
pub func html_htmlo_list_element_is_html_olist_element_impl(base: DomNode*) -> bool:
    return true