dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / svg / svga_element.lucb
#==============================================================================================
#
# svga_element - SVG::SVGAElement: <a> in SVG, a hyperlink
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGAElement.cpp (lines 1-114) with the inline members of
# SVGAElement.h (https://svgwg.org/svg2-draft/linking.html#AElement): an
# SVGGraphicsElement with an href (SVGURIReferenceMixin, xlink:href supported), the
# target and relList reflections, the tab index, and the activation behavior that follows
# the hyperlink.
#
#==============================================================================================
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:21 Web::SVG::SVGAElement::SVGAElement.
pub func svg_svga_element_construct(this: SvgSvgaElement*, document: DomDocument*, qualified_name: DomQualifiedName):
svg_graphics_element_construct(this.svg_graphics_element(), document, qualified_name)
# The vptrs of the mixin bases move to SVGAElement's tables.
let element = this.svg_element()
element.element.slottable_mixin.vtable = &svg_svga_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &svg_svga_element_aria_mixin_vtable
element.element.animatable.vtable = &svg_svga_element_animatable_vtable
element.global_event_handlers.vtable = &svg_svga_element_global_event_handlers_vtable
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:28 Web::SVG::SVGAElement::initialize (override).
pub func svg_svga_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svga_element)
svg_graphics_element_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:34 Web::SVG::SVGAElement::visit_edges (override).
pub func svg_svga_element_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (SvgSvgaElement*)base
svg_element_visit_edges_impl(base, visitor)
svg_svguri_reference_mixin_visit_edges(&this.svguri_reference_mixin, visitor)
gc.cell_visitor_visit_t(visitor, this.m_rel_list)
gc.cell_visitor_visit_t(visitor, this.m_target)
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:42 Web::SVG::SVGAElement::attribute_changed (override).
pub func svg_svga_element_attribute_changed_impl(base: DomElement*, name: ak.FlyString, old_value: ak.String?, value: ak.String?, namespace_: ak.FlyString?):
let this = (SvgSvgaElement*)base
svg_graphics_element_attribute_changed_impl(base, name, old_value, value, namespace_)
if ak.fly_string_eq_fly_string(&name, &svg_attribute_names_href):
css_invalidation_invalidate_style_after_hyperlink_state_change(base)
if ak.fly_string_eq_fly_string(&name, &html_attribute_names_rel):
if let rel_list = this.m_rel_list:
let value_text = value else ak.String() # value.value_or(String {})
dom_token_list_associated_attribute_changed(rel_list, ak.string_bytes_as_string_view(&value_text))
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:55 Web::SVG::SVGAElement::default_tab_index_value (override).
# https://html.spec.whatwg.org/multipage/interaction.html#dom-tabindex
pub func svg_svga_element_default_tab_index_value_impl(base: DomElement*) -> i32:
# See the base function for the spec comments.
return 0
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:62 Web::SVG::SVGAElement::target.
# https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__target
pub func svg_svga_element_target(this: SvgSvgaElement*) -> SvgAnimatedString*:
if this.m_target == none:
var reflected_attribute: DomQualifiedName = ---
dom_qualified_name_construct(&reflected_attribute, html_attribute_names_target, none, none)
this.m_target = svg_animated_string_create(dom_element_realm(this.dom_element()), this.svg_element(), reflected_attribute)
return this.m_target else trap("VERIFY: m_target")
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:70 Web::SVG::SVGAElement::rel_list.
# https://svgwg.org/svg2-draft/linking.html#__svg__SVGAElement__relList
pub func svg_svga_element_rel_list(this: SvgSvgaElement*) -> DomTokenList*:
# The relList IDL attribute reflects the ‘rel’ content attribute.
if this.m_rel_list == none:
this.m_rel_list = dom_token_list_create(this.dom_element(), html_attribute_names_rel)
return this.m_rel_list else trap("VERIFY: m_rel_list")
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:78 Web::SVG::SVGAElement::create_layout_node (override).
pub func svg_svga_element_create_layout_node_impl(base: DomElement*, style: CssComputedProperties*) -> LayoutNode*?:
let this = (SvgSvgaElement*)base
# heap().allocate<Layout::SVGGraphicsBox>(...): a layout node's initialize is JS::Cell's, which does nothing.
return realm_create_layout_svg_graphics_box(dom_element_realm(base), dom_node_document(base.dom_node()), this.svg_graphics_element(), style).layout_node()
## Ported from Libraries/LibWeb/SVG/SVGAElement.cpp:84 Web::SVG::SVGAElement::activation_behavior (override).
# https://html.spec.whatwg.org/multipage/links.html#links-created-by-a-and-area-elements
pub func svg_svga_element_activation_behavior_impl(base: DomEventTarget*, event: DomEvent*):
let this = (SvgSvgaElement*)base
# The activation behavior of an a or area element element given an event event is:
# 1. If element has no href attribute, then return.
let href = svg_svguri_reference_mixin_href(&this.svguri_reference_mixin, this.svg_element(), SvgSupportsXLinkHref.yes)
let href_base_val = svg_animated_string_base_val(href)
if ak.string_is_empty(&href_base_val):
return
# AD-HOC: Do not activate the element for clicks with the ctrl/cmd modifier present. This lets
# the browser process open the link in a new tab.
if dom_event_is_mouse_event(event):
let mouse_event = as_ui_events_mouse_event(event)
if ui_events_mouse_event_platform_ctrl_key(mouse_event):
return
# 2. Let hyperlinkSuffix be null.
let hyperlink_suffix: ak.String? = none
# FIXME: 3. If element is an a element, and event's target is an img with an ismap attribute specified, then:
# 4. Let userInvolvement be event's user navigation involvement.
let user_involvement = html_user_navigation_involvement(event)
# FIXME: 5. If the user has expressed a preference to download the hyperlink, then set userInvolvement to "browser UI".
# FIXME: 6. If element has a download attribute, or if the user has expressed a preference to download the
# hyperlink, then download the hyperlink created by element with hyperlinkSuffix set to hyperlinkSuffix and
# userInvolvement set to userInvolvement.
# 7. Otherwise, follow the hyperlink created by element with hyperlinkSuffix set to hyperlinkSuffix and userInvolvement set to userInvolvement.
dom_element_follow_the_hyperlink(this.dom_element(), hyperlink_suffix, user_involvement)
## Ported from Libraries/LibWeb/SVG/SVGAElement.h:36 Web::SVG::SVGAElement::is_svg_a_element (override).
pub func svg_svga_element_is_svg_a_element_impl(base: DomNode*) -> bool:
return true
## Ported from Libraries/LibWeb/SVG/SVGAElement.h:42 Web::SVG::SVGAElement::has_activation_behavior (override).
pub func svg_svga_element_has_activation_behavior_impl(base: DomEventTarget*) -> bool:
return true