Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / html_opt_group_element.lucb

#==============================================================================================
#
#   html_opt_group_element - HTML::HTMLOptGroupElement: <optgroup>
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLOptGroupElement.cpp (lines 1-49) and the inline functions of
#       HTMLOptGroupElement.h: construction (which moves the mixin tables to
#       HTMLOptGroupElement's, as C++'s vptrs move), and the insertion and removing steps that
#       run the select element's selectedness setting algorithm.
#
#       Copyright (c) 2020, the SerenityOS developers.
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from HTMLOptGroupElement.cpp:16 Web::HTML::HTMLOptGroupElement::HTMLOptGroupElement.
pub func html_opt_group_element_construct(this: HtmlOptGroupElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLOptGroupElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_opt_group_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_opt_group_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_opt_group_element_animatable_vtable
    element.global_event_handlers.vtable = &html_opt_group_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_opt_group_element_form_associated_element_vtable

## Ported from HTMLOptGroupElement.cpp:23 Web::HTML::HTMLOptGroupElement::initialize (override).
pub func html_opt_group_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_opt_group_element)
    html_element_initialize_impl(base, realm)

## Ported from HTMLOptGroupElement.cpp:29 Web::HTML::HTMLOptGroupElement::inserted (override).
pub func html_opt_group_element_inserted_impl(base: DomNode*):
    html_element_inserted_impl(base)

    # AD-HOC: We update the selectedness of our <select> parent here,
    #         to ensure that the correct <option> is selected after an <optgroup> is dynamically inserted.
    let parent = base.tree_node.m_parent else trap("VERIFY: parent")
    if is_html_select_element(parent) and tree_node_first_child_of_type(base, &html_option_element_class) != none:
        html_select_element_update_selectedness((HtmlSelectElement*)parent)

## Ported from HTMLOptGroupElement.cpp:39 Web::HTML::HTMLOptGroupElement::removed_from (override).
pub func html_opt_group_element_removed_from_impl(base: DomNode*, is_subtree_root: DomNodeIsSubtreeRoot, old_ancestor: DomNode*?, old_root: DomNode*):
    html_element_removed_from_impl(base, is_subtree_root, old_ancestor, old_root)

    # The optgroup HTML element removing steps, given removedNode and oldParent, are:
    # 1. If oldParent is a select element and removedNode has an option child, then run oldParent's selectedness setting algorithm.
    if let ancestor = old_ancestor:
        if is_html_select_element(ancestor) and tree_node_first_child_of_type(base, &html_option_element_class) != none:
            html_select_element_update_selectedness((HtmlSelectElement*)ancestor)

## Ported from HTMLOptGroupElement.h:23 Web::HTML::HTMLOptGroupElement::default_role (override).
# https://www.w3.org/TR/html-aria/#el-optgroup
pub func html_opt_group_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
    _ = base
    return AriaRole.group

## Ported from HTMLOptGroupElement.h:28 Web::HTML::HTMLOptGroupElement::is_html_optgroup_element (override).
pub func html_opt_group_element_is_html_optgroup_element_impl(base: DomNode*) -> bool:
    _ = base
    return true