mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Get rid of gecko_size_type.
This also fixes a style sharing issue with MaxLength, anecdotally.
This commit is contained in:
parent
100f4cd7c3
commit
32c409d5aa
10 changed files with 154 additions and 173 deletions
|
@ -5,13 +5,15 @@
|
|||
//! `<length>` computed values, and related ones.
|
||||
|
||||
use app_units::Au;
|
||||
use logical_geometry::WritingMode;
|
||||
use ordered_float::NotNaN;
|
||||
use properties::LonghandId;
|
||||
use std::fmt::{self, Write};
|
||||
use std::ops::{Add, Neg};
|
||||
use style_traits::{CssWriter, ToCss};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::{Number, ToComputedValue, Context, Percentage};
|
||||
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified};
|
||||
use values::{Auto, CSSFloat, Either, None_, Normal, specified};
|
||||
use values::animated::{Animate, Procedure, ToAnimatedZero};
|
||||
use values::computed::NonNegativeNumber;
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
@ -874,6 +876,49 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
|||
/// Either a computed NonNegativeLength or a NonNegativeNumber value.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
|
||||
|
||||
/// A type for possible values for min- and max- flavors of width, height,
|
||||
/// block-size, and inline-size.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
||||
pub enum ExtremumLength {
|
||||
MozMaxContent,
|
||||
MozMinContent,
|
||||
MozFitContent,
|
||||
MozAvailable,
|
||||
}
|
||||
|
||||
impl ExtremumLength {
|
||||
/// Returns whether this size keyword can be used for the given writing-mode
|
||||
/// and property.
|
||||
fn valid_for(&self, wm: WritingMode, longhand: LonghandId) -> bool {
|
||||
// We only make sense on the inline axis.
|
||||
match longhand {
|
||||
LonghandId::MinWidth |
|
||||
LonghandId::MaxWidth |
|
||||
LonghandId::Width => !wm.is_vertical(),
|
||||
|
||||
LonghandId::MinHeight |
|
||||
LonghandId::MaxHeight |
|
||||
LonghandId::Height => wm.is_vertical(),
|
||||
|
||||
LonghandId::MinInlineSize |
|
||||
LonghandId::MaxInlineSize |
|
||||
LonghandId::InlineSize => true,
|
||||
// The block-* properties are rejected at parse-time, so they're
|
||||
// unexpected here.
|
||||
_ => {
|
||||
debug_assert!(
|
||||
false,
|
||||
"Unexpected property using ExtremumLength: {:?}",
|
||||
longhand,
|
||||
);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A value suitable for a `min-width`, `min-height`, `width` or `height` property.
|
||||
/// See values/specified/length.rs for more details.
|
||||
#[allow(missing_docs)]
|
||||
|
@ -899,16 +944,22 @@ impl ToComputedValue for specified::MozLength {
|
|||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> MozLength {
|
||||
debug_assert!(
|
||||
context.for_non_inherited_property.is_some(),
|
||||
"Someone added a MozLength to an inherited property? Evil!"
|
||||
);
|
||||
match *self {
|
||||
specified::MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
MozLength::LengthOrPercentageOrAuto(lopoa.to_computed_value(context))
|
||||
}
|
||||
specified::MozLength::ExtremumLength(ref ext) => {
|
||||
debug_assert!(context.for_non_inherited_property.is_some(),
|
||||
"should check whether we're a non-inherited property");
|
||||
specified::MozLength::ExtremumLength(ext) => {
|
||||
context.rule_cache_conditions.borrow_mut()
|
||||
.set_writing_mode_dependency(context.builder.writing_mode);
|
||||
MozLength::ExtremumLength(ext.clone())
|
||||
if !ext.valid_for(context.builder.writing_mode, context.for_non_inherited_property.unwrap()) {
|
||||
MozLength::auto()
|
||||
} else {
|
||||
MozLength::ExtremumLength(ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -916,11 +967,14 @@ impl ToComputedValue for specified::MozLength {
|
|||
#[inline]
|
||||
fn from_computed_value(computed: &MozLength) -> Self {
|
||||
match *computed {
|
||||
MozLength::LengthOrPercentageOrAuto(ref lopoa) =>
|
||||
MozLength::LengthOrPercentageOrAuto(ref lopoa) => {
|
||||
specified::MozLength::LengthOrPercentageOrAuto(
|
||||
specified::LengthOrPercentageOrAuto::from_computed_value(&lopoa)),
|
||||
MozLength::ExtremumLength(ref ext) =>
|
||||
specified::MozLength::ExtremumLength(ext.clone()),
|
||||
specified::LengthOrPercentageOrAuto::from_computed_value(lopoa)
|
||||
)
|
||||
},
|
||||
MozLength::ExtremumLength(ext) => {
|
||||
specified::MozLength::ExtremumLength(ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -938,21 +992,33 @@ pub enum MaxLength {
|
|||
|
||||
impl MaxLength {
|
||||
/// Returns the `none` value.
|
||||
#[inline]
|
||||
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 {
|
||||
debug_assert!(
|
||||
context.for_non_inherited_property.is_some(),
|
||||
"Someone added a MaxLength to an inherited property? Evil!"
|
||||
);
|
||||
match *self {
|
||||
specified::MaxLength::LengthOrPercentageOrNone(ref lopon) => {
|
||||
MaxLength::LengthOrPercentageOrNone(lopon.to_computed_value(context))
|
||||
}
|
||||
specified::MaxLength::ExtremumLength(ref ext) => {
|
||||
MaxLength::ExtremumLength(ext.clone())
|
||||
specified::MaxLength::ExtremumLength(ext) => {
|
||||
context.rule_cache_conditions.borrow_mut()
|
||||
.set_writing_mode_dependency(context.builder.writing_mode);
|
||||
if !ext.valid_for(context.builder.writing_mode, context.for_non_inherited_property.unwrap()) {
|
||||
MaxLength::none()
|
||||
} else {
|
||||
MaxLength::ExtremumLength(ext)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ pub use super::{Auto, Either, None_};
|
|||
pub use super::specified::{BorderStyle, TextDecorationLine};
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNone, LengthOrNumber, LengthOrPercentage};
|
||||
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||
pub use self::length::{CSSPixelLength, NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength, NonNegativeLengthOrPercentage};
|
||||
pub use self::list::{ListStyleImage, Quotes};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::list::ListStyleType;
|
||||
|
|
|
@ -195,14 +195,3 @@ impl ToCss for KeyframesName {
|
|||
}
|
||||
}
|
||||
|
||||
/// A type for possible values for min- and max- flavors of width,
|
||||
/// height, block-size, and inline-size.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToCss)]
|
||||
pub enum ExtremumLength {
|
||||
MozMaxContent,
|
||||
MozMinContent,
|
||||
MozFitContent,
|
||||
MozAvailable,
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use style_traits::{ParseError, StyleParseErrorKind};
|
|||
use style_traits::values::specified::AllowedNumericType;
|
||||
use stylesheets::CssRuleType;
|
||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||
use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context};
|
||||
use values::{Auto, CSSFloat, Either, None_, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
|
||||
use values::generics::NonNegative;
|
||||
use values::specified::NonNegativeNumber;
|
||||
use values::specified::calc::CalcNode;
|
||||
|
@ -1126,6 +1126,17 @@ impl Parse for MozLength {
|
|||
}
|
||||
|
||||
impl MozLength {
|
||||
/// Parses, without quirks, and disallowing ExtremumLength values.
|
||||
///
|
||||
/// Used for logical props in the block direction.
|
||||
pub fn parse_disallow_keyword<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let length = LengthOrPercentageOrAuto::parse_non_negative(context, input)?;
|
||||
Ok(MozLength::LengthOrPercentageOrAuto(length))
|
||||
}
|
||||
|
||||
/// Parses, with quirks.
|
||||
pub fn parse_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
@ -1172,6 +1183,17 @@ impl Parse for MaxLength {
|
|||
}
|
||||
|
||||
impl MaxLength {
|
||||
/// Parses, without quirks, and disallowing ExtremumLength values.
|
||||
///
|
||||
/// Used for logical props in the block direction.
|
||||
pub fn parse_disallow_keyword<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let length = LengthOrPercentageOrNone::parse_non_negative(context, input)?;
|
||||
Ok(MaxLength::LengthOrPercentageOrNone(length))
|
||||
}
|
||||
|
||||
/// Parses, with quirks.
|
||||
pub fn parse_quirky<'i, 't>(
|
||||
context: &ParserContext,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue