mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Add AngleOrPercentage to style system.
Differential Revision: https://phabricator.services.mozilla.com/D62158
This commit is contained in:
parent
97382a2c41
commit
5ed8fe8ee2
3 changed files with 93 additions and 3 deletions
|
@ -465,6 +465,54 @@ trivial_to_computed_value!(String);
|
||||||
trivial_to_computed_value!(Box<str>);
|
trivial_to_computed_value!(Box<str>);
|
||||||
trivial_to_computed_value!(crate::OwnedStr);
|
trivial_to_computed_value!(crate::OwnedStr);
|
||||||
|
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[derive(
|
||||||
|
Animate,
|
||||||
|
Clone,
|
||||||
|
ComputeSquaredDistance,
|
||||||
|
Copy,
|
||||||
|
Debug,
|
||||||
|
MallocSizeOf,
|
||||||
|
PartialEq,
|
||||||
|
ToAnimatedZero,
|
||||||
|
ToCss,
|
||||||
|
ToResolvedValue,
|
||||||
|
)]
|
||||||
|
#[repr(C, u8)]
|
||||||
|
pub enum AngleOrPercentage {
|
||||||
|
Percentage(Percentage),
|
||||||
|
Angle(Angle),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToComputedValue for specified::AngleOrPercentage {
|
||||||
|
type ComputedValue = AngleOrPercentage;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, context: &Context) -> AngleOrPercentage {
|
||||||
|
match *self {
|
||||||
|
specified::AngleOrPercentage::Percentage(percentage) => {
|
||||||
|
AngleOrPercentage::Percentage(percentage.to_computed_value(context))
|
||||||
|
},
|
||||||
|
specified::AngleOrPercentage::Angle(angle) => {
|
||||||
|
AngleOrPercentage::Angle(angle.to_computed_value(context))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn from_computed_value(computed: &AngleOrPercentage) -> Self {
|
||||||
|
match *computed {
|
||||||
|
AngleOrPercentage::Percentage(percentage) => {
|
||||||
|
specified::AngleOrPercentage::Percentage(ToComputedValue::from_computed_value(
|
||||||
|
&percentage,
|
||||||
|
))
|
||||||
|
},
|
||||||
|
AngleOrPercentage::Angle(angle) => {
|
||||||
|
specified::AngleOrPercentage::Angle(ToComputedValue::from_computed_value(&angle))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A `<number>` value.
|
/// A `<number>` value.
|
||||||
pub type Number = CSSFloat;
|
pub type Number = CSSFloat;
|
||||||
|
|
||||||
|
|
|
@ -163,7 +163,8 @@ impl Angle {
|
||||||
/// https://github.com/w3c/fxtf-drafts/issues/228
|
/// https://github.com/w3c/fxtf-drafts/issues/228
|
||||||
///
|
///
|
||||||
/// See also: https://github.com/w3c/csswg-drafts/issues/1162.
|
/// See also: https://github.com/w3c/csswg-drafts/issues/1162.
|
||||||
enum AllowUnitlessZeroAngle {
|
#[allow(missing_docs)]
|
||||||
|
pub enum AllowUnitlessZeroAngle {
|
||||||
Yes,
|
Yes,
|
||||||
No,
|
No,
|
||||||
}
|
}
|
||||||
|
@ -203,7 +204,7 @@ impl Angle {
|
||||||
Self::parse_internal(context, input, AllowUnitlessZeroAngle::Yes)
|
Self::parse_internal(context, input, AllowUnitlessZeroAngle::Yes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_internal<'i, 't>(
|
pub(super) fn parse_internal<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
allow_unitless_zero: AllowUnitlessZeroAngle,
|
allow_unitless_zero: AllowUnitlessZeroAngle,
|
||||||
|
|
|
@ -31,7 +31,7 @@ use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKin
|
||||||
pub use self::align::{AlignContent, AlignItems, AlignSelf, ContentDistribution};
|
pub use self::align::{AlignContent, AlignItems, AlignSelf, ContentDistribution};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub use self::align::{JustifyContent, JustifyItems, JustifySelf, SelfAlignment};
|
pub use self::align::{JustifyContent, JustifyItems, JustifySelf, SelfAlignment};
|
||||||
pub use self::angle::Angle;
|
pub use self::angle::{Angle, AllowUnitlessZeroAngle};
|
||||||
pub use self::background::{BackgroundRepeat, BackgroundSize};
|
pub use self::background::{BackgroundRepeat, BackgroundSize};
|
||||||
pub use self::basic_shape::FillRule;
|
pub use self::basic_shape::FillRule;
|
||||||
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth};
|
||||||
|
@ -130,6 +130,47 @@ pub mod transform;
|
||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod url;
|
pub mod url;
|
||||||
|
|
||||||
|
/// <angle> | <percentage>
|
||||||
|
/// https://drafts.csswg.org/css-values/#typedef-angle-percentage
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||||
|
pub enum AngleOrPercentage {
|
||||||
|
Percentage(Percentage),
|
||||||
|
Angle(Angle),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AngleOrPercentage {
|
||||||
|
fn parse_internal<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
allow_unitless_zero: AllowUnitlessZeroAngle,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
if let Ok(per) = input.try(|i| Percentage::parse(context, i)) {
|
||||||
|
return Ok(AngleOrPercentage::Percentage(per));
|
||||||
|
}
|
||||||
|
|
||||||
|
Angle::parse_internal(context, input, allow_unitless_zero).map(AngleOrPercentage::Angle)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Allow unitless angles, used for conic-gradients as specified by the spec.
|
||||||
|
/// https://drafts.csswg.org/css-images-4/#valdef-conic-gradient-angle
|
||||||
|
pub fn parse_with_unitless<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
AngleOrPercentage::parse_internal(context, input, AllowUnitlessZeroAngle::Yes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for AngleOrPercentage {
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>,
|
||||||
|
) -> Result<Self, ParseError<'i>> {
|
||||||
|
AngleOrPercentage::parse_internal(context, input, AllowUnitlessZeroAngle::No)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Parse a `<number>` value, with a given clamping mode.
|
/// Parse a `<number>` value, with a given clamping mode.
|
||||||
fn parse_number_with_clamping_mode<'i, 't>(
|
fn parse_number_with_clamping_mode<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue