Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / html_element_2.lucb

#==============================================================================================
#
#   html_element_2 - HTML::HTMLElement: scrollParent, offsetParent and the offset metrics,
#                    attribute changes, inertness, cloning, insertion, click and hidden
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLElement.cpp (lines 457-947): scrollParent and offsetParent,
#       offsetTop/Left/Width/Height, the attribute change steps (contenteditable, inert, the
#       event handler content attributes, popover, form association), the subtree inertness,
#       the cloning and insertion steps, firing a synthetic pointer event, labels, the hidden
#       attribute, click() and form-associated custom elements.
#
#==============================================================================================

# mark: scrollParent and offsetParent ===========================================================

## The first flat-tree ancestor of `node` that is an Element.
func html_element_first_flat_tree_ancestor_element(node: DomNode*) -> DomElement*?:
    let ancestor = dom_node_first_flat_tree_ancestor_of_type(node, &dom_element_class) else return none
    return as_dom_element(ancestor)

## Ported from HTMLElement.cpp:464 Web::HTML::HTMLElement::scroll_parent.
# https://drafts.csswg.org/cssom-view/#dom-htmlelement-scrollparent
pub func html_element_scroll_parent(this: HtmlElement*) -> DomElement*?:
    # NOTE: We have to ensure that the layout is up-to-date before querying the layout tree.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_scroll_parent)

    # 1. If any of the following holds true, return null and terminate this algorithm:
    #    - The element does not have an associated box.
    #    - The element is the root element.
    #    - The element is the body element.
    #    - The element’s computed value of the position property is fixed and no ancestor establishes a fixed position containing block.
    let layout_node = dom_element_layout_node(this.dom_element()) else return none
    if dom_element_is_document_element(this.dom_element()):
        return none
    if dom_node_is_html_body_element(this.dom_node()):
        return none
    let no_ancestor_establishes_a_fixed_position_containing_block = not html_any_ancestor_establishes_a_fixed_position_containing_block(layout_node)
    if layout_node_is_fixed_position(layout_node.layout_node()) and no_ancestor_establishes_a_fixed_position_containing_block:
        return none

    # 2. Let ancestor be the containing block of the element in the flat tree and repeat these substeps:
    var ancestor = layout_node_containing_block(layout_node.layout_node())
    while let box = ancestor:
        # 1. If ancestor is the initial containing block, return the scrollingElement for the element’s document if it
        #    is not closed-shadow-hidden from the element, otherwise return null.
        if layout_node_is_viewport(box.layout_node()):
            let scrolling_element = dom_document_scrolling_element(html_element_document(this))
            if let element = scrolling_element:
                if not dom_node_is_closed_shadow_hidden_from(element.dom_node(), this.dom_node()):
                    return element
            return none

        # 2. If ancestor is not closed-shadow-hidden from the element, and is a scroll container, terminate this
        #    algorithm and return ancestor.
        if let dom_node = layout_node_dom_node(box.layout_node()):
            if not dom_node_is_closed_shadow_hidden_from(dom_node, this.dom_node()) and layout_node_with_style_is_scroll_container(box.layout_node_with_style()):
                return (DomElement*)dom_node

        # 3. If the computed value of the position property of ancestor is fixed, and no ancestor establishes a fixed
        #    position containing block, terminate this algorithm and return null.
        let computed_values = layout_node_computed_values(box.layout_node())
        if css_computed_values_position(&computed_values.computed_values) == css_data.Positioning.fixed and no_ancestor_establishes_a_fixed_position_containing_block:
            return none

        # 4. Let ancestor be the containing block of ancestor in the flat tree.
        ancestor = layout_node_containing_block(box.layout_node())

    return none

## Ported from HTMLElement.cpp:513 Web::HTML::HTMLElement::offset_parent.
# https://drafts.csswg.org/cssom-view-1/#dom-htmlelement-offsetparent
pub func html_element_offset_parent(this: HtmlElement*) -> DomElement*?:
    # NOTE: We have to ensure that the layout is up-to-date before querying the layout tree.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_offset_parent)

    # 1. If any of the following holds true return null and terminate this algorithm:
    #    - The element does not have an associated box.
    #    - The element is the root element.
    #    - The element is the HTML body element.
    #    - The element’s computed value of the position property is fixed and no ancestor establishes a fixed position containing block.
    let layout_node = dom_element_layout_node(this.dom_element()) else return none
    if dom_element_is_document_element(this.dom_element()):
        return none
    if dom_node_is_html_body_element(this.dom_node()):
        return none
    let no_ancestor_establishes_a_fixed_position_containing_block = not html_any_ancestor_establishes_a_fixed_position_containing_block(layout_node)
    if layout_node_is_fixed_position(layout_node.layout_node()) and no_ancestor_establishes_a_fixed_position_containing_block:
        return none

    # 2. Let ancestor be the parent of the element in the flat tree and repeat these substeps:
    var ancestor = html_element_first_flat_tree_ancestor_element(this.dom_node()) else trap("VERIFY: GC::Ptr<Element>::operator-> on null")
    while true:
        # 1. If ancestor is closed-shadow-hidden from the element, its computed value of the position property is
        #    fixed, and no ancestor establishes a fixed position containing block, terminate this algorithm and return
        #    null.
        let ancestor_is_closed_shadow_hidden = dom_node_is_closed_shadow_hidden_from(ancestor.dom_node(), this.dom_node())
        if ancestor_is_closed_shadow_hidden:
            let ancestor_properties = dom_element_computed_properties(ancestor) else trap("VERIFY: GC::Ptr<ComputedProperties>::operator-> on null")
            if css_computed_properties_position(ancestor_properties) == css_data.Positioning.fixed and no_ancestor_establishes_a_fixed_position_containing_block:
                return none

        # 2. If ancestor is not closed-shadow-hidden from the element and satisfies at least one of the following,
        #    terminate this algorithm and return ancestor.
        if not ancestor_is_closed_shadow_hidden:
            # NB: An ancestor in the flat tree may not have a layout node (e.g., it has display: none).
            #     Such ancestors can't be positioned or establish containing blocks, so we skip those checks.
            # - The element is in a fixed position containing block, and ancestor is a containing block for
            #   fixed-positioned descendants.
            # FIXME: This is ambiguous but I believe it means any ancestor establishes a fixed position containing block.
            #        https://github.com/w3c/csswg-drafts/pull/12531/commits/48e905bb3859f80ce822299f7e6b76515d867fc3#r2623785087
            if not no_ancestor_establishes_a_fixed_position_containing_block:
                if let ancestor_layout_node = dom_element_layout_node(ancestor):
                    if layout_node_establishes_a_fixed_positioning_containing_block(ancestor_layout_node.layout_node()):
                        return ancestor
            # - The element is not in a fixed position containing block, and:
            if no_ancestor_establishes_a_fixed_position_containing_block:
                # - ancestor is a containing block of absolutely-positioned descendants (regardless of whether there
                #   are any absolutely-positioned descendants).
                if let ancestor_layout_node = dom_element_layout_node(ancestor):
                    if layout_node_is_positioned(ancestor_layout_node.layout_node()):
                        return ancestor
                # - It is the body element.
                if dom_node_is_html_body_element(ancestor.dom_node()):
                    return ancestor
                # - The computed value of the position property of the element is static and the ancestor is one of
                #   the following HTML elements: td, th, or table.
                let properties = dom_element_computed_properties(this.dom_element()) else trap("VERIFY: GC::Ptr<ComputedProperties>::operator-> on null")
                let ancestor_local_name = dom_element_local_name(ancestor)
                let cell_names: ak.FlyString[3] = [html_tag_names_td, html_tag_names_th, html_tag_names_table]
                if css_computed_properties_position(properties) == css_data.Positioning.static_ and dom_fly_string_is_one_of_fly_strings(ancestor_local_name, cell_names):
                    return ancestor
            # - FIXME: The element has a different effective zoom than ancestor.

        # 3. If there is no more parent of ancestor in the flat tree, terminate this algorithm and return null.
        let parent_of_ancestor = html_element_first_flat_tree_ancestor_element(ancestor.dom_node()) else return none

        # 4. Let ancestor be the parent of ancestor in the flat tree.
        ancestor = parent_of_ancestor

# mark: Offset metrics ==========================================================================

## Ported from HTMLElement.cpp:587 Web::HTML::HTMLElement::offset_top.
# https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsettop
pub func html_element_offset_top(this: HtmlElement*) -> i32:
    # 1. If the element is the HTML body element or does not have any associated CSS layout box
    #    return zero and terminate this algorithm.
    if is_html_body_element(this):
        return 0

    # NOTE: Ensure that layout is up-to-date before looking at metrics.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_offset_top)

    let paintable_box = dom_node_paintable_box(this.dom_node()) else return 0

    let border_box = paint_paintable_box_absolute_united_border_box_rect(paintable_box)
    let top_border_edge_of_element = gfx.css_pixel_rect_y(&border_box)

    # 2. If the offsetParent of the element is null
    #    return the y-coordinate of the top border edge of the first CSS layout box associated with the element,
    #    relative to the initial containing block origin,
    #    ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
    let offset_parent_or_none = html_element_offset_parent(this)
    if offset_parent_or_none == none or dom_element_layout_node(offset_parent_or_none else trap("unreachable")) == none:
        return gfx.css_pixels_to_int_const(&top_border_edge_of_element)
    let offset_parent = offset_parent_or_none else trap("unreachable")

    # 3. Return the result of subtracting the y-coordinate of the top padding edge
    #    of the first box associated with the offsetParent of the element
    #    from the y-coordinate of the top border edge of the first box associated with the element,
    #    relative to the initial containing block origin,
    #    ignoring any transforms that apply to the element and its ancestors.

    # NOTE: We give special treatment to the body element to match other browsers.
    #       Spec bug: https://github.com/w3c/csswg-drafts/issues/10549

    let offset_parent_box = dom_node_paintable_box(offset_parent.dom_node()) else trap("VERIFY: GC::Ptr<PaintableBox>::operator-> on null")
    var top_padding_edge_of_offset_parent: gfx.CssPixels
    if dom_node_is_html_body_element(offset_parent.dom_node()) and not paint_paintable_is_positioned(offset_parent_box.paint_paintable()):
        top_padding_edge_of_offset_parent = gfx.css_pixels_from_int(0)
    else:
        let padding_box = paint_paintable_box_absolute_united_padding_box_rect(offset_parent_box)
        top_padding_edge_of_offset_parent = gfx.css_pixel_rect_y(&padding_box)
    let difference = gfx.css_pixels_sub(&top_border_edge_of_element, top_padding_edge_of_offset_parent)
    return gfx.css_pixels_to_int_const(&difference)

## Ported from HTMLElement.cpp:634 Web::HTML::HTMLElement::offset_left.
# https://www.w3.org/TR/cssom-view-1/#dom-htmlelement-offsetleft
pub func html_element_offset_left(this: HtmlElement*) -> i32:
    # 1. If the element is the HTML body element or does not have any associated CSS layout box return zero and terminate this algorithm.
    if is_html_body_element(this):
        return 0

    # NOTE: Ensure that layout is up-to-date before looking at metrics.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_offset_left)

    let paintable_box = dom_node_paintable_box(this.dom_node()) else return 0

    let border_box = paint_paintable_box_absolute_united_border_box_rect(paintable_box)
    let left_border_edge_of_element = gfx.css_pixel_rect_x(&border_box)

    # 2. If the offsetParent of the element is null
    #    return the x-coordinate of the left border edge of the first CSS layout box associated with the element,
    #    relative to the initial containing block origin,
    #    ignoring any transforms that apply to the element and its ancestors, and terminate this algorithm.
    let offset_parent_or_none = html_element_offset_parent(this)
    if offset_parent_or_none == none or dom_element_layout_node(offset_parent_or_none else trap("unreachable")) == none:
        return gfx.css_pixels_to_int_const(&left_border_edge_of_element)
    let offset_parent = offset_parent_or_none else trap("unreachable")

    # 3. Return the result of subtracting the x-coordinate of the left padding edge
    #    of the first CSS layout box associated with the offsetParent of the element
    #    from the x-coordinate of the left border edge of the first CSS layout box associated with the element,
    #    relative to the initial containing block origin,
    #    ignoring any transforms that apply to the element and its ancestors.

    # NOTE: We give special treatment to the body element to match other browsers.
    #       Spec bug: https://github.com/w3c/csswg-drafts/issues/10549

    let offset_parent_box = dom_node_paintable_box(offset_parent.dom_node()) else trap("VERIFY: GC::Ptr<PaintableBox>::operator-> on null")
    var left_padding_edge_of_offset_parent: gfx.CssPixels
    if dom_node_is_html_body_element(offset_parent.dom_node()) and not paint_paintable_is_positioned(offset_parent_box.paint_paintable()):
        left_padding_edge_of_offset_parent = gfx.css_pixels_from_int(0)
    else:
        let padding_box = paint_paintable_box_absolute_united_padding_box_rect(offset_parent_box)
        left_padding_edge_of_offset_parent = gfx.css_pixel_rect_x(&padding_box)
    let difference = gfx.css_pixels_sub(&left_border_edge_of_element, left_padding_edge_of_offset_parent)
    return gfx.css_pixels_to_int_const(&difference)

## Ported from HTMLElement.cpp:679 Web::HTML::HTMLElement::offset_width.
# https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetwidth
pub func html_element_offset_width(this: HtmlElement*) -> i32:
    # NOTE: Ensure that layout is up-to-date before looking at metrics.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_offset_width)

    # 1. If the element does not have any associated box return zero and terminate this algorithm.
    let box = dom_node_paintable_box(this.dom_node()) else return 0

    # 2. Return the unscaled width of the axis-aligned bounding box of the border boxes of all fragments generated by
    #    the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
    #
    #    If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also
    #    include fragments generated by the block-level descendants, unless they are zero width or height.
    let border_box = paint_paintable_box_absolute_united_border_box_rect(box)
    let rounded = gfx.round(gfx.css_pixel_rect_width(&border_box))
    return gfx.css_pixels_to_int_const(&rounded)

## Ported from HTMLElement.cpp:697 Web::HTML::HTMLElement::offset_height.
# https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetheight
pub func html_element_offset_height(this: HtmlElement*) -> i32:
    # NOTE: Ensure that layout is up-to-date before looking at metrics.
    dom_document_update_layout_if_needed_for_node(html_element_document(this), this.dom_node(), DomUpdateLayoutReason.html_element_offset_height)

    # 1. If the element does not have any associated box return zero and terminate this algorithm.
    let box = dom_node_paintable_box(this.dom_node()) else return 0

    # 2. Return the unscaled height of the axis-aligned bounding box of the border boxes of all fragments generated by
    #    the element’s principal box, ignoring any transforms that apply to the element and its ancestors.
    #
    #    If the element’s principal box is an inline-level box which was "split" by a block-level descendant, also
    #    include fragments generated by the block-level descendants, unless they are zero width or height.
    let border_box = paint_paintable_box_absolute_united_border_box_rect(box)
    let rounded = gfx.round(gfx.css_pixel_rect_height(&border_box))
    return gfx.css_pixels_to_int_const(&rounded)

# mark: Attribute changes =======================================================================

## Ported from HTMLElement.cpp:715 Web::HTML::HTMLElement::attribute_changed (override).
pub func html_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    let this = (HtmlElement*)base
    dom_element_attribute_changed_impl(base, name, old_value, value, namespace_)
    html_or_svg_element_attribute_changed(&this.html_or_svg_element, name, old_value, value, namespace_)

    if ak.fly_string_eq_fly_string(&name, &html_attribute_names_contenteditable):
        if value == none:
            # No value maps to the "inherit" state.
            this.m_content_editable_state = HtmlContentEditableState.inherit
        elif html_element_string_is_empty(value) or html_element_string_is(value, "true"):
            # "true", an empty string or a missing value map to the "true" state.
            this.m_content_editable_state = HtmlContentEditableState.true_
        elif html_element_string_is(value, "false"):
            # "false" maps to the "false" state.
            this.m_content_editable_state = HtmlContentEditableState.false_
        elif html_element_string_is(value, "plaintext-only"):
            # "plaintext-only" maps to the "plaintext-only" state.
            this.m_content_editable_state = HtmlContentEditableState.plaintext_only
        else:
            # Having an invalid value maps to the "inherit" state.
            this.m_content_editable_state = HtmlContentEditableState.inherit
        for node in dom_node_inclusive_subtree(this.dom_node()):
            dom_node_recompute_editable_subtree_flag(node)
    elif ak.fly_string_eq_fly_string(&name, &html_attribute_names_inert):
        # https://html.spec.whatwg.org/multipage/interaction.html#the-inert-attribute
        # The inert attribute is a boolean attribute that indicates, by its presence, that the element and all its flat tree descendants which don't otherwise escape inertness
        # (such as modal dialogs) are to be made inert by the user agent.
        let is_inert = value != none
        html_element_set_subtree_inertness(this, is_inert)

    # 1. If namespace is not null, or localName is not the name of an event handler content attribute on element, then return.
    # FIXME: Add the namespace part once we support attribute namespaces.
    # (ENUMERATE_GLOBAL_EVENT_HANDLERS: one test per event handler content attribute, in order.)
    html_element_global_event_handler_attribute_changed(this, name, value)

    html_element_popover_attribute_change_steps(this, name, old_value, value, namespace_)

    if html_form_associated_element_is_form_associated_element(&this.form_associated_element):
        html_form_associated_element_form_node_attribute_changed(&this.form_associated_element, name, value)
        html_form_associated_element_form_associated_element_attribute_changed(&this.form_associated_element, name, old_value, value, namespace_)

