Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / html / html_embed_element.lucb

#==============================================================================================
#
#   html_embed_element - HTML::HTMLEmbedElement: <embed>
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLEmbedElement.cpp (lines 1-84) and the is_html_embed_element
#       inline of HTMLEmbedElement.h: construction (which moves the mixin tables to
#       HTMLEmbedElement's, as C++'s vptrs move), initialize, the align / height / hspace /
#       vspace / width presentational hints and the display adjustment. (Loading the embedded
#       content is not in this file.)
#
#==============================================================================================

## Ported from HTMLEmbedElement.cpp:19 Web::HTML::HTMLEmbedElement::HTMLEmbedElement.
pub func html_embed_element_construct(this: HtmlEmbedElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLEmbedElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_embed_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_embed_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_embed_element_animatable_vtable
    element.global_event_handlers.vtable = &html_embed_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_embed_element_form_associated_element_vtable

## Ported from HTMLEmbedElement.cpp:26 Web::HTML::HTMLEmbedElement::initialize (override).
pub func html_embed_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_embed_element)
    html_element_initialize_impl(base, realm)

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

    let names: ak.FlyString[5] = [
        html_attribute_names_align,
        html_attribute_names_height,
        html_attribute_names_hspace,
        html_attribute_names_vspace,
        html_attribute_names_width]
    return html_name_is_one_of(name, names)

## Ported from HTMLEmbedElement.cpp:45 Web::HTML::HTMLEmbedElement::apply_presentational_hints (override).
pub func html_embed_element_apply_presentational_hints_impl(base: DomElement*, properties: ak.Vector[CssStyleProperty]*):
    dom_element_apply_presentational_hints_impl(base, properties)
    # for_each_attribute([&](auto& name, auto& value) { ... })
    let attributes = base.m_attributes else return
    for i in 0..<dom_named_node_map_length(attributes):
        let attribute = dom_named_node_map_item(attributes, (u32)i) else trap("NamedNodeMap::item in range")
        let name = dom_attr_name(attribute)
        let value = dom_attr_value(attribute)
        if html_name_is(name, html_attribute_names_align):
            if html_value_is_ignoring_case(value, "center"):
                html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.center)
            elif html_value_is_ignoring_case(value, "middle"):
                html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.middle)
        elif html_name_is(name, html_attribute_names_height):
            if let parsed_value = html_parse_dimension_value(ak.string_bytes_as_string_view(&value)):
                html_append_presentational_hint(properties, css_data.PropertyId.height, parsed_value)
        # https://html.spec.whatwg.org/multipage/rendering.html#attributes-for-embedded-content-and-images:maps-to-the-dimension-property
        elif html_name_is(name, html_attribute_names_hspace):
            if let parsed_value = html_parse_dimension_value(ak.string_bytes_as_string_view(&value)):
                html_append_presentational_hint(properties, css_data.PropertyId.margin_left, parsed_value)
                html_append_presentational_hint(properties, css_data.PropertyId.margin_right, parsed_value)
        elif html_name_is(name, html_attribute_names_vspace):
            if let parsed_value = html_parse_dimension_value(ak.string_bytes_as_string_view(&value)):
                html_append_presentational_hint(properties, css_data.PropertyId.margin_top, parsed_value)
                html_append_presentational_hint(properties, css_data.PropertyId.margin_bottom, parsed_value)
        elif html_name_is(name, html_attribute_names_width):
            if let parsed_value = html_parse_dimension_value(ak.string_bytes_as_string_view(&value)):
                html_append_presentational_hint(properties, css_data.PropertyId.width, parsed_value)

## Ported from HTMLEmbedElement.cpp:77 Web::HTML::HTMLEmbedElement::adjust_computed_style (override).
pub func html_embed_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 HTMLEmbedElement.h:23 Web::HTML::HTMLEmbedElement::is_html_embed_element (override).
pub func html_embed_element_is_html_embed_element_impl(base: DomNode*) -> bool:
    return true