Skip to content

Implement CSS3 Calc - #7185

Closed
dzbarsky wants to merge 20 commits into
servo:masterfrom
dzbarsky:calc
Closed

dzbarsky wants to merge 20 commits into
servo:masterfrom
dzbarsky:calc

Conversation

@dzbarsky

Copy link
Copy Markdown
Contributor

Doesn't work for font-size and I need to investigate how it should work for units that aren't lengths, but what I have so far should be ok. r? @SimonSapin

Fixes #7156.

Review on Reviewable

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 13, 2015
@highfive

Copy link
Copy Markdown

warning Warning warning

  • These commits modify layout code, but no reftests are modified. Please consider adding a reftest!

@dzbarsky

Copy link
Copy Markdown
Contributor Author

Also need to figure out if we have tests or can steal some from Gecko.

@dzbarsky

Copy link
Copy Markdown
Contributor Author

Pretty sure the AST simplification code isn't quite right and can actually enter some places I thought were unreachable. I'll plug those up as part of writing the tests, but let me know if you can think of a cleaner way to do this.

Comment thread components/style/values.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Remove this before committing)

@dzbarsky

Copy link
Copy Markdown
Contributor Author

Ok, the implementation now passes all the tests I've written. I want to figure out if I can somehow clean up the code because it's a little messy

@SimonSapin

Copy link
Copy Markdown
Member

@dzbarsky Do you want to keep iterating on this some more, or is this ready for review?

@dzbarsky

Copy link
Copy Markdown
Contributor Author

It's ready for review now. I'm gone for the next week so there's no rush.

@SimonSapin

Copy link
Copy Markdown
Member

Reviewed 1 of 6 files at r1, 5 of 7 files at r2, 1 of 2 files at r3, 3 of 4 files at r8, 1 of 2 files at r11.
Review status: 11 of 12 files reviewed at latest revision, 10 unresolved discussions, all commit checks successful.


components/layout/block.rs, line 333 [r16] (raw file):
Is this ignoring the percentage component? I think this should rather resolved to auto: the "real" value that we would want is not known yet, same as the percentage case in https://drafts.csswg.org/css2/visudet.html#the-height-property

Though perhaps there should be a special case when the percentage component is zero.


components/layout/block.rs, line 334 [r16] (raw file):
Nit: I think a {} block is more readable when you’re going to the next line anyway… hopefully rustfmt will make this a non-issue eventually.


components/layout/block.rs, line 347 [r16] (raw file):
Same comment as above regarding ignoring the percentage component.


components/layout/block.rs, line 1130 [r16] (raw file):
Same comment as above regarding ignoring the percentage component.


components/layout/fragment.rs, line 459 [r16] (raw file):
Same comment as above regarding ignoring the percentage component.


components/layout/fragment.rs, line 615 [r16] (raw file):
Nit: This sum is duplicated all over the place. Maybe make it a method of Calc or even of LengthOrPercentage?


components/style/properties.mako.rs, line 1864 [r16] (raw file):
Reject unsupported things by returning Err, don’t make up an incorrect value.


components/style/values.rs, line 423 [r16] (raw file):
Is None different from Some(zero)?


components/style/values.rs, line 1287 [r16] (raw file):
Is None different from Some(zero)?


Comments from the review on Reviewable.io

@dzbarsky

Copy link
Copy Markdown
Contributor Author

Review status: 11 of 12 files reviewed at latest revision, 8 unresolved discussions, all commit checks successful.


components/layout/block.rs, line 333 [r16] (raw file):
Hmmm, I think you're probably right, but I think that will end up ignoring the absolute component. But maybe that's ok. I'll investigate when I write reftests.


components/layout/block.rs, line 334 [r16] (raw file):
Ok I'll put it back.


components/layout/block.rs, line 347 [r16] (raw file):
Percentages without a containing block size are given a min_block_size of 0 here, so it seems ok to ignore the percentage and just use the absolute length (when there is no containing block size).


components/layout/block.rs, line 1130 [r16] (raw file):
Same as above, percentage returns None or a fraction of containing block size, so calc is doing the same thing.


components/layout/fragment.rs, line 0 [r16] (raw file):
Yeah, I think it makes sense on Calc, since we'll also need it on LengthOrPercentageOrAuto


components/layout/fragment.rs, line 459 [r16] (raw file):
Agreed, this should probably be Auto.


components/style/properties.mako.rs, line 1864 [r16] (raw file):
Good point, I was worried about throwing but we were already throwing for this case


components/style/values.rs, line 423 [r16] (raw file):
Yes. https://drafts.csswg.org/css-values-3/#calc-computed-value "Where percentages are not resolved at computed-value time, they are not resolved in calc() expressions, e.g. calc(100% - 100% + 1em) resolves to calc(0% + 1em), not to calc(1em)." So Some(zero) isn't enough to distinguish these two cases.


components/style/values.rs, line 1287 [r16] (raw file):
Yes. calc(100px) serializes as 100px, while calc(100px + 0%) stays as a calc expression. "A value like calc(20px + 0%) would serialize as calc(20px + 0%), maintaining both terms in the serialized value. (It’s important to maintain zero-valued terms, so the calc() doesn’t suddenly "change shape" in the middle of a transition when one of the values happens to have a zero value temporarily. This also removes the need to "pick a unit" when all the terms are zero.)"


Comments from the review on Reviewable.io

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7265) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Aug 20, 2015
@SimonSapin

Copy link
Copy Markdown
Member

Reviewed 1 of 1 files at r17.
Review status: all files reviewed at latest revision, 9 unresolved discussions, some commit checks failed.


components/layout/block.rs, line 333 [r16] (raw file):
The reasoning is that the sum of something unknown plus something known is also unknown.


components/layout/block.rs, line 347 [r16] (raw file):
Alright, makes sense. (x + 0 = x)


components/layout/block.rs, line 1130 [r16] (raw file):
But None is more like "unknown" than like zero. Is this is more similar to the first case: a known + unknown sum is unknown.


components/style/values.rs, line 442 [r17] (raw file):
#7306 can be a follow-up later.


components/style/values.rs, line 1303 [r17] (raw file):
Is this missing * 100.?


components/style/values.rs, line 1327 [r17] (raw file):
Use &[] instead of vec!() here and in the previous loop to avoid allocating.


Comments from the review on Reviewable.io

@dzbarsky

Copy link
Copy Markdown
Contributor Author

Review status: 1 of 17 files reviewed at latest revision, 9 unresolved discussions, all commit checks successful.


components/style/values.rs, line 442 [r17] (raw file):
I pushed a new commit with tests for this - I don't think #7306 is actually an issue.


components/style/values.rs, line 1303 [r17] (raw file):
Yep!


Comments from the review on Reviewable.io

@jdm jdm removed the S-needs-rebase There are merge conflict errors. label Aug 23, 2015
@dzbarsky
dzbarsky force-pushed the calc branch 2 times, most recently from 436e2a3 to 25829bb Compare August 26, 2015 21:48
@jdm

jdm commented Sep 1, 2015

Copy link
Copy Markdown
Member

Is this superseded by #7400?

@dzbarsky

dzbarsky commented Sep 1, 2015

Copy link
Copy Markdown
Contributor Author

Yes, but I can either rebase #7400 after this merges or merge it all at once. Whichever is easier for @SimonSapin

@SimonSapin

Copy link
Copy Markdown
Member

@bors-servo r+

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 2591a89 has been approved by SimonSapin

@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. labels Sep 2, 2015
bors-servo pushed a commit that referenced this pull request Sep 2, 2015
Implement CSS3 Calc

This is #7185 with one commit added to make it build merged with master, which got support for the `ch` unit in the meantime.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7496)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #7510) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added S-needs-rebase There are merge conflict errors. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Sep 2, 2015
@SimonSapin

Copy link
Copy Markdown
Member

I had hoped this would auto-merge with #7496. Is there something here that’s not there?

@dzbarsky

dzbarsky commented Sep 3, 2015

Copy link
Copy Markdown
Contributor Author

Yeah, I added a commit adding ch support and modified the test. I see you merged your version already so I'll just roll the test change into the other calc PR I have open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed. S-needs-rebase There are merge conflict errors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants