mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Prefer Either<A, B> for LengthOrNumber
This commit is contained in:
parent
73eabad1c2
commit
6ac3fcbfeb
4 changed files with 20 additions and 110 deletions
|
@ -11,8 +11,8 @@ use gecko_bindings::structs::nsStyleCoord;
|
|||
use gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, CoordDataValue};
|
||||
use std::cmp::max;
|
||||
use values::Either;
|
||||
use values::computed::{LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use values::computed::{LengthOrPercentageOrNone, Angle};
|
||||
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
|
||||
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
use values::computed::basic_shape::ShapeRadius;
|
||||
|
||||
pub trait StyleCoordHelpers {
|
||||
|
@ -26,7 +26,6 @@ impl StyleCoordHelpers for nsStyleCoord {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait GeckoStyleCoordConvertible : Sized {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T);
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self>;
|
||||
|
@ -47,6 +46,19 @@ impl<A: GeckoStyleCoordConvertible, B: GeckoStyleCoordConvertible> GeckoStyleCoo
|
|||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for Number {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
coord.set_value(CoordDataValue::Factor(*self));
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
match coord.as_value() {
|
||||
CoordDataValue::Factor(f) => Some(f),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for LengthOrPercentage {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
let value = match *self {
|
||||
|
@ -124,24 +136,6 @@ 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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue