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

SVG Painting: computed property values #14211

Merged
merged 3 commits into from Dec 5, 2018

Conversation

ewilligers
Copy link
Contributor

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]

@AmeliaBR
Copy link
Contributor

AmeliaBR commented Dec 3, 2018

Do all browsers downcase keyword values? (e.g., srgb instead of sRGB) I know they are case-insensitive, but I'd expect to use the canonical spelling in the spec. Or maybe change the spec to match, unless there's guidance in a CSS spec about computed format of keywords.

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');
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.)

Copy link
Contributor Author

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)');
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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");
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

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");
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@AmeliaBR
Copy link
Contributor

AmeliaBR commented Dec 3, 2018

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 calc() values render as, to find out what I mean). But it's a start.

@ewilligers
Copy link
Contributor Author

Do all browsers downcase keyword values

Firefox and Chrome Canary downcase, consistent with the spec Serializing CSS Values

To serialize a CSS component value depends on the component, as follows:
keyword

  • The keyword converted to ASCII lowercase.

There are open bugs for WebKit and Edge.

I'd expect to use the canonical spelling in the spec.

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 currentColor and currentcolor:

  • css-backgrounds-3/Overview.bs
  • css-color-3/Overview.html
  • css-color-3/Overview.src.html
  • css-color-4/Overview.bs
  • css-pseudo-4/Overview.bs
  • css-text-decor-3/Overview.bs
  • css-ui-4/Overview.bs
  • css-values-4/Overview.bs

@AmeliaBR
Copy link
Contributor

AmeliaBR commented Dec 5, 2018

We have free choice: the Values and Units spec has Hz, kHz and Q, and all of the following CSS spec files contain both currentColor and currentcolor:

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]
@ewilligers
Copy link
Contributor Author

I think all comments have been addressed now, in either this PR or #14367.

@ewilligers ewilligers merged commit 5781139 into web-platform-tests:master Dec 5, 2018
@ewilligers ewilligers deleted the painting-computed branch December 5, 2018 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants