mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Properly parse text-shadow property
This commit is contained in:
parent
7fc01437f4
commit
1e975b9833
1 changed files with 15 additions and 52 deletions
|
@ -720,6 +720,7 @@ ${helpers.single_keyword("text-align-last",
|
|||
use cssparser;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::specified::Shadow;
|
||||
use values::HasViewportPercentage;
|
||||
|
||||
impl HasViewportPercentage for SpecifiedValue {
|
||||
|
@ -750,6 +751,17 @@ ${helpers.single_keyword("text-align-last",
|
|||
pub color: Option<specified::CSSColor>,
|
||||
}
|
||||
|
||||
impl From<Shadow> for SpecifiedTextShadow {
|
||||
fn from(shadow: Shadow) -> SpecifiedTextShadow {
|
||||
SpecifiedTextShadow {
|
||||
offset_x: shadow.offset_x,
|
||||
offset_y: shadow.offset_y,
|
||||
blur_radius: shadow.blur_radius,
|
||||
color: shadow.color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod computed_value {
|
||||
use app_units::Au;
|
||||
use cssparser::Color;
|
||||
|
@ -842,61 +854,12 @@ ${helpers.single_keyword("text-align-last",
|
|||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
Ok(SpecifiedValue(Vec::new()))
|
||||
} else {
|
||||
input.parse_comma_separated(|i| parse_one_text_shadow(context, i)).map(SpecifiedValue)
|
||||
input.parse_comma_separated(|i| {
|
||||
Ok(SpecifiedTextShadow::from(Shadow::parse(context, i, true)?))
|
||||
}).map(SpecifiedValue)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_one_text_shadow(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedTextShadow,()> {
|
||||
use app_units::Au;
|
||||
let mut lengths = [specified::Length::zero(), specified::Length::zero(), specified::Length::zero()];
|
||||
let mut lengths_parsed = false;
|
||||
let mut color = None;
|
||||
|
||||
loop {
|
||||
if !lengths_parsed {
|
||||
if let Ok(value) = input.try(|i| specified::Length::parse(context, i)) {
|
||||
lengths[0] = value;
|
||||
let mut length_parsed_count = 1;
|
||||
while length_parsed_count < 3 {
|
||||
if let Ok(value) = input.try(|i| specified::Length::parse(context, i)) {
|
||||
lengths[length_parsed_count] = value
|
||||
} else {
|
||||
break
|
||||
}
|
||||
length_parsed_count += 1;
|
||||
}
|
||||
|
||||
// The first two lengths must be specified.
|
||||
if length_parsed_count < 2 {
|
||||
return Err(())
|
||||
}
|
||||
|
||||
lengths_parsed = true;
|
||||
continue
|
||||
}
|
||||
}
|
||||
if color.is_none() {
|
||||
if let Ok(value) = input.try(|i| specified::CSSColor::parse(context, i)) {
|
||||
color = Some(value);
|
||||
continue
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// Lengths must be specified.
|
||||
if !lengths_parsed {
|
||||
return Err(())
|
||||
}
|
||||
|
||||
Ok(SpecifiedTextShadow {
|
||||
offset_x: lengths[0].take(),
|
||||
offset_y: lengths[1].take(),
|
||||
blur_radius: lengths[2].take(),
|
||||
color: color,
|
||||
})
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue