Skip to content

[css-backgrounds] calc() values when interpolating background-position #6197

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

Closed
graouts opened this issue Apr 9, 2021 · 2 comments
Closed
Labels
css-backgrounds-3 Current Work

Comments

@graouts
Copy link
Contributor

graouts commented Apr 9, 2021

I'm confused by the two interpolation WPT tests for background-position.

First, in css/css-backgrounds/animations/background-position-origin-interpolation.html:

test_interpolation({
  property: 'background-position',
  from: 'initial',
  to: 'left 20px top 20px',
}, [
  {at: 0, expect: '0% 0%'},
  {at: 0.25, expect: '5px 5px'},
  {at: 0.5, expect: '10px 10px'},
  {at: 0.75, expect: '15px 15px'},
  {at: 1, expect: '20px 20px'},
]);

Chrome passes this test while Firefox yields calc() values with an addition with 0%, for instance calc(0 % + 10px) calc(0% + 10px) for the 0.5 case. Safari fails in a different way but I have a pending WebKit fix that would produce the same result as Firefox.

Then, consider css/css-backgrounds/animations/background-position-interpolation.html:

test_interpolation({
  property: 'background-position',
  from: 'initial',
  to: '80px 80px, 80px 80px, 80px 80px, 80px 80px',
}, [
  {at: -0.25, expect: 'calc(0% - 20px)  calc(0% - 20px),  calc(0% - 20px)  calc(0% - 20px),  calc(0% - 20px)  calc(0% - 20px),  calc(0% - 20px)  calc(0% - 20px)'},
  {at: 0, expect:     '0% 0%, 0% 0%, 0% 0%, 0% 0%'},
  {at: 0.25, expect:  'calc(0% + 20px)  calc(0% + 20px),  calc(0% + 20px)  calc(0% + 20px),  calc(0% + 20px)  calc(0% + 20px),  calc(0% + 20px)  calc(0% + 20px)'},
  {at: 0.5, expect:   'calc(0% + 40px)  calc(0% + 40px),  calc(0% + 40px)  calc(0% + 40px),  calc(0% + 40px)  calc(0% + 40px),  calc(0% + 40px)  calc(0% + 40px)'},
  {at: 0.75, expect:  'calc(0% + 60px)  calc(0% + 60px),  calc(0% + 60px)  calc(0% + 60px),  calc(0% + 60px)  calc(0% + 60px),  calc(0% + 60px)  calc(0% + 60px)'},
  {at: 1, expect:     'calc(0% + 80px)  calc(0% + 80px),  calc(0% + 80px)  calc(0% + 80px),  calc(0% + 80px)  calc(0% + 80px),  calc(0% + 80px)  calc(0% + 80px)'},
  {at: 1.25, expect:  'calc(0% + 100px) calc(0% + 100px), calc(0% + 100px) calc(0% + 100px), calc(0% + 100px) calc(0% + 100px), calc(0% + 100px) calc(0% + 100px)'},
]);

There, Firefox and Chrome both pass the test, and my pending patch in WebKit also passes it.

Is there spec wording anywhere that would support this difference?

As far as WebKit is concerned, I can explain the behavior: since left and top keywords compute to 0%, we blend between a percentage and a dimension and yield calc() values. I imagine Chrome might treat these values differently due to their origin as keywords, but I'm not finding wording in the spec to support this approach.

Prior discussion about this with @birtles and @flackr can be found in an Animation at work Slack thread but all the relevant information is found in this issue as well.

@graouts graouts added the css-backgrounds-3 Current Work label Apr 9, 2021
@graouts
Copy link
Contributor Author

graouts commented Apr 9, 2021

@birtles suggested I Cc @emilio to this issue.

@graouts
Copy link
Contributor Author

graouts commented Apr 9, 2021

@emilio pointed out on the WebKit Slack that this is covered by #3482.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-backgrounds-3 Current Work
Projects
None yet
Development

No branches or pull requests

1 participant