Skip to content

Fix parsing behavior of text-shadow property#16754

Merged
bors-servo merged 2 commits intoservo:masterfrom
canova:text-shadow
May 6, 2017
Merged

Fix parsing behavior of text-shadow property#16754
bors-servo merged 2 commits intoservo:masterfrom
canova:text-shadow

Conversation

@canova
Copy link
Copy Markdown
Contributor

@canova canova commented May 6, 2017

Blur radius should reject negative values. There was already Shadow struct for properties like this. filter: drop-shadow also has the same syntax with that property. I thought sharing the same code would be better and used Shadow struct for parsing. Converted to SpecifiedTextShadow to get rid of unneccessary fields and to be able to convert its computed value. Maybe it would be better to avoid using Shadow or just using Shadow but sharing code and avoiding unneccessary fields seems better.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors

This change is Reviewable

@highfive
Copy link
Copy Markdown

highfive commented May 6, 2017

Heads up! This PR modifies the following files:

  • @bholley: components/style/properties/longhand/inherited_text.mako.rs
  • @emilio: components/style/properties/longhand/inherited_text.mako.rs

@highfive
Copy link
Copy Markdown

highfive commented May 6, 2017

warning Warning warning

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

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label May 6, 2017
Copy link
Copy Markdown
Member

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, if you double-check they use the exact same parsing rules. If so, r=me with or without the nit below.

let mut iter = self.0.iter();
if let Some(shadow) = iter.next() {
try!(shadow.to_css(dest));
shadow.to_css(dest)?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given you're refactoring all this, why not:

match iter.next() {
    Some(shadow) => shadow.to_css(dest)?,
    None => return dest.write_str("none"),
}
// ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that looks better.

}

impl From<Shadow> for SpecifiedTextShadow {
fn from(shadow: Shadow) -> SpecifiedTextShadow {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given it's pretty much the same type, and they share parsing, the only thing that differs is the to_computed_value impl, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, also Shadow has 2 additional fields but they are not getting parsed if disable_spread_and_inset argument is true in parse method(which is true in that property).

@canova
Copy link
Copy Markdown
Contributor Author

canova commented May 6, 2017

I double-checked parsing methods and they are nearly same except third value rejects negative values in Shadow. Fortunately that's what we need :)

@bors-servo r=emilio

@bors-servo
Copy link
Copy Markdown
Contributor

📌 Commit c072f3a has been approved by emilio

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels May 6, 2017
@bors-servo
Copy link
Copy Markdown
Contributor

⌛ Testing commit c072f3a with merge bd2cd40...

bors-servo pushed a commit that referenced this pull request May 6, 2017
Fix parsing behavior of text-shadow property

Blur radius should reject negative values. There was already `Shadow` struct for properties like this. `filter: drop-shadow` also has the same syntax with that property. I thought sharing the same code would be better and used Shadow struct for parsing. Converted to SpecifiedTextShadow to get rid of unneccessary fields and to be able to convert its computed value. Maybe it would be better to avoid using `Shadow` or just using `Shadow` but sharing code and avoiding unneccessary fields seems better.

---
<!-- 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

<!-- 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/16754)
<!-- Reviewable:end -->
@bors-servo
Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css, mac-rel-wpt1, mac-rel-wpt2, windows-msvc-dev
Approved by: emilio
Pushing bd2cd40 to master...

@bors-servo bors-servo merged commit c072f3a into servo:master May 6, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label May 6, 2017
@canova canova deleted the text-shadow branch May 8, 2017 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants