mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Change code for serialization of {box,text}-shadow so blur-radius
can be parsed as non-negavite
This commit is contained in:
parent
4757a9b712
commit
f30537ba2b
2 changed files with 18 additions and 15 deletions
|
@ -639,7 +639,6 @@ impl Shadow {
|
||||||
// disable_spread_and_inset is for filter: drop-shadow(...)
|
// disable_spread_and_inset is for filter: drop-shadow(...)
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result<Shadow, ()> {
|
pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result<Shadow, ()> {
|
||||||
let length_count = if disable_spread_and_inset { 3 } else { 4 };
|
|
||||||
let mut lengths = [Length::zero(), Length::zero(), Length::zero(), Length::zero()];
|
let mut lengths = [Length::zero(), Length::zero(), Length::zero(), Length::zero()];
|
||||||
let mut lengths_parsed = false;
|
let mut lengths_parsed = false;
|
||||||
let mut color = None;
|
let mut color = None;
|
||||||
|
@ -655,21 +654,15 @@ impl Shadow {
|
||||||
if !lengths_parsed {
|
if !lengths_parsed {
|
||||||
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
|
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
|
||||||
lengths[0] = value;
|
lengths[0] = value;
|
||||||
let mut length_parsed_count = 1;
|
lengths[1] = try!(Length::parse(context, input));
|
||||||
while length_parsed_count < length_count {
|
if let Ok(value) = input.try(|i| Length::parse_non_negative(i)) {
|
||||||
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
|
lengths[2] = value;
|
||||||
lengths[length_parsed_count] = value
|
if !disable_spread_and_inset {
|
||||||
} else {
|
if let Ok(value) = input.try(|i| Length::parse(context, i)) {
|
||||||
break
|
lengths[3] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
length_parsed_count += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The first two lengths must be specified.
|
|
||||||
if length_parsed_count < 2 {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
|
|
||||||
lengths_parsed = true;
|
lengths_parsed = true;
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -688,11 +681,12 @@ impl Shadow {
|
||||||
return Err(())
|
return Err(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_assert!(!disable_spread_and_inset || lengths[3] == Length::zero());
|
||||||
Ok(Shadow {
|
Ok(Shadow {
|
||||||
offset_x: lengths[0].take(),
|
offset_x: lengths[0].take(),
|
||||||
offset_y: lengths[1].take(),
|
offset_y: lengths[1].take(),
|
||||||
blur_radius: lengths[2].take(),
|
blur_radius: lengths[2].take(),
|
||||||
spread_radius: if disable_spread_and_inset { Length::zero() } else { lengths[3].take() },
|
spread_radius: lengths[3].take(),
|
||||||
color: color,
|
color: color,
|
||||||
inset: inset,
|
inset: inset,
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
use cssparser::Parser;
|
use cssparser::Parser;
|
||||||
use media_queries::CSSErrorReporterTest;
|
use media_queries::CSSErrorReporterTest;
|
||||||
|
use parsing::parse;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use style::parser::ParserContext;
|
use style::parser::ParserContext;
|
||||||
use style::properties::longhands::{self, perspective_origin, transform_origin};
|
use style::properties::longhands::{self, perspective_origin, transform_origin};
|
||||||
|
@ -106,3 +107,11 @@ fn test_parse_factor() {
|
||||||
assert!(parse(filter::parse, "sepia(-1)").is_err());
|
assert!(parse(filter::parse, "sepia(-1)").is_err());
|
||||||
assert!(parse(filter::parse, "saturate(-1)").is_err());
|
assert!(parse(filter::parse, "saturate(-1)").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn blur_radius_should_not_accept_negavite_values() {
|
||||||
|
use style::properties::longhands::box_shadow;
|
||||||
|
assert!(parse(box_shadow::parse, "1px 1px -1px").is_err());// for -ve values
|
||||||
|
assert!(parse(box_shadow::parse, "1px 1px 0").is_ok());// for zero
|
||||||
|
assert!(parse(box_shadow::parse, "1px 1px 1px").is_ok());// for +ve value
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue