Rename MinLength to MozLength.

So that we can reuse this for non-min-prefixed properties (e.g. width).
This commit is contained in:
Hiroyuki Ikezoe 2017-05-20 11:58:58 +09:00
parent 95bda2dff9
commit 57c27e5d35
8 changed files with 59 additions and 58 deletions

View file

@ -14,7 +14,7 @@ use std::cmp::max;
use values::{Auto, Either, ExtremumLength, None_, Normal}; use values::{Auto, Either, ExtremumLength, None_, Normal};
use values::computed::{Angle, LengthOrPercentage, LengthOrPercentageOrAuto}; use values::computed::{Angle, LengthOrPercentage, LengthOrPercentageOrAuto};
use values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage}; use values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage};
use values::computed::{MaxLength, MinLength}; use values::computed::{MaxLength, MozLength};
use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use values::computed::basic_shape::ShapeRadius as ComputedShapeRadius;
use values::generics::basic_shape::ShapeRadius; use values::generics::basic_shape::ShapeRadius;
use values::specified::Percentage; use values::specified::Percentage;
@ -335,17 +335,17 @@ impl GeckoStyleCoordConvertible for ExtremumLength {
} }
} }
impl GeckoStyleCoordConvertible for MinLength { impl GeckoStyleCoordConvertible for MozLength {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) { fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
match *self { match *self {
MinLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord), MozLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord),
MinLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord),
} }
} }
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> { fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
LengthOrPercentageOrAuto::from_gecko_style_coord(coord).map(MinLength::LengthOrPercentageOrAuto) LengthOrPercentageOrAuto::from_gecko_style_coord(coord).map(MozLength::LengthOrPercentageOrAuto)
.or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MinLength::ExtremumLength)) .or_else(|| ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength))
} }
} }

View file

