dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / html / html_summary_element.lucb
#==============================================================================================
#
# html_summary_element - HTML::HTMLSummaryElement: <summary>
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLSummaryElement.cpp (lines 1-81) and HTMLSummaryElement.h: the
# constructor (which moves the mixin tables to HTMLSummaryElement's, as C++'s vptrs
# move), the activation behavior that toggles the parent details' open attribute, the
# summary for its parent details, focusability and initialize.
#
#==============================================================================================
## Ported from HTMLSummaryElement.cpp:15 Web::HTML::HTMLSummaryElement::HTMLSummaryElement.
pub func html_summary_element_construct(this: HtmlSummaryElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLSummaryElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_summary_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_summary_element_aria_mixin_vtable
element.element.animatable.vtable = &html_summary_element_animatable_vtable
element.global_event_handlers.vtable = &html_summary_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_summary_element_form_associated_element_vtable
## Ported from HTMLSummaryElement.cpp:20 Web::HTML::HTMLSummaryElement::has_activation_behavior (override).
pub func html_summary_element_has_activation_behavior_impl(base: DomEventTarget*) -> bool:
return true
## Ported from HTMLSummaryElement.cpp:25 Web::HTML::HTMLSummaryElement::activation_behavior (override).
pub func html_summary_element_activation_behavior_impl(base: DomEventTarget*, arg0: DomEvent*):
let this = (HtmlSummaryElement*)base
# The activation behavior of summary elements is to run the following steps:
# 1. If this summary element is not the summary for its parent details, then return.
if not html_summary_element_is_summary_for_its_parent_details(this):
return
# 2. Let parent be this summary element's parent.
let parent = dom_node_parent_element(this.dom_node()) else trap("the summary for its parent details has a parent")
# 3. If the open attribute is present on parent, then remove it. Otherwise, set parent's open attribute to the empty string.
if dom_element_has_attribute(parent, html_attribute_names_open):
dom_element_remove_attribute(parent, html_attribute_names_open)
else:
dom_element_set_attribute_value(parent, html_attribute_names_open, ak.string_new())
## Ported from HTMLSummaryElement.cpp:44 Web::HTML::HTMLSummaryElement::is_summary_for_its_parent_details.
# https://html.spec.whatwg.org/multipage/interactive-elements.html#summary-for-its-parent-details
pub func html_summary_element_is_summary_for_its_parent_details(this: HtmlSummaryElement*) -> bool:
# A summary element is a summary for its parent details if the following algorithm returns true:
# 1. If this summary element has no parent, then return false.
# 2. Let parent be this summary element's parent.
let parent = dom_node_parent_element(this.dom_node()) else return false
# 3. If parent is not a details element, then return false.
if not is_html_details_element(parent):
return false
# 4. If parent's first summary element child is not this summary element, then return false.
if tree_node_first_child_of_type(parent.dom_node(), &html_summary_element_class) != this.dom_node():
return false
# 5. Return true.
return true
## Ported from HTMLSummaryElement.cpp:68 Web::HTML::HTMLSummaryElement::is_focusable (override).
# https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-summary-element
pub func html_summary_element_is_focusable_impl(base: DomEventTarget*) -> bool:
# summary elements that are the first summary element child of a details element
return html_element_is_focusable_impl(base) or html_summary_element_is_summary_for_its_parent_details((HtmlSummaryElement*)base)
## Ported from HTMLSummaryElement.cpp:76 Web::HTML::HTMLSummaryElement::initialize (override).
pub func html_summary_element_initialize_impl(base: JsCell*, realm: Realm*):
html_element_initialize_impl(base, realm)
## Ported from HTMLSummaryElement.h:22 Web::HTML::HTMLSummaryElement::default_role (override).
pub func html_summary_element_default_role_impl(base: AriaMixin*) -> AriaRole?:
return AriaRole.button