Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / html / html_paragraph_element.lucb

#==============================================================================================
#
#   html_paragraph_element - HTML::HTMLParagraphElement: <p> and its align presentational hint
#
#   DESCRIPTION:
#       Port of LibWeb/HTML/HTMLParagraphElement.cpp (lines 1-56) and the default_role inline of
#       HTMLParagraphElement.h: construction (which moves the mixin tables to
#       HTMLParagraphElement's, as C++'s vptrs move), initialize and the align presentational hint.
#
#==============================================================================================

## Ported from HTMLParagraphElement.cpp:17 Web::HTML::HTMLParagraphElement::HTMLParagraphElement.
pub func html_paragraph_element_construct(this: HtmlParagraphElement*, document: DomDocument*, qualified_name: DomQualifiedName):
    html_element_construct(this.html_element(), document, qualified_name)
    # The vptrs of the mixin bases move to HTMLParagraphElement's tables.
    let element = this.html_element()
    element.element.slottable_mixin.vtable = &html_paragraph_element_slottable_mixin_vtable
    element.element.aria_mixin.vtable = &html_paragraph_element_aria_mixin_vtable
    element.element.animatable.vtable = &html_paragraph_element_animatable_vtable
    element.global_event_handlers.vtable = &html_paragraph_element_global_event_handlers_vtable
    element.form_associated_element.vtable = &html_paragraph_element_form_associated_element_vtable

## Ported from HTMLParagraphElement.cpp:24 Web::HTML::HTMLParagraphElement::initialize (override).
pub func html_paragraph_element_initialize_impl(base: JsCell*, realm: Realm*):
    web_set_prototype_for_interface(base, realm, BindInterfaceName.html_paragraph_element)
    html_element_initialize_impl(base, realm)

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

    return html_name_is(name, html_attribute_names_align)

## Ported from HTMLParagraphElement.cpp:39 Web::HTML::HTMLParagraphElement::apply_presentational_hints (override).
# https://html.spec.whatwg.org/multipage/rendering.html#tables-2
pub func html_paragraph_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, "left"):
                html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.left)
            elif html_value_is_ignoring_case(value, "right"):
                html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.right)
            elif 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, "justify"):
                html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.justify)

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