/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! Parsing for registered custom properties. use std::fmt::{self, Write}; use super::{ registry::PropertyRegistrationData, syntax::{ data_type::DataType, Component as SyntaxComponent, ComponentName, Descriptor, Multiplier, }, }; use crate::custom_properties::ComputedValue as ComputedPropertyValue; use crate::parser::{Parse, ParserContext}; use crate::properties; use crate::stylesheets::{CssRuleType, Origin, UrlExtraData}; use crate::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. pub type 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. pub type 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, >; impl GenericValueComponent { fn serialization_types(&self) -> (TokenSerializationType, TokenSerializationType) { let first_token_type = match self { Self::Length(_) | Self::Angle(_) | Self::Time(_) | Self::Resolution(_) => { TokenSerializationType::Dimension }, Self::Number(_) | Self::Integer(_) => TokenSerializationType::Number, Self::Percentage(_) | Self::LengthPercentage(_) => TokenSerializationType::Percentage, Self::Color(_) | Self::Image(_) | Self::Url(_) | Self::TransformFunction(_) | Self::TransformList(_) => TokenSerializationType::Function, Self::CustomIdent(_) => TokenSerializationType::Ident, Self::String(_) => TokenSerializationType::Other, }; let last_token_type = if first_token_type == TokenSerializationType::Function { TokenSerializationType::Other } else { first_token_type }; (first_token_type, last_token_type) } } /// A generic enum used for both specified value components and computed value components. #[derive(Animate, Clone, ToCss, ToComputedValue, Debug, MallocSizeOf, PartialEq)] #[animation(no_bound(Image, Url))] pub enum GenericValueComponent< Length, Number, Percentage, LengthPercentage, Color, Image, Url, Integer, Angle, Time, Resolution, TransformFunction, > { /// A value Length(Length), /// A value Number(Number), /// A value Percentage(Percentage), /// A value LengthPercentage(LengthPercentage), /// A value Color(Color), /// An value #[animation(error)] Image(Image), /// A value #[animation(error)] Url(Url), /// An value Integer(Integer), /// An value Angle(Angle), /// A