mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Minor gradient parsing cleanup.
I suggested the compat_mode bit in D62923 but it was somehow only applied to one of the branches. Also rustfmt the code for consistency, and add a local alias. Differential Revision: https://phabricator.services.mozilla.com/D63015
This commit is contained in:
parent
25b265a10f
commit
f25e0b77e9
1 changed files with 20 additions and 20 deletions
|
@ -47,6 +47,8 @@ pub type Gradient = generic::Gradient<
|
||||||
Color,
|
Color,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
type LengthPercentageItemList = crate::OwnedSlice<generic::GradientItem<Color, LengthPercentage>>;
|
||||||
|
|
||||||
impl SpecifiedValueInfo for Gradient {
|
impl SpecifiedValueInfo for Gradient {
|
||||||
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
const SUPPORTED_TYPES: u8 = CssType::GRADIENT;
|
||||||
|
|
||||||
|
@ -189,7 +191,7 @@ impl Parse for Gradient {
|
||||||
}
|
}
|
||||||
|
|
||||||
let func = input.expect_function()?;
|
let func = input.expect_function()?;
|
||||||
let (shape, repeating, mut compat_mode) = match_ignore_ascii_case! { &func,
|
let (shape, repeating, compat_mode) = match_ignore_ascii_case! { &func,
|
||||||
"linear-gradient" => {
|
"linear-gradient" => {
|
||||||
(Shape::Linear, false, GradientCompatMode::Modern)
|
(Shape::Linear, false, GradientCompatMode::Modern)
|
||||||
},
|
},
|
||||||
|
@ -243,7 +245,7 @@ impl Parse for Gradient {
|
||||||
|
|
||||||
Ok(input.parse_nested_block(|i| {
|
Ok(input.parse_nested_block(|i| {
|
||||||
Ok(match shape {
|
Ok(match shape {
|
||||||
Shape::Linear => Self::parse_linear(context, i, repeating, &mut compat_mode)?,
|
Shape::Linear => Self::parse_linear(context, i, repeating, compat_mode)?,
|
||||||
Shape::Radial => Self::parse_radial(context, i, repeating, compat_mode)?,
|
Shape::Radial => Self::parse_radial(context, i, repeating, compat_mode)?,
|
||||||
})
|
})
|
||||||
})?)
|
})?)
|
||||||
|
@ -421,7 +423,7 @@ impl Gradient {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
reverse_stops: bool,
|
reverse_stops: bool,
|
||||||
) -> Result<crate::OwnedSlice<generic::GradientItem<Color, LengthPercentage>>, ParseError<'i>> {
|
) -> Result<LengthPercentageItemList, ParseError<'i>> {
|
||||||
let mut items = input
|
let mut items = input
|
||||||
.try(|i| {
|
.try(|i| {
|
||||||
i.expect_comma()?;
|
i.expect_comma()?;
|
||||||
|
@ -507,13 +509,11 @@ impl Gradient {
|
||||||
fn parse_stops<'i, 't>(
|
fn parse_stops<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<crate::OwnedSlice<generic::GradientItem<Color, LengthPercentage>>, ParseError<'i>> {
|
) -> Result<LengthPercentageItemList, ParseError<'i>> {
|
||||||
let items = generic::GradientItem::parse_comma_separated(context, input)?;
|
let items = generic::GradientItem::parse_comma_separated(context, input)?;
|
||||||
|
|
||||||
if items.len() < 2 {
|
if items.len() < 2 {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(items)
|
Ok(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,27 +523,27 @@ impl Gradient {
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
repeating: bool,
|
repeating: bool,
|
||||||
compat_mode: &mut GradientCompatMode,
|
mut compat_mode: GradientCompatMode,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
let direction = if let Ok(d) = input.try(|i| LineDirection::parse(context, i, compat_mode))
|
let direction =
|
||||||
{
|
if let Ok(d) = input.try(|i| LineDirection::parse(context, i, &mut compat_mode)) {
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
d
|
d
|
||||||
} else {
|
} else {
|
||||||
match compat_mode {
|
match compat_mode {
|
||||||
GradientCompatMode::Modern => {
|
GradientCompatMode::Modern => {
|
||||||
LineDirection::Vertical(VerticalPositionKeyword::Bottom)
|
LineDirection::Vertical(VerticalPositionKeyword::Bottom)
|
||||||
},
|
},
|
||||||
_ => LineDirection::Vertical(VerticalPositionKeyword::Top),
|
_ => LineDirection::Vertical(VerticalPositionKeyword::Top),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let items = Gradient::parse_stops(context, input)?;
|
let items = Gradient::parse_stops(context, input)?;
|
||||||
|
|
||||||
Ok(Gradient::Linear {
|
Ok(Gradient::Linear {
|
||||||
direction,
|
direction,
|
||||||
items,
|
items,
|
||||||
repeating,
|
repeating,
|
||||||
compat_mode: *compat_mode,
|
compat_mode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue