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 upHandle 3- and 4- valued <position>s in style #13042
Conversation
highfive
commented
Aug 25, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Aug 25, 2016
|
@Manishearth Sorry accidentally deleted the branch and it closed the other pr :( (-d instead of -f) Updated the commit could you look at it when you are available? This is not building yet. |
| keyword == Keyword::Top => LengthOrPercentage::Percentage(Percentage(0.0)), | ||
| PositionComponent::Keyword(keyword) if keyword == Keyword::Right || | ||
| keyword == Keyword::Bottom => LengthOrPercentage::Percentage(Percentage(1.0)), | ||
| PositionComponent::Keyword(_) => unimplemented!(), // TODO: All keywords are covered but rust forcing me to add this too? |
This comment has been minimized.
This comment has been minimized.
izgzhen
Aug 25, 2016
Contributor
Maybe match further on keyword looks better and eliminate the compiler's complain?
This comment has been minimized.
This comment has been minimized.
canova
Aug 26, 2016
Author
Member
You are right. Probably this is better solution. I'll update soon, thanks!
| @@ -265,8 +265,10 @@ impl Circle { | |||
| } else { | |||
| // Defaults to origin | |||
| Position { | |||
| horizontal: LengthOrPercentage::Percentage(Percentage(0.5)), | |||
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| impl ToCss for Position { | ||
| fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { | ||
| try!(self.horizontal.to_css(dest)); | ||
| // TODO: canaltinova: We should add keywords, probably? |
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 26, 2016
Member
Yes, this could also be just a keyword. Print the components in order, with spaces between them if they exist.
This comment has been minimized.
This comment has been minimized.
canova
Aug 26, 2016
•
Author
Member
Actually if background position is center bottom 10px, Position::parse function sends center as value and it stores as 50% bottom 10px. Keywords are storing if second keyword is explicitly defined. Otherwise it's assuming LengthOrPercentage. Is it a bad behaviour? If so, we have to check PositionComponents at Position::parse whether if they are keyword or length.
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 26, 2016
Member
Yes, this is not the right behavior. This was done because basic-shape has different requirements for Position serialization, which I now know to not generalize to all positions.
We should store keywords as-is, and only reorder. The ToCss impl should be relatively simple, so that we can add any additional complexity to the basic-shape side. It's fine if you break basic-shape for now, I'll fix it later.
| -> Result<Position, ()> { | ||
| let (horiz, vert) = match (category(first), category(second)) { | ||
| // Check firts and second positions, this is more like for 2 value backgrounds. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Could you write tests for these in tests/unit/style/parsing/position.rs (by using the examples from the spec)? Your changes may make the basic shape tests fail. That is okay, comment them out for now, I'll fix them later. basic-shape serializes positions differently. |
| if let Ok(third) = input.try(PositionComponent::parse) { | ||
| if let Ok(fourth) = input.try(PositionComponent::parse) { | ||
| // Handle 4 value background position | ||
| Position::new(Some(second), Some(fourth), Some(first), Some(third)) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| impl ToCss for Keyword { | ||
| fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { | ||
| match *self { | ||
| Keyword::Right => try!(dest.write_str("right ")), |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
canova
Aug 26, 2016
Author
Member
I didn't write them because of comment above. Just explicit keywords are storing.
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 26, 2016
Member
This is also wrong, my bad: we want to store explicit keywords for background-positions and general positions. basic-shape needs special treatment whilst serializing.
| @@ -107,16 +233,16 @@ impl ToComputedValue for Position { | |||
| #[inline] | |||
| fn to_computed_value(&self, context: &Context) -> computed_position::Position { | |||
| computed_position::Position { | |||
| horizontal: self.horizontal.to_computed_value(context), | |||
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 26, 2016
Member
This shouldn't be too hard to implement now. You can convert each position to a pair of Options for length and percentage, and then construct a calc value out of them. In case the keyword is right or bottom, you make the len/percentage negative and add 100%. For center, you add 50% but don't make it negative.
|
@Manishearth Made a new commit can you review when you have time? I made a new commit instead of squashing first, so you can review more easily. After last changes I can squash them. |
| assert_roundtrip!(Position::parse, "right 10px bottom", "right 10px bottom"); | ||
| assert_roundtrip!(Position::parse, "bottom right 10px", "right 10px bottom"); | ||
| assert_roundtrip!(Position::parse, "center right 10px", "right 10px center"); | ||
| assert_roundtrip!(Position::parse, "center bottom 10px", "center bottom 10px"); |
This comment has been minimized.
This comment has been minimized.
canova
Aug 27, 2016
Author
Member
Added some additional example apart from specs to cover most of cases.
| @@ -77,6 +77,7 @@ fn test_border_radius() { | |||
|
|
|||
| #[test] | |||
| fn test_circle() { | |||
| /* | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 27, 2016
Member
Open an issue and leave a comment linking to them
(or just link to a comment on this issue)
This comment has been minimized.
This comment has been minimized.
| assert_roundtrip!(Position::parse, "center bottom", "center bottom"); | ||
| assert_roundtrip!(Position::parse, "center 10px", "center 10px"); | ||
| assert_roundtrip!(Position::parse, "center 10%", "center 10%"); | ||
| assert_roundtrip!(Position::parse, "right 10%", "right 10%"); |
This comment has been minimized.
This comment has been minimized.
| } | ||
| }, | ||
| Keyword::Center => { | ||
| horiz_keyword.to_length_or_percentage().to_computed_value(context) |
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 27, 2016
Member
center is 50% + length, so you need to take the length, and add 50% to its calc value percentage
This comment has been minimized.
This comment has been minimized.
canova
Aug 27, 2016
Author
Member
I wrote in irc but I'm writing here just in case :)
By 50% + length you mean we can write positions like this center 10px center 10px? I tried it in firefox and chrome but it seems invalid. And spec is also agree:
[ center | [ left | right ] ? ] &&
[ center | [ top | bottom ] ? ]
But I might misunderstood your comment I'm not sure :)
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 28, 2016
Member
No, you are right. Make sure you error if the length is anything but none here.
|
Looking good, with a few small issues. |
| }; | ||
|
|
||
| // Unwrap positions from PositionComponent and wrap with Option | ||
| let (horiz_position, vert_position) = if let Some(PositionComponent::Length(horiz_pos)) = first_position { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Aug 27, 2016
Member
You can use match first_position, second_position) here. But this is ok too.
This comment has been minimized.
This comment has been minimized.
|
@bors-servo try |
Handle 3- and 4- valued <position>s in style <!-- Please describe your changes on the following line: --> This is first part of fix #12690 and covers just specified style part for now. r? @Manishearth --- - [X] These changes fix #12690 (github issue number if applicable). <!-- 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/13042) <!-- Reviewable:end -->
|
|
highfive
commented
Aug 28, 2016
|
|
@bors-servo retry |
Handle 3- and 4- valued <position>s in style <!-- Please describe your changes on the following line: --> This is first part of fix #12690 and covers just specified style part for now. r? @Manishearth --- - [X] These changes fix #12690 (github issue number if applicable). <!-- 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/13042) <!-- Reviewable:end -->
Handle 3- and 4- valued <position>s in style <!-- Please describe your changes on the following line: --> This is first part of fix #12690 and covers just specified style part for now. r? @Manishearth --- - [X] These changes fix #12690 (github issue number if applicable). <!-- 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/13042) <!-- Reviewable:end -->
|
|
|
Needs to error on |
|
Oh, it already does, just not there. @bors-servo r+ |
|
|
|
@Manishearth Is something wrong with bors? :) |
|
@bors-servo r+ try- retry it doesn't forget the |
|
|
|
|
Handle 3- and 4- valued <position>s in style <!-- Please describe your changes on the following line: --> This is first part of fix #12690 and covers just specified style part for now. r? @Manishearth --- - [X] These changes fix #12690 (github issue number if applicable). <!-- 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/13042) <!-- Reviewable:end -->
|
|
|
Thanks! |
|
@Manishearth Thank you also for mentoring me on this :) I learned so much and you helped me a lot. I'm sorry if I took a lot of your time :) |
|
Not much of my time -- most of the time went into figuring out what we were supposed to do, which I would have had to do anyway if I'd have done it myself. And mentoring is fun and it's great to see new contributors work on this project, so it's definitely not a waste of time |
…nSapin Handle specialized serialization of <position> in basic shapes Fixes #13083 We temporarily broke basic-shape serialization in #13042 when 4-value positions were implemented, since I didn't want to increase the scope of that PR too much. This fixes it. r? @SimonSapin cc @canaltinova <!-- 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/13122) <!-- Reviewable:end -->
canova commentedAug 25, 2016
•
edited by larsbergstrom
This is first part of fix #12690 and covers just specified style part for now.
r? @Manishearth
This change is