Bug 217286 - CSS transform doesn't override transform attribute on SVG element
Summary: CSS transform doesn't override transform attribute on SVG element
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-03 17:39 PDT by leewhite128
Modified: 2022-09-03 11:20 PDT (History)
9 users (show)

See Also:


Attachments
Testcase (145 bytes, image/svg+xml)
2020-10-19 08:59 PDT, Antoine Quint
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description leewhite128 2020-10-03 17:39:31 PDT
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0

Steps to reproduce:

Have SVG element with transform attribute and CSS transform set. Example: <svg>
<style>
circle {transform: none;}
</style>
<circle r="50" transform="scale(2)"/>
</svg>

Originally posted here: https://stackoverflow.com/questions/25926007/override-svg-transform-attributes-with-css
Equivalent chromium issue: https://bugs.chromium.org/p/chromium/issues/detail?id=415950

Actual results:

Transform didn't get set to none.

Expected results:

Transform should have been set to none, that way can easily set transform on multiple SVG elements at once if prefers-reduced-motion is on.
Comment 1 Radar WebKit Bug Importer 2020-10-04 14:25:15 PDT
<rdar://problem/69934881>
Comment 2 Antoine Quint 2020-10-19 08:55:12 PDT
I bet this is due to this in SVGGraphicsElement::animatedLocalTransform():

    bool hasSpecifiedTransform = style && style->hasTransform();

I don't think this can tell whether the transform property was set explicitly on the element, it only checks whether there are operations in the StyleTransformData. We need a different call that determines whether the transform property was explicitly set on this element.
Comment 3 Antoine Quint 2020-10-19 08:59:41 PDT
Created attachment 411749 [details]
Testcase
Comment 4 Antoine Quint 2020-10-19 09:00:14 PDT
The attached test only has the behavior expected by the originator in Chrome. In Firefox and Safari setting `transform: none` in CSS does not affect the element.
Comment 5 Antoine Quint 2020-10-19 11:34:30 PDT
Actually, if I understand the spec correctly, presentation attributes should be considered during style resolution, per https://www.w3.org/TR/css-transforms-1/#transform-attribute-specificity:

"The participation in the CSS cascade is determined by the specificity of presentation attributes in the SVG specification. According to SVG, user agents conceptually insert a new author style sheet for presentation attributes, which is the first in the author style sheet collection."

So I think we should always be using what is set in the RenderStyle, assuming the RenderStyle accounts for presentation attributes :)
Comment 6 Ahmad Saleem 2022-09-03 11:19:59 PDT
I am not sure on web-spec but Safari 15.6.1, Safari Technology Preview 152 and Firefox Nightly 106 are matching each other in test case and showing circle 'bigger / larger' in size compared to Chrome Canary 107. Just wanted to share updated testing results. Thanks!