mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Support x as a resolution unit.
Bug: 1460655 Reviewed-by: xidorn MozReview-Commit-ID: TjU0FLCLMN
This commit is contained in:
parent
2f18b67ce1
commit
ce62cb1ba7
1 changed files with 6 additions and 0 deletions
|
@ -17,6 +17,9 @@ pub enum Resolution {
|
||||||
/// Dots per inch.
|
/// Dots per inch.
|
||||||
#[css(dimension)]
|
#[css(dimension)]
|
||||||
Dpi(CSSFloat),
|
Dpi(CSSFloat),
|
||||||
|
/// An alias unit for dots per pixel.
|
||||||
|
#[css(dimension)]
|
||||||
|
X(CSSFloat),
|
||||||
/// Dots per pixel.
|
/// Dots per pixel.
|
||||||
#[css(dimension)]
|
#[css(dimension)]
|
||||||
Dppx(CSSFloat),
|
Dppx(CSSFloat),
|
||||||
|
@ -29,6 +32,7 @@ impl Resolution {
|
||||||
/// Convert this resolution value to dppx units.
|
/// Convert this resolution value to dppx units.
|
||||||
pub fn to_dppx(&self) -> CSSFloat {
|
pub fn to_dppx(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
|
Resolution::X(f) |
|
||||||
Resolution::Dppx(f) => f,
|
Resolution::Dppx(f) => f,
|
||||||
_ => self.to_dpi() / 96.0,
|
_ => self.to_dpi() / 96.0,
|
||||||
}
|
}
|
||||||
|
@ -38,6 +42,7 @@ impl Resolution {
|
||||||
pub fn to_dpi(&self) -> CSSFloat {
|
pub fn to_dpi(&self) -> CSSFloat {
|
||||||
match *self {
|
match *self {
|
||||||
Resolution::Dpi(f) => f,
|
Resolution::Dpi(f) => f,
|
||||||
|
Resolution::X(f) |
|
||||||
Resolution::Dppx(f) => f * 96.0,
|
Resolution::Dppx(f) => f * 96.0,
|
||||||
Resolution::Dpcm(f) => f * 2.54,
|
Resolution::Dpcm(f) => f * 2.54,
|
||||||
}
|
}
|
||||||
|
@ -65,6 +70,7 @@ impl Parse for Resolution {
|
||||||
"dpi" => Ok(Resolution::Dpi(value)),
|
"dpi" => Ok(Resolution::Dpi(value)),
|
||||||
"dppx" => Ok(Resolution::Dppx(value)),
|
"dppx" => Ok(Resolution::Dppx(value)),
|
||||||
"dpcm" => Ok(Resolution::Dpcm(value)),
|
"dpcm" => Ok(Resolution::Dpcm(value)),
|
||||||
|
"x" => Ok(Resolution::X(value)),
|
||||||
_ => Err(location.new_custom_error(
|
_ => Err(location.new_custom_error(
|
||||||
StyleParseErrorKind::UnexpectedDimension(unit.clone())
|
StyleParseErrorKind::UnexpectedDimension(unit.clone())
|
||||||
)),
|
)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue