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

Fix perspective interpolation test to allow 0 as value #28036

Merged

Conversation

graouts
Copy link
Contributor

@graouts graouts commented Mar 11, 2021

The perspective property allows 0 as a value, per the CSS Transforms spec:

As very small values can produce bizarre rendering results and stress the numerical accuracy of transform calculations, values less than 1px must be treated as 1px for rendering purposes. (This clamping does not affect the underlying value, so perspective: 0; in a stylesheet will still serialize back as 0.)

…orms spec](https://drafts.csswg.org/css-transforms-2/#perspective-property):

> As very small <length> values can produce bizarre rendering results and stress the numerical accuracy of transform calculations, values less than 1px must be treated as 1px for rendering purposes. (This clamping does not affect the underlying value, so perspective: 0; in a stylesheet will still serialize back as 0.)
@graouts
Copy link
Contributor Author

graouts commented Mar 11, 2021

Firefox has the correct behavior I believe, while Chrome has the incorrect behavior where 0 is treated as none. I have fixed WebKit to have the same behavior as Firefox.

webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this pull request Mar 12, 2021
https://bugs.webkit.org/show_bug.cgi?id=223111

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Add an extra 59 PASS results, although we also have 18 new FAIL results. Of those
new failures, 16 are due to what I believe to be an issue in the WPT test and I filed
web-platform-tests/wpt#28036 to address this. With this change
in the test, we pass all perspective interpolation tests.

* web-platform-tests/css/css-transforms/animation/perspective-composition-expected.txt:
* web-platform-tests/css/css-transforms/animation/perspective-interpolation-expected.txt:

Source/WebCore:

In order to correctly interplate the "perspective" CSS property, we must not interpolate
between "none" values and lengths. To do this, we add a new wrapper for this property with
a canInterpolate() implementation that uses RenderStyle::hasPerspective() to determine
whether we're dealing with a "none" value.

We also had to make a change to the way the "none" value is represented internally, since it
used to be 0 although the spec (https://drafts.csswg.org/css-transforms-2/#perspective-property)
says "perspective: 0 in a stylesheet will still serialize back as 0". So we now change the
initial value to be -1, which is fine since negative values are otherwise not allowed.

To correctly support this, we must also change consumePerspective() to no longer disallow the
0 value at parse time.

* animation/CSSPropertyAnimation.cpp:
(WebCore::PerspectiveWrapper::PerspectiveWrapper):
(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumePerspective):
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::hasPerspective const):
(WebCore::RenderStyle::initialPerspective):
* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertPerspective):

Canonical link: https://commits.webkit.org/235217@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@274329 268f45cc-cd09-0410-ab3c-d52691b4dbfc
bertogg pushed a commit to Igalia/webkit that referenced this pull request Mar 12, 2021
https://bugs.webkit.org/show_bug.cgi?id=223111

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Add an extra 59 PASS results, although we also have 18 new FAIL results. Of those
new failures, 16 are due to what I believe to be an issue in the WPT test and I filed
web-platform-tests/wpt#28036 to address this. With this change
in the test, we pass all perspective interpolation tests.

* web-platform-tests/css/css-transforms/animation/perspective-composition-expected.txt:
* web-platform-tests/css/css-transforms/animation/perspective-interpolation-expected.txt:

Source/WebCore:

In order to correctly interplate the "perspective" CSS property, we must not interpolate
between "none" values and lengths. To do this, we add a new wrapper for this property with
a canInterpolate() implementation that uses RenderStyle::hasPerspective() to determine
whether we're dealing with a "none" value.

We also had to make a change to the way the "none" value is represented internally, since it
used to be 0 although the spec (https://drafts.csswg.org/css-transforms-2/#perspective-property)
says "perspective: 0 in a stylesheet will still serialize back as 0". So we now change the
initial value to be -1, which is fine since negative values are otherwise not allowed.

To correctly support this, we must also change consumePerspective() to no longer disallow the
0 value at parse time.

* animation/CSSPropertyAnimation.cpp:
(WebCore::PerspectiveWrapper::PerspectiveWrapper):
(WebCore::CSSPropertyAnimationWrapperMap::CSSPropertyAnimationWrapperMap):
* css/parser/CSSPropertyParser.cpp:
(WebCore::consumePerspective):
* rendering/style/RenderStyle.h:
(WebCore::RenderStyle::hasPerspective const):
(WebCore::RenderStyle::initialPerspective):
* style/StyleBuilderConverter.h:
(WebCore::Style::BuilderConverter::convertPerspective):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@274329 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@tabatkins
Copy link
Contributor

So having -1 be a (still valid) 0px looks good, but -20 would be -190px, right? Is there defined behavior for clamping to the valid range when an extended transition exceeds the normal bounds?

@graouts
Copy link
Contributor Author

graouts commented Mar 12, 2021

Is there defined behavior for clamping to the valid range when an extended transition exceeds the normal bounds?

The existing tests expects the value to be clipped to 0, but the spec doesn't mention anything like other specs do about the value being non-negative.

@tabatkins
Copy link
Contributor

tabatkins commented Mar 13, 2021

Okay, after combing thru several specs, as far as I can tell it is not defined what happens if an interpolation results in a value that is outside the valid range. I've opened w3c/csswg-drafts#6097 to address this.

That said, I think there's an obvious correct answer (clamp to the valid range, like math functions do), and this test conforms to that, so I'm gonna go ahead and approve this ahead of the WG discussion.

@tabatkins tabatkins merged commit 416fe32 into web-platform-tests:master Mar 13, 2021
@graouts graouts deleted the perspective-interpolation branch March 13, 2021 11:04
webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this pull request Mar 13, 2021
…hat resulted

from web-platform-tests/wpt#28036 and update the expectations
now that we pass this test entirely with 16 new PASS results.

* web-platform-tests/css/css-transforms/animation/perspective-interpolation-expected.txt:
* web-platform-tests/css/css-transforms/animation/perspective-interpolation.html:

Canonical link: https://commits.webkit.org/235251@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@274384 268f45cc-cd09-0410-ab3c-d52691b4dbfc
philn pushed a commit to philn/old-webkit that referenced this pull request Mar 14, 2021
…hat resulted

from web-platform-tests/wpt#28036 and update the expectations
now that we pass this test entirely with 16 new PASS results.

* web-platform-tests/css/css-transforms/animation/perspective-interpolation-expected.txt:
* web-platform-tests/css/css-transforms/animation/perspective-interpolation.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@274384 268f45cc-cd09-0410-ab3c-d52691b4dbfc
@tabatkins
Copy link
Contributor

Following up: I confirmed in w3c/csswg-drafts#6097 that clamping is indeed the desired effect, and it was present in the spec previously before getting accidentally removed by unrelated edits. It's fixed now.

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

4 participants