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
Conversation
Heads up! This PR modifies the following files:
|
This depends on #17649 get merged and servo/webrender#1461 get resolved first, but IMO it can accepts reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super-exciting @stshine! \o/
match item.data { | ||
SVGData::Circle => { | ||
let fill_style = match item.style.get_inheritedsvg().fill.kind { | ||
SVGPaintKind::Color(color) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Indentation here looks weird, without a wrapping block.
components/script/dom/svgelement.rs
Outdated
|
||
#[dom_struct] | ||
pub struct SVGElement { | ||
element: Element, | ||
presentation_attributes: DOMRefCell<PropertyDeclarationBlock> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to use Arc<Locked<PropertyDeclarationBlock>>
, and use the document write guard to modify it in place. That way passing it to style is just a refcount bump.
components/script/dom/svgelement.rs
Outdated
#[allow(unsafe_code)] | ||
fn presentation_attributes(&self) -> PropertyDeclarationBlock { | ||
unsafe { | ||
(*self.unsafe_get()).presentation_attributes.borrow_for_layout().clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This clone is quite expensive actually, see above for what may be better.
components/script/dom/svgelement.rs
Outdated
|
||
match attr.local_name() { | ||
&local_name!("fill") => { | ||
self.mutate_svg_prehint(attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean mutate_svg_preshint
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed :)
let key = window.image_cache().create_geometry_key(); | ||
self.geometry_key.set(Some(key)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Indentation is off.
@@ -158,3 +158,27 @@ ${helpers.predefined_type("mask-image", "ImageLayer", | |||
animation_value_type="discrete", | |||
flags="CREATES_STACKING_CONTEXT", | |||
has_uncacheable_values="True" if product == "gecko" else "False")} | |||
|
|||
${helpers.predefined_type( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these actual CSS properties? This will allow them to be parsed from style attributes, which may not be what you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes they are, according the SVG2 spec every SVG presentation attribute is a css property. For example, you can do this in Chrome.
pub enum DeclaredValueOwned<T> { | ||
/// A known specified value from the stylesheet. | ||
Value(T), | ||
/// An unparsed value that contains `var()` functions. | ||
WithVariables(Arc<UnparsedValue>), | ||
WithVariables( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this would look nicer changing it to:
WithVariables {
#[cfg_attr(feature = "servo", ...)]
value: Arc<UnparsedValue>,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@@ -1108,7 +1114,9 @@ pub enum PropertyDeclaration { | |||
/// A css-wide keyword. | |||
CSSWideKeyword(LonghandId, CSSWideKeyword), | |||
/// An unparsed value that contains `var()` functions. | |||
WithVariables(LonghandId, Arc<UnparsedValue>), | |||
WithVariables(LonghandId, | |||
#[cfg_attr(feature = "servo", ignore_heap_size_of = "Arc")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -218,7 +218,8 @@ fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> Servo | |||
get_inheritedbox.direction, get_inheritedbox.writing_mode, | |||
get_text.text_decoration_line, get_text.unicode_bidi, | |||
get_inheritedtable.empty_cells, get_inheritedtable.caption_side, | |||
get_column.column_width, get_column.column_count | |||
get_column.column_width, get_column.column_count, | |||
get_inheritedsvg.fill, get_svg.cx, get_svg.cy, get_svg.r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so you actually want a style struct field, but not exposing it as a CSS property... So at least you need to use internal="True"
on the property definition, and document that it's not web-exposed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are you sure you want changes to fill
to fully reflow the element? Why is that needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I am not really familiar with the incremental reflow infrastructure, will try to resolve this.
☔ The latest upstream changes (presumably #17694) made this pull request unmergeable. Please resolve the merge conflicts. |
bda8775
to
4d91780
Compare
☔ The latest upstream changes (presumably #17744) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @emilio |
Implement "fill", "x", "y", and "r" svg properties in servo.
Add a PropertyDeclarationBlock to SVGElement to parse and store SVG presentation attributes. For now, parse and store attributes if the attribute name is "fill".
Add api to create, update, delete geometry from ImageCache.
Add SVGGeometryElement implementation.
Add a geometry key field to the SVGSVGElement, When the <svg> element is bind to a parent html element, ensure it contains one, and delete it when the element is unbind. Also, pass the svg data to layout when the key is present.
Add basic support for <circle>, and create dom for it.
Currently, layout objects for an SVG are store in a vector.
Add SvgDisplayItem to display list, and generate geometries for SVG.
@stshine Apologies for the long delay in reviewing these changes. Do you plan to continue working on this if we find a reviewer? |
Tracking this work in #12975 but closing due to lack of activity. |
Add basic support for SVG element.
Currently, this only support filling with solid color.
./mach build -d
does not report any errors./mach test-tidy
does not report any errorsThis change is