Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / html_html_element.lucb

#==============================================================================================
#
#   html_html_element - HTML::HTMLHtmlElement: <html>
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLHtmlElement.cpp (lines 1-52) and the inlines of HTMLHtmlElement.h:
#       construction (which moves the mixin tables to HTMLHtmlElement's, as C++'s vptrs move),
#       initialize, whether the canvas background propagates from <body>, and the default ARIA
#       role.
#
#==============================================================================================

## Ported from HTMLHtmlElement.cpp:18 Web::HTML::HTMLHtmlElement::HTMLHtmlElement.
pub func html_html_element_construct(this: HtmlHtmlElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLHtmlElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_html_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_html_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_html_element_animatable_vtable
    element.global_event_handlers.vtable = &html_html_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_html_element_form_associated_element_vtable

## Ported from HTMLHtmlElement.cpp:25 Web::HTML::HTMLHtmlElement::initialize (override).
pub func html_html_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_html_element)
    html_element_initialize_impl(base, realm)

## Ported from HTMLHtmlElement.cpp:31 Web::HTML::HTMLHtmlElement::should_use_body_background_properties.
pub func html_html_element_should_use_body_background_properties(this: HtmlHtmlElement*) -> bool:
    # https://drafts.csswg.org/css-contain-2/#contain-property
    # Additionally, when any containments are active on either the HTML <html> or <body> elements, propagation of
    # properties from the <body> element to the initial containing block, the viewport, or the canvas background, is
    # disabled. Notably, this affects:
    # - 'background' and its longhands (see CSS Backgrounds 3 ยง 2.11.2 The Canvas Background and the HTML <body> Element)
    let computed_properties = dom_element_computed_properties(this.dom_element()) else trap("HTMLHtmlElement: no computed properties")
    let contain = css_computed_properties_contain(computed_properties)
    if not css_containment_is_empty(&contain):
        return false

    if let body_node = tree_node_first_child_of_type(this.dom_node(), &html_body_element_class):
        let body_element = (HtmlBodyElement*)body_node
        let body_properties = dom_element_computed_properties(body_element.dom_element()) else trap("HTMLBodyElement: no computed properties")
        let body_contain = css_computed_properties_contain(body_properties)
        if not css_containment_is_empty(&body_contain):
            return false

    # NB: Called during rendering, reading background properties.
    let layout_node = dom_element_unsafe_layout_node(this.dom_element()) else trap("HTMLHtmlElement: no layout node")
    let computed_values = layout_node_with_style_computed_values(layout_node)
    let background_color = css_computed_values_background_color(&computed_values.computed_values)
    let background_layers = layout_node_with_style_background_layers(layout_node)

    return ak.vector_is_empty(background_layers) and background_color == gfx.color_new_named_color(gfx.ColorNamedColor.transparent)

## Ported from HTMLHtmlElement.h:25 Web::HTML::HTMLHtmlElement::default_role (override).
# https://www.w3.org/TR/html-aria/#el-html
pub func html_html_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
    return AriaRole.document

## Ported from HTMLHtmlElement.h:31 Web::HTML::HTMLHtmlElement::is_html_html_element (override).
pub func html_html_element_is_html_html_element_impl(base: DomNode*) -> bool:
    return true