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
Closed

Conversation

stshine
Copy link
Contributor

@stshine stshine commented Jul 11, 2017

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 errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/longhand/svg.mako.rs, components/style/properties/properties.mako.rs, components/style/properties/longhand/font.mako.rs, components/style/properties/longhand/counters.mako.rs, components/style/properties/helpers.mako.rs and 3 more
  • @canaltinova: components/style/properties/longhand/svg.mako.rs, components/style/properties/properties.mako.rs, components/style/properties/longhand/font.mako.rs, components/style/properties/longhand/counters.mako.rs, components/style/properties/helpers.mako.rs and 3 more
  • @KiChjang: components/script/dom/webidls/CSSStyleDeclaration.webidl, components/script/dom/svgelement.rs, components/net/image_cache.rs, components/script/dom/svggeometryelement.rs, components/script/dom/mod.rs and 14 more
  • @fitzgen: components/script/dom/webidls/CSSStyleDeclaration.webidl, components/script/dom/svgelement.rs, components/script/dom/svggeometryelement.rs, components/script/dom/mod.rs, components/script/dom/element.rs and 11 more
  • @emilio: components/layout/display_list_builder.rs, components/layout/webrender_helpers.rs, components/style/properties/longhand/svg.mako.rs, components/style/properties/properties.mako.rs, components/style/properties/longhand/font.mako.rs and 7 more

@highfive
Copy link

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!
  • These commits modify net, layout, style, gfx, and script code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jul 11, 2017
@stshine
Copy link
Contributor Author

stshine commented Jul 11, 2017

This depends on #17649 get merged and servo/webrender#1461 get resolved first, but IMO it can accepts reviews.

@stshine stshine added A-content/svg S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. labels Jul 11, 2017
Copy link
Member

@emilio emilio left a 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) =>
Copy link
Member

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.


#[dom_struct]
pub struct SVGElement {
element: Element,
presentation_attributes: DOMRefCell<PropertyDeclarationBlock>
Copy link
Member

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.

#[allow(unsafe_code)]
fn presentation_attributes(&self) -> PropertyDeclarationBlock {
unsafe {
(*self.unsafe_get()).presentation_attributes.borrow_for_layout().clone()
Copy link
Member

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.


match attr.local_name() {
&local_name!("fill") => {
self.mutate_svg_prehint(attr);
Copy link
Member

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?

Copy link
Contributor Author

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));
}
}
Copy link
Member

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(
Copy link
Member

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.

Copy link
Contributor Author

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(
Copy link
Member

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>,
}

Copy link
Contributor Author

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")]
Copy link
Member

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
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #17694) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 13, 2017
@stshine stshine closed this Jul 13, 2017
@stshine stshine reopened this Jul 13, 2017
@stshine stshine removed the S-needs-rebase There are merge conflict errors. label Jul 13, 2017
@stshine stshine force-pushed the svg-circle branch 2 times, most recently from bda8775 to 4d91780 Compare July 13, 2017 15:29
@bors-servo
Copy link
Contributor

☔ The latest upstream changes (presumably #17744) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jul 15, 2017
@KiChjang
Copy link
Contributor

KiChjang commented Aug 3, 2017

r? @emilio

@highfive highfive assigned emilio and unassigned KiChjang Aug 3, 2017
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.
@jdm
Copy link
Member

jdm commented Nov 15, 2017

@stshine Apologies for the long delay in reviewing these changes. Do you plan to continue working on this if we find a reviewer?

@jdm
Copy link
Member

jdm commented Jun 19, 2018

Tracking this work in #12975 but closing due to lack of activity.

@jdm jdm closed this Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/svg S-awaiting-review There is new code that needs to be reviewed. S-blocked-on-external Something, somewhere else, needs to happen before this PR can be merged. S-needs-rebase There are merge conflict errors.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants