mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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:
parent
11fedf18d9
commit
42def5a011
11 changed files with 142 additions and 209 deletions
|
@ -11,7 +11,7 @@
|
|||
use app_units::Au;
|
||||
use gecko::values::GeckoStyleCoordConvertible;
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs::{self, nsCSSUnit, nsStyleCoord_CalcValue};
|
||||
use gecko_bindings::structs::{self, nsStyleCoord_CalcValue};
|
||||
use gecko_bindings::structs::{nsresult, SheetType, nsStyleImage};
|
||||
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use std::f32::consts::PI;
|
||||
|
@ -128,35 +128,7 @@ impl From<nsStyleCoord_CalcValue> for NonNegativeLengthOrPercentageOrAuto {
|
|||
|
||||
impl From<Angle> for CoordDataValue {
|
||||
fn from(reference: Angle) -> Self {
|
||||
match reference {
|
||||
Angle::Deg(val) => CoordDataValue::Degree(val),
|
||||
Angle::Grad(val) => CoordDataValue::Grad(val),
|
||||
Angle::Rad(val) => CoordDataValue::Radian(val),
|
||||
Angle::Turn(val) => CoordDataValue::Turn(val),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Angle {
|
||||
/// Converts Angle struct into (value, unit) pair.
|
||||
pub fn to_gecko_values(&self) -> (f32, nsCSSUnit) {
|
||||
match *self {
|
||||
Angle::Deg(val) => (val, nsCSSUnit::eCSSUnit_Degree),
|
||||
Angle::Grad(val) => (val, nsCSSUnit::eCSSUnit_Grad),
|
||||
Angle::Rad(val) => (val, nsCSSUnit::eCSSUnit_Radian),
|
||||
Angle::Turn(val) => (val, nsCSSUnit::eCSSUnit_Turn),
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts gecko (value, unit) pair into Angle struct
|
||||
pub fn from_gecko_values(value: f32, unit: nsCSSUnit) -> Angle {
|
||||
match unit {
|
||||
nsCSSUnit::eCSSUnit_Degree => Angle::Deg(value),
|
||||
nsCSSUnit::eCSSUnit_Grad => Angle::Grad(value),
|
||||
nsCSSUnit::eCSSUnit_Radian => Angle::Rad(value),
|
||||
nsCSSUnit::eCSSUnit_Turn => Angle::Turn(value),
|
||||
_ => panic!("Unexpected unit for angle"),
|
||||
}
|
||||
CoordDataValue::Degree(reference.degrees())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue