mirror of
https://github.com/servo/servo.git
synced 2025-08-17 11:25:35 +01:00
Refactor BorderRadius and move it to the border modules
BorderRadius now parses itself reusing Rect<T>.
This commit is contained in:
parent
4144dc74db
commit
af3ede418b
20 changed files with 269 additions and 286 deletions
|
@ -8,6 +8,7 @@ use style::properties::MaybeBoxed;
|
|||
use style::properties::longhands::{border_image_outset, border_image_repeat, border_image_slice};
|
||||
use style::properties::longhands::{border_image_source, border_image_width};
|
||||
use style::properties::shorthands::border_image;
|
||||
use style::values::specified::BorderRadius;
|
||||
use style_traits::ToCss;
|
||||
|
||||
macro_rules! assert_longhand {
|
||||
|
@ -22,6 +23,64 @@ macro_rules! assert_initial {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! assert_border_radius_values {
|
||||
($input:expr; $tlw:expr, $trw:expr, $brw:expr, $blw:expr ;
|
||||
$tlh:expr, $trh:expr, $brh:expr, $blh:expr) => {
|
||||
let input = parse(BorderRadius::parse, $input)
|
||||
.expect(&format!("Failed parsing {} as border radius",
|
||||
$input));
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.top_left.0.width), $tlw);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.top_right.0.width), $trw);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.bottom_right.0.width), $brw);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.bottom_left.0.width), $blw);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.top_left.0.height), $tlh);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.top_right.0.height), $trh);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.bottom_right.0.height), $brh);
|
||||
assert_eq!(::style_traits::ToCss::to_css_string(&input.bottom_left.0.height), $blh);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_border_radius() {
|
||||
assert_border_radius_values!("10px";
|
||||
"10px", "10px", "10px", "10px" ;
|
||||
"10px", "10px", "10px", "10px");
|
||||
assert_border_radius_values!("10px 20px";
|
||||
"10px", "20px", "10px", "20px" ;
|
||||
"10px", "20px", "10px", "20px");
|
||||
assert_border_radius_values!("10px 20px 30px";
|
||||
"10px", "20px", "30px", "20px" ;
|
||||
"10px", "20px", "30px", "20px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"10px", "20px", "30px", "40px");
|
||||
assert_border_radius_values!("10% / 20px";
|
||||
"10%", "10%", "10%", "10%" ;
|
||||
"20px", "20px", "20px", "20px");
|
||||
assert_border_radius_values!("10px / 20px 30px";
|
||||
"10px", "10px", "10px", "10px" ;
|
||||
"20px", "30px", "20px", "30px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"1px", "2px", "3px", "4px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"1px", "2px", "3px", "4px");
|
||||
assert_border_radius_values!("10px 20px 30px 40px / 1px 2px 3px 4px";
|
||||
"10px", "20px", "30px", "40px" ;
|
||||
"1px", "2px", "3px", "4px");
|
||||
assert_border_radius_values!("10px -20px 30px 40px";
|
||||
"10px", "10px", "10px", "10px";
|
||||
"10px", "10px", "10px", "10px");
|
||||
assert_border_radius_values!("10px 20px -30px 40px";
|
||||
"10px", "20px", "10px", "20px";
|
||||
"10px", "20px", "10px", "20px");
|
||||
assert_border_radius_values!("10px 20px 30px -40px";
|
||||
"10px", "20px", "30px", "20px";
|
||||
"10px", "20px", "30px", "20px");
|
||||
assert!(parse(BorderRadius::parse, "-10px 20px 30px 40px").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn border_image_shorthand_should_parse_when_all_properties_specified() {
|
||||
let input = "linear-gradient(red, blue) 30 30% 45 fill / 20px 40px / 10px round stretch";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue