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

Implement serialization of transform functions #15194

Closed
upsuper opened this issue Jan 25, 2017 · 35 comments
Closed

Implement serialization of transform functions #15194

upsuper opened this issue Jan 25, 2017 · 35 comments

Comments

@upsuper
Copy link
Member

@upsuper upsuper commented Jan 25, 2017

Currently, only serialization of translate() function is implmeneted. We should have the rest implemented as well.

Spec: https://drafts.csswg.org/css-transforms/#serialization-of-transform-functions

The relevant code is https://github.com/servo/servo/blob/master/components/style/properties/longhand/box.mako.rs#L1183-L1237

(I think this is an easy one, but not sure. cc @Manishearth)

@highfive
Copy link

@highfive highfive commented Jan 25, 2017

Please make a comment here if you intend to work on this issue. Thank you!

@Manishearth Manishearth added the E-easy label Jan 25, 2017
@dpyro
Copy link
Contributor

@dpyro dpyro commented Jan 25, 2017

Am working on now!

@upsuper upsuper added the C-assigned label Jan 25, 2017
@upsuper
Copy link
Member Author

@upsuper upsuper commented Jan 25, 2017

Great! Please ask questions here if there is anything unclear.

@dpyro
Copy link
Contributor

@dpyro dpyro commented Jan 25, 2017

It looks like we are implementing serialization of the specified transforms, not the computed ones. If that is correct, it looks like we are discarding needed information to regenerate the original specified transforms in parse. Should I then modify the specified data structures to retain the necessary information and drop it into the compute section?

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Jan 25, 2017

Nah. It is okay to drop info during computing. Should parse+compute back to the same computed value.

@dpyro
Copy link
Contributor

@dpyro dpyro commented Jan 25, 2017

Advice requested: when should I use ref while matching?

enum SpecifiedOperation {
    Matrix(SpecifiedMatrix),
    Skew(specified::Angle, specified::Angle),
    Translate(TranslateKind,
              specified::LengthOrPercentage,
              specified::LengthOrPercentage,
              specified::Length),
    Scale(CSSFloat, CSSFloat, CSSFloat),
    Rotate(CSSFloat, CSSFloat, CSSFloat, specified::Angle),
    Perspective(specified::Length),
}

For example, currently there is: SpecifiedOperation::Translate(kind, ref tx, ref ty, ref tz)

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Jan 25, 2017

Whenever the type is not copyable. The length ones and perhaps the angle ones aren't. It's okay to use an unnecessary ref.

@dpyro
Copy link
Contributor

@dpyro dpyro commented Jan 27, 2017

How would I properly test this using the css-tests? Currently I am trying $ ./mach test-css css-transforms-1_dev, but this takes a long time to run (I may try running it on my desktop instead) and outputs verbose info instead of a summary of expectations vs. pass/fails.

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Jan 27, 2017

I don't think there's a way to step around the verbose summary -- it only outputs a list of things which have changed. You can get a shorter (but still verbose) summary via --log-errorsummary foo.log. You can also make a pull request containing your changes and ask one of us to trigger a run on the try server which will run all the tests.

I'm unsure if those tests actually contain any serialization tests. Create a new one in wpt if you can't find one (via ./mach create-wpt). Or just add to the existing roundtrip parse/serialization tests in tests/unit/style.

@jdm
Copy link
Member

@jdm jdm commented Jan 27, 2017

The verbose summary is caused by #15193.

@dpyro
Copy link
Contributor

@dpyro dpyro commented Feb 4, 2017

I’m starting to get stuff to work! There is an issue: the current implementation expresses Angle in terms of radians, but the canonical and default unit is degrees. Do we also need to keep track of the specified unit for serializing Angles back out?

@upsuper
Copy link
Member Author

@upsuper upsuper commented Feb 4, 2017

Per spec, and other major browsers' behavior, I think for specified value, the original unit should be preserved. (That said, 10rad is serialized as 10rad, and 10deg is serialized as 10deg.)

This means you'll probably also need to change some of the parsing code to preserve the units. In addition to that, it seems that Servo is currently normalizing rotate{X,Y,Z} to rotate3d, skew{X,Y} to skew etc., which also loses information necessary for serialization.

For computed value... I guess it doesn't really matter, because we don't need to serialize transform functions in their original form for value returned by getComputedStyle. They are always resolved to matrix.

@wafflespeanut
Copy link
Member

@wafflespeanut wafflespeanut commented Mar 21, 2017

Previous work and reviews are in #15508

@highfive
Copy link