@ -675,7 +675,7 @@ impl Debug for ${style_struct.gecko_struct_name} {
"LengthOrNone": impl_style_coord, "LengthOrNone": impl_style_coord,
"LengthOrNormal": impl_style_coord, "LengthOrNormal": impl_style_coord,
"MaxLength": impl_style_coord, "MaxLength": impl_style_coord,
"MinLength": impl_style_coord, "MozLength": impl_style_coord,
"Number": impl_simple, "Number": impl_simple,
"Integer": impl_simple, "Integer": impl_simple,
"Opacity": impl_simple, "Opacity": impl_simple,

View file

@ -41,7 +41,7 @@ use values::{Auto, Either, generics};
use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone};
use values::computed::{BorderRadiusSize, ClipRect}; use values::computed::{BorderRadiusSize, ClipRect};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage}; use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
use values::computed::{MaxLength, MinLength}; use values::computed::{MaxLength, MozLength};
use values::computed::ToComputedValue; use values::computed::ToComputedValue;
use values::generics::position as generic_position; use values::generics::position as generic_position;
@ -1237,14 +1237,14 @@ impl Animatable for LengthOrPercentageOrNone {
} }
/// https://drafts.csswg.org/css-transitions/#animtype-lpcalc /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc
impl Animatable for MinLength { impl Animatable for MozLength {
#[inline] #[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
match (*self, *other) { match (*self, *other) {
(MinLength::LengthOrPercentageOrAuto(ref this), (MozLength::LengthOrPercentageOrAuto(ref this),
MinLength::LengthOrPercentageOrAuto(ref other)) => { MozLength::LengthOrPercentageOrAuto(ref other)) => {
this.add_weighted(other, self_portion, other_portion) this.add_weighted(other, self_portion, other_portion)
.map(MinLength::LengthOrPercentageOrAuto) .map(MozLength::LengthOrPercentageOrAuto)
} }
_ => Err(()), _ => Err(()),
} }
@ -1253,8 +1253,8 @@ impl Animatable for MinLength {
#[inline] #[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> { fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
match (*self, *other) { match (*self, *other) {
(MinLength::LengthOrPercentageOrAuto(ref this), (MozLength::LengthOrPercentageOrAuto(ref this),
MinLength::LengthOrPercentageOrAuto(ref other)) => { MozLength::LengthOrPercentageOrAuto(ref other)) => {
this.compute_distance(other) this.compute_distance(other)
}, },
_ => Err(()), _ => Err(()),

View file

@ -163,7 +163,7 @@ ${helpers.predefined_type("flex-basis",
% if product == "gecko": % if product == "gecko":
% for min_max in ["min", "max"]: % for min_max in ["min", "max"]:
<% <%
MinMax = min_max.title() LengthType = "MaxLength" if "max" == min_max else "MozLength"
initial = "none()" if "max" == min_max else "auto()" initial = "none()" if "max" == min_max else "auto()"
%> %>
@ -174,37 +174,38 @@ ${helpers.predefined_type("flex-basis",
// be replaced with auto/none in block. // be replaced with auto/none in block.
<%helpers:longhand name="${min_max}-${size}" spec="${spec % ('%s-%s' % (min_max, size))}" <%helpers:longhand name="${min_max}-${size}" spec="${spec % ('%s-%s' % (min_max, size))}"
animation_value_type="ComputedValue" animation_value_type="ComputedValue"
logical="${logical}" predefined_type="${MinMax}Length"> logical="${logical}" predefined_type="${LengthType}">
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
% if not logical: % if not logical:
use values::specified::AllowQuirks; use values::specified::AllowQuirks;
% endif % endif
use values::specified::${MinMax}Length; use values::specified::${LengthType};
pub mod computed_value { pub mod computed_value {
pub type T = ::values::computed::${MinMax}Length; pub type T = ::values::computed::${LengthType};
} }
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)] #[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue(${MinMax}Length); pub struct SpecifiedValue(${LengthType});
#[inline] #[inline]
pub fn get_initial_value() -> computed_value::T { pub fn get_initial_value() -> computed_value::T {
use values::computed::${MinMax}Length; use values::computed::${LengthType};
${MinMax}Length::${initial} ${LengthType}::${initial}
} }
fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
% if logical: % if logical:
let ret = ${MinMax}Length::parse(context, input); let ret = ${LengthType}::parse(context, input);
% else: % else:
let ret = ${MinMax}Length::parse_quirky(context, input, AllowQuirks::Yes); let ret = ${LengthType}::parse_quirky(context, input, AllowQuirks::Yes);
% endif % endif
// Keyword values don't make sense in the block direction; don't parse them // Keyword values don't make sense in the block direction; don't parse them
% if "block" in size: % if "block" in size:
if let Ok(${MinMax}Length::ExtremumLength(..)) = ret { if let Ok(${LengthType}::ExtremumLength(..)) = ret {
return Err(()) return Err(())
} }
% endif % endif
@ -222,19 +223,19 @@ ${helpers.predefined_type("flex-basis",
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> computed_value::T { fn to_computed_value(&self, context: &Context) -> computed_value::T {
% if not logical or "block" in size: % if not logical or "block" in size:
use values::computed::${MinMax}Length; use values::computed::${LengthType};
% endif % endif
let computed = self.0.to_computed_value(context); let computed = self.0.to_computed_value(context);
// filter out keyword values in the block direction // filter out keyword values in the block direction
% if logical: % if logical:
% if "block" in size: % if "block" in size:
if let ${MinMax}Length::ExtremumLength(..) = computed { if let ${LengthType}::ExtremumLength(..) = computed {
return get_initial_value() return get_initial_value()
} }
% endif % endif
% else: % else:
if let ${MinMax}Length::ExtremumLength(..) = computed { if let ${LengthType}::ExtremumLength(..) = computed {
<% is_height = "true" if "height" in size else "false" %> <% is_height = "true" if "height" in size else "false" %>
if ${is_height} != context.style().writing_mode.is_vertical() { if ${is_height} != context.style().writing_mode.is_vertical() {
return get_initial_value() return get_initial_value()

View file

@ -606,56 +606,56 @@ pub type LengthOrNumber = Either<Length, Number>;
/// Either a computed `<length>` or the `normal` keyword. /// Either a computed `<length>` or the `normal` keyword.
pub type LengthOrNormal = Either<Length, Normal>; pub type LengthOrNormal = Either<Length, Normal>;
/// A value suitable for a `min-width` or `min-height` property. /// A value suitable for a `min-width`, `min-height`, `width` or `height` property.
/// See specified/values/length.rs for more details. /// See specified/values/length.rs for more details.
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum MinLength { pub enum MozLength {
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
ExtremumLength(ExtremumLength), ExtremumLength(ExtremumLength),
} }
impl MinLength { impl MozLength {
/// Returns the `auto` value. /// Returns the `auto` value.
pub fn auto() -> Self { pub fn auto() -> Self {
MinLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)
} }
} }
impl ToComputedValue for specified::MinLength { impl ToComputedValue for specified::MozLength {
type ComputedValue = MinLength; type ComputedValue = MozLength;
#[inline] #[inline]
fn to_computed_value(&self, context: &Context) -> MinLength { fn to_computed_value(&self, context: &Context) -> MozLength {
match *self { match *self {
specified::MinLength::LengthOrPercentageOrAuto(ref lopoa) => { specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
MinLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context)) MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
} }
specified::MinLength::ExtremumLength(ref ext) => { specified::MozLength::ExtremumLength(ref ext) => {
MinLength::ExtremumLength(ext.clone()) MozLength::ExtremumLength(ext.clone())
} }
} }
} }
#[inline] #[inline]
fn from_computed_value(computed: &MinLength) -> Self { fn from_computed_value(computed: &MozLength) -> Self {
match *computed { match *computed {
MinLength::LengthOrPercentageOrAuto(ref lopoa) => MozLength::LengthOrPercentageOrAuto(ref lopoa) =>
specified::MinLength::LengthOrPercentageOrAuto( specified::MozLength::LengthOrPercentageOrAuto(
specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)), specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)),
MinLength::ExtremumLength(ref ext) => MozLength::ExtremumLength(ref ext) =>
specified::MinLength::ExtremumLength(ext.clone()), specified::MozLength::ExtremumLength(ext.clone()),
} }
} }
} }
impl ToCss for MinLength { impl ToCss for MozLength {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
MinLength::LengthOrPercentageOrAuto(lopoa) => MozLength::LengthOrPercentageOrAuto(lopoa) =>
lopoa.to_css(dest), lopoa.to_css(dest),
MinLength::ExtremumLength(ext) => MozLength::ExtremumLength(ext) =>
ext.to_css(dest), ext.to_css(dest),
} }
} }

View file

@ -31,7 +31,7 @@ pub use super::specified::{BorderStyle, GridLine, Percentage, UrlOrNone};
pub use super::specified::url::SpecifiedUrl; pub use super::specified::url::SpecifiedUrl;
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone}; pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
pub use self::length::{MaxLength, MinLength}; pub use self::length::{MaxLength, MozLength};
pub use self::position::Position; pub use self::position::Position;
pub mod basic_shape; pub mod basic_shape;

View file

@ -1176,41 +1176,41 @@ impl LengthOrNumber {
} }
/// A value suitable for a `min-width` or `min-height` property. /// A value suitable for a `min-width` or `min-height` property.
/// Unlike `max-width` or `max-height` properties, a MinLength can be /// Unlike `max-width` or `max-height` properties, a MozLength can be
/// `auto`, and cannot be `none`. /// `auto`, and cannot be `none`.
#[derive(Clone, Debug, HasViewportPercentage, PartialEq)] #[derive(Clone, Debug, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum MinLength { pub enum MozLength {
LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), LengthOrPercentageOrAuto(LengthOrPercentageOrAuto),
ExtremumLength(ExtremumLength), ExtremumLength(ExtremumLength),
} }
impl ToCss for MinLength { impl ToCss for MozLength {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self { match *self {
MinLength::LengthOrPercentageOrAuto(ref lopoa) => MozLength::LengthOrPercentageOrAuto(ref lopoa) =>
lopoa.to_css(dest), lopoa.to_css(dest),
MinLength::ExtremumLength(ref ext) => MozLength::ExtremumLength(ref ext) =>
ext.to_css(dest), ext.to_css(dest),
} }
} }
} }
impl Parse for MinLength { impl Parse for MozLength {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
MinLength::parse_quirky(context, input, AllowQuirks::No) MozLength::parse_quirky(context, input, AllowQuirks::No)
} }
} }
impl MinLength { impl MozLength {
/// Parses, with quirks. /// Parses, with quirks.
pub fn parse_quirky(context: &ParserContext, pub fn parse_quirky(context: &ParserContext,
input: &mut Parser, input: &mut Parser,
allow_quirks: AllowQuirks) -> Result<Self, ()> { allow_quirks: AllowQuirks) -> Result<Self, ()> {
input.try(ExtremumLength::parse).map(MinLength::ExtremumLength) input.try(ExtremumLength::parse).map(MozLength::ExtremumLength)
.or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks)) .or_else(|()| input.try(|i| LengthOrPercentageOrAuto::parse_non_negative_quirky(context, i, allow_quirks))
.map(MinLength::LengthOrPercentageOrAuto)) .map(MozLength::LengthOrPercentageOrAuto))
} }
} }

View file

@ -37,7 +37,7 @@ pub use self::length::AbsoluteLength;
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage}; pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength}; pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength};
pub use self::length::{MaxLength, MinLength}; pub use self::length::{MaxLength, MozLength};
pub use self::position::{Position, PositionComponent}; pub use self::position::{Position, PositionComponent};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]