mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Simplify some code in NoCalcLength::parse_dimension.
Differential Revision: https://phabricator.services.mozilla.com/D3473
This commit is contained in:
parent
dc0f937224
commit
f1fe15981a
1 changed files with 26 additions and 38 deletions
|
@ -421,46 +421,34 @@ impl NoCalcLength {
|
||||||
value: CSSFloat,
|
value: CSSFloat,
|
||||||
unit: &str,
|
unit: &str,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, ()> {
|
||||||
match_ignore_ascii_case! { unit,
|
Ok(match_ignore_ascii_case! { unit,
|
||||||
"px" => Ok(NoCalcLength::Absolute(AbsoluteLength::Px(value))),
|
"px" => NoCalcLength::Absolute(AbsoluteLength::Px(value)),
|
||||||
"in" => Ok(NoCalcLength::Absolute(AbsoluteLength::In(value))),
|
"in" => NoCalcLength::Absolute(AbsoluteLength::In(value)),
|
||||||
"cm" => Ok(NoCalcLength::Absolute(AbsoluteLength::Cm(value))),
|
"cm" => NoCalcLength::Absolute(AbsoluteLength::Cm(value)),
|
||||||
"mm" => Ok(NoCalcLength::Absolute(AbsoluteLength::Mm(value))),
|
"mm" => NoCalcLength::Absolute(AbsoluteLength::Mm(value)),
|
||||||
"q" => Ok(NoCalcLength::Absolute(AbsoluteLength::Q(value))),
|
"q" => NoCalcLength::Absolute(AbsoluteLength::Q(value)),
|
||||||
"pt" => Ok(NoCalcLength::Absolute(AbsoluteLength::Pt(value))),
|
"pt" => NoCalcLength::Absolute(AbsoluteLength::Pt(value)),
|
||||||
"pc" => Ok(NoCalcLength::Absolute(AbsoluteLength::Pc(value))),
|
"pc" => NoCalcLength::Absolute(AbsoluteLength::Pc(value)),
|
||||||
// font-relative
|
// font-relative
|
||||||
"em" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Em(value))),
|
"em" => NoCalcLength::FontRelative(FontRelativeLength::Em(value)),
|
||||||
"ex" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Ex(value))),
|
"ex" => NoCalcLength::FontRelative(FontRelativeLength::Ex(value)),
|
||||||
"ch" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Ch(value))),
|
"ch" => NoCalcLength::FontRelative(FontRelativeLength::Ch(value)),
|
||||||
"rem" => Ok(NoCalcLength::FontRelative(FontRelativeLength::Rem(value))),
|
"rem" => NoCalcLength::FontRelative(FontRelativeLength::Rem(value)),
|
||||||
// viewport percentages
|
// viewport percentages
|
||||||
"vw" => {
|
"vw" if !context.in_page_rule() => {
|
||||||
if context.in_page_rule() {
|
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value))
|
||||||
return Err(())
|
}
|
||||||
}
|
"vh" if !context.in_page_rule() => {
|
||||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(value)))
|
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value))
|
||||||
},
|
}
|
||||||
"vh" => {
|
"vmin" if !context.in_page_rule() => {
|
||||||
if context.in_page_rule() {
|
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value))
|
||||||
return Err(())
|
}
|
||||||
}
|
"vmax" if !context.in_page_rule() => {
|
||||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(value)))
|
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value))
|
||||||
},
|
}
|
||||||
"vmin" => {
|
_ => return Err(())
|
||||||
if context.in_page_rule() {
|
})
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmin(value)))
|
|
||||||
},
|
|
||||||
"vmax" => {
|
|
||||||
if context.in_page_rule() {
|
|
||||||
return Err(())
|
|
||||||
}
|
|
||||||
Ok(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vmax(value)))
|
|
||||||
},
|
|
||||||
_ => Err(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue