mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Combine LengthOrPercentage and Auto into LengthOrPercentageOrAuto for {Min,Max}Length.
This commit is contained in:
parent
323760f47e
commit
95bda2dff9
5 changed files with 54 additions and 80 deletions
|
@ -338,38 +338,28 @@ impl GeckoStyleCoordConvertible for ExtremumLength {
|
|||
impl GeckoStyleCoordConvertible for MinLength {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord),
|
||||
MinLength::Auto => coord.set_value(CoordDataValue::Auto),
|
||||
MinLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord),
|
||||
MinLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
LengthOrPercentage::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentage)
|
||||
LengthOrPercentageOrAuto::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentageOrAuto)
|
||||
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MinLength::ExtremumLength))
|
||||
.or_else(|| match coord.as_value() {
|
||||
CoordDataValue::Auto => Some(MinLength::Auto),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl GeckoStyleCoordConvertible for MaxLength {
|
||||
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
|
||||
match *self {
|
||||
MaxLength::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord),
|
||||
MaxLength::None => coord.set_value(CoordDataValue::None),
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord),
|
||||
MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
|
||||
}
|
||||
}
|
||||
|
||||
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
|
||||
LengthOrPercentage::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentage)
|
||||
LengthOrPercentageOrNone::from_gecko_style_coord(coord).map(MaxLength::LengthOrPercentageOrNone)
|
||||
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength))
|
||||
.or_else(|| match coord.as_value() {
|
||||
CoordDataValue::None => Some(MaxLength::None),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1241,10 +1241,10 @@ impl Animatable for MinLength {
|
|||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
match (*self, *other) {
|
||||
(MinLength::LengthOrPercentage(ref this),
|
||||
MinLength::LengthOrPercentage(ref other)) => {
|
||||
(MinLength::LengthOrPercentageOrAuto(ref this),
|
||||
MinLength::LengthOrPercentageOrAuto(ref other)) => {
|
||||
this.add_weighted(other, self_portion, other_portion)
|
||||
.map(MinLength::LengthOrPercentage)
|
||||
.map(MinLength::LengthOrPercentageOrAuto)
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
|
@ -1253,8 +1253,8 @@ impl Animatable for MinLength {
|
|||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
(MinLength::LengthOrPercentage(ref this),
|
||||
MinLength::LengthOrPercentage(ref other)) => {
|
||||
(MinLength::LengthOrPercentageOrAuto(ref this),
|
||||
MinLength::LengthOrPercentageOrAuto(ref other)) => {
|
||||
this.compute_distance(other)
|
||||
},
|
||||
_ => Err(()),
|
||||
|
@ -1267,10 +1267,10 @@ impl Animatable for MaxLength {
|
|||
#[inline]
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||
match (*self, *other) {
|
||||
(MaxLength::LengthOrPercentage(ref this),
|
||||
MaxLength::LengthOrPercentage(ref other)) => {
|
||||
(MaxLength::LengthOrPercentageOrNone(ref this),
|
||||
MaxLength::LengthOrPercentageOrNone(ref other)) => {
|
||||
this.add_weighted(other, self_portion, other_portion)
|
||||
.map(MaxLength::LengthOrPercentage)
|
||||
.map(MaxLength::LengthOrPercentageOrNone)
|
||||
}
|
||||
_ => Err(()),
|
||||
}
|
||||
|
@ -1279,8 +1279,8 @@ impl Animatable for MaxLength {
|
|||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
match (*self, *other) {
|
||||
(MaxLength::LengthOrPercentage(ref this),
|
||||
MaxLength::LengthOrPercentage(ref other)) => {
|
||||
(MaxLength::LengthOrPercentageOrNone(ref this),
|
||||
MaxLength::LengthOrPercentageOrNone(ref other)) => {
|
||||
this.compute_distance(other)
|
||||
},
|
||||
_ => Err(()),
|
||||
|
|
|
@ -164,7 +164,7 @@ ${helpers.predefined_type("flex-basis",
|
|||
% for min_max in ["min", "max"]:
|
||||
<%
|
||||
MinMax = min_max.title()
|
||||
initial = "None" if "max" == min_max else "Auto"
|
||||
initial = "none()" if "max" == min_max else "auto()"
|
||||
%>
|
||||
|
||||
// min-width, min-height, min-block-size, min-inline-size,
|
||||
|
|
|
@ -612,22 +612,25 @@ pub type LengthOrNormal = Either<Length, Normal>;
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MinLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
Auto,
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl MinLength {
|
||||
/// Returns the `auto` value.
|
||||
pub fn auto() -> Self {
|
||||
MinLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::MinLength {
|
||||
type ComputedValue = MinLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MinLength {
|
||||
match *self {
|
||||
specified::MinLength::LengthOrPercentage(ref lop) => {
|
||||
MinLength::LengthOrPercentage(lop.to_computed_value(context))
|
||||
}
|
||||
specified::MinLength::Auto => {
|
||||
MinLength::Auto
|
||||
specified::MinLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
MinLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
|
||||
}
|
||||
specified::MinLength::ExtremumLength(ref ext) => {
|
||||
MinLength::ExtremumLength(ext.clone())
|
||||
|
@ -638,10 +641,9 @@ impl ToComputedValue for specified::MinLength {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &MinLength) -> Self {
|
||||
match *computed {
|
||||
MinLength::Auto =>
|
||||
specified::MinLength::Auto,
|
||||
MinLength::LengthOrPercentage(ref lop) =>
|
||||
specified::MinLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)),
|
||||
MinLength::LengthOrPercentageOrAuto(ref lopoa) =>
|
||||
specified::MinLength::LengthOrPercentageOrAuto(
|
||||
specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)),
|
||||
MinLength::ExtremumLength(ref ext) =>
|
||||
specified::MinLength::ExtremumLength(ext.clone()),
|
||||
}
|
||||
|
@ -651,10 +653,8 @@ impl ToComputedValue for specified::MinLength {
|
|||
impl ToCss for MinLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(lop) =>
|
||||
lop.to_css(dest),
|
||||
MinLength::Auto =>
|
||||
dest.write_str("auto"),
|
||||
MinLength::LengthOrPercentageOrAuto(lopoa) =>
|
||||
lopoa.to_css(dest),
|
||||
MinLength::ExtremumLength(ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
|
@ -667,22 +667,24 @@ impl ToCss for MinLength {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
None,
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl MaxLength {
|
||||
/// Returns the `none` value.
|
||||
pub fn none() -> Self {
|
||||
MaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None)
|
||||
}
|
||||
}
|
||||
impl ToComputedValue for specified::MaxLength {
|
||||
type ComputedValue = MaxLength;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MaxLength {
|
||||
match *self {
|
||||
specified::MaxLength::LengthOrPercentage(ref lop) => {
|
||||
MaxLength::LengthOrPercentage(lop.to_computed_value(context))
|
||||
}
|
||||
specified::MaxLength::None => {
|
||||
MaxLength::None
|
||||
specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => {
|
||||
MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context))
|
||||
}
|
||||
specified::MaxLength::ExtremumLength(ref ext) => {
|
||||
MaxLength::ExtremumLength(ext.clone())
|
||||
|
@ -693,10 +695,9 @@ impl ToComputedValue for specified::MaxLength {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &MaxLength) -> Self {
|
||||
match *computed {
|
||||
MaxLength::None =>
|
||||
specified::MaxLength::None,
|
||||
MaxLength::LengthOrPercentage(ref lop) =>
|
||||
specified::MaxLength::LengthOrPercentage(specified::LengthOrPercentage::from_computed_value(&lop)),
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) =>
|
||||
specified::MaxLength::LengthOrPercentageOrNone(
|
||||
specified::LengthOrPercentageOrNone::from_computed_value(&lopon)),
|
||||
MaxLength::ExtremumLength(ref ext) =>
|
||||
specified::MaxLength::ExtremumLength(ext.clone()),
|
||||
}
|
||||
|
@ -706,10 +707,8 @@ impl ToComputedValue for specified::MaxLength {
|
|||
impl ToCss for MaxLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MaxLength::LengthOrPercentage(lop) =>
|
||||
lop.to_css(dest),
|
||||
MaxLength::None =>
|
||||
dest.write_str("none"),
|
||||
MaxLength::LengthOrPercentageOrNone(lopon) =>
|
||||
lopon.to_css(dest),
|
||||
MaxLength::ExtremumLength(ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
|
|
|
@ -1182,18 +1182,15 @@ impl LengthOrNumber {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MinLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
Auto,
|
||||
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
impl ToCss for MinLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MinLength::LengthOrPercentage(ref lop) =>
|
||||
lop.to_css(dest),
|
||||
MinLength::Auto =>
|
||||
dest.write_str("auto"),
|
||||
MinLength::LengthOrPercentageOrAuto(ref lopoa) =>
|
||||
lopoa.to_css(dest),
|
||||
MinLength::ExtremumLength(ref ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
|
@ -1212,9 +1209,8 @@ impl MinLength {
|
|||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ()> {
|
||||
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength)
|
||||
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MinLength::LengthOrPercentage))
|
||||
.or_else(|()| input.expect_ident_matching("auto").map(|()| MinLength::Auto))
|
||||
.or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MinLength::LengthOrPercentageOrAuto))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1223,19 +1219,15 @@ impl MinLength {
|
|||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum MaxLength {
|
||||
LengthOrPercentage(LengthOrPercentage),
|
||||
None,
|
||||
LengthOrPercentageOrNone(LengthOrPercentageOrNone),
|
||||
ExtremumLength(ExtremumLength),
|
||||
}
|
||||
|
||||
|
||||
impl ToCss for MaxLength {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
MaxLength::LengthOrPercentage(ref lop) =>
|
||||
lop.to_css(dest),
|
||||
MaxLength::None =>
|
||||
dest.write_str("none"),
|
||||
MaxLength::LengthOrPercentageOrNone(ref lopon) =>
|
||||
lopon.to_css(dest),
|
||||
MaxLength::ExtremumLength(ref ext) =>
|
||||
ext.to_css(dest),
|
||||
}
|
||||
|
@ -1254,14 +1246,7 @@ impl MaxLength {
|
|||
input: &mut Parser,
|
||||
allow_quirks: AllowQuirks) -> Result<Self, ()> {
|
||||
input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
|
||||
.or_else(|()| input.try(|i| LengthOrPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MaxLength::LengthOrPercentage))
|
||||
.or_else(|()| {
|
||||
match_ignore_ascii_case! { &try!(input.expect_ident()),
|
||||
"none" =>
|
||||
Ok(MaxLength::None),
|
||||
_ => Err(())
|
||||
}
|
||||
})
|
||||
.or_else(|()| input.try(|i| LengthOrPercentageOrNone::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
.map(MaxLength::LengthOrPercentageOrNone))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue