From db41081c9f1b62a83902608143d526eeb488ee80 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Fri, 23 May 2025 16:49:52 -0700 Subject: [PATCH] initial stubs Signed-off-by: Ashwin Naren --- components/script/dom/mod.rs | 3 + components/script/dom/svganimatednumber.rs | 36 ++++++++++++ components/script/dom/svggeometryelement.rs | 55 +++++++++++++++++++ components/script/dom/svgpathelement.rs | 54 ++++++++++++++++++ .../webidls/SVGAnimatedNumber.webidl | 10 ++++ .../webidls/SVGGeometryElement.webidl | 14 +++++ .../webidls/SVGPathElement.webidl | 8 +++ 7 files changed, 180 insertions(+) create mode 100644 components/script/dom/svganimatednumber.rs create mode 100644 components/script/dom/svggeometryelement.rs create mode 100644 components/script/dom/svgpathelement.rs create mode 100644 components/script_bindings/webidls/SVGAnimatedNumber.webidl create mode 100644 components/script_bindings/webidls/SVGGeometryElement.webidl create mode 100644 components/script_bindings/webidls/SVGPathElement.webidl diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 388d8cfde2a..1c9285d83db 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -545,9 +545,12 @@ pub(crate) mod stylesheet; pub(crate) mod stylesheetlist; pub(crate) mod submitevent; pub(crate) mod subtlecrypto; +pub(crate) mod svganimatednumber; pub(crate) mod svgelement; +pub(crate) mod svggeometryelement; pub(crate) mod svggraphicselement; pub(crate) mod svgimageelement; +pub(crate) mod svgpathelement; pub(crate) mod svgsvgelement; #[cfg(feature = "testbinding")] pub(crate) mod testbinding; diff --git a/components/script/dom/svganimatednumber.rs b/components/script/dom/svganimatednumber.rs new file mode 100644 index 00000000000..cfd6721023c --- /dev/null +++ b/components/script/dom/svganimatednumber.rs @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use std::cell::Cell; + +use dom_struct::dom_struct; +use crate::dom::virtualmethods::VirtualMethods; + +#[dom_struct] +pub(crate) struct SVGAnimatedNumber { + anim_val: f32, + base_val: Cell, +} + +impl SVGAnimatedNumber { + // attribute float baseVal; + pub fn base_val(&self) -> f32 { + self.base_val.get() + } + + pub fn set_base_val(&self, value: f32) { + self.base_val.set(value); + } + + // readonly attribute float animVal; + pub fn anim_val(&self) -> f32 { + self.anim_val + } +} + +impl VirtualMethods for SVGAnimatedNumber { + fn super_type(&self) -> Option<&dyn VirtualMethods> { + None + } +} diff --git a/components/script/dom/svggeometryelement.rs b/components/script/dom/svggeometryelement.rs new file mode 100644 index 00000000000..85832d07879 --- /dev/null +++ b/components/script/dom/svggeometryelement.rs @@ -0,0 +1,55 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use dom_struct::dom_struct; +use html5ever::{LocalName, Prefix}; +use stylo_dom::ElementState; + +use crate::dom::bindings::inheritance::Castable; +use crate::dom::document::Document; +use crate::dom::svggraphicselement::SVGGraphicsElement; +use crate::dom::svganimatednumber::SVGAnimatedNumber; +use crate::dom::virtualmethods::VirtualMethods; + +#[dom_struct] +pub(crate) struct SVGGeometryElement { + svggraphicelement: SVGGraphicsElement, +} + +impl SVGGeometryElement { + pub(crate) fn new_inherited( + tag_name: LocalName, + prefix: Option, + document: &Document, + ) -> SVGGeometryElement { + SVGGeometryElement::new_inherited_with_state( + ElementState::empty(), + tag_name, + prefix, + document, + ) + } + + pub(crate) fn new_inherited_with_state( + state: ElementState, + tag_name: LocalName, + prefix: Option, + document: &Document, + ) -> SVGGeometryElement { + SVGGeometryElement { + svggraphicelement: SVGGraphicsElement::new_inherited_with_state( + state, + tag_name, + prefix, + document, + ), + } + } +} + +impl VirtualMethods for SVGGeometryElement { + fn super_type(&self) -> Option<&dyn VirtualMethods> { + Some(self.upcast::() as &dyn VirtualMethods) + } +} diff --git a/components/script/dom/svgpathelement.rs b/components/script/dom/svgpathelement.rs new file mode 100644 index 00000000000..a7e7451710d --- /dev/null +++ b/components/script/dom/svgpathelement.rs @@ -0,0 +1,54 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use dom_struct::dom_struct; +use html5ever::{LocalName, Prefix}; +use stylo_dom::ElementState; + +use crate::dom::bindings::inheritance::Castable; +use crate::dom::document::Document; +use crate::dom::svggeometryelement::SVGGeometryElement; +use crate::dom::virtualmethods::VirtualMethods; + +#[dom_struct] +pub(crate) struct SVGPathElement { + svggeometryelement: SVGGeometryElement, +} + +impl SVGPathElement { + pub(crate) fn new_inherited( + tag_name: LocalName, + prefix: Option, + document: &Document, + ) -> SVGPathElement { + SVGPathElement::new_inherited_with_state( + ElementState::empty(), + tag_name, + prefix, + document, + ) + } + + pub(crate) fn new_inherited_with_state( + state: ElementState, + tag_name: LocalName, + prefix: Option, + document: &Document, + ) -> SVGPathElement { + SVGPathElement { + svggeometryelement: SVGGeometryElement::new_inherited_with_state( + state, + tag_name, + prefix, + document, + ), + } + } +} + +impl VirtualMethods for SVGPathElement { + fn super_type(&self) -> Option<&dyn VirtualMethods> { + Some(self.upcast::() as &dyn VirtualMethods) + } +} \ No newline at end of file diff --git a/components/script_bindings/webidls/SVGAnimatedNumber.webidl b/components/script_bindings/webidls/SVGAnimatedNumber.webidl new file mode 100644 index 00000000000..e97173664c7 --- /dev/null +++ b/components/script_bindings/webidls/SVGAnimatedNumber.webidl @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://www.w3.org/TR/SVG/types.html#InterfaceSVGAnimatedNumber +[Exposed=Window, Pref="dom_svg_enabled"] +interface SVGAnimatedNumber { + attribute float baseVal; + readonly attribute float animVal; +}; \ No newline at end of file diff --git a/components/script_bindings/webidls/SVGGeometryElement.webidl b/components/script_bindings/webidls/SVGGeometryElement.webidl new file mode 100644 index 00000000000..6ce745e3c19 --- /dev/null +++ b/components/script_bindings/webidls/SVGGeometryElement.webidl @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://www.w3.org/TR/SVG/types.html#InterfaceSVGGeometryElement +[Exposed=Window, Pref="dom_svg_enabled"] +interface SVGGeometryElement : SVGGraphicsElement { + // [SameObject] readonly attribute SVGAnimatedNumber pathLength; + + // boolean isPointInFill(optional DOMPointInit point); + // boolean isPointInStroke(optional DOMPointInit point); + // float getTotalLength(); + // DOMPoint getPointAtLength(float distance); +}; diff --git a/components/script_bindings/webidls/SVGPathElement.webidl b/components/script_bindings/webidls/SVGPathElement.webidl new file mode 100644 index 00000000000..e310b9a9477 --- /dev/null +++ b/components/script_bindings/webidls/SVGPathElement.webidl @@ -0,0 +1,8 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +// https://www.w3.org/TR/SVG/paths.html#InterfaceSVGPathElement +[Exposed=Window, Pref="dom_svg_enabled"] +interface SVGPathElement : SVGGeometryElement { +};