style: Always compute angle values to degrees.

This matches the spec, https://drafts.csswg.org/css-values/#angles, which says:

> All <angle> units are compatible, and deg is their canonical unit.

And https://drafts.csswg.org/css-values/#compat, which says:

>When serializing computed values [...], compatible units [...] are converted into a single canonical unit.

And also other implementations (Blink always serializes angles as degrees in
computed style for example).

Also allows us to get rid of quite a bit of code, and makes computed angle value
representation just a number, which is nice.

Differential Revision: https://phabricator.services.mozilla.com/D8619
This commit is contained in:
Emilio Cobos Álvarez 2018-10-13 00:41:03 +00:00
parent 11fedf18d9
commit 42def5a011
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
11 changed files with 142 additions and 209 deletions

View file

@ -198,19 +198,19 @@ impl nsCSSValue {
/// Returns an `Angle` value from this `nsCSSValue`.
///
/// Panics if the unit is not `eCSSUnit_Degree` `eCSSUnit_Grad`, `eCSSUnit_Turn`
/// or `eCSSUnit_Radian`.
/// Panics if the unit is not `eCSSUnit_Degree`.
#[inline]
pub fn get_angle(&self) -> Angle {
Angle::from_gecko_values(self.float_unchecked(), self.mUnit)
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_Degree);
Angle::from_degrees(self.float_unchecked())
}
/// Sets Angle value to this nsCSSValue.
pub fn set_angle(&mut self, angle: Angle) {
debug_assert_eq!(self.mUnit, nsCSSUnit::eCSSUnit_Null);
let (value, unit) = angle.to_gecko_values();
self.mUnit = unit;
self.mUnit = nsCSSUnit::eCSSUnit_Degree;
unsafe {
*self.mValue.mFloat.as_mut() = value;
*self.mValue.mFloat.as_mut() = angle.degrees();
}
}

View file

@ -200,12 +200,6 @@ pub enum CoordDataValue {
Factor(f32),
/// eStyleUnit_Degree
Degree(f32),
/// eStyleUnit_Grad
Grad(f32),
/// eStyleUnit_Radian
Radian(f32),
/// eStyleUnit_Turn
Turn(f32),
/// eStyleUnit_FlexFraction
FlexFraction(f32),
/// eStyleUnit_Coord
@ -317,18 +311,6 @@ pub unsafe trait CoordDataMut: CoordData {
*unit = eStyleUnit_Degree;
*union.mFloat.as_mut() = f;
},
Grad(f) => {
*unit = eStyleUnit_Grad;
*union.mFloat.as_mut() = f;
},
Radian(f) => {
*unit = eStyleUnit_Radian;
*union.mFloat.as_mut() = f;
},
Turn(f) => {
*unit = eStyleUnit_Turn;
*union.mFloat.as_mut() = f;
},
FlexFraction(f) => {
*unit = eStyleUnit_FlexFraction;
*union.mFloat.as_mut() = f;
@ -393,9 +375,6 @@ pub unsafe trait CoordData {
eStyleUnit_Percent => Percent(self.get_float()),
eStyleUnit_Factor => Factor(self.get_float()),
eStyleUnit_Degree => Degree(self.get_float()),
eStyleUnit_Grad => Grad(self.get_float()),
eStyleUnit_Radian => Radian(self.get_float()),
eStyleUnit_Turn => Turn(self.get_float()),
eStyleUnit_FlexFraction => FlexFraction(self.get_float()),
eStyleUnit_Coord => Coord(self.get_integer()),
eStyleUnit_Integer => Integer(self.get_integer()),
@ -413,9 +392,6 @@ pub unsafe trait CoordData {
self.unit() == eStyleUnit_Percent ||
self.unit() == eStyleUnit_Factor ||
self.unit() == eStyleUnit_Degree ||
self.unit() == eStyleUnit_Grad ||
self.unit() == eStyleUnit_Radian ||
self.unit() == eStyleUnit_Turn ||
self.unit() == eStyleUnit_FlexFraction
);
*self.union().mFloat.as_ref()