Move LengthOrNumber to style/values and implement GeckoStyleCoordConvertible

This commit is contained in:
Nazım Can Altınova 2016-11-04 21:30:07 +03:00
parent 9a2ef2e6ef
commit 7720fe4d9c
7 changed files with 131 additions and 90 deletions

View file

@ -10,8 +10,8 @@ use gecko_bindings::structs::{NS_RADIUS_CLOSEST_SIDE, NS_RADIUS_FARTHEST_SIDE};
use gecko_bindings::structs::nsStyleCoord;
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
use std::cmp::max;
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::Angle;
use values::computed::{LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, Angle};
use values::computed::basic_shape::ShapeRadius;
pub trait StyleCoordHelpers {
@ -108,6 +108,24 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone {
}
}
impl GeckoStyleCoordConvertible for LengthOrNumber {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
let value = match *self {
LengthOrNumber::Length(au) => CoordDataValue::Coord(au.0),
LengthOrNumber::Number(number) => CoordDataValue::Factor(number),
};
coord.set_value(value);
}
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
match coord.as_value() {
CoordDataValue::Coord(coord) => Some(LengthOrNumber::Length(Au(coord))),
CoordDataValue::Factor(f) => Some(LengthOrNumber::Number(f)),
_ => None,
}
}
}
impl GeckoStyleCoordConvertible for ShapeRadius {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self {