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

Enhance modern component serialization with inf and nan support #351

Merged
merged 2 commits into from
Jul 24, 2023

Conversation

tiaanl
Copy link
Collaborator

@tiaanl tiaanl commented Jul 20, 2023

Modern syntax colors support NaN and infinity values. These values are now allowed, where previously for some lab/lch/oklab/oklch components, NaN values were truncated to 0.0.

NaN and infinity now also correctly serializes to calc(NaN) and calc(infinity) respectively.

Modern syntax colors support NaN and infinity values. These values are
now allowed, where previously for some lab/lch/oklab/oklch components,
NaN values were truncated to 0.0.

NaN and infinity now also correctly serializes to calc(NaN) and
calc(infinity) respectively.
Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

This seems related to web-platform-tests/interop#369 / w3c/csswg-drafts#8629 which is still under discussion. Could you elaborate on the behavior you're implementing?

In particular, the clamping infinity but not NaN at specified value time seems like a bug?

src/color.rs Outdated
@@ -1495,7 +1521,7 @@ where
P::parse_number_or_percentage,
)?;

let lightness = lightness.map(|l| l.value(lightness_range).max(0.0));
let lightness = lightness.map(|l| max_preserve_nan(l.value(lightness_range), 0.0));
Copy link
Member

Choose a reason for hiding this comment

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

So it is really weird to clamp negatives and so on but not nan, I think we should be consistent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The clamping is now being done in Gecko here: https://phabricator.services.mozilla.com/D183983

I only kept in the clamping to 0 for chroma and lightness, because it used to be here. I would prefer to remove these validations here so that the parser only gives your the raw values and not a value that is a "specified" value.

Once the colors are converted to "computed" more rules apply, like NaN becomes 0.0.

So this change is more about allowing calc(nan) values to be passed along to Gecko.

Maybe for consistency I can remove validations here like the clamping, because if I start doing validations here, then it feels like the "computed" value validations are missing.

wdyt?

@tiaanl
Copy link
Collaborator Author

tiaanl commented Jul 23, 2023

Ok now without any of the adjusting or clamping.

Copy link
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

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

So, my understanding is that this is consistent with other out-of-range components like negatives, and that we'd serialize the negatives just fine, but lmk if that's not the case somehow.

src/color.rs Show resolved Hide resolved
if let Some(value) = self.0 {
if value.is_infinite() {
if value.is_sign_negative() {
dest.write_str("calc(-infinity)")
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so the behavior of out-of-range negative values like -3 would be different than -infinity? Or would it be consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

-3 would serialize to -3 and -infinity would serialize to calc(-infinity).

As far as the parser is concerned now, there is no range, just numbers between -inf..inf. Up to the user of the lib to clamp/decide what is a range.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, we should make sure that Gecko is also consistent in how we treat these but that seems fine.

use super::*;

#[test]
fn serialize_modern_components() {
Copy link
Member

Choose a reason for hiding this comment

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

(Not convinced this test is particularly useful but...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What would you change to be convinced?

Copy link
Member

Choose a reason for hiding this comment

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

I mean, the test is just testing fairly straight-forward code directly, so I don't think it brings much value, but...

@emilio
Copy link
Member

emilio commented Jul 24, 2023

@bors-servo delegate+

@bors-servo
Copy link
Contributor

✌️ @tiaanl can now approve this pull request

@emilio
Copy link
Member

emilio commented Jul 24, 2023

Ah I guess we're not doing the bors thing. Anyways please confirm this is consistent and hit merge yourself? I think you can, if not happy to do that :)

@emilio emilio added this pull request to the merge queue Jul 24, 2023
Merged via the queue into servo:master with commit a09f283 Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants