Skip to content

Commit

Permalink
Bug 1857674 - Pass computed context to substitute_block r=firefox-sty…
Browse files Browse the repository at this point in the history
…le-system-reviewers,emilio

This is necessary in order to compute registered custom properties from
substitute_block.

Depends on D191159

Differential Revision: https://phabricator.services.mozilla.com/D191614
  • Loading branch information
zrhoffman committed Oct 23, 2023
1 parent dce0a41 commit 899d1d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
19 changes: 17 additions & 2 deletions servo/components/style/custom_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ fn parse_and_substitute_fallback<'i>(
input: &mut Parser<'i, '_>,
custom_properties: &ComputedCustomProperties,
stylist: &Stylist,
computed_context: &computed::Context,
) -> Result<ComputedValue, ParseError<'i>> {
input.skip_whitespace();
let after_comma = input.state();
Expand All @@ -743,6 +744,7 @@ fn parse_and_substitute_fallback<'i>(
&mut fallback,
custom_properties,
stylist,
computed_context,
)?;
fallback.push_from(input, position, last_token_type)?;
Ok(fallback)
Expand Down Expand Up @@ -865,6 +867,7 @@ impl<'a, 'b: 'a> CustomPropertiesBuilder<'a, 'b> {
map,
self.inherited,
self.stylist,
self.computed_context,
self.is_root_element,
);
return;
Expand Down Expand Up @@ -1258,6 +1261,7 @@ fn substitute_all(
&mut context.map,
context.inherited,
context.stylist,
context.computed_context,
context.is_root_element,
);

Expand Down Expand Up @@ -1324,6 +1328,7 @@ fn substitute_references_in_value_and_apply(
custom_properties: &mut ComputedCustomProperties,
inherited: &ComputedCustomProperties,
stylist: &Stylist,
computed_context: &computed::Context,
is_root_element: bool,
) {
debug_assert!(value.has_references());
Expand All @@ -1342,6 +1347,7 @@ fn substitute_references_in_value_and_apply(
&mut computed_value,
custom_properties,
stylist,
computed_context,
);

let last_token_type = match last_token_type {
Expand Down Expand Up @@ -1465,6 +1471,7 @@ fn substitute_block<'i>(
partial_computed_value: &mut ComputedValue,
custom_properties: &ComputedCustomProperties,
stylist: &Stylist,
computed_context: &computed::Context,
) -> Result<TokenSerializationType, ParseError<'i>> {
let mut last_token_type = TokenSerializationType::nothing();
let mut set_position_at_next_iteration = false;
Expand Down Expand Up @@ -1534,6 +1541,7 @@ fn substitute_block<'i>(
input,
custom_properties,
stylist,
computed_context,
)?;
let mut fallback_input = ParserInput::new(&fallback.css);
let mut fallback_input = Parser::new(&mut fallback_input);
Expand All @@ -1555,8 +1563,12 @@ fn substitute_block<'i>(
partial_computed_value.push_variable(input, v)?;
} else {
input.expect_comma()?;
let fallback =
parse_and_substitute_fallback(input, custom_properties, stylist)?;
let fallback = parse_and_substitute_fallback(
input,
custom_properties,
stylist,
computed_context,
)?;
last_token_type = fallback.last_token_type;

if let Some(registration) = registration {
Expand Down Expand Up @@ -1592,6 +1604,7 @@ fn substitute_block<'i>(
partial_computed_value,
custom_properties,
stylist,
computed_context,
)
})?;
// It's the same type for CloseCurlyBracket and CloseSquareBracket.
Expand All @@ -1618,6 +1631,7 @@ pub fn substitute<'i>(
first_token_type: TokenSerializationType,
custom_properties: &ComputedCustomProperties,
stylist: &Stylist,
computed_context: &computed::Context,
) -> Result<String, ParseError<'i>> {
let mut substituted = ComputedValue::empty();
let mut input = ParserInput::new(input);
Expand All @@ -1629,6 +1643,7 @@ pub fn substitute<'i>(
&mut substituted,
custom_properties,
stylist,
computed_context,
)?;
substituted.push_from(&input, position, last_token_type)?;
Ok(substituted.css)
Expand Down
1 change: 1 addition & 0 deletions servo/components/style/properties/cascade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> {
self.context.builder.custom_properties(),
self.context.quirks_mode,
self.context.builder.stylist.unwrap(),
self.context,
shorthand_cache,
)
}
Expand Down
1 change: 1 addition & 0 deletions servo/components/style/properties/declaration_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ impl PropertyDeclarationBlock {
&context.builder.custom_properties,
QuirksMode::NoQuirks,
stylist,
&context,
&mut Default::default(),
)
.to_css(dest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ impl AnimationValue {
custom_properties,
context.quirks_mode,
context.builder.stylist.unwrap(),
context,
&mut cache,
)
};
Expand Down
2 changes: 2 additions & 0 deletions servo/components/style/properties/properties.mako.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1727,6 +1727,7 @@ impl UnparsedValue {
custom_properties: &crate::custom_properties::ComputedCustomProperties,
quirks_mode: QuirksMode,
stylist: &Stylist,
computed_context: &computed::Context,
shorthand_cache: &'cache mut ShorthandsWithPropertyReferencesCache,
) -> Cow<'cache, PropertyDeclaration> {
let invalid_at_computed_value_time = || {
Expand Down Expand Up @@ -1754,6 +1755,7 @@ impl UnparsedValue {
self.first_token_type,
custom_properties,
stylist,
computed_context,
) {
Ok(css) => css,
Err(..) => return invalid_at_computed_value_time(),
Expand Down

0 comments on commit 899d1d6

Please sign in to comment.