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 border-image-* longhands in stylo #13989

Merged
merged 8 commits into from Nov 6, 2016
Merged

Conversation

@canova
Copy link
Member

canova commented Oct 30, 2016

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


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

@highfive
Copy link

highfive commented Oct 30, 2016

Heads up! This PR modifies the following files:

  • @bholley: components/style/values/specified/mod.rs, components/style/properties/longhand/border.mako.rs
  • @emilio: components/style/values/specified/mod.rs, components/style/properties/longhand/border.mako.rs
@highfive
Copy link

highfive commented Oct 30, 2016

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!
Copy link
Member

Manishearth left a comment

overall lgtm, minor nits.

Would be nice if you could make common utility functions for the {1,4} ones (seems tricky though). Might need a generic type "FourSidesComputed" for the computed value instead of individual tuple structs. We already have parse_four_sides but that's different iirc.

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

@Manishearth

Manishearth Oct 31, 2016

Member

spec links for all, please

let length = self.0.len();

try!(self.0[0].to_css(dest));
if length > 1 {

This comment has been minimized.

@Manishearth

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.

@Manishearth

Manishearth Oct 31, 2016

Member

nit: probably call it RepeatKeyword?

let length = self.0.len();

try!(self.0[0].to_css(dest));
if length > 1 {

This comment has been minimized.

@Manishearth

Manishearth Oct 31, 2016

Member

same comment about looping

}
}

impl SingleSpecifiedValue {

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@Manishearth

Manishearth Oct 31, 2016

Member

nit: wrap this somehow.

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.

@Manishearth

Manishearth Oct 31, 2016

Member

nit: wrap this somehow

let length = self.corners.len();

try!(self.corners[0].to_css(dest));
if length > 1 {

This comment has been minimized.

@Manishearth

Manishearth Oct 31, 2016

Member

ditto about looping

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.

@Manishearth

Manishearth Oct 31, 2016

Member

surprised we didn't have this already

@canova canova force-pushed the canova:border-image branch from 0b298c5 to 03eddf3 Nov 2, 2016
@canova
Copy link
Member Author

canova commented Nov 2, 2016

@Manishearth I pushed a commit about refactoring image code and implementing border-image-source glue. I couldn't test it with a stylo build yet. But it builds with build-geckolib.

}

if let Some(image) = v.0 {
set_image(image, &mut self.gecko.mBorderImageSource)

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@Manishearth

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.

@canova

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.

@canova

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.

@Manishearth

Manishearth Nov 2, 2016

Member

Yeah, the ongoing background-image: url work makes that if necessary

@Manishearth
Copy link
Member

Manishearth commented Nov 2, 2016

Great! Let me know when you have it tested!

@canova canova force-pushed the canova:border-image branch from 03eddf3 to f88008c Nov 2, 2016
@@ -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.

@canova

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.

@Manishearth

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.

@Manishearth

Manishearth Nov 4, 2016

Member

I would make this a method on nsStyleImage btw.

This comment has been minimized.

@canova

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.

@Manishearth

Manishearth Nov 4, 2016

Member

Yep. Make it private.

@canova canova force-pushed the canova:border-image branch from f88008c to aa6d303 Nov 3, 2016
@canova
Copy link
Member Author

canova commented Nov 3, 2016

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 gecko_conversions.rs as you mentioned.
Also maybe we can write a helper for handling 4 sided attributes?

@canova
Copy link
Member Author

canova commented Nov 3, 2016

Test case:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        #box {
            border: 100px solid transparent;
            border-image-source: linear-gradient(red, blue);
            border-image-slice: 30 30% 45 fill;
            border-image-width: 20px 40px;
            border-image-repeat: round;
        }
    </style>
</head>
<body>
<div id="box"></div>
</body>
</html>

comparison


for (i, corner) in v.corners.iter().enumerate() {
match *corner {
PercentageOrNumber::Percentage(p) =>

This comment has been minimized.

@Manishearth

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.

@canova

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.

@Manishearth

Manishearth Nov 4, 2016

Member

Yes. You can also move it into style::values::* :)

@canova canova force-pushed the canova:border-image branch from aa6d303 to c5b90ac Nov 4, 2016
@canova
Copy link
Member Author

canova commented Nov 4, 2016

@Manishearth Made the changes :)

@canova canova changed the title [WIP] Implement border-image-* longhands in stylo Implement border-image-* longhands in stylo Nov 4, 2016
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.

@Manishearth

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.

@Manishearth

Manishearth Nov 5, 2016

Member

Use braces here (and below)

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.

@Manishearth

Manishearth Nov 5, 2016

Member

braces in this function too

@Manishearth
Copy link
Member

Manishearth commented Nov 5, 2016

Minor issues, r=me with them fixed

@bors-servo delegate+

@bors-servo
Copy link
Contributor

bors-servo commented Nov 5, 2016

✌️ @canaltinova can now approve this pull request


impl Parse for LengthOrNumber {
fn parse(input: &mut Parser) -> Result<Self, ()> {
let length = input.try(|input| Length::parse(input));

This comment has been minimized.

@emilio

emilio Nov 5, 2016

Member

nit: This can be written input.try(Length::parse)

@canova canova force-pushed the canova:border-image branch from c5b90ac to 570aa24 Nov 5, 2016
@bors-servo
Copy link
Contributor

bors-servo commented Nov 6, 2016

The latest upstream changes (presumably #14077) made this pull request unmergeable. Please resolve the merge conflicts.

@Manishearth
Copy link
Member

Manishearth commented Nov 6, 2016

The other PR merged, you probably can rebase and land this now.

@canova canova force-pushed the canova:border-image branch from 570aa24 to 7720fe4 Nov 6, 2016
@canova
Copy link
Member Author

canova commented Nov 6, 2016

@bors-servo r=Manishearth
Rebased thanks.

@bors-servo
Copy link
Contributor

bors-servo commented Nov 6, 2016

📌 Commit 7720fe4 has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Nov 6, 2016

Testing commit 7720fe4 with merge 60e09ad...

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

bors-servo commented Nov 6, 2016

@bors-servo bors-servo merged commit 7720fe4 into servo:master Nov 6, 2016
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/appveyor/pr AppVeyor build failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@canova canova deleted the canova:border-image branch Nov 7, 2016
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.

None yet

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