Bug 1806273 - Partial fix for container units in pseudo-elements. r=emilio

When apply_declarations is used for a pseudo-element, make it pass the
parent_style as the originating_element_style for container queries.

This requires changing some parameters from Option<&Arc<ComputedValues>>
to Option<&ComputedValues>.

It's not a complete solution, since e.g. parent_style is not the style
of the originating element of a ::backdrop. But here it's not as simple
as in D164908, so leaving these details for later.

Differential Revision: https://phabricator.services.mozilla.com/D164977
This commit is contained in:
Oriol Brufau
2022-12-21 01:04:05 +00:00
parent b54817e903
commit 23590b6c6f
5 changed files with 14 additions and 45 deletions

View File

@@ -282,7 +282,8 @@ where
};
let is_root_element = pseudo.is_none() && element.map_or(false, |e| e.is_root());
let container_size_query = ContainerSizeQuery::for_option_element(element, None);
let container_size_query =
ContainerSizeQuery::for_option_element(element, pseudo.and(parent_style));
let mut context = computed::Context::new(
// We'd really like to own the rules here to avoid refcount traffic, but

View File

@@ -135,14 +135,14 @@ enum TraversalResult<T> {
Done(T),
}
fn traverse_container<E, F, R>(
fn traverse_container<E, S, F, R>(
mut e: E,
originating_element_style: Option<&Arc<ComputedValues>>,
originating_element_style: Option<&S>,
evaluator: F,
) -> Option<(E, R)>
where
E: TElement,
F: Fn(E, Option<&Arc<ComputedValues>>) -> TraversalResult<R>,
F: Fn(E, Option<&S>) -> TraversalResult<R>,
{
if originating_element_style.is_some() {
match evaluator(e, originating_element_style) {
@@ -479,7 +479,7 @@ pub enum ContainerSizeQuery<'a> {
impl<'a> ContainerSizeQuery<'a> {
fn evaluate_potential_size_container<E>(
e: E,
originating_element_style: Option<&Arc<ComputedValues>>,
originating_element_style: Option<&ComputedValues>,
) -> TraversalResult<ContainerSizeQueryResult>
where
E: TElement,
@@ -492,7 +492,7 @@ impl<'a> ContainerSizeQuery<'a> {
Some(d) => d,
None => return TraversalResult::InProgress,
};
data.styles.primary()
&**data.styles.primary()
},
};
if !style
@@ -533,7 +533,7 @@ impl<'a> ContainerSizeQuery<'a> {
/// Find the query container size for a given element. Meant to be used as a callback for new().
fn lookup<E>(
element: E,
originating_element_style: Option<&Arc<ComputedValues>>,
originating_element_style: Option<&ComputedValues>,
) -> ContainerSizeQueryResult
where
E: TElement + 'a,
@@ -558,10 +558,7 @@ impl<'a> ContainerSizeQuery<'a> {
}
/// Create a new instance of the container size query for given element, with a deferred lookup callback.
pub fn for_element<E>(
element: E,
originating_element_style: Option<&'a Arc<ComputedValues>>,
) -> Self
pub fn for_element<E>(element: E, originating_element_style: Option<&'a ComputedValues>) -> Self
where
E: TElement + 'a,
{
@@ -576,7 +573,7 @@ impl<'a> ContainerSizeQuery<'a> {
None => return Self::none(),
};
data = parent.borrow_data();
data.as_ref().map(|data| data.styles.primary())
data.as_ref().map(|data| &**data.styles.primary())
},
};
let should_traverse = match style {
@@ -596,7 +593,7 @@ impl<'a> ContainerSizeQuery<'a> {
/// Create a new instance, but with optional element.
pub fn for_option_element<E>(
element: Option<E>,
originating_element_style: Option<&'a Arc<ComputedValues>>,
originating_element_style: Option<&'a ComputedValues>,
) -> Self
where
E: TElement + 'a,

View File

@@ -6051,7 +6051,8 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(
let parent_data = parent_element.as_ref().and_then(|e| e.borrow_data());
let parent_style = parent_data
.as_ref()
.map(|d| d.styles.primary());
.map(|d| d.styles.primary())
.map(|x| &**x);
let container_size_query =
ContainerSizeQuery::for_element(element, pseudo.as_ref().and(parent_style));
@@ -6059,7 +6060,7 @@ pub extern "C" fn Servo_GetComputedKeyframeValues(
let mut context = create_context_for_animation(
&data,
&style,
parent_style.map(|x| &**x),
parent_style,
/* for_smil_animation = */ false,
&mut conditions,
container_size_query,

View File

@@ -2,23 +2,8 @@
[Originating element container for ::before]
expected: FAIL
[Originating element container for ::after]
expected: FAIL
[Originating element container for ::marker]
expected: FAIL
[Originating element container for ::first-line]
expected: FAIL
[Originating element container for ::first-letter]
expected: FAIL
[Originating element container for outer ::first-line]
expected: FAIL
[Originating element container for outer ::first-letter]
expected: FAIL
[Originating element container for ::backdrop]
expected: FAIL

View File

@@ -1,18 +1,3 @@
[pseudo-elements-007.html]
[font-size for ::before depending on container]
expected: FAIL
[font-size for ::after depending on container]
expected: FAIL
[font-size for ::marker depending on container]
expected: FAIL
[font-size for ::first-line depending on container]
expected: FAIL
[font-size for ::first-letter depending on container]
expected: FAIL
[font-size for ::backdrop depending on container]
expected: FAIL