aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/gecko/conversions.rs
diff options
context:
space:
mode:
authorNazım Can Altınova <canaltinova@gmail.com>2017-04-28 18:33:00 +0300
committerNazım Can Altınova <canaltinova@gmail.com>2017-05-01 16:25:18 +0300
commitf8710bc189565ee15e2fed5bdcbc4781e9b43afb (patch)
treefee0ccecbf52c765334122572a3d1f6ea7130939 /components/style/gecko/conversions.rs
parent4483a7694a9576599a474726d366e0d39b12bd52 (diff)
downloadservo-f8710bc189565ee15e2fed5bdcbc4781e9b43afb.tar.gz
servo-f8710bc189565ee15e2fed5bdcbc4781e9b43afb.zip
stylo: Support other unit types in computed angle
Diffstat (limited to 'components/style/gecko/conversions.rs')
-rw-r--r--components/style/gecko/conversions.rs38
1 files changed, 36 insertions, 2 deletions
diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs
index 9f7420ecbbf..5b2e726583e 100644
--- a/components/style/gecko/conversions.rs
+++ b/components/style/gecko/conversions.rs
@@ -12,11 +12,11 @@ use app_units::Au;
use gecko::values::{convert_rgba_to_nscolor, GeckoStyleCoordConvertible};
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElement};
-use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
+use gecko_bindings::structs::{nsCSSUnit, nsStyleCoord_CalcValue, nsStyleImage};
use gecko_bindings::structs::{nsresult, SheetType};
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
use stylesheets::{Origin, RulesMutateError};
-use values::computed::{CalcLengthOrPercentage, Gradient, GradientItem, Image};
+use values::computed::{Angle, CalcLengthOrPercentage, Gradient, GradientItem, Image};
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
impl From<CalcLengthOrPercentage> for nsStyleCoord_CalcValue {
@@ -100,6 +100,40 @@ impl From<nsStyleCoord_CalcValue> for LengthOrPercentage {
}
}
+impl From<Angle> for CoordDataValue {
+ fn from(reference: Angle) -> Self {
+ match reference {
+ Angle::Degree(val) => CoordDataValue::Degree(val),
+ Angle::Gradian(val) => CoordDataValue::Grad(val),
+ Angle::Radian(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::Degree(val) => (val, nsCSSUnit::eCSSUnit_Degree),
+ Angle::Gradian(val) => (val, nsCSSUnit::eCSSUnit_Grad),
+ Angle::Radian(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::Degree(value),
+ nsCSSUnit::eCSSUnit_Grad => Angle::Gradian(value),
+ nsCSSUnit::eCSSUnit_Radian => Angle::Radian(value),
+ nsCSSUnit::eCSSUnit_Turn => Angle::Turn(value),
+ _ => panic!("Unexpected unit {:?} for angle", unit),
+ }
+ }
+}
+
impl nsStyleImage {
/// Set a given Servo `Image` value into this `nsStyleImage`.
pub fn set(&mut self, image: Image, cacheable: &mut bool) {