dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / htmlli_element.lucb
#==============================================================================================
#
# htmlli_element - HTML::HTMLLIElement: <li>
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLLIElement.cpp (lines 1-99) and HTMLLIElement.h: the constructor
# (which moves the mixin tables to HTMLLIElement's, as C++'s vptrs move), initialize, the
# value attribute's change steps, value, the default role and the type attribute's
# presentational hint. Also the two helpers this region's presentational hints share:
# Element::for_each_attribute as a loop (DESIGN.md §2.9) and a list-style-type counter
# style property.
#
#==============================================================================================
## Ported from HTMLLIElement.cpp:19 Web::HTML::HTMLLIElement::HTMLLIElement.
pub func html_htmlli_element_construct(this: HtmlHtmlliElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLLIElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_htmlli_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_htmlli_element_aria_mixin_vtable
element.element.animatable.vtable = &html_htmlli_element_animatable_vtable
element.global_event_handlers.vtable = &html_htmlli_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_htmlli_element_form_associated_element_vtable
## Ported from HTMLLIElement.cpp:26 Web::HTML::HTMLLIElement::initialize (override).
pub func html_htmlli_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.htmlli_element)
html_element_initialize_impl(base, realm)
## Ported from HTMLLIElement.cpp:32 Web::HTML::HTMLLIElement::attribute_changed (override).
pub func html_htmlli_element_attribute_changed_impl(base: DomElement*, local_name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
html_element_attribute_changed_impl(base, local_name, old_value, value, namespace_)
if ak.fly_string_eq_fly_string(&local_name, &html_attribute_names_value):
if let owner = dom_element_list_owner(base):
dom_node_set_needs_layout_tree_update(owner.dom_node(), true, DomSetNeedsLayoutTreeUpdateReason.htmlo_list_element_ordinal_values)
dom_element_maybe_invalidate_ordinals_for_list_owner(base)
## Ported from HTMLLIElement.cpp:45 Web::HTML::HTMLLIElement::value.
# https://html.spec.whatwg.org/multipage/grouping-content.html#dom-li-value
pub func html_htmlli_element_value(this: HtmlHtmlliElement*) -> i32:
# The value IDL attribute must reflect the value of the value content attribute.
# NOTE: This is equivalent to the code that would be generated by the IDL generator if we used [Reflect] on the value attribute.
# We don't do that in this case, since this method is used elsewhere.
let content_attribute_value = dom_element_get_attribute(this.dom_element(), html_attribute_names_value) else ak.string_from_str("0")
if let maybe_number = html_parse_integer(ak.string_bytes_as_string_view(&content_attribute_value)):
return maybe_number
return 0
## Ported from HTMLLIElement.cpp:56 Web::HTML::HTMLLIElement::set_value.
pub func html_htmlli_element_set_value(this: HtmlHtmlliElement*, value: i32):
dom_element_set_attribute_value(this.dom_element(), html_attribute_names_value, ak.string_number_i64(value))
## Ported from HTMLLIElement.cpp:61 Web::HTML::HTMLLIElement::is_presentational_hint (override).
pub func html_htmlli_element_is_presentational_hint_impl(base: DomElement*, name: ak.FlyString) -> bool:
if dom_element_is_presentational_hint_impl(base, name):
return true
return ak.fly_string_eq_fly_string(&name, &html_attribute_names_type)
## Ported from HTMLLIElement.cpp:69 Web::HTML::HTMLLIElement::apply_presentational_hints (override).
pub func html_htmlli_element_apply_presentational_hints_impl(base: DomElement*, properties: ak.Vector[CssStyleProperty]*):
dom_element_apply_presentational_hints_impl(base, properties)
# https://html.spec.whatwg.org/multipage/rendering.html#lists
for attribute in dom_element_attribute_span(base):
let name = dom_attr_name(attribute)
let value = dom_attr_value(attribute)
if ak.fly_string_eq_fly_string(&name, &html_attribute_names_type):
if ak.string_eq_string_view(&value, ak.sv("1")):
ak.vector_append_t(properties, html_list_style_type_counter_style("decimal"))
elif ak.string_eq_string_view(&value, ak.sv("a")):
ak.vector_append_t(properties, html_list_style_type_counter_style("lower-alpha"))
elif ak.string_eq_string_view(&value, ak.sv("A")):
ak.vector_append_t(properties, html_list_style_type_counter_style("upper-alpha"))
elif ak.string_eq_string_view(&value, ak.sv("i")):
ak.vector_append_t(properties, html_list_style_type_counter_style("lower-roman"))
elif ak.string_eq_string_view(&value, ak.sv("I")):
ak.vector_append_t(properties, html_list_style_type_counter_style("upper-roman"))
elif ak.string_equals_ignoring_ascii_case_string_view(&value, ak.sv("none")):
ak.vector_append_t(properties, CssStyleProperty(property_id = css_data.PropertyId.list_style_type, value = css_keyword_style_value_create(css_data.Keyword.none_).css_style_value()))
elif ak.string_equals_ignoring_ascii_case_string_view(&value, ak.sv("disc")):
ak.vector_append_t(properties, html_list_style_type_counter_style("disc"))
elif ak.string_equals_ignoring_ascii_case_string_view(&value, ak.sv("circle")):
ak.vector_append_t(properties, html_list_style_type_counter_style("circle"))
elif ak.string_equals_ignoring_ascii_case_string_view(&value, ak.sv("square")):
ak.vector_append_t(properties, html_list_style_type_counter_style("square"))
## Ported from HTMLLIElement.h:25 Web::HTML::HTMLLIElement::default_role (override).
# https://www.w3.org/TR/html-aria/#el-li
pub func html_htmlli_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
let this = dom_element_from_aria_mixin(base)
var ancestor = dom_node_parent_element(this.dom_node())
while let element = ancestor:
if aria_mixin_role_or_default(&element.aria_mixin) == AriaRole.list:
return AriaRole.listitem
ancestor = dom_node_parent_element(element.dom_node())
# https://w3c.github.io/core-aam/#roleMappingComputedRole
# When an element has a role but is not contained in the required context (for example, an orphaned listitem
# without the required accessible parent of role list), User Agents MUST ignore the role token, and return the
# computedrole as if the ignored role token had not been included.
return AriaRole.none_
## Ported from HTMLLIElement.h:41 Web::HTML::HTMLLIElement::is_html_li_element (override).
pub func html_htmlli_element_is_html_li_element_impl(base: DomNode*) -> bool:
return true
# mark: Helpers of this region's presentational hints ===========================================
## Element::for_each_attribute(name, value) as a loop (DESIGN.md §2.9): the element's attributes
## in order, read with dom_attr_name / dom_attr_value; none when the element has no NamedNodeMap.
pub func dom_element_attribute_span(element: DomElement*) -> DomAttr*[]:
let attributes = element.m_attributes else return ak.empty_span[DomAttr*]()
return ak.vector_span(&attributes.m_attributes)
## `{ .property_id = CSS::PropertyID::ListStyleType, .value = CSS::CounterStyleStyleValue::create(name) }`:
## the list-style-type presentational hint of a counter style name.
pub func html_list_style_type_counter_style(name: str) -> CssStyleProperty:
let value = css_counter_style_style_value_create(FlyStringOrCssCounterStyleStyleValueSymbolsFunction.fly_string(ak.fly_string_from_str(name)))
return CssStyleProperty(property_id = css_data.PropertyId.list_style_type, value = value.css_style_value())