@highfive highfive commented Mar 26, 2017

cc @emilio

@pyfisch
Copy link
Contributor

@pyfisch pyfisch commented Apr 1, 2017

@upsuper I would like to work on this. What is the best way to start?

@upsuper
Copy link
Member Author

@upsuper upsuper commented Apr 1, 2017

@pyfisch Probably you can have a look at #15508 to see where the code should go. Actually you can probably just try simplifying the code in that PR.

@canova canova mentioned this issue Apr 2, 2017
3 of 3 tasks complete
@pyfisch
Copy link
Contributor

@pyfisch pyfisch commented Apr 3, 2017

I can't figure out how the impl would look like. :( Can you please write a complete impl block?

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2017

impl<T: AsRef<U>, U: ToCss> Display for Css<U>?

Though, that may fall afoul of the covered rule, hm.

@emilio
Copy link
Member

@emilio emilio commented Apr 3, 2017

Why not just struct Css<'a, T>(&'a T)? Seems like the most straight-forward way to implement this.

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2017

They want it to be usable in other cases too, without forcing a borrow.

But yes, that's a decent solution.

@emilio
Copy link
Member

@emilio emilio commented Apr 3, 2017

Who's "They", if I can ask? And what's the use case?

@wafflespeanut
Copy link
Member

@wafflespeanut wafflespeanut commented Apr 3, 2017

I think having Css<'a, T> should just be enough. It's gonna be created/used only in ToCss impls, right?

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2017

"they" is @pyfisch

Usecase was a bad way of framing it, I meant that @pyfisch wanted it to be usable for both Css(T) and Css(&T)

@emilio
Copy link
Member

@emilio emilio commented Apr 3, 2017

Right, but what's the use case for Css taking ownership of anything ever?

@Manishearth
Copy link
Member

@Manishearth Manishearth commented Apr 3, 2017

Just ergonomics. But yeah, not much of a use case, Css(&T) should be fine

@emilio
Copy link
Member

@emilio emilio commented Apr 3, 2017

And apologies, didn't know that usage of "they" as a gender-neutral, singular pronoun (I'd have expected a mention, "the assignee" or something like that). Didn't want to be mean :)

pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
@pyfisch
Copy link
Contributor

@pyfisch pyfisch commented Apr 3, 2017

Thanks for your help. I looked up how Display works and found that it is implemented for borrowed values. I added a similar impl for ToCss. If this causes any problems I can also insert '&' chars everywhere. The PR is also uploaded.

pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
bors-servo added a commit that referenced this issue Apr 3, 2017
Implement serialization for transform functions.

Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes #15194

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15194 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16242)
<!-- Reviewable:end -->
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 3, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
bors-servo added a commit that referenced this issue Apr 3, 2017
Implement serialization for transform functions.

Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes #15194

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15194 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16242)
<!-- Reviewable:end -->
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 4, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
bors-servo added a commit that referenced this issue Apr 4, 2017
Implement serialization for transform functions.

Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes #15194

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15194 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16242)
<!-- Reviewable:end -->
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 4, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
pyfisch added a commit to pyfisch/servo that referenced this issue Apr 4, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
bors-servo added a commit that referenced this issue Apr 4, 2017
Implement serialization for transform functions.

Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes #15194

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #15194 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16242)
<!-- Reviewable:end -->
clementmiao added a commit to clementmiao/servo that referenced this issue Apr 7, 2017
Preserve more information from transform function parsing.
Preserve angle unit while parsing.
Simplify SpecifiedMatrix.
Use the write! macro for formatting with a helper called Css.
Implement ToCss for &T if T implements ToCss.
Add some tests and update others.

closes servo#15194
bors-servo added a commit that referenced this issue Apr 19, 2017
stylo: Implement -moz-transform property

-moz-transform property is an alias shorthand property. It has transform as sub-property but their parsing is different in some cases(matrix/matrix3d). -moz-transform also accepts LengthOrPercentage in the nondiagonal homogeneous components of matrix and matrix3d.

It looks like length and percentage values are getting computed to number directly. For example 120px converts into 120 and calc(120px + 20%) converts into 140. So I did like this. But we need to check this behavior again to be sure, I guess.

Also I spent half day investigating why matrices are not serializing after this change and found out their ToCss functions is not completely implemented yet 😄 I was going to implement them but there is an easy issue about it(#15194) so I left it that way. Probably all tests won't pass without it.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #16003 and [Bug 1351356](https://bugzilla.mozilla.org/show_bug.cgi?id=1351356)

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16231)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

9 participants
You can’t perform that action at this time.