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 upImplement border-image-* longhands in stylo #13989
Conversation
highfive
commented
Oct 30, 2016
highfive
commented
Oct 30, 2016
|
overall lgtm, minor nits. Would be nice if you could make common utility functions for the |
| @@ -91,3 +91,749 @@ ${helpers.single_keyword("-moz-float-edge", "content-box margin-box", | |||
| gecko_enum_prefix="StyleFloatEdge", | |||
| products="gecko", | |||
| animatable=False)} | |||
|
|
|||
| <%helpers:longhand name="border-image-source" products="none" animatable="False"> | |||
This comment has been minimized.
This comment has been minimized.
| let length = self.0.len(); | ||
|
|
||
| try!(self.0[0].to_css(dest)); | ||
| if length > 1 { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 31, 2016
Member
Just loop through self.0.iter().skip(1) emitting a space and the element each iteration.
| pub struct SpecifiedValue(pub SingleSpecifiedValue, | ||
| pub Option<SingleSpecifiedValue>); | ||
|
|
||
| define_css_keyword_enum!(SingleSpecifiedValue: |
This comment has been minimized.
This comment has been minimized.
| let length = self.0.len(); | ||
|
|
||
| try!(self.0[0].to_css(dest)); | ||
| if length > 1 { |
This comment has been minimized.
This comment has been minimized.
| } | ||
| } | ||
|
|
||
| impl SingleSpecifiedValue { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 31, 2016
Member
nit: Make this an impl of Parse since you're not using the context anyway
| } | ||
|
|
||
| let length = input.try(|input| LengthOrPercentage::parse(input)); | ||
| if let Ok(len) = length { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Oct 31, 2016
Member
nit: Collapse this into a single if let? Unless there are line size issues.
| fn from_computed_value(computed: &computed_value::SingleComputedValue) -> Self { | ||
| match *computed { | ||
| computed_value::SingleComputedValue::LengthOrPercentage(len) => | ||
| SingleSpecifiedValue::LengthOrPercentage(ToComputedValue::from_computed_value(&len)), |
This comment has been minimized.
This comment has been minimized.
| fn to_computed_value(&self, context: &Context) -> computed_value::SingleComputedValue { | ||
| match *self { | ||
| SingleSpecifiedValue::LengthOrPercentage(len) => | ||
| computed_value::SingleComputedValue::LengthOrPercentage(len.to_computed_value(context)), |
This comment has been minimized.
This comment has been minimized.
| let length = self.corners.len(); | ||
|
|
||
| try!(self.corners[0].to_css(dest)); | ||
| if length > 1 { |
This comment has been minimized.
This comment has been minimized.
| fn parse(input: &mut Parser) -> Result<Self, ()> { | ||
| let context = AllowedNumericType::All; | ||
| match try!(input.next()) { | ||
| Token::Percentage(ref value) if context.is_ok(value.unit_value) => |
This comment has been minimized.
This comment has been minimized.
|
@Manishearth I pushed a commit about refactoring image code and implementing |
| } | ||
|
|
||
| if let Some(image) = v.0 { | ||
| set_image(image, &mut self.gecko.mBorderImageSource) |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 2, 2016
Member
fwiw this could be a method on nsStyleImage in gecko_conversions.rs. But not necessary, this is fine too.
| Image::Gradient(gradient) => { | ||
| set_gradient(gradient, &mut geckoimage) | ||
| }, | ||
| Image::Url(..) => { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 2, 2016
Member
There should be a third argument, with_url, that turns on this branch. (Image::Url if with_url => ..). The if shorthand == "background" above needs to set with_url.
| background-image: url() not yet implemented"); | ||
| } | ||
| } | ||
| set_image(image, &mut geckoimage.mImage) |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 2, 2016
Member
Both branches of the if shorthand do the same thing now. We need to pass a boolean arg down.
This comment has been minimized.
This comment has been minimized.
canova
Nov 2, 2016
Author
Member
@Manishearth It looks like else branch has only one more match pattern than if branch. And I kept that match in else part. Moved the inner match pattern which looks pretty same. In if branch, Image::Url prints a warning about url and in else branch, it does nothing except gradient(with this line _ => () // we need to support image values) I thought we can give a warning in else branch too since url's not implemented in both. Should I check this still?
This comment has been minimized.
This comment has been minimized.
canova
Nov 2, 2016
•
Author
Member
Oh, actually I have a merge conflict in these lines. The new changes forces to do what you said, changing as you said.
This comment has been minimized.
This comment has been minimized.
|
Great! Let me know when you have it tested! |
| @@ -1466,6 +1296,195 @@ fn static_assert() { | |||
| } | |||
| </%def> | |||
|
|
|||
| fn set_image(image: Image, mut geckoimage: &mut structs::nsStyleImage, with_url: bool, cacheable: &mut bool) { | |||
This comment has been minimized.
This comment has been minimized.
canova
Nov 2, 2016
Author
Member
I needed to add another reference parameter to pass cacheable variable after resolving merge conflicts.
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 2, 2016
Member
Good. Ultimately we need to make the border-image-source glue match background-image, but for now set with_url to false for border-image-source and leave a todo comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
canova
Nov 4, 2016
Author
Member
I'm moving it. But I'm also moving set_gradient into impl nsStyleImage is it ok?
This comment has been minimized.
This comment has been minimized.
|
Implemented their stylo glue and tested them in stylo. They're working currently. But in a special case, Firefox 51 acts different from stylo and chrome. It might be a gecko bug. I'll post a screenshot soon. From now on, I want to move image code to |
|
Test case:
|
|
|
||
| for (i, corner) in v.corners.iter().enumerate() { | ||
| match *corner { | ||
| PercentageOrNumber::Percentage(p) => |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 3, 2016
Member
You can impl ToGeckoStyleCoordConvertible or whatever that trait is in style::gecko::values for PercentageorNumber to make this cleaner.
This comment has been minimized.
This comment has been minimized.
canova
Nov 4, 2016
Author
Member
Oh the LengthOrNumber is actually single value of border_image_outset. It's not actually stored in style/values/.., it's stored in border_image_outset longhand. Should I implement it still?
This comment has been minimized.
This comment has been minimized.
|
@Manishearth Made the changes :) |
| use gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_REPEAT_ROUND, NS_STYLE_BORDER_IMAGE_REPEAT_SPACE}; | ||
| let mut keywords = vec![]; | ||
|
|
||
| % for side in range(2): |
This comment has been minimized.
This comment has been minimized.
Manishearth
Nov 5, 2016
Member
Don't create a vector here, just set directly. for i,side in enumerate(["H", "V"]) will help.
| % for side in SIDES: | ||
| match v.${side.index} { | ||
| SingleComputedValue::Auto => | ||
| self.gecko.mBorderImageWidth.data_at_mut(${side.index}).set_value(CoordDataValue::Auto), |
This comment has been minimized.
This comment has been minimized.
| PercentageOrNumber::Percentage(p) => | ||
| self.gecko.mBorderImageSlice.data_at_mut(i).set_value(CoordDataValue::Percent(p.0)), | ||
| PercentageOrNumber::Number(n) => | ||
| self.gecko.mBorderImageSlice.data_at_mut(i).set_value(CoordDataValue::Factor(n)), |
This comment has been minimized.
This comment has been minimized.
|
Minor issues, r=me with them fixed @bors-servo delegate+ |
|
|
|
|
||
| impl Parse for LengthOrNumber { | ||
| fn parse(input: &mut Parser) -> Result<Self, ()> { | ||
| let length = input.try(|input| Length::parse(input)); |
This comment has been minimized.
This comment has been minimized.
|
|
|
The other PR merged, you probably can rebase and land this now. |
|
@bors-servo r=Manishearth |
|
|
Implement border-image-* longhands in stylo
Implementation of border-image-\* longhands in stylo. PR covers just parsing/serialization part for now. I'll write gecko glue next.
I wanted to open a WIP pr to get early feedback about these parts. I made a `SingleSpecifiedValue` enums to handle {1, 4} values. I'm not sure about naming. I did like this because `keyword_list` helper is doing similar.
r? @emilio or @Manishearth
---
<!-- 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
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- 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/13989)
<!-- Reviewable:end -->
|
|

canova commentedOct 30, 2016
•
edited by larsbergstrom
Implementation of border-image-* longhands in stylo. PR covers just parsing/serialization part for now. I'll write gecko glue next.
I wanted to open a WIP pr to get early feedback about these parts. I made a
SingleSpecifiedValueenums to handle {1, 4} values. I'm not sure about naming. I did like this becausekeyword_listhelper is doing similar.r? @emilio or @Manishearth
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is