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

[3003] Allow mathematical expressions in image sizes #3084

Merged
merged 2 commits into from
Apr 9, 2018
Merged

[3003] Allow mathematical expressions in image sizes #3084

merged 2 commits into from
Apr 9, 2018

Conversation

musgravejw
Copy link
Contributor

@musgravejw musgravejw commented Sep 30, 2017

This PR attempts to clarify that mathematical functions "min()" and "max()" can also be used as a valid arguments for source-size-value in Image size attributes.

#3003

https://drafts.csswg.org/css-values/#math-functions


/images.html ( diff )
/infrastructure.html ( diff )

@annevk annevk added topic: img needs tests Moving the issue forward requires someone to write tests labels Sep 30, 2017
@annevk
Copy link
Member

annevk commented Sep 30, 2017

Thank you! We'll also need to update https://html.spec.whatwg.org/#parsing-a-sizes-attribute. (I wonder how that algorithm works, when is the value computed? It seems that with calc() you could easily end up with a negative value, but not know it yet.)

And we'll need additional test coverage over at https://github.com/w3c/web-platform-tests.

@musgravejw
Copy link
Contributor Author

@annevk Ah, you're right, I missed that reference to calc(). I will update the web platform tests as well. What would be the best way to document the algorithm for calc() returning negative values? Also, could you point me in the right direction for documentation? Looks like the CSSWG covers parsing.

@annevk
Copy link
Member

annevk commented Oct 2, 2017

Thank you!

I hope @zcorpan or @tabatkins can help out with the parsing question. I don't really know how this is supposed to work unfortunately.

@zcorpan
Copy link
Member

zcorpan commented Oct 4, 2017

The entry points to parsing sizes are from https://html.spec.whatwg.org/multipage/images.html#update-the-source-set

which is invoked from https://html.spec.whatwg.org/multipage/images.html#select-an-image-source

which is invoked from
https://html.spec.whatwg.org/multipage/images.html#updating-the-image-data:select-an-image-source
and
https://html.spec.whatwg.org/multipage/images.html#reacting-to-environment-changes:select-an-image-source

The calc() value is evaluated during parsing, so you should know what it evaluates to right away.

A source size is a <source-size-value>. When a source size has a unit relative to the viewport, it must be interpreted relative to the img element's node document's viewport. Other units must be interpreted the same as in Media Queries. [MQ]

https://html.spec.whatwg.org/multipage/images.html#source-size-2

("the same as in Media Queries" means that font-relative units use initial values, so 1em is the user's default font size, not the img element's computed 'font-size'.)

However, a mathematical function could evaluate differently each time sizes is parsed, and indeed it's possible it could be negative some of the time (e.g. for calc(500px - 50vw)). I don't remember why we made it invalid (and skipped over in parsing), rather than clamping to 0. The latter seems like it's less surprising behavior, so I'm open to changing that, but that's probably a separate issue and doesn't need to block this PR imo.

source Outdated
@@ -26775,7 +26777,7 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
<dfn>&lt;source-size-value></dfn> = <span>&lt;length></span></pre>

<p>A <span>&lt;source-size-value></span> must not be negative, and must not use CSS functions
other than the <span>'calc()'</span> function.</p>
other than the mathematical functions <span>'calc()'</span>, <span>'min()'</span>, and <span>'max()'</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to cross-reference "mathematical functions" and not limit to these 3 -- if CSS adds more mathematical functions, they should work here as well.

other than the <span>mathematical functions</span> (such as <span>'calc()'</span>,
<span>'min()'</span>, and <span>'max()'</span>).</p>

source Outdated
@@ -27929,7 +27931,7 @@ was an English &lt;a href="/wiki/Music_hall">music hall&lt;/a> singer, ...</pre>
is a valid non-negative <span>&lt;source-size-value></span>,
let <var>size</var> be its value
and remove the <span>component value</span> from <var>unparsed size</var>.
Any CSS function other than the <span>'calc()'</span> function is invalid.
Any CSS function other than the mathematical functions <span>'calc()'</span>, <span>'min()'</span>, and <span>'max()'</span> is invalid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just cross-reference mathematical functions here without listing what they are.

@zcorpan
Copy link
Member

zcorpan commented Oct 4, 2017

The relevant test is /html/semantics/embedded-content/the-img-element/sizes/parse-a-sizes-attribute.html

@annevk
Copy link
Member

annevk commented Oct 9, 2017

Mathematical functions should probably not have single quotes around it?

@zcorpan
Copy link
Member

zcorpan commented Oct 9, 2017

@annevk indeed.

