dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / html_heading_element.lucb
#==============================================================================================
#
# html_heading_element - HTML::HTMLHeadingElement: <h1>-<h6>
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLHeadingElement.cpp (lines 1-69) and the inlines of
# HTMLHeadingElement.h: construction (which moves the mixin tables to HTMLHeadingElement's,
# as C++'s vptrs move), initialize, the align presentational hint, the cached heading level
# and the ARIA role and level.
#
#==============================================================================================
## Ported from HTMLHeadingElement.cpp:19 Web::HTML::HTMLHeadingElement::HTMLHeadingElement.
pub func html_heading_element_construct(this: HtmlHeadingElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLHeadingElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_heading_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_heading_element_aria_mixin_vtable
element.element.animatable.vtable = &html_heading_element_animatable_vtable
element.global_event_handlers.vtable = &html_heading_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_heading_element_form_associated_element_vtable
## Ported from HTMLHeadingElement.cpp:26 Web::HTML::HTMLHeadingElement::initialize (override).
pub func html_heading_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.html_heading_element)
html_element_initialize_impl(base, realm)
## Ported from HTMLHeadingElement.cpp:32 Web::HTML::HTMLHeadingElement::is_presentational_hint (override).
pub func html_heading_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 HTMLHeadingElement.cpp:41 Web::HTML::HTMLHeadingElement::apply_presentational_hints (override).
# https://html.spec.whatwg.org/multipage/rendering.html#tables-2
pub func html_heading_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 ak.string_eq_string_view(&value, ak.sv("left")):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.left)
elif ak.string_eq_string_view(&value, ak.sv("right")):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.right)
elif ak.string_eq_string_view(&value, ak.sv("center")):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.center)
elif ak.string_eq_string_view(&value, ak.sv("justify")):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.justify)
## Ported from HTMLHeadingElement.cpp:59 Web::HTML::HTMLHeadingElement::heading_level.
# https://html.spec.whatwg.org/multipage/sections.html#heading-level
pub func html_heading_element_heading_level(this: HtmlHeadingElement*) -> u32:
# h1–h6 elements have a heading level, which is given by getting the element's computed heading level.
let document = dom_node_document(this.dom_node())
if this.m_dom_tree_version_for_cached_heading_level < dom_document_dom_tree_version(document):
this.m_dom_tree_version_for_cached_heading_level = dom_document_dom_tree_version(document)
this.m_cached_heading_level = html_element_computed_heading_level(this.html_element())
return this.m_cached_heading_level
## Ported from HTMLHeadingElement.h:26 Web::HTML::HTMLHeadingElement::default_role (override).
# https://www.w3.org/TR/html-aria/#el-h1-h6
pub func html_heading_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
return AriaRole.heading
## Ported from HTMLHeadingElement.h:30 Web::HTML::HTMLHeadingElement::aria_level (override).
pub func html_heading_element_aria_level_impl(base: AriaMixin*) -> ak.String?:
let element = dom_element_from_aria_mixin(base)
if let attr = dom_element_get_attribute(element, aria_attribute_names_aria_level):
return attr
# Implicit defaults to the number in the element's tag name.
let local_name_fly = dom_element_local_name(element)
let local_name = ak.fly_string_to_string_const(&local_name_fly)
return ak.string_substring_from_byte_offset(&local_name, 1) else trap("MUST: substring_from_byte_offset")
## Ported from HTMLHeadingElement.h:42 Web::HTML::HTMLHeadingElement::is_html_heading_element (override).
pub func html_heading_element_is_html_heading_element_impl(base: DomNode*) -> bool:
return true