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
SVG Painting: computed property values #14211
SVG Painting: computed property values #14211
Conversation
Do all browsers downcase keyword values? (e.g., |
const target = document.getElementById('target'); | ||
target.style['fill'] = 'url("a.b#c")'; | ||
const result = getComputedStyle(target)['fill']; | ||
assert_true(result.includes('/a.b#c'), result + ' is absolute'); |
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.
Is there a way to test this more precisely?
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: there should be a test of bare hash urls (fill="url(#x)"
).
Advance warning: that's not currently consistently handled by browsers.
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.
let resolved = new URL("a.b#c", document.URL).href;
assert_equals('url("' + resolved + '")', result);
or so ought to work. (Or use HTMLAnchorElement.href, but URL is probably supported widely enough by now.)
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.
Changed to use URL
|
||
test_computed_value("stroke", 'url("https://example.com/")'); | ||
test_computed_value("stroke", 'url("https://example.com/") none'); | ||
test_computed_value("stroke", 'url("https://example.com/") rgb(12, 34, 56)'); |
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.
Might want to test (here and for fill
) that the color url()
values get swapped into a canonical order.
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.
I think values may only occur in one order - there is no ||
in the <paint>
grammar.
The stroke-invalid.svg and fill-invalid.svg tests reject invalid orders.
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.
Interesting. I'd never tested it. Another case where SVG rules aren't following modern CSS practices. But I'm not going to argue for changing it at this point.
test_computed_value("stroke-dasharray", "calc(50% + 60px)"); | ||
|
||
test_computed_value("stroke-dasharray", "10px, 20%, 30px"); | ||
test_computed_value("stroke-dasharray", "0, 5", "0px, 5px"); |
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.
Do we have a canonical rule about using comma separators vs space separators?
(I would have expected space to be the canonical version, myself.) Either way, we should test both.
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.
https://drafts.csswg.org/css-values-4/#component-multipliers
A hash mark (#) indicates that the preceding type, word, or group occurs one or more times, separated by comma tokens
https://drafts.csswg.org/cssom/#common-serializing-idioms
To serialize a comma-separated list concatenate all items of the list in list order while separating them by ", ", i.e., COMMA (U+002C) followed by a single SPACE (U+0020).
I have added a test to stroke-dasharray-computed.svg (this PR) and stroke-dasharray-valid.svg (#14367)
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.
It's a bit more complicated than that with SVG, because most properties allow either comma or space separation, with no distinction in meaning. SVG 2 uses the <value>#*
combination list operator to describe it (a space-separated list of comma-separated lists), but that is slightly abusing the CSS syntax.
In this particular case, comma separation makes sense since it's an arbitrary-length list of similar values. And all browsers I tested did it that way, anyway. If we ever make viewBox
or points
or other attributes into CSS properties, then we'll have to deal with whether we want to enforce logic on the list separators!
Thanks for adding the extra test for space-separated values.
test_computed_value("stroke-miterlimit", "0"); | ||
test_computed_value("stroke-miterlimit", "0.5"); | ||
test_computed_value("stroke-miterlimit", "1"); | ||
test_computed_value("stroke-miterlimit", "7.5"); |
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.
Can this particular testing framework test correct handling of invalid values? E.g., a negative value in this case should be rejected by the parser.
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.
Invalid values are tested in */parsing/*-invalid.svg
; these found browser bugs relating to image-rendering, stroke-opacity, stroke-dasharray, stroke-width and more.
stroke-miterlimit-invalid.svg tests that negative values and misformed numbers are rejected.
Another general comment: The testing of length values should include more units, including CSS3 units. Of course, confirming that the CSS systems correctly handle those units doesn't mean that the rendering system will handle them correctly (test what some of the |
Firefox and Chrome Canary downcase, consistent with the spec Serializing CSS Values
There are open bugs for WebKit and Edge.
I'd also be happy for the spec to use lower case. We have free choice: the Values and Units spec has Hz, kHz and Q, and all of the following CSS spec files contain both
|
OK, then let's leave it as is. The mixed case versions are more readable, but so long as there is a clear spec that says the lowercase versions should be used for serialization. If it was a new CSS spec, we'd use hyphenated words, but too late for that, now. |
Keyword values are as specified. Lengths are converted to absolute lengths. Urls are converted to absolute paths. Found bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908058 *-opacity should be clamped to [0.1]
d1eb774
to
87b7fb4
Compare
I think all comments have been addressed now, in either this PR or #14367. |
Keyword values are as specified.
Lengths are converted to absolute lengths.
Urls are converted to absolute paths.
Found bug:
https://bugs.chromium.org/p/chromium/issues/detail?id=908058
*-opacity should be clamped to [0.1]