Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded image-orientation property #14498
Conversation
|
Needs tests and should not be enabled in anything but testing mode. |
| @@ -359,6 +359,8 @@ partial interface CSSStyleDeclaration { | |||
|
|
|||
| [SetterThrows, TreatNullAs=EmptyString] attribute DOMString imageRendering; | |||
| [SetterThrows, TreatNullAs=EmptyString] attribute DOMString image-rendering; | |||
| [SetterThrows, TreatNullAs=EmptyString] attribute DOMString imageOrientation; | |||
This comment has been minimized.
This comment has been minimized.
| @@ -50,6 +50,131 @@ ${helpers.single_keyword("image-rendering", | |||
| custom_consts=image_rendering_custom_consts, | |||
| animatable=False)} | |||
|
|
|||
| // Image Orientation | |||
| // https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation | |||
| <%helpers:longhand name="image-orientation" | |||
This comment has been minimized.
This comment has been minimized.
Manishearth
Dec 8, 2016
Member
Please add products="none" here, and add parse tests for it (see https://github.com/servo/servo/wiki/Property-hacking-guide#testing). Use ./mach test-unit -p style to test.
| } | ||
| } | ||
|
|
||
| pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Dec 8, 2016
Member
Nit: Since we're using the context inside, we should probably rename this to context?
This comment has been minimized.
This comment has been minimized.
dpyro
Dec 8, 2016
Author
Contributor
I used the parameter names from the property hacking guide. Will change.
| } else { | ||
| // Handle flip | ||
| input.expect_ident_matching("flip") | ||
| .map(|()| SpecifiedValue { angle: Some(Angle::from_radians(0f32)), flipped: true }) |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Dec 8, 2016
Member
Nit: Should we have f32 in the suffix here? (and everywhere?) Doesn't rustc figure this out?
This comment has been minimized.
This comment has been minimized.
canova
Dec 8, 2016
Member
We can write 0. or 0.0 as an alternative to this. Rust considers it as an integer otherwise.
This comment has been minimized.
This comment has been minimized.
| fn normalize_angle(angle: &Angle) -> Angle { | ||
| let radians = angle.radians(); | ||
| let normalized_radians = ((radians % TWO_PI) + TWO_PI) % TWO_PI; | ||
| Angle::from_radians(normalized_radians) |
This comment has been minimized.
This comment has been minimized.
wafflespeanut
Dec 8, 2016
Member
Does this really work as expected? The spec says that this should rounded to the nearest "90 deg"
This comment has been minimized.
This comment has been minimized.
dpyro
Dec 8, 2016
Author
Contributor
Yes, this is a careless error. I will be testing to make sure I have the correct implementation.
|
r? @canaltinova |
|
@bors-servo delegate=canaltinova |
|
|
|
This looks good! Some comments: |
| // Image Orientation | ||
| // https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation | ||
| <%helpers:longhand name="image-orientation" | ||
| experimental="True" |
This comment has been minimized.
This comment has been minimized.
| @@ -50,6 +50,132 @@ ${helpers.single_keyword("image-rendering", | |||
| custom_consts=image_rendering_custom_consts, | |||
| animatable=False)} | |||
|
|
|||
| // Image Orientation | |||
| // https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation | |||
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
You should write spec link(https://drafts.csswg.org/css-images/#the-image-orientation) instead of mdn link here
| // Handle flip | ||
| input.expect_ident_matching("flip") | ||
| .map(|()| SpecifiedValue { angle: Some(INITIAL_ANGLE), flipped: true }) | ||
| } |
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
•
Member
I think you can unify this else if and else parts like this:
} else {
let angle = input.try(|i| Angle::parse(context, i)).or(Some(INITIAL_ANGLE));
let flipped = input.try(|input| input.expect_ident_matching("flip")).is_ok();
Ok(SpecifiedValue { angle: angle, flipped: flipped })
}
This comment has been minimized.
This comment has been minimized.
dpyro
Dec 9, 2016
Author
Contributor
Should we be able to return a parse error or just silently ignore? Ex. 0deg fl
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
•
Member
We don't need to return a parse error for this. It will parse it as 0deg. After this parsing, fl will be unconsumed from parser and will try to consume ; but it'll find fl instead and fail.
| #[derive(Clone, PartialEq, Copy, Debug)] | ||
| #[cfg_attr(feature = "servo", derive(HeapSizeOf))] | ||
| pub enum T { | ||
| FromImage, |
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
Computed value: an , rounded and normalized (see text), plus optionally a flip keyword
According to spec, FromImage should be converted to Angle in computed value. To do that, we need to access image metadata. But I don't think we can do that here. Maybe this process needs to be done in glue/layout parts? What do you think @Manishearth?
This comment has been minimized.
This comment has been minimized.
dpyro
Dec 9, 2016
Author
Contributor
Thanks for the spec link. Should the computed value v be bounded to -180deg <= v < 180deg or 0 <= v < 360deg?
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
The computed value of the property is calculated by rounding the specified angle to the nearest quarter-turn (90deg, 100grad, .25turn, etc.), rounding away from 0 (that is, 45deg is rounded to 90deg, while -45deg is rounded to -90deg), then moduloing the value by 1 turn (360deg, 400grad, etc.).
It says 0-360 degrees. Btw, normalize_angle function seems wrong. We should round radians to nearest quarter. But currently adding a quarter instead of rounding. You might want to look how gecko does:
https://dxr.mozilla.org/mozilla-central/source/layout/style/nsStyleStruct.h#2165-2171
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
Oops, sorry I didn't see the last commit about normalize_angle. Will look at it.
This comment has been minimized.
This comment has been minimized.
Manishearth
Dec 9, 2016
Member
So while it does say that the computed value is based on the image, we can defer that to layout (which is what Gecko does). Keep the computed value as is for now.
| computed_value::T::AngleWithFlipped(INITIAL_ANGLE, false) | ||
| } | ||
|
|
||
| use values::CSSFloat; |
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
nit: These declarations can be moved to top, where other use declarations are.
|
It looks good to me! Could you squash your commits? |
| rounded_quarter_turns % 4.0 | ||
| }; | ||
| let normalized_radians = normalized_quarter_turns/4.0 * TWO_PI; | ||
| Angle::from_radians(normalized_radians) |
This comment has been minimized.
This comment has been minimized.
canova
Dec 9, 2016
Member
Well, I didn't quite understand this function but I tried with some numbers and it looks working
|
@canaltinova How would I go about squashing the commits? |
|
@dpyro You can see how to squash here: https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing#squashing |
|
@bors-servo r+ |
|
|
Added image-orientation property
<!-- Please describe your changes on the following line: -->
Implemented as per the MDN documentation—I could not find a current CSS draft. I am not sure if this is the complete correct metadata for the longhand helper:
```
<%helpers:longhand name="image-orientation”
experimental=“True”
animatable=“False”>
```
Also I am not sure how to test this and would appreciate help in creating a testing strategy.
---
<!-- 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 #13877.
<!-- Either: -->
- [X] There are tests for these changes
<!-- 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/14498)
<!-- Reviewable:end -->
|
|
|
@bors-servo retry
|
Added image-orientation property
<!-- Please describe your changes on the following line: -->
Implemented as per the MDN documentation—I could not find a current CSS draft. I am not sure if this is the complete correct metadata for the longhand helper:
```
<%helpers:longhand name="image-orientation”
experimental=“True”
animatable=“False”>
```
Also I am not sure how to test this and would appreciate help in creating a testing strategy.
---
<!-- 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 #13877.
<!-- Either: -->
- [X] There are tests for these changes
<!-- 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/14498)
<!-- Reviewable:end -->
|
|
|
@bors-servo retry |
|
|
|
|
|
This is intermittent, updated #13919 |
|
|
dpyro commentedDec 8, 2016
•
edited
Implemented as per the MDN documentation—I could not find a current CSS draft. I am not sure if this is the complete correct metadata for the longhand helper:
Also I am not sure how to test this and would appreciate help in creating a testing strategy.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is