## attribute_changed's `[&]() {...}()`: the popover attribute's change steps.
# https://html.spec.whatwg.org/multipage/popover.html#the-popover-attribute:concept-element-attributes-change-ext
# https://whatpr.org/html/9457/popover.html#the-popover-attribute:concept-element-attributes-change-ext
func html_element_popover_attribute_change_steps(this: HtmlElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    # The following attribute change steps, given element, localName, oldValue, value, and namespace, are used for all HTML elements:

    # 1. If namespace is not null, then return.
    if namespace_ != none:
        return

    # 2. If localName is not popover, then return.
    if not ak.fly_string_eq_fly_string(&name, &html_attribute_names_popover):
        return

    # 3. If element's popover visibility state is in the showing state
    #    and oldValue and value are in different states,
    #    then run the hide popover algorithm given element, true, true, false, true, and null.
    if this.m_popover_visibility_state == HtmlElementPopoverVisibilityState.showing and not dom_node_optional_strings_equal(html_element_popover_value_to_state(old_value), html_element_popover_value_to_state(value)):
        html_element_hide_popover(this, HtmlFocusPreviousElement.yes, HtmlFireEvents.yes, HtmlThrowExceptions.no, HtmlIgnoreDomState.yes, none) else trap("MUST: hide_popover")

## Ported from HTMLElement.cpp:783 Web::HTML::HTMLElement::set_subtree_inertness.
pub func html_element_set_subtree_inertness(this: HtmlElement*, is_inert: bool):
    html_element_set_inert(this, is_inert)
    var it = dom_node_subtree(this.dom_node()).iterator()
    while let node = it.next():
        let html_element = as_if_html_element(node) else continue
        if dom_element_has_attribute(html_element.dom_element(), html_attribute_names_inert):
            it.skip_children()
            continue
        # FIXME: Exclude elements that should escape inertness.
        html_element_set_inert(html_element, is_inert)

## Ported from HTMLElement.cpp:795 Web::HTML::HTMLElement::cloned (override).
pub func html_element_cloned_impl(base: DomNode*, copy: DomNode*, clone_children: bool) -> !:
    let this = (HtmlElement*)base
    try dom_node_cloned_impl(base, copy, clone_children)
    try html_or_svg_element_cloned(&this.html_or_svg_element, copy, clone_children)

## Ported from HTMLElement.cpp:802 Web::HTML::HTMLElement::inserted (override).
pub func html_element_inserted_impl(base: DomNode*):
    let this = (HtmlElement*)base
    dom_element_inserted_impl(base)
    html_or_svg_element_inserted(&this.html_or_svg_element)

    if let parent = tree_node_first_ancestor_of_type(this.dom_node(), &html_element_class):
        let parent_html_element = as_html_element(parent)
        if html_element_is_inert(parent_html_element) and not dom_element_has_attribute(this.dom_element(), html_attribute_names_inert):
            html_element_set_subtree_inertness(this, true)

    if html_form_associated_element_is_form_associated_element(&this.form_associated_element):
        html_form_associated_element_form_node_was_inserted(&this.form_associated_element)
        html_form_associated_element_form_associated_element_was_inserted(&this.form_associated_element)

# mark: Synthetic pointer events and labels =====================================================

## Ported from HTMLElement.cpp:817 Web::HTML::HTMLElement::fire_a_synthetic_pointer_event.
# https://html.spec.whatwg.org/multipage/webappapis.html#fire-a-synthetic-pointer-event
pub func html_element_fire_a_synthetic_pointer_event(this: HtmlElement*, type_: ak.FlyString, target: DomElement*, not_trusted: bool) -> bool:
    # 1. Let event be the result of creating an event using PointerEvent.
    # 2. Initialize event's type attribute to e.
    # (PointerEvent is opaque until phase 4; it is a DOM::Event first.)
    let event = (DomEvent*)ui_events_pointer_event_create(html_element_realm(this), type_)

    # 3. Initialize event's bubbles and cancelable attributes to true.
    dom_event_set_bubbles(event, true)
    dom_event_set_cancelable(event, true)

    # 4. Set event's composed flag.
    dom_event_set_composed(event, true)

    # 5. If the not trusted flag is set, initialize event's isTrusted attribute to false.
    if not_trusted:
        dom_event_set_is_trusted(event, false)

    # FIXME: 6. Initialize event's ctrlKey, shiftKey, altKey, and metaKey attributes according to the current state
    #           of the key input device, if any (false for any keys that are not available).

    # FIXME: 7. Initialize event's view attribute to target's node document's Window object, if any, and null otherwise.

    # FIXME: 8. event's getModifierState() method is to return values appropriately describing the current state of the key input device.

    # 9. Return the result of dispatching event at target.
    return dom_event_target_dispatch_event(target.dom_event_target(), event)

## labels()' LiveNodeList filter: `[&](auto& node) { ...label_element->control() == this; }`.
func html_element_labels_filter(context: void*?, node: DomNode*) -> bool:
    let this = (HtmlElement*)(context else trap("labels: no element"))
    let label_element = as_if_html_label_element(node) else return false
    return html_label_element_control(label_element) == this

## Ported from HTMLElement.cpp:845 Web::HTML::HTMLElement::labels.
# https://html.spec.whatwg.org/multipage/forms.html#dom-lfe-labels-dev
pub func html_element_labels(this: HtmlElement*) -> DomNodeList*?:
    # Labelable elements and all input elements have a live NodeList object associated with them that represents the list of label elements, in tree order,
    # whose labeled control is the element in question. The labels IDL attribute of labelable elements that are not form-associated custom elements,
    # and the labels IDL attribute of input elements, on getting, must return that NodeList object, and that same value must always be returned,
    # unless this element is an input element whose type attribute is in the Hidden state, in which case it must instead return null.
    if not html_element_is_labelable(this):
        return none

    if this.m_labels == none:
        this.m_labels = dom_live_node_list_create(html_element_realm(this), tree_node_root(this.dom_node()), DomLiveNodeListScope.descendants, ak.Function1[DomNode*, bool](call = html_element_labels_filter, context = this))

    return this.m_labels

# mark: hidden and click() ======================================================================

## Ported from HTMLElement.cpp:865 Web::HTML::HTMLElement::hidden.
# https://html.spec.whatwg.org/multipage/interaction.html#dom-hidden
pub func html_element_hidden(this: HtmlElement*) -> ak.BoolOrF64OrStringOrEmpty:
    # 1. If the hidden attribute is in the hidden until found state, then return "until-found".
    let hidden = dom_element_get_attribute(this.dom_element(), html_attribute_names_hidden)
    if html_element_string_is(hidden, "until-found"):
        return .string(ak.string_from_str("until-found"))
    # 2. If the hidden attribute is set, then return true.
    if hidden != none:
        return .bool_(true)
    # 3. Return false.
    return .bool_(false)

## Ported from HTMLElement.cpp:878 Web::HTML::HTMLElement::set_hidden.
pub func html_element_set_hidden(this: HtmlElement*, given_value: ak.BoolOrF64OrStringOrEmpty):
    match given_value:
        # 1. If the given value is a string that is an ASCII case-insensitive match for "until-found", then set the hidden attribute to "until-found".
        .string(string):
            if ak.string_equals_ignoring_ascii_case_string_view(&string, ak.sv("until-found")):
                dom_element_set_attribute_value(this.dom_element(), html_attribute_names_hidden, ak.string_from_str("until-found"))
                return
            # 3. Otherwise, if the given value is the empty string, then remove the hidden attribute.
            if ak.string_is_empty(&string):
                dom_element_remove_attribute(this.dom_element(), html_attribute_names_hidden)
                return
        # 2. Otherwise, if the given value is false, then remove the hidden attribute.
        .bool_(flag):
            if not flag:
                dom_element_remove_attribute(this.dom_element(), html_attribute_names_hidden)
                return
        # 5. Otherwise, if the given value is 0, then remove the hidden attribute.
        # 6. Otherwise, if the given value is NaN, then remove the hidden attribute.
        .f64_(double_value):
            if double_value == 0.0 or math.is_nan(double_value):
                dom_element_remove_attribute(this.dom_element(), html_attribute_names_hidden)
                return
        # 4. Otherwise, if the given value is null, then remove the hidden attribute.
        .empty:
            dom_element_remove_attribute(this.dom_element(), html_attribute_names_hidden)
            return
    # 7. Otherwise, set the hidden attribute to the empty string.
    dom_element_set_attribute_value(this.dom_element(), html_attribute_names_hidden, ak.string_new())

## Ported from HTMLElement.cpp:918 Web::HTML::HTMLElement::click.
# https://html.spec.whatwg.org/multipage/interaction.html#dom-click
pub func html_element_click(this: HtmlElement*):
    # 1. If this element is a form control that is disabled, then return.
    if let form_control = as_if_form_associated_element(this):
        if not html_form_associated_element_enabled(form_control):
            return

    # 2. If this element's click in progress flag is set, then return.
    if this.m_click_in_progress:
        return

    # 3. Set this element's click in progress flag.
    this.m_click_in_progress = true

    # 4. Fire a synthetic pointer event named click at this element, with the not trusted flag set.
    _ = html_element_fire_a_synthetic_pointer_event(this, html_event_names_click, this.dom_element(), true)

    # 5. Unset this element's click in progress flag.
    this.m_click_in_progress = false

## Ported from HTMLElement.cpp:940 Web::HTML::HTMLElement::is_form_associated_custom_element.
# https://html.spec.whatwg.org/multipage/custom-elements.html#form-associated-custom-element
pub func html_element_is_form_associated_custom_element(this: HtmlElement*) -> bool:
    # An autonomous custom element is called a form-associated custom element if the element is associated with a
    # custom element definition whose form-associated field is set to true.
    let definition = dom_element_custom_element_definition(this.dom_element()) else return false
    return html_custom_element_definition_form_associated(definition)