Skip to content

Commit

Permalink
Bug 1846628 - [css-properties-values-api] Optionally allow computatio…
Browse files Browse the repository at this point in the history
…nally dependent values in ComputedValue::parse r=emilio

This will be useful at computed value time, when registered properties
can be be computationally dependent.

Differential Revision: https://phabricator.services.mozilla.com/D186996
  • Loading branch information
zrhoffman committed Aug 28, 2023
1 parent e4ba2c2 commit 2ce483a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions servo/components/style/properties_and_values/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use super::{
registry::PropertyRegistration,
syntax::{Descriptor, ParsedDescriptor},
value::ComputedValue,
value::{AllowComputationallyDependent, ComputedValue},
};
use crate::custom_properties::{Name as CustomPropertyName, SpecifiedValue};
use crate::error_reporting::ContextualParseError;
Expand Down Expand Up @@ -239,7 +239,12 @@ impl PropertyRuleData {
return Err(ToRegistrationError::InitialValueNotComputationallyIndependent);
}

match ComputedValue::parse(&mut input, syntax, url_data) {
match ComputedValue::parse(
&mut input,
syntax,
url_data,
AllowComputationallyDependent::No,
) {
Ok(_) => {},
Err(_) => return Err(ToRegistrationError::InvalidInitialValue),
}
Expand Down
22 changes: 20 additions & 2 deletions servo/components/style/properties_and_values/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl ComputedValue {
mut input: &mut CSSParser<'i, 't>,
syntax: &Descriptor,
url_data: &UrlExtraData,
allow_computationally_dependent: AllowComputationallyDependent,
) -> Result<Self, StyleParseError<'i>> {
if syntax.is_universal() {
return Ok(Self::Universal(ComputedPropertyValue::parse(&mut input)?));
Expand All @@ -83,7 +84,7 @@ impl ComputedValue {
let mut has_multiplier = false;
{
let mut parser = Parser::new(syntax, &mut values, &mut has_multiplier);
parser.parse(&mut input, url_data)?;
parser.parse(&mut input, url_data, allow_computationally_dependent)?;
}
Ok(if has_multiplier {
Self::List(ArcSlice::from_iter(values.into_iter()))
Expand All @@ -93,6 +94,17 @@ impl ComputedValue {
}
}

/// 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
pub enum AllowComputationallyDependent {
/// Only computationally independent values are allowed.
No,
/// Computationally independent and dependent values are allowed.
Yes,
}

type SmallComponentVec = SmallVec<[ValueComponent; 1]>;

struct Parser<'a> {
Expand All @@ -118,12 +130,18 @@ impl<'a> Parser<'a> {
&mut self,
input: &mut CSSParser<'i, 't>,
url_data: &UrlExtraData,
allow_computationally_dependent: AllowComputationallyDependent,
) -> Result<(), StyleParseError<'i>> {
use self::AllowComputationallyDependent::*;
let parsing_mode = match allow_computationally_dependent {
No => ParsingMode::DISALLOW_FONT_RELATIVE,
Yes => ParsingMode::DEFAULT,
};
let ref context = ParserContext::new(
Origin::Author,
url_data,
Some(CssRuleType::Style),
ParsingMode::DISALLOW_FONT_RELATIVE,
parsing_mode,
QuirksMode::NoQuirks,
/* namespaces = */ Default::default(),
None,
Expand Down

0 comments on commit 2ce483a

Please sign in to comment.