mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Rename and move PercentageOrNumber to values
This commit is contained in:
parent
fe45283169
commit
645971b387
7 changed files with 128 additions and 93 deletions
|
@ -20,7 +20,7 @@ pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
|||
pub use super::{Auto, Either, None_};
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use super::specified::{AlignItems, AlignJustifyContent, AlignJustifySelf, JustifyItems};
|
||||
pub use super::specified::{Angle, BorderStyle, GridLine, Time, UrlOrNone};
|
||||
pub use super::specified::{Angle, BorderStyle, GridLine, Percentage, Time, UrlOrNone};
|
||||
pub use super::specified::url::SpecifiedUrl;
|
||||
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrAutoOrContent, LengthOrPercentageOrNone, LengthOrNone};
|
||||
|
@ -264,6 +264,46 @@ pub struct Shadow {
|
|||
/// A `<number>` value.
|
||||
pub type Number = CSSFloat;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum NumberOrPercentage {
|
||||
Percentage(Percentage),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::NumberOrPercentage {
|
||||
type ComputedValue = NumberOrPercentage;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> NumberOrPercentage {
|
||||
match *self {
|
||||
specified::NumberOrPercentage::Percentage(percentage) =>
|
||||
NumberOrPercentage::Percentage(percentage.to_computed_value(context)),
|
||||
specified::NumberOrPercentage::Number(number) =>
|
||||
NumberOrPercentage::Number(number.to_computed_value(context)),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &NumberOrPercentage) -> Self {
|
||||
match *computed {
|
||||
NumberOrPercentage::Percentage(percentage) =>
|
||||
specified::NumberOrPercentage::Percentage(ToComputedValue::from_computed_value(&percentage)),
|
||||
NumberOrPercentage::Number(number) =>
|
||||
specified::NumberOrPercentage::Number(ToComputedValue::from_computed_value(&number)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for NumberOrPercentage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
NumberOrPercentage::Percentage(percentage) => percentage.to_css(dest),
|
||||
NumberOrPercentage::Number(number) => number.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A type used for opacity.
|
||||
pub type Opacity = CSSFloat;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ use style_traits::values::specified::AllowedNumericType;
|
|||
use super::{Angle, Number, SimplifiedValueNode, SimplifiedSumNode, Time};
|
||||
use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, HasViewportPercentage, None_, Normal};
|
||||
use values::ExtremumLength;
|
||||
use values::computed::Context;
|
||||
use values::computed::{ComputedValueAsSpecified, Context};
|
||||
|
||||
pub use super::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use super::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||
|
@ -921,6 +921,8 @@ impl Parse for Percentage {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputedValueAsSpecified for Percentage {}
|
||||
|
||||
/// A length or a percentage value.
|
||||
///
|
||||
/// TODO(emilio): Does this make any sense vs. CalcLengthOrPercentage?
|
||||
|
|
|
@ -572,6 +572,38 @@ impl ToCss for Number {
|
|||
}
|
||||
}
|
||||
|
||||
/// <number-percentage>
|
||||
/// Accepts only non-negative numbers.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
pub enum NumberOrPercentage {
|
||||
Percentage(Percentage),
|
||||
Number(Number),
|
||||
}
|
||||
|
||||
no_viewport_percentage!(NumberOrPercentage);
|
||||
|
||||
impl Parse for NumberOrPercentage {
|
||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
if let Ok(per) = input.try(|input| Percentage::parse(context, input)) {
|
||||
return Ok(NumberOrPercentage::Percentage(per));
|
||||
}
|
||||
|
||||
let num = try!(Number::parse_non_negative(input));
|
||||
Ok(NumberOrPercentage::Number(num))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for NumberOrPercentage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
NumberOrPercentage::Percentage(percentage) => percentage.to_css(dest),
|
||||
NumberOrPercentage::Number(number) => number.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[allow(missing_docs)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue