style: Centralize construction of computed::Context

For controlled construction and access of upcoming, lazily-evaluated container query size.

Differential Revision: https://phabricator.services.mozilla.com/D158055
This commit is contained in:
David Shin 2022-10-17 17:26:12 +00:00 committed by Martin Robinson
parent d8785f3a22
commit 3acb103324
3 changed files with 45 additions and 20 deletions

View file

@ -26,7 +26,6 @@ use fxhash::FxHashMap;
use servo_arc::Arc; use servo_arc::Arc;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use std::mem; use std::mem;
@ -277,11 +276,11 @@ where
let is_root_element = pseudo.is_none() && element.map_or(false, |e| e.is_root()); let is_root_element = pseudo.is_none() && element.map_or(false, |e| e.is_root());
let mut context = computed::Context { let mut context = computed::Context::new(
// We'd really like to own the rules here to avoid refcount traffic, but // We'd really like to own the rules here to avoid refcount traffic, but
// animation's usage of `apply_declarations` make this tricky. See bug // animation's usage of `apply_declarations` make this tricky. See bug
// 1375525. // 1375525.
builder: StyleBuilder::new( StyleBuilder::new(
device, device,
parent_style, parent_style,
parent_style_ignoring_first_line, parent_style_ignoring_first_line,
@ -290,14 +289,9 @@ where
custom_properties, custom_properties,
is_root_element, is_root_element,
), ),
cached_system_font: None,
in_media_query: false,
for_smil_animation: false,
for_non_inherited_property: None,
container_info: None,
quirks_mode, quirks_mode,
rule_cache_conditions: RefCell::new(rule_cache_conditions), rule_cache_conditions,
}; );
let using_cached_reset_properties; let using_cached_reset_properties;
let mut cascade = Cascade::new(&mut context, cascade_mode, &referenced_properties); let mut cascade = Cascade::new(&mut context, cascade_mode, &referenced_properties);

View file

@ -28,7 +28,6 @@ use cssparser::{parse_important, AtRuleParser, DeclarationListParser, Declaratio
use euclid::Size2D; use euclid::Size2D;
use selectors::parser::SelectorParseErrorKind; use selectors::parser::SelectorParseErrorKind;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use std::iter::Enumerate; use std::iter::Enumerate;
use std::str::Chars; use std::str::Chars;
@ -665,18 +664,13 @@ impl MaybeNew for ViewportConstraints {
let initial_viewport = device.au_viewport_size(); let initial_viewport = device.au_viewport_size();
let mut conditions = RuleCacheConditions::default(); let mut conditions = RuleCacheConditions::default();
let context = Context { let context = Context::new(
// Note: DEVICE-ADAPT § 5. states that relative length values are // Note: DEVICE-ADAPT § 5. states that relative length values are
// resolved against initial values // resolved against initial values
builder: StyleBuilder::for_inheritance(device, None, None), StyleBuilder::for_inheritance(device, None, None),
cached_system_font: None,
in_media_query: false,
quirks_mode, quirks_mode,
container_info: None, &mut conditions,
for_smil_animation: false, );
for_non_inherited_property: None,
rule_cache_conditions: RefCell::new(&mut conditions),
};
// DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom' // DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom'
let extend_width; let extend_width;

View file

@ -246,6 +246,43 @@ impl<'a> Context<'a> {
f(&context) f(&context)
} }
/// Creates a context suitable for more general cases.
pub fn new(
builder: StyleBuilder<'a>,
quirks_mode: QuirksMode,
rule_cache_conditions: &'a mut RuleCacheConditions,
) -> Self {
Self {
builder,
cached_system_font: None,
in_media_query: false,
quirks_mode,
container_info: None,
for_smil_animation: false,
for_non_inherited_property: None,
rule_cache_conditions: RefCell::new(rule_cache_conditions),
}
}
/// Creates a context suitable for computing animations.
pub fn new_for_animation(
builder: StyleBuilder<'a>,
for_smil_animation: bool,
quirks_mode: QuirksMode,
rule_cache_conditions: &'a mut RuleCacheConditions,
) -> Self {
Self {
builder,
cached_system_font: None,
in_media_query: false,
quirks_mode,
container_info: None,
for_smil_animation,
for_non_inherited_property: None,
rule_cache_conditions: RefCell::new(rule_cache_conditions),
}
}
/// The current device. /// The current device.
pub fn device(&self) -> &Device { pub fn device(&self) -> &Device {
self.builder.device self.builder.device