dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / html_br_element.lucb
#==============================================================================================
#
# html_br_element - HTML::HTMLBRElement: <br>
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLBRElement.cpp (lines 1-71) and the is_html_br_element inline of
# HTMLBRElement.h: construction (which moves the mixin tables to HTMLBRElement's, as C++'s
# vptrs move), initialize, the BreakNode layout node, the clear presentational hint and the
# display adjustment that always makes a BreakNode.
#
#==============================================================================================
## Ported from HTMLBRElement.cpp:19 Web::HTML::HTMLBRElement::HTMLBRElement.
pub func html_htmlbr_element_construct(this: HtmlHtmlbrElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLBRElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_htmlbr_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_htmlbr_element_aria_mixin_vtable
element.element.animatable.vtable = &html_htmlbr_element_animatable_vtable
element.global_event_handlers.vtable = &html_htmlbr_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_htmlbr_element_form_associated_element_vtable
## Ported from HTMLBRElement.cpp:26 Web::HTML::HTMLBRElement::initialize (override).
pub func html_htmlbr_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.htmlbr_element)
html_element_initialize_impl(base, realm)
## Ported from HTMLBRElement.cpp:32 Web::HTML::HTMLBRElement::create_layout_node (override).
pub func html_htmlbr_element_create_layout_node_impl(base: DomElement*, style: CssComputedProperties*) -> LayoutNode*?:
let this = (HtmlHtmlbrElement*)base
# heap().allocate<Layout::BreakNode>(...): a layout node's initialize is JS::Cell's, which does nothing.
return realm_create_layout_break_node(dom_element_realm(base), dom_node_document(base.dom_node()), this, style).layout_node()
## Ported from HTMLBRElement.cpp:37 Web::HTML::HTMLBRElement::is_presentational_hint (override).
pub func html_htmlbr_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_clear)
## Ported from HTMLBRElement.cpp:45 Web::HTML::HTMLBRElement::apply_presentational_hints (override).
pub func html_htmlbr_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)
# https://html.spec.whatwg.org/multipage/rendering.html#phrasing-content-3
if html_name_is(name, html_attribute_names_clear):
if html_value_is_ignoring_case(value, "left"):
html_append_keyword_hint(properties, css_data.PropertyId.clear, css_data.Keyword.left)
elif html_value_is_ignoring_case(value, "right"):
html_append_keyword_hint(properties, css_data.PropertyId.clear, css_data.Keyword.right)
elif html_value_is_ignoring_case(value, "all") or html_value_is_ignoring_case(value, "both"):
html_append_keyword_hint(properties, css_data.PropertyId.clear, css_data.Keyword.both)
## Ported from HTMLBRElement.cpp:61 Web::HTML::HTMLBRElement::adjust_computed_style (override).
pub func html_htmlbr_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())
elif not css_display_is_none(&display):
# AD-HOC: Prevent other display values from applying, so that we always create a BreakNode
css_computed_properties_set_property(style, css_data.PropertyId.display, css_display_style_value_create(css_display_from_short(CssDisplayShort.inline)).css_style_value())
## Ported from HTMLBRElement.h:26 Web::HTML::HTMLBRElement::is_html_br_element (override).
pub func html_htmlbr_element_is_html_br_element_impl(base: DomNode*) -> bool:
return true