Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / html_frame_element.lucb

#==============================================================================================
#
#   html_frame_element - HTML::HTMLFrameElement: <frame>
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLFrameElement.cpp (lines 1-116): construction (which moves the
#       mixin tables to HTMLFrameElement's, as C++'s vptrs move), initialize, the insertion and
#       removal steps that create and destroy the child navigable, attribute_changed, the tab
#       index, the display adjustment and processing the frame attributes.
#
#==============================================================================================

## Ported from HTMLFrameElement.cpp:22 Web::HTML::HTMLFrameElement::HTMLFrameElement.
pub func html_frame_element_construct(this: HtmlFrameElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_navigable_container_construct(&this.navigable_container, document, qualified_name)
    # The vptrs of the mixin bases move to HTMLFrameElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_frame_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_frame_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_frame_element_animatable_vtable
    element.global_event_handlers.vtable = &html_frame_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_frame_element_form_associated_element_vtable

    # https://html.spec.whatwg.org/multipage/obsolete.html#frames:potentially-delays-the-load-event
    # The frame element potentially delays the load event.
    html_navigable_container_set_potentially_delays_the_load_event(&this.navigable_container, true)

## Ported from HTMLFrameElement.cpp:32 Web::HTML::HTMLFrameElement::initialize (override).
pub func html_frame_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_frame_element)
    html_element_initialize_impl(base, realm)

## Ported from HTMLFrameElement.cpp:39 Web::HTML::HTMLFrameElement::inserted (override).
# https://html.spec.whatwg.org/multipage/obsolete.html#frames:html-element-insertion-steps
pub func html_frame_element_inserted_impl(base: DomNode*):
    let this = (HtmlFrameElement*)base
    html_element_inserted_impl(base)

    # 1. If insertedNode is not in a document tree, then return.
    if not dom_node_in_a_document_tree(base):
        return

    # 2. If insertedNode's root's browsing context is null, then return.
    if dom_document_browsing_context(dom_node_document(tree_node_root(base))) == none:
        return

    # 3. Create a new child navigable for insertedNode.
    html_navigable_container_create_new_child_navigable(&this.navigable_container)

    # 4. Process the frame attributes for insertedNode, with initialInsertion set to true.
    html_frame_element_process_the_frame_attributes(this, HtmlInitialInsertion.yes)

## Ported from HTMLFrameElement.cpp:59 Web::HTML::HTMLFrameElement::removed_from (override).
# https://html.spec.whatwg.org/multipage/obsolete.html#frames:html-element-removing-steps
pub func html_frame_element_removed_from_impl(base: DomNode*, is_subtree_root: DomNodeIsSubtreeRoot, old_ancestor: DomNode*?, old_root: DomNode*):
    let this = (HtmlFrameElement*)base
    html_element_removed_from_impl(base, is_subtree_root, old_ancestor, old_root)

    # The frame HTML element removing steps, given removedNode, are to destroy a child navigable given removedNode.
    html_navigable_container_destroy_the_child_navigable(&this.navigable_container)

## Ported from HTMLFrameElement.cpp:68 Web::HTML::HTMLFrameElement::attribute_changed (override).
# https://html.spec.whatwg.org/multipage/obsolete.html#frames:frame-3
pub func html_frame_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
    let this = (HtmlFrameElement*)base
    html_element_attribute_changed_impl(base, name, old_value, value, namespace_)

    # Whenever a frame element with a non-null content navigable has its src attribute set, changed, or removed, the
    # user agent must process the frame attributes.
    if html_navigable_container_content_navigable(&this.navigable_container) != none and html_name_is(name, html_attribute_names_src):
        html_frame_element_process_the_frame_attributes(this)

## Ported from HTMLFrameElement.cpp:79 Web::HTML::HTMLFrameElement::default_tab_index_value (override).
# https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
pub func html_frame_element_default_tab_index_value_impl(base: DomElement*) -> i32:
    # See the base function for the spec comments.
    return 0

## Ported from HTMLFrameElement.cpp:85 Web::HTML::HTMLFrameElement::adjust_computed_style (override).
pub func html_frame_element_adjust_computed_style_impl(base: DomElement*, style: CssComputedProperties*):
    # https://drafts.csswg.org/css-display-3/#unbox
    let display = css_computed_properties_display(style)
    if css_display_is_contents(&display):
        css_computed_properties_set_property(style, css_data.PropertyId.display, css_display_style_value_create(css_display_from_short(CssDisplayShort.none_)).css_style_value())

## Ported from HTMLFrameElement.cpp:93 Web::HTML::HTMLFrameElement::process_the_frame_attributes.
# https://html.spec.whatwg.org/multipage/obsolete.html#process-the-frame-attributes
pub func html_frame_element_process_the_frame_attributes(this: HtmlFrameElement*, initial_insertion: HtmlInitialInsertion = HtmlInitialInsertion.no):
    # 1. Let url be the result of running the shared attribute processing steps for iframe and frame elements given
    #    element and initialInsertion.
    let maybe_url = html_navigable_container_shared_attribute_processing_steps_for_iframe_and_frame(&this.navigable_container, initial_insertion)

    # 2. If url is null, then return.
    let url = maybe_url else return

    # 3. If url matches about:blank and initialInsertion is true, then:
    if html_url_matches_about_blank(url) and initial_insertion == HtmlInitialInsertion.yes:
        # 1. Fire an event named load at element.
        _ = dom_event_target_dispatch_event(this.dom_event_target(), dom_event_create(dom_element_realm(this.dom_element()), html_event_names_load))

        # 2. Return.
        return

    # 3. Navigate an iframe or frame given element, url, the empty string, and initialInsertion.
    html_navigable_container_navigate_an_iframe_or_frame(&this.navigable_container, url, ReferrerPolicyReferrerPolicy.empty_string, none, initial_insertion)