dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / svg / svg_circle_element.lucb
#==============================================================================================
#
# svg_circle_element - SVG::SVGCircleElement: <circle>
#
# DESCRIPTION:
# Port of LibWeb/SVG/SVGCircleElement.cpp (lines 1-127): cx, cy and r as presentation
# attributes (CSS properties), the circle's path from the layout node's computed values
# (https://svgwg.org/svg2-draft/shapes.html#CircleElement) and the SVGAnimatedLength
# accessors.
#
#==============================================================================================
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:21 Web::SVG::SVGCircleElement::SVGCircleElement.
pub func svg_circle_element_construct(this: SvgCircleElement*, document: DomDocument*, qualified_name: DomQualifiedName):
svg_geometry_element_construct(this.svg_geometry_element(), document, qualified_name)
# The vptrs of the mixin bases move to SVGCircleElement's tables.
let element = this.svg_element()
element.element.slottable_mixin.vtable = &svg_circle_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &svg_circle_element_aria_mixin_vtable
element.element.animatable.vtable = &svg_circle_element_animatable_vtable
element.global_event_handlers.vtable = &svg_circle_element_global_event_handlers_vtable
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:26 Web::SVG::SVGCircleElement::initialize (override).
pub func svg_circle_element_initialize_impl(base: JsCell*, realm: Realm*):
web_set_prototype_for_interface(base, realm, BindInterfaceName.svg_circle_element)
svg_geometry_element_initialize_impl(base, realm)
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:32 Web::SVG::SVGCircleElement::is_presentational_hint (override).
pub func svg_circle_element_is_presentational_hint_impl(base: DomElement*, name: ak.FlyString) -> bool:
if svg_element_is_presentational_hint_impl(base, name):
return true
return html_name_is_one_of(name, [svg_attribute_names_cx, svg_attribute_names_cy, svg_attribute_names_r])
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:43 Web::SVG::SVGCircleElement::apply_presentational_hints (override).
pub func svg_circle_element_apply_presentational_hints_impl(base: DomElement*, properties: ak.Vector[CssStyleProperty]*):
svg_element_apply_presentational_hints_impl(base, properties)
var parsing_context: CssParsingParams = ---
css_parsing_params_construct_dom_document(&parsing_context, dom_node_document(base.dom_node()), CssParsingMode.svg_presentation_attribute)
let cx_attribute = dom_element_attribute(base, svg_attribute_names_cx)
let cx_attribute_text = cx_attribute else ak.String()
if let cx_value = parse_css_value(parsing_context, ak.string_bytes_as_string_view(&cx_attribute_text), css_data.PropertyId.cx):
html_append_presentational_hint(properties, css_data.PropertyId.cx, cx_value)
let cy_attribute = dom_element_attribute(base, svg_attribute_names_cy)
let cy_attribute_text = cy_attribute else ak.String()
if let cy_value = parse_css_value(parsing_context, ak.string_bytes_as_string_view(&cy_attribute_text), css_data.PropertyId.cy):
html_append_presentational_hint(properties, css_data.PropertyId.cy, cy_value)
let r_attribute = dom_element_attribute(base, svg_attribute_names_r)
let r_attribute_text = r_attribute else ak.String()
if let r_value = parse_css_value(parsing_context, ak.string_bytes_as_string_view(&r_attribute_text), css_data.PropertyId.r):
html_append_presentational_hint(properties, css_data.PropertyId.r, r_value)
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:61 Web::SVG::normalized_diagonal_length (static).
func svg_normalized_diagonal_length(viewport_size: gfx.CssPixelSize) -> gfx.CssPixels:
let width = viewport_size.m_width
let height = viewport_size.m_height
if width.m_value == height.m_value:
return width
let fraction = gfx.div_css_pixels_int(width.mul(width).add(height.mul(height)), 2)
return gfx.sqrt(gfx.css_pixel_fraction_to_css_pixels(&fraction))
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:68 Web::SVG::SVGCircleElement::get_path (override).
pub func svg_circle_element_get_path_impl(base: SvgGeometryElement*, viewport_size: gfx.CssPixelSize) -> gfx.Path:
# NB: Called during SVG layout.
let maybe_node = dom_node_unsafe_layout_node(base.dom_node())
if maybe_node == none:
ak.dbgln("FIXME: Null layout node in SVGCircleElement::get_path")
return gfx.Path()
let node = maybe_node else trap("VERIFY: unsafe_layout_node()")
let computed_values = layout_node_computed_values(node)
let cx_length = css_computed_values_cx(&computed_values.computed_values)
let cy_length = css_computed_values_cy(&computed_values.computed_values)
let r_length = css_computed_values_r(&computed_values.computed_values)
let cx = css_percentage_or_to_px(&cx_length.percentage_or, node, viewport_size.m_width).to_float()
let cy = css_percentage_or_to_px(&cy_length.percentage_or, node, viewport_size.m_height).to_float()
# Percentages refer to the normalized diagonal of the current SVG viewport
# (see Units: https://svgwg.org/svg2-draft/coords.html#Units)
let r = css_percentage_or_to_px(&r_length.percentage_or, node, svg_normalized_diagonal_length(viewport_size)).to_float()
# A zero radius disables rendering.
if r == 0.0:
return gfx.Path()
var path: gfx.Path
let large_arc = false
let sweep = true
# 1. A move-to command to the point cx+r,cy;
gfx.path_move_to(&path, gfx.FloatPoint(m_x = cx + r, m_y = cy))
# 2. arc to cx,cy+r;
gfx.path_arc_to(&path, gfx.FloatPoint(m_x = cx, m_y = cy + r), r, large_arc, sweep)
# 3. arc to cx-r,cy;
gfx.path_arc_to(&path, gfx.FloatPoint(m_x = cx - r, m_y = cy), r, large_arc, sweep)
# 4. arc to cx,cy-r;
gfx.path_arc_to(&path, gfx.FloatPoint(m_x = cx, m_y = cy - r), r, large_arc, sweep)
# 5. arc with a segment-completing close path operation.
gfx.path_arc_to(&path, gfx.FloatPoint(m_x = cx + r, m_y = cy), r, large_arc, sweep)
return path
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:110 Web::SVG::SVGCircleElement::cx.
# https://www.w3.org/TR/SVG11/shapes.html#CircleElementCXAttribute
pub func svg_circle_element_cx(this: SvgCircleElement*) -> SvgAnimatedLength*:
return svg_element_svg_animated_length_for_property(this.svg_element(), css_data.PropertyId.cx)
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:116 Web::SVG::SVGCircleElement::cy.
# https://www.w3.org/TR/SVG11/shapes.html#CircleElementCYAttribute
pub func svg_circle_element_cy(this: SvgCircleElement*) -> SvgAnimatedLength*:
return svg_element_svg_animated_length_for_property(this.svg_element(), css_data.PropertyId.cy)
## Ported from Libraries/LibWeb/SVG/SVGCircleElement.cpp:122 Web::SVG::SVGCircleElement::r.
# https://www.w3.org/TR/SVG11/shapes.html#CircleElementRAttribute
pub func svg_circle_element_r(this: SvgCircleElement*) -> SvgAnimatedLength*:
return svg_element_svg_animated_length_for_property(this.svg_element(), css_data.PropertyId.r)