Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] svg: support <circle> element #17681

Closed
wants to merge 10 commits into from

script: Implement SVGCircleElement

Add basic support for <circle>, and create dom for it.
  • Loading branch information
stshine committed Sep 11, 2017
commit 75f00caee86d33aca1dd3f2e26994753d8dabf56
@@ -78,6 +78,7 @@ use dom::htmltrackelement::HTMLTrackElement;
use dom::htmlulistelement::HTMLUListElement;
use dom::htmlunknownelement::HTMLUnknownElement;
use dom::htmlvideoelement::HTMLVideoElement;
use dom::svgcircleelement::SVGCircleElement;
use dom::svgsvgelement::SVGSVGElement;
use html5ever::{LocalName, Prefix, QualName};
use js::jsapi::JSAutoCompartment;
@@ -107,6 +108,7 @@ fn create_svg_element(name: QualName,

match name.local {
local_name!("svg") => make!(SVGSVGElement),
local_name!("circle") => make!(SVGCircleElement),
_ => Element::new(name.local, name.ns, prefix, document),
}
}
@@ -429,6 +429,7 @@ pub mod storageevent;
pub mod stylepropertymapreadonly;
pub mod stylesheet;
pub mod stylesheetlist;
pub mod svgcircleelement;
pub mod svgelement;
pub mod svggeometryelement;
pub mod svggraphicselement;
@@ -21,7 +21,7 @@ use dom::bindings::conversions::{self, DerivedFrom};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::inheritance::{Castable, CharacterDataTypeId, ElementTypeId};
use dom::bindings::inheritance::{EventTargetTypeId, HTMLElementTypeId, NodeTypeId};
use dom::bindings::inheritance::{SVGElementTypeId, SVGGraphicsElementTypeId};
use dom::bindings::inheritance::{SVGElementTypeId, SVGGraphicsElementTypeId, SVGGeometryElementTypeId};
use dom::bindings::js::{JS, LayoutJS, MutNullableJS};
use dom::bindings::js::Root;
use dom::bindings::js::RootedReference;
@@ -2774,6 +2774,11 @@ impl Into<LayoutElementType> for ElementTypeId {
LayoutElementType::HTMLTextAreaElement,
ElementTypeId::SVGElement(SVGElementTypeId::SVGGraphicsElement(SVGGraphicsElementTypeId::SVGSVGElement)) =>
LayoutElementType::SVGSVGElement,
ElementTypeId::SVGElement(
SVGElementTypeId::SVGGraphicsElement(
SVGGraphicsElementTypeId::SVGGeometryElement(
SVGGeometryElementTypeId::SVGCircleElement
))) => LayoutElementType::SVGCircleElement,
_ => LayoutElementType::Element,
}
}
@@ -0,0 +1,72 @@
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::SVGCircleElementBinding;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::Root;
use dom::document::Document;
use dom::element::AttributeMutation;
use dom::node::Node;
use dom::svgelement::SVGElement;
use dom::svggeometryelement::SVGGeometryElement;
use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use style::element_state::ElementState;

#[dom_struct]
pub struct SVGCircleElement {
geometryelement: SVGGeometryElement,
}

impl SVGCircleElement {
pub fn new_inherited(tag_name: LocalName,
prefix: Option<Prefix>,
document: &Document)
-> Self {
SVGCircleElement::new_inherited_with_state(ElementState::empty(), tag_name, prefix, document)
}

pub fn new_inherited_with_state(state: ElementState,
tag_name: LocalName,
prefix: Option<Prefix>,
document: &Document)
-> Self {
SVGCircleElement {
geometryelement: SVGGeometryElement::new_inherited_with_state(state,
tag_name,
prefix,
document),
}
}

#[allow(unrooted_must_root)]
pub fn new(local_name: LocalName, prefix: Option<Prefix>, document: &Document)
-> Root<SVGCircleElement> {
Node::reflect_node(box SVGCircleElement::new_inherited(local_name, prefix, document),
document,
SVGCircleElementBinding::Wrap)
}
}

impl VirtualMethods for SVGCircleElement {
fn super_type(&self) -> Option<&VirtualMethods> {
Some(self.upcast::<SVGGeometryElement>() as &VirtualMethods)
}

fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
self.super_type().unwrap().attribute_mutated(attr, mutation);
let name = attr.local_name();

match name {
&local_name!("cx") => {
self.upcast::<SVGElement>().mutate_svg_preshint(attr);
}
&local_name!("cy") => {
self.upcast::<SVGElement>().mutate_svg_preshint(attr);
}
&local_name!("r") => {
self.upcast::<SVGElement>().mutate_svg_preshint(attr);
}
_ => {}
}
}
}
@@ -8,6 +8,7 @@ use dom::bindings::inheritance::ElementTypeId;
use dom::bindings::inheritance::HTMLElementTypeId;
use dom::bindings::inheritance::NodeTypeId;
use dom::bindings::inheritance::SVGElementTypeId;
use dom::bindings::inheritance::SVGGeometryElementTypeId;
use dom::bindings::inheritance::SVGGraphicsElementTypeId;
use dom::bindings::str::DOMString;
use dom::document::Document;
@@ -50,6 +51,7 @@ use dom::htmltemplateelement::HTMLTemplateElement;
use dom::htmltextareaelement::HTMLTextAreaElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
use dom::svgcircleelement::SVGCircleElement;
use dom::svgsvgelement::SVGSVGElement;
use html5ever::LocalName;
use style::attr::AttrValue;
@@ -260,6 +262,14 @@ pub fn vtable_for(node: &Node) -> &VirtualMethods {
))) => {
node.downcast::<SVGSVGElement>().unwrap() as &VirtualMethods
}
NodeTypeId::Element(
ElementTypeId::SVGElement(
SVGElementTypeId::SVGGraphicsElement(
SVGGraphicsElementTypeId::SVGGeometryElement(
SVGGeometryElementTypeId::SVGCircleElement
)))) => {
node.downcast::<SVGCircleElement>().unwrap() as &VirtualMethods
}
NodeTypeId::Element(ElementTypeId::Element) => {
node.downcast::<Element>().unwrap() as &VirtualMethods
}
@@ -0,0 +1,6 @@
[Pref="dom.svg.enabled"]
interface SVGCircleElement : SVGGeometryElement {
// [SameObject] readonly attribute SVGAnimatedLength cx;
// [SameObject] readonly attribute SVGAnimatedLength cy;
// [SameObject] readonly attribute SVGAnimatedLength r;
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.