From bfa293c5c5c48e8792881441093dde722aae6496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 20 Oct 2022 14:24:36 +0000 Subject: [PATCH] style: Split in_media_query and in_container_query bits from computed::Context No behavior change, but it makes more sense this way :) Differential Revision: https://phabricator.services.mozilla.com/D159851 --- components/style/values/computed/mod.rs | 18 +++++++++++++++--- components/style/values/specified/length.rs | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 0ef6568c669..1eeaeee316a 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -166,9 +166,12 @@ pub struct Context<'a> { #[cfg(feature = "servo")] pub cached_system_font: Option<()>, - /// Whether or not we are computing the media list in a media query + /// Whether or not we are computing the media list in a media query. pub in_media_query: bool, + /// Whether or not we are computing the container query condition. + pub in_container_query: bool, + /// The quirks mode of this context. pub quirks_mode: QuirksMode, @@ -215,6 +218,7 @@ impl<'a> Context<'a> { builder: StyleBuilder::for_inheritance(device, None, None), cached_system_font: None, in_media_query: true, + in_container_query: true, quirks_mode, for_smil_animation: false, container_info: None, @@ -248,7 +252,8 @@ impl<'a> Context<'a> { let context = Context { builder: StyleBuilder::for_inheritance(device, style, None), cached_system_font: None, - in_media_query: true, + in_media_query: false, + in_container_query: true, quirks_mode, for_smil_animation: false, container_info, @@ -271,6 +276,7 @@ impl<'a> Context<'a> { builder, cached_system_font: None, in_media_query: false, + in_container_query: false, quirks_mode, container_info: None, for_smil_animation: false, @@ -292,6 +298,7 @@ impl<'a> Context<'a> { builder, cached_system_font: None, in_media_query: false, + in_container_query: false, quirks_mode, container_info: None, for_smil_animation, @@ -344,7 +351,7 @@ impl<'a> Context<'a> { vertical, font, size, - self.in_media_query, + self.in_media_or_container_query(), retrieve_math_scales, ) } @@ -359,6 +366,11 @@ impl<'a> Context<'a> { .au_viewport_size_for_viewport_unit_resolution(variant) } + /// Whether we're in a media or container query. + pub fn in_media_or_container_query(&self) -> bool { + self.in_media_query || self.in_container_query + } + /// The default computed style we're getting our reset style from. pub fn default_style(&self) -> &ComputedValues { self.builder.default_style() diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 523ae05354a..7ae816aebd2 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -264,7 +264,7 @@ impl FontRelativeLength { // element, the rem units refer to the property's initial // value. // - let reference_size = if context.builder.is_root_element || context.in_media_query { + let reference_size = if context.builder.is_root_element || context.in_media_or_container_query() { reference_font_size } else { context.device().root_font_size()