dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / html_div_element.lucb
#==============================================================================================
#
# html_div_element - HTML::HTMLDivElement: <div> and its align presentational hint
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLDivElement.cpp (lines 1-56) and the inlines of HTMLDivElement.h:
# construction (which moves the mixin tables to HTMLDivElement's, as C++'s vptrs move),
# the align presentational hint, initialize and the default ARIA role.
#
# It also holds two helpers the presentational hints of region r27's elements share:
# appending a `{ .property_id, .value }` StyleProperty (C++'s aggregate initialization,
# whose `important` defaults to No) and `first_is_one_of` over attribute names.
#
#==============================================================================================
# mark: Helpers of the presentational hints ======================================================
## `properties.append({ .property_id = property_id, .value = value })`: a StyleProperty whose
## `important` keeps its default, No.
func html_append_presentational_hint(properties: ak.Vector[CssStyleProperty]*, property_id: css_data.PropertyId, value: CssStyleValue*):
ak.vector_append_t(properties, CssStyleProperty(important = css_syntax.Important.no, property_id = property_id, value = value))
## `properties.append(...)` of a keyword: `CSS::KeywordStyleValue::create(keyword)`.
func html_append_keyword_hint(properties: ak.Vector[CssStyleProperty]*, property_id: css_data.PropertyId, keyword: css_data.Keyword):
html_append_presentational_hint(properties, property_id, css_keyword_style_value_create(keyword).css_style_value())
## `properties.append(...)` of a pixel length: `CSS::LengthStyleValue::create(CSS::Length::make_px(value))`.
func html_append_px_hint(properties: ak.Vector[CssStyleProperty]*, property_id: css_data.PropertyId, value: f64):
html_append_presentational_hint(properties, property_id, css_length_style_value_create(css_length_make_px_f64(value)).css_style_value())
## `first_is_one_of(name, names...)` of an attribute name.
func html_name_is_one_of(name: ak.FlyString, names: const ak.FlyString[]) -> bool:
for candidate in names:
if ak.fly_string_eq_fly_string(&name, &candidate):
return true
return false
## `name == HTML::AttributeNames::x` of a FlyString.
func html_name_is(name: ak.FlyString, attribute_name: ak.FlyString) -> bool:
return ak.fly_string_eq_fly_string(&name, &attribute_name)
## `value.equals_ignoring_ascii_case("text"sv)` of an attribute's value.
func html_value_is_ignoring_case(value: ak.String, text: str) -> bool:
return ak.string_equals_ignoring_ascii_case_string_view(&value, ak.sv(text))
# mark: HTMLDivElement ===========================================================================
## Ported from HTMLDivElement.cpp:17 Web::HTML::HTMLDivElement::HTMLDivElement.
pub func html_div_element_construct(this: HtmlDivElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLDivElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_div_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_div_element_aria_mixin_vtable
element.element.animatable.vtable = &html_div_element_animatable_vtable
element.global_event_handlers.vtable = &html_div_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_div_element_form_associated_element_vtable
## Ported from HTMLDivElement.cpp:24 Web::HTML::HTMLDivElement::is_presentational_hint (override).
pub func html_div_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 HTMLDivElement.cpp:33 Web::HTML::HTMLDivElement::apply_presentational_hints (override).
# https://html.spec.whatwg.org/multipage/rendering.html#flow-content-3
pub func html_div_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.libweb_left)
elif html_value_is_ignoring_case(value, "right"):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.libweb_right)
elif html_value_is_ignoring_case(value, "center"):
html_append_keyword_hint(properties, css_data.PropertyId.text_align, css_data.Keyword.libweb_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 HTMLDivElement.cpp:50 Web::HTML::HTMLDivElement::initialize (override).
pub func html_div_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.html_div_element)
html_element_initialize_impl(base, realm)
## Ported from HTMLDivElement.h:22 Web::HTML::HTMLDivElement::default_role (override).
# https://www.w3.org/TR/html-aria/#el-div
pub func html_div_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
return AriaRole.generic
## Ported from HTMLDivElement.h:24 Web::HTML::HTMLDivElement::is_html_div_element (override).
pub func html_div_element_is_html_div_element_impl(base: DomNode*) -> bool:
return true