mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
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:
parent
d8785f3a22
commit
3acb103324
3 changed files with 45 additions and 20 deletions
|
@ -26,7 +26,6 @@ use fxhash::FxHashMap;
|
|||
use servo_arc::Arc;
|
||||
use smallvec::SmallVec;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
#[cfg(feature = "gecko")]
|
||||
use std::mem;
|
||||
|
||||
|
@ -277,11 +276,11 @@ where
|
|||
|
||||
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
|
||||
// animation's usage of `apply_declarations` make this tricky. See bug
|
||||
// 1375525.
|
||||
builder: StyleBuilder::new(
|
||||
StyleBuilder::new(
|
||||
device,
|
||||
parent_style,
|
||||
parent_style_ignoring_first_line,
|
||||
|
@ -290,14 +289,9 @@ where
|
|||
custom_properties,
|
||||
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,
|
||||
rule_cache_conditions: RefCell::new(rule_cache_conditions),
|
||||
};
|
||||
rule_cache_conditions,
|
||||
);
|
||||
|
||||
let using_cached_reset_properties;
|
||||
let mut cascade = Cascade::new(&mut context, cascade_mode, &referenced_properties);
|
||||
|
|
|
@ -28,7 +28,6 @@ use cssparser::{parse_important, AtRuleParser, DeclarationListParser, Declaratio
|
|||
use euclid::Size2D;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::{self, Write};
|
||||
use std::iter::Enumerate;
|
||||
use std::str::Chars;
|
||||
|
@ -665,18 +664,13 @@ impl MaybeNew for ViewportConstraints {
|
|||
let initial_viewport = device.au_viewport_size();
|
||||
|
||||
let mut conditions = RuleCacheConditions::default();
|
||||
let context = Context {
|
||||
let context = Context::new(
|
||||
// Note: DEVICE-ADAPT § 5. states that relative length values are
|
||||
// resolved against initial values
|
||||
builder: StyleBuilder::for_inheritance(device, None, None),
|
||||
cached_system_font: None,
|
||||
in_media_query: false,
|
||||
StyleBuilder::for_inheritance(device, None, None),
|
||||
quirks_mode,
|
||||
container_info: None,
|
||||
for_smil_animation: false,
|
||||
for_non_inherited_property: None,
|
||||
rule_cache_conditions: RefCell::new(&mut conditions),
|
||||
};
|
||||
&mut conditions,
|
||||
);
|
||||
|
||||
// DEVICE-ADAPT § 9.3 Resolving 'extend-to-zoom'
|
||||
let extend_width;
|
||||
|
|
|
@ -246,6 +246,43 @@ impl<'a> Context<'a> {
|
|||
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.
|
||||
pub fn device(&self) -> &Device {
|
||||
self.builder.device
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue