style: Implement CSS 'contain: style'

Add an implementation of CSS `contain: style`. This introduces two new
data structures, the ContainStyleScope and ContainStyleScopeManager.

ContainStyleScope manages one `contain: style` "world" which has its own
counter and quote lists. The contents of these lists depend on their
parent scopes, but are not affected by their children.
ContainStyleScopeManager manages a tree of scopes starting at a root
scope which is outside of any `contain: style` element.

Scopes are stored in a hash table that is keyed off of the nsIContent
which establishes the `contain: style` scope. When modifying quote or
content lists, the ContainStyleScopeManager is responsible for finding
the appropriate `contain: style` scope to modify.

Perhaps the most complex part of this is that counters and quotes have
read access to the state of counters and quotes that are in ancestor
`contain: style` scopes. In the case of counters, USE nodes that are at
the beginning of counter lists might have a counter scope that starts in
an ancestor `contain: style` scope. When nsCounterNode::SetScope() is
called, the code may look upward in the `contain: style` scope tree to
find the start of the counter scope. In the case of quotes, the first
node in the quote list must look for the state of quotes in ancestor
`contain: style` scopes.

Differential Revision: https://phabricator.services.mozilla.com/D149508
This commit is contained in:
Martin Robinson 2022-06-22 16:16:59 +00:00
parent ad68880627
commit 64febfbe9a
3 changed files with 24 additions and 6 deletions

View file

@ -42,6 +42,9 @@ bitflags! {
/// A flag used to mark styles which are a pseudo-element or under one.
const IS_IN_PSEUDO_ELEMENT_SUBTREE = 1 << 4;
/// A flag used to mark styles which have contain:style or under one.
const SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE = 1 << 5;
/// Whether this style's `display` property depends on our parent style.
///
/// This is important because it may affect our optimizations to avoid
@ -109,7 +112,9 @@ impl ComputedValueFlags {
Self::CAN_BE_FRAGMENTED |
Self::IS_IN_PSEUDO_ELEMENT_SUBTREE |
Self::HAS_TEXT_DECORATION_LINES |
Self::IS_IN_OPACITY_ZERO_SUBTREE
Self::IS_IN_OPACITY_ZERO_SUBTREE |
Self::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE
}
/// Flags that may be propagated to descendants.

View file

@ -7,11 +7,13 @@
use crate::computed_value_flags::ComputedValueFlags;
use crate::dom::TElement;
use crate::properties::longhands::contain::SpecifiedValue;
use crate::properties::longhands::display::computed_value::T as Display;
use crate::properties::longhands::float::computed_value::T as Float;
use crate::properties::longhands::position::computed_value::T as Position;
use crate::properties::{self, ComputedValues, StyleBuilder};
/// A struct that implements all the adjustment methods.
///
/// NOTE(emilio): If new adjustments are introduced that depend on reset
@ -245,6 +247,15 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
.add_flags(ComputedValueFlags::IS_ROOT_ELEMENT_STYLE);
}
if self.style
.get_box()
.clone_contain()
.contains(SpecifiedValue::STYLE)
{
self.style
.add_flags(ComputedValueFlags::SELF_OR_ANCESTOR_HAS_CONTAIN_STYLE);
}
if self.style.get_parent_column().is_multicol() {
self.style.add_flags(ComputedValueFlags::CAN_BE_FRAGMENTED);
}

View file

@ -1402,7 +1402,7 @@ impl TouchAction {
bitflags! {
#[derive(MallocSizeOf, Parse, SpecifiedValueInfo, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
#[css(bitflags(single = "none,strict,content", mixed="size,layout,paint,inline-size", overlapping_bits))]
#[css(bitflags(single = "none,strict,content", mixed="size,layout,style,paint,inline-size", overlapping_bits))]
#[repr(C)]
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
pub struct Contain: u8 {
@ -1414,14 +1414,16 @@ bitflags! {
const BLOCK_SIZE = 1 << 1;
/// `layout` variant, turns on layout containment
const LAYOUT = 1 << 2;
/// `style` variant, turns on style containment
const STYLE = 1 << 3;
/// `paint` variant, turns on paint containment
const PAINT = 1 << 3;
const PAINT = 1 << 4;
/// 'size' variant, turns on size containment
const SIZE = 1 << 4 | Contain::INLINE_SIZE.bits | Contain::BLOCK_SIZE.bits;
const SIZE = 1 << 5 | Contain::INLINE_SIZE.bits | Contain::BLOCK_SIZE.bits;
/// `content` variant, turns on layout and paint containment
const CONTENT = 1 << 5 | Contain::LAYOUT.bits | Contain::PAINT.bits;
const CONTENT = 1 << 6 | Contain::LAYOUT.bits | Contain::STYLE.bits | Contain::PAINT.bits;
/// `strict` variant, turns on all types of containment
const STRICT = 1 << 6 | Contain::LAYOUT.bits | Contain::PAINT.bits | Contain::SIZE.bits;
const STRICT = 1 << 7 | Contain::LAYOUT.bits | Contain::STYLE.bits | Contain::PAINT.bits | Contain::SIZE.bits;
}
}