From 73eabad1c2dd6e286c8f2af9c3fb6f1efd381f56 Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Thu, 17 Nov 2016 20:14:05 +0530 Subject: [PATCH] Add impl GeckoStyleCoordConvertible for Either --- components/style/gecko/values.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 39faa388040..5537cdac6e4 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -10,6 +10,7 @@ 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::Either; use values::computed::{LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; use values::computed::{LengthOrPercentageOrNone, Angle}; use values::computed::basic_shape::ShapeRadius; @@ -31,6 +32,21 @@ pub trait GeckoStyleCoordConvertible : Sized { fn from_gecko_style_coord(coord: &T) -> Option; } +impl GeckoStyleCoordConvertible for Either { + fn to_gecko_style_coord(&self, coord: &mut T) { + match *self { + Either::First(ref v) => v.to_gecko_style_coord(coord), + Either::Second(ref v) => v.to_gecko_style_coord(coord), + } + } + + fn from_gecko_style_coord(coord: &T) -> Option { + A::from_gecko_style_coord(coord) + .map(Either::First) + .or_else(|| B::from_gecko_style_coord(coord).map(Either::Second)) + } +} + impl GeckoStyleCoordConvertible for LengthOrPercentage { fn to_gecko_style_coord(&self, coord: &mut T) { let value = match *self {