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

Added image-orientation property #14498

Merged
merged 1 commit into from Dec 11, 2016
Merged

Conversation

@dpyro
Copy link
Contributor

dpyro commented Dec 8, 2016

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.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13877.
  • There are tests for these changes

This change is Reviewable

Copy link
Member

Manishearth left a comment

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.

@Manishearth

Manishearth Dec 8, 2016

Member

Please remove these

@@ -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.

@Manishearth

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.

@wafflespeanut

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.

@dpyro

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.

@wafflespeanut

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.

@canova

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.

@dpyro

dpyro Dec 8, 2016

Author Contributor

I will double-check but it would not take a plain 0 by itself.

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.

@wafflespeanut

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.

@dpyro

dpyro Dec 8, 2016

Author Contributor

Yes, this is a careless error. I will be testing to make sure I have the correct implementation.

@Manishearth
Copy link
Member

Manishearth commented Dec 9, 2016

@highfive highfive assigned canova and unassigned Manishearth Dec 9, 2016
@KiChjang
Copy link
Member

KiChjang commented Dec 9, 2016

@bors-servo delegate=canaltinova

@bors-servo
Copy link
Contributor

bors-servo commented Dec 9, 2016

✌️ @canaltinova can now approve this pull request

Copy link
Member

canova left a comment

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.

@canova

canova Dec 9, 2016

Member

You can remove this line I think. This property is not used by servo yet.

@@ -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.

@canova

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.

@canova

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.

@dpyro

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.

@canova

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.

@canova

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.

@dpyro

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.

@canova

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.

@canova

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.

@Manishearth

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.

@canova

canova Dec 9, 2016

Member

nit: These declarations can be moved to top, where other use declarations are.

Copy link
Member

canova left a comment

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.

@canova

canova Dec 9, 2016

Member

Well, I didn't quite understand this function but I tried with some numbers and it looks working 😄

@dpyro
Copy link
Contributor Author

dpyro commented Dec 10, 2016

@canaltinova How would I go about squashing the commits?

@canova
Copy link
Member

canova commented Dec 10, 2016

@dpyro dpyro force-pushed the dpyro:image-orientation branch from 81bfff1 to faddb0c Dec 10, 2016
@canova
Copy link
Member

canova commented Dec 10, 2016

@bors-servo r+
Thanks for doing this!

@bors-servo
Copy link
Contributor

bors-servo commented Dec 10, 2016

📌 Commit faddb0c has been approved by canaltinova

@bors-servo
Copy link
Contributor

bors-servo commented Dec 10, 2016

Testing commit faddb0c with merge 5c2d401...

bors-servo added a commit that referenced this pull request Dec 10, 2016
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
Copy link
Contributor

bors-servo commented Dec 10, 2016

💔 Test failed - mac-rel-wpt2

@canova
Copy link
Member

canova commented Dec 10, 2016

@bors-servo retry

  • network error
@bors-servo
Copy link
Contributor

bors-servo commented Dec 10, 2016

Testing commit faddb0c with merge 37c4051...

bors-servo added a commit that referenced this pull request Dec 10, 2016
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
Copy link
Contributor

bors-servo commented Dec 10, 2016

💔 Test failed - linux-rel-css

@KiChjang
Copy link
Member

KiChjang commented Dec 11, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 11, 2016

Previous build results for arm32, arm64, linux-dev, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev are reusable. Rebuilding only linux-rel-css...

@bors-servo
Copy link
Contributor

bors-servo commented Dec 11, 2016

Previous build results for arm32, arm64, linux-dev, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-dev are reusable. Rebuilding only linux-rel-css...

@Manishearth
Copy link
Member

Manishearth commented Dec 11, 2016

This is intermittent, updated #13919

@bors-servo
Copy link
Contributor

bors-servo commented Dec 11, 2016

@bors-servo bors-servo merged commit faddb0c into servo:master Dec 11, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

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