/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Parsing for registered custom properties.
use std::fmt::{self, Write};
usesuper::{
registry::PropertyRegistrationData,
syntax::{
data_type::DataType, Component as SyntaxComponent, ComponentName, Descriptor, Multiplier,
},
}; usecrate::custom_properties::ComputedValue as ComputedPropertyValue; usecrate::parser::{Parse, ParserContext}; usecrate::properties; usecrate::stylesheets::{CssRuleType, Origin, UrlExtraData}; usecrate::values::{
animated::{self, Animate, Procedure},
computed::{self, ToComputedValue},
specified, CustomIdent,
}; use cssparser::{BasicParseErrorKind, ParseErrorKind, Parser as CSSParser, TokenSerializationType}; use selectors::matching::QuirksMode; use servo_arc::Arc; use smallvec::SmallVec; use style_traits::{
owned_str::OwnedStr, CssWriter, ParseError as StyleParseError, ParsingMode,
PropertySyntaxParseError, StyleParseErrorKind, ToCss,
};
/// A single component of the computed value. pubtype ComputedValueComponent = GenericValueComponent<
computed::Length,
computed::Number,
computed::Percentage,
computed::LengthPercentage,
computed::Color,
computed::Image,
computed::url::ComputedUrl,
computed::Integer,
computed::Angle,
computed::Time,
computed::Resolution,
computed::Transform,
>;
/// A single component of the specified value. pubtype SpecifiedValueComponent = GenericValueComponent<
specified::Length,
specified::Number,
specified::Percentage,
specified::LengthPercentage,
specified::Color,
specified::Image,
specified::url::SpecifiedUrl,
specified::Integer,
specified::Angle,
specified::Time,
specified::Resolution,
specified::Transform,
>;
/// A generic enum used for both specified value components and computed value components. #[derive(
Animate, Clone, ToCss, ToComputedValue, ToResolvedValue, Debug, MallocSizeOf, PartialEq, ToShmem
)] #[animation(no_bound(Image, Url))] pubenum GenericValueComponent<
Length,
Number,
Percentage,
LengthPercentage,
Color,
Image,
Url,
Integer,
Angle,
Time,
Resolution,
TransformFunction,
> { /// A <length> value
Length(Length), /// A <number> value
Number(Number), /// A <percentage> value
Percentage(Percentage), /// A <length-percentage> value
LengthPercentage(LengthPercentage), /// A <color> value
Color(Color), /// An <image> value #[animation(error)]
Image(Image), /// A <url> value #[animation(error)]
Url(Url), /// An <integer> value
Integer(Integer), /// An <angle> value
Angle(Angle), /// A <time> value
Time(Time), /// A <resolution> value
Resolution(Resolution), /// A <transform-function> value /// TODO(bug 1884606): <transform-function> `none` should not interpolate.
TransformFunction(TransformFunction), /// A <custom-ident> value #[animation(error)]
CustomIdent(CustomIdent), /// A <transform-list> value, equivalent to <transform-function>+ /// TODO(bug 1884606): <transform-list> `none` should not interpolate.
TransformList(ComponentList<Self>), /// A <string> value #[animation(error)]
String(OwnedStr),
}
/// A list of component values, including the list's multiplier. #[derive(Clone, ToComputedValue, ToResolvedValue, Debug, MallocSizeOf, PartialEq, ToShmem)] pubstruct ComponentList<Component> { /// Multiplier pub multiplier: Multiplier, /// The list of components contained. pub components: crate::OwnedSlice<Component>,
}
/// A struct for a single specified registered custom property value that includes its original URL // data so the value can be uncomputed later. #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToComputedValue, ToResolvedValue, ToShmem)] pubstruct Value<Component> { /// The registered custom property value. pub(crate) v: ValueInner<Component>, /// The URL data of the registered custom property from before it was computed. This is /// necessary to uncompute registered custom properties. #[css(skip)]
url_data: UrlExtraData,
}
impl<Component: Animate> Animate for Value<Component> { fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { let v = self.v.animate(&other.v, procedure)?;
Ok(Value {
v,
url_data: self.url_data.clone(),
})
}
}
/// Creates a new registered custom property value presumed to have universal syntax. pubfn universal(var: Arc<ComputedPropertyValue>) -> Self { let url_data = var.url_data.clone(); let v = ValueInner::Universal(var); Self { v, url_data }
}
}
/// A specified registered custom property value. #[derive(
Animate, ToComputedValue, ToResolvedValue, ToCss, Clone, Debug, MallocSizeOf, PartialEq, ToShmem,
)] pubenum ValueInner<Component> { /// A single specified component value whose syntax descriptor component did not have a /// multiplier.
Component(Component), /// A specified value whose syntax descriptor was the universal syntax definition. #[animation(error)]
Universal(#[ignore_malloc_size_of = "Arc"] Arc<ComputedPropertyValue>), /// A list of specified component values whose syntax descriptor component had a multiplier.
List(#[animation(field_bound)] ComponentList<Component>),
}
/// Whether the computed value parsing should allow computationaly dependent values like 3em or /// var(-foo). /// /// https://drafts.css-houdini.org/css-properties-values-api-1/#computationally-independent pubenum AllowComputationallyDependent { /// Only computationally independent values are allowed.
No, /// Computationally independent and dependent values are allowed.
Yes,
}
type SmallComponentVec = SmallVec<[SpecifiedValueComponent; 1]>;
fn expect_multiplier<'i, 't>(
input: &mut CSSParser<'i, 't>,
multiplier: &Multiplier,
) -> Result<(), StyleParseError<'i>> { match multiplier {
Multiplier::Space => {
input.expect_whitespace()?; if input.is_exhausted() { // If there was trailing whitespace, do not interpret it as a multiplier return Err(input.new_error(BasicParseErrorKind::EndOfInput));
}
Ok(())
},
Multiplier::Comma => Ok(input.expect_comma()?),
}
}
}
/// An animated value for custom property. #[derive(Clone, Debug, MallocSizeOf, PartialEq)] pubstruct CustomAnimatedValue { /// The name of the custom property. pub(crate) name: crate::custom_properties::Name, /// The computed value of the custom property.
value: ComputedValue,
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.