aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/style/gecko/values.rs21
-rw-r--r--components/style/properties/gecko.mako.rs1
-rw-r--r--components/style/properties/helpers/animated_properties.mako.rs16
-rw-r--r--components/style/properties/longhand/position.mako.rs22
-rw-r--r--components/style/values/computed/length.rs55
-rw-r--r--components/style/values/computed/mod.rs2
-rw-r--r--components/style/values/specified/length.rs46
-rw-r--r--components/style/values/specified/mod.rs2
8 files changed, 154 insertions, 11 deletions
diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs
index 814633e4517..cccb5ca697f 100644
--- a/components/style/gecko/values.rs
+++ b/components/style/gecko/values.rs
@@ -14,7 +14,7 @@ use std::cmp::max;
use values::{Auto, Either, ExtremumLength, None_, Normal};
use values::computed::{Angle, LengthOrPercentageOrNone, Number};
use values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
-use values::computed::MinLength;
+use values::computed::{MaxLength, MinLength};
use values::computed::basic_shape::ShapeRadius;
use values::specified::grid::{TrackBreadth, TrackKeyword};
@@ -321,6 +321,25 @@ impl GeckoStyleCoordConvertible for MinLength {
}
}
+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::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)
+ .or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength))
+ .or_else(|| match coord.as_value() {
+ CoordDataValue::None => Some(MaxLength::None),
+ _ => None,
+ })
+ }
+}
+
/// Convert a given RGBA value to `nscolor`.
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
((rgba.alpha as u32) << 24) |
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs
index a5c9504fb7a..e5062de0f4e 100644
--- a/components/style/properties/gecko.mako.rs
+++ b/components/style/properties/gecko.mako.rs
@@ -635,6 +635,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"LengthOrPercentageOrAuto": impl_style_coord,
"LengthOrPercentageOrNone": impl_style_coord,
"LengthOrNone": impl_style_coord,
+ "MaxLength": impl_style_coord,
"MinLength": impl_style_coord,
"Number": impl_simple,
"Opacity": impl_simple,
diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs
index 4340e1870cc..e145420befd 100644
--- a/components/style/properties/helpers/animated_properties.mako.rs
+++ b/components/style/properties/helpers/animated_properties.mako.rs
@@ -33,7 +33,7 @@ use values::Either;
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
-use values::computed::MinLength;
+use values::computed::{MaxLength, MinLength};
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
use values::computed::ToComputedValue;
use values::specified::Angle as SpecifiedAngle;
@@ -645,6 +645,20 @@ impl Interpolate for MinLength {
}
}
+/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
+impl Interpolate for MaxLength {
+ #[inline]
+ fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
+ match (*self, *other) {
+ (MaxLength::LengthOrPercentage(ref this),
+ MaxLength::LengthOrPercentage(ref other)) => {
+ this.interpolate(other, progress).map(MaxLength::LengthOrPercentage)
+ }
+ _ => Err(()),
+ }
+ }
+}
+
/// https://drafts.csswg.org/css-transitions/#animtype-number
/// https://drafts.csswg.org/css-transitions/#animtype-length
impl Interpolate for LineHeight {
diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs
index ba33367227a..c9431031b3f 100644
--- a/components/style/properties/longhand/position.mako.rs
+++ b/components/style/properties/longhand/position.mako.rs
@@ -237,13 +237,21 @@ ${helpers.predefined_type("flex-basis",
% endif
// max-width, max-height, max-block-size, max-inline-size
- ${helpers.predefined_type("max-%s" % size,
- "LengthOrPercentageOrNone",
- "computed::LengthOrPercentageOrNone::None",
- "parse_non_negative",
- needs_context=False,
- spec=spec % ("max-%s" % size),
- animatable=True, logical = logical)}
+ % if product == "gecko":
+ ${helpers.predefined_type("max-%s" % size,
+ "MaxLength",
+ "computed::MaxLength::None",
+ spec=spec % ("max-%s" % size),
+ animatable=True, logical = logical)}
+ % else:
+ ${helpers.predefined_type("max-%s" % size,
+ "LengthOrPercentageOrNone",
+ "computed::LengthOrPercentageOrNone::None",
+ "parse_non_negative",
+ needs_context=False,
+ spec=spec % ("max-%s" % size),
+ animatable=True, logical = logical)}
+ % endif
% endfor
${helpers.single_keyword("box-sizing",
diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs
index d3065f29761..e512a623492 100644
--- a/components/style/values/computed/length.rs
+++ b/components/style/values/computed/length.rs
@@ -601,3 +601,58 @@ impl ToCss for MinLength {
}
}
}
+
+/// A value suitable for a `max-width` or `max-height` property.
+/// See specified/values/length.rs for more details.
+#[derive(Debug, Copy, Clone, PartialEq)]
+#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+#[allow(missing_docs)]
+pub enum MaxLength {
+ LengthOrPercentage(LengthOrPercentage),
+ None,
+ ExtremumLength(ExtremumLength),
+}
+
+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::ExtremumLength(ref ext) => {
+ MaxLength::ExtremumLength(ext.clone())
+ }
+ }
+ }
+
+ #[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::ExtremumLength(ref ext) =>
+ specified::MaxLength::ExtremumLength(ext.clone()),
+ }
+ }
+}
+
+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::ExtremumLength(ext) =>
+ ext.to_css(dest),
+ }
+ }
+}
diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs
index 206ee3ae5c9..323927cdf88 100644
--- a/components/style/values/computed/mod.rs
+++ b/components/style/values/computed/mod.rs
@@ -23,7 +23,7 @@ pub use super::specified::{Angle, BorderStyle, GridLine, Time, UrlOrNone};
pub use super::specified::url::{SpecifiedUrl, UrlExtraData};
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
-pub use self::length::MinLength;
+pub use self::length::{MaxLength, MinLength};
pub use self::position::Position;
pub mod basic_shape;
diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs
index 8ffb12058a5..ba344eff300 100644
--- a/components/style/values/specified/length.rs
+++ b/components/style/values/specified/length.rs
@@ -1353,3 +1353,49 @@ impl Parse for MinLength {
})
}
}
+
+/// A value suitable for a `max-width` or `max-height` property.
+#[derive(Debug, Clone, PartialEq)]
+#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
+#[allow(missing_docs)]
+pub enum MaxLength {
+ LengthOrPercentage(LengthOrPercentage),
+ None,
+ ExtremumLength(ExtremumLength),
+}
+
+impl HasViewportPercentage for MaxLength {
+ fn has_viewport_percentage(&self) -> bool {
+ match *self {
+ MaxLength::LengthOrPercentage(ref lop) => lop.has_viewport_percentage(),
+ _ => false
+ }
+ }
+}
+
+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::ExtremumLength(ref ext) =>
+ ext.to_css(dest),
+ }
+ }
+}
+
+impl Parse for MaxLength {
+ fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
+ input.try(ExtremumLength::parse).map(MaxLength::ExtremumLength)
+ .or_else(|()| input.try(LengthOrPercentage::parse_non_negative).map(MaxLength::LengthOrPercentage))
+ .or_else(|()| {
+ match_ignore_ascii_case! { try!(input.expect_ident()),
+ "none" =>
+ Ok(MaxLength::None),
+ _ => Err(())
+ }
+ })
+ }
+}
diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs
index 5a7dfffc090..af127a15249 100644
--- a/components/style/values/specified/mod.rs
+++ b/components/style/values/specified/mod.rs
@@ -30,7 +30,7 @@ pub use self::image::{SizeKeyword, VerticalDirection};
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength, CalcUnit};
-pub use self::length::MinLength;
+pub use self::length::{MaxLength, MinLength};
pub use self::position::{HorizontalPosition, Position, VerticalPosition};
#[cfg(feature = "gecko")]