style: Support x as a resolution unit.

Bug: 1460655
Reviewed-by: xidorn
MozReview-Commit-ID: TjU0FLCLMN
This commit is contained in:
Emilio Cobos Álvarez 2018-05-10 18:11:52 +02:00
parent 2f18b67ce1
commit ce62cb1ba7
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -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())
)), )),