source Outdated
@@ -3700,7 +3700,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li>The <dfn data-x-href="https://drafts.csswg.org/css-values/#in">'in'</dfn> unit</li>
<li>The <dfn data-x-href="https://drafts.csswg.org/css-values/#px">'px'</dfn> unit</li>
<li>The <dfn data-x-href="https://drafts.csswg.org/css-values/#funcdef-attr">'attr()'</dfn> function</li>
<li>The <dfn data-x-href="https://drafts.csswg.org/css-values/#funcdef-calc">'calc()'</dfn> function</li>
<li>The <dfn data-x-href="https://drafts.csswg.org/css-values/#calc-notation">'mathematical functions'</dfn></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should call this "math functions" and link to https://drafts.csswg.org/css-values/#math-functions.

@musgravejw
Copy link
Contributor Author

Thanks @sideshowbarker... ugh, so many dumb mistakes on my part:

https://media.giphy.com/media/bkklBjAmlYjv2/giphy.gif

@musgravejw
Copy link
Contributor Author

@zcorpan I had a question about the W3C test, should I open an issue there instead?

@annevk
Copy link
Member

annevk commented Oct 11, 2017

@musgravejw up to you. You should feel free to ask questions here about tests as well. Note that per https://whatwg.org/working-mode#changes we'll wait for the tests before merging.

@musgravejw
Copy link
Contributor Author

Test suite is throwing an exception for me, I have opened an issue in the web-platform-tests repo, and will update as soon as I can get it resolved.

@donovanglover
Copy link
Contributor

Hi @musgravejw,

Mind if I try working on the tests?

@musgravejw
Copy link
Contributor Author

@gloverdonovan Not at all, that would be really helpful actually. Sorry I didn't mean to leave this hanging, I have been meaning to wrap it up as soon as I had some bandwidth.

Thank you.

@domfarolino
Copy link
Member

domfarolino commented Mar 23, 2018

How's it going @gloverdonovan ?

@donovanglover
Copy link
Contributor

Honestly forgot about this issue. I don't think I can dedicate the time to figure out how to write the tests. If anyone else can do it that'd be great.

@domfarolino
Copy link
Member

I rebased this PR (because I couldn't build without linting errors in the current state) and fixed the CSSWG link (the link seems to be singular and not plural).

For right now, seems like the next step is to have @musgravejw sign the participant agreement (https://participate.whatwg.org/agreement) as an individual.

I'll take a look at some tests for this.

domfarolino added a commit to domfarolino/web-platform-tests that referenced this pull request Mar 25, 2018
@domfarolino
Copy link
Member

I've added web-platform-tests/wpt#10167 which should suffice for testing this change.

@annevk
Copy link
Member

annevk commented Mar 26, 2018

Great, thanks all! So the one thing still lacking is browser bugs. https://github.com/whatwg/meta/blob/master/MAINTAINERS.md#handling-pull-requests has links for each browser's bug database if someone would like to take that on. Please paste the resulting bugs URLs here.

@domfarolino
Copy link
Member

domfarolino commented Mar 26, 2018

I've filed https://crbug.com/825895 for Chromium, @musgravejw how do you feel about taking some of the others? That Chromium issue should be a good template to follow :)

annevk pushed a commit to web-platform-tests/wpt that referenced this pull request Apr 9, 2018
@annevk annevk merged commit 5d091c2 into whatwg:master Apr 9, 2018
@annevk
Copy link
Member

annevk commented Apr 9, 2018

Thanks again all, the change is now official! 🎂

If anyone is interested in more, #3093 might be a nice follow-up to fix.

@domfarolino domfarolino deleted the 3003-img-size branch April 9, 2018 16:55
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Apr 15, 2018
…<img sizes="">, a=testonly

Automatic update from web-platform-testsAdd tests for mathematical functions in <img sizes="">

Tests for whatwg/html#3084.

wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167
wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 2, 2019
…<img sizes="">, a=testonly

Automatic update from web-platform-testsAdd tests for mathematical functions in <img sizes="">

Tests for whatwg/html#3084.

wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167
wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167

UltraBlame original commit: 38df35b53e6b8c3fb67629a873c98401edb1492f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 2, 2019
…<img sizes="">, a=testonly

Automatic update from web-platform-testsAdd tests for mathematical functions in <img sizes="">

Tests for whatwg/html#3084.

wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167
wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167

UltraBlame original commit: 38df35b53e6b8c3fb67629a873c98401edb1492f
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 2, 2019
…<img sizes="">, a=testonly

Automatic update from web-platform-testsAdd tests for mathematical functions in <img sizes="">

Tests for whatwg/html#3084.

wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167
wpt-commits: cc9648dde51ca42dfa40d1ff05c017dd3966929f
wpt-pr: 10167

UltraBlame original commit: 38df35b53e6b8c3fb67629a873c98401edb1492f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs tests Moving the issue forward requires someone to write tests topic: img
Development

Successfully merging this pull request may close these issues.

5 participants