mirror of
https://github.com/servo/servo.git
synced 2025-08-08 15:05:35 +01:00
style: More container queries plumbing
Provide container information in computed::Context and use it to resolve the container queries. This still fails a lot of tests because we are not ensuring that layout is up-to-date when we style the container descendants, but that's expected. Differential Revision: https://phabricator.services.mozilla.com/D146478
This commit is contained in:
parent
5c2fac087f
commit
bbf10a43b8
18 changed files with 420 additions and 143 deletions
|
@ -16,6 +16,7 @@ use super::specified;
|
|||
use super::{CSSFloat, CSSInteger};
|
||||
use crate::computed_value_flags::ComputedValueFlags;
|
||||
use crate::context::QuirksMode;
|
||||
use crate::stylesheets::container_rule::ContainerInfo;
|
||||
use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
|
||||
use crate::media_queries::Device;
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -170,6 +171,9 @@ pub struct Context<'a> {
|
|||
/// values, which SMIL allows.
|
||||
pub for_smil_animation: bool,
|
||||
|
||||
/// Returns the container information to evaluate a given container query.
|
||||
pub container_info: Option<ContainerInfo>,
|
||||
|
||||
/// The property we are computing a value for, if it is a non-inherited
|
||||
/// property. None if we are computed a value for an inherited property
|
||||
/// or not computing for a property at all (e.g. in a media query
|
||||
|
@ -198,6 +202,42 @@ impl<'a> Context<'a> {
|
|||
in_media_query: true,
|
||||
quirks_mode,
|
||||
for_smil_animation: false,
|
||||
container_info: None,
|
||||
for_non_inherited_property: None,
|
||||
rule_cache_conditions: RefCell::new(&mut conditions),
|
||||
};
|
||||
|
||||
f(&context)
|
||||
}
|
||||
|
||||
/// Creates a suitable context for container query evaluation for the style
|
||||
/// specified.
|
||||
pub fn for_container_query_evaluation<F, R>(
|
||||
device: &Device,
|
||||
container_info_and_style: Option<(ContainerInfo, Arc<ComputedValues>)>,
|
||||
f: F,
|
||||
) -> R
|
||||
where
|
||||
F: FnOnce(&Context) -> R,
|
||||
{
|
||||
let mut conditions = RuleCacheConditions::default();
|
||||
let provider = get_metrics_provider_for_product();
|
||||
|
||||
let (container_info, style) = match container_info_and_style {
|
||||
Some((ci, s)) => (Some(ci), Some(s)),
|
||||
None => (None, None),
|
||||
};
|
||||
|
||||
let style = style.as_ref().map(|s| &**s);
|
||||
let quirks_mode = device.quirks_mode();
|
||||
let context = Context {
|
||||
builder: StyleBuilder::for_inheritance(device, style, None),
|
||||
font_metrics_provider: &provider,
|
||||
cached_system_font: None,
|
||||
in_media_query: true,
|
||||
quirks_mode,
|
||||
for_smil_animation: false,
|
||||
container_info,
|
||||
for_non_inherited_property: None,
|
||||
rule_cache_conditions: RefCell::new(&mut conditions),
|
||||
};
|
||||
|
@ -304,8 +344,8 @@ impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ComputedVecIter<'a, 'cx, 'cx_
|
|||
/// Construct an iterator from a slice of specified values and a context
|
||||
pub fn new(cx: &'cx Context<'cx_a>, values: &'a [S]) -> Self {
|
||||
ComputedVecIter {
|
||||
cx: cx,
|
||||
values: values,
|
||||
cx,
|
||||
values,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue