style: Simplify container-type implementation

It was made a bitfield so that we could include style. But then style
containment was removed and the bitfield keeps causing us to do wrong
check (since INLINE_SIZE intersects SIZE).

So just make it an enum. This causes a progression and a test that
failed now times out (which is a pre-existing issue, just like the
pseudo-elements test that times out).

Differential Revision: https://phabricator.services.mozilla.com/D160371
This commit is contained in:
Emilio Cobos Álvarez 2022-10-27 10:48:58 +00:00 committed by Martin Robinson
parent 8a5ba3fe16
commit b2ab136cd9
5 changed files with 38 additions and 40 deletions

View file

@ -912,7 +912,7 @@ pub trait MatchMethods: TElement {
let is_container = !new_primary_style
.get_box()
.clone_container_type()
.is_empty();
.is_normal();
if is_root || is_container {
let new_font_size = new_primary_style.get_font().clone_font_size();
let old_font_size = old_styles

View file

@ -447,7 +447,7 @@ ${helpers.predefined_type(
${helpers.predefined_type(
"container-type",
"ContainerType",
"computed::ContainerType::NORMAL",
"computed::ContainerType::Normal",
engines="gecko servo",
animation_value_type="none",
gecko_pref="layout.css.container-queries.enabled",

View file

@ -40,19 +40,19 @@ ${helpers.two_properties_shorthand(
gecko_pref="layout.css.container-queries.enabled",
spec="https://drafts.csswg.org/css-contain-3/#container-shorthand"
>
use crate::values::specified::box_::{ContainerName, ContainerType};
pub fn parse_value<'i>(
context: &ParserContext,
input: &mut Parser<'i, '_>,
) -> Result<Longhands, ParseError<'i>> {
use crate::parser::Parse;
use crate::values::specified::box_::{ContainerName, ContainerType};
// See https://github.com/w3c/csswg-drafts/issues/7180 for why we don't
// match the spec.
let container_name = ContainerName::parse(context, input)?;
let container_type = if input.try_parse(|input| input.expect_delim('/')).is_ok() {
ContainerType::parse(context, input)?
ContainerType::parse(input)?
} else {
ContainerType::NORMAL
ContainerType::Normal
};
Ok(expanded! {
container_name: container_name,
@ -63,7 +63,7 @@ ${helpers.two_properties_shorthand(
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.container_name.to_css(dest)?;
if !self.container_type.is_empty() {
if !self.container_type.is_normal() {
dest.write_str(" / ")?;
self.container_type.to_css(dest)?;
}

View file

@ -114,18 +114,18 @@ pub struct ContainerLookupResult<E> {
}
fn container_type_axes(ty_: ContainerType, wm: WritingMode) -> FeatureFlags {
if ty_.contains(ContainerType::SIZE) {
return FeatureFlags::all_container_axes();
match ty_ {
ContainerType::Size => FeatureFlags::all_container_axes(),
ContainerType::InlineSize => {
let physical_axis = if wm.is_vertical() {
FeatureFlags::CONTAINER_REQUIRES_HEIGHT_AXIS
} else {
FeatureFlags::CONTAINER_REQUIRES_WIDTH_AXIS
};
FeatureFlags::CONTAINER_REQUIRES_INLINE_AXIS | physical_axis
},
ContainerType::Normal => FeatureFlags::empty(),
}
if ty_.contains(ContainerType::INLINE_SIZE) {
let physical_axis = if wm.is_vertical() {
FeatureFlags::CONTAINER_REQUIRES_HEIGHT_AXIS
} else {
FeatureFlags::CONTAINER_REQUIRES_WIDTH_AXIS
};
return FeatureFlags::CONTAINER_REQUIRES_INLINE_AXIS | physical_axis;
}
FeatureFlags::empty()
}
enum TraversalResult<T> {
@ -476,7 +476,7 @@ impl<'a> ContainerSizeQuery<'a> {
let container_type = box_style.clone_container_type();
let size = e.primary_box_size();
match container_type {
ContainerType::SIZE => {
ContainerType::Size=> {
TraversalResult::Done(
ContainerSizeQueryResult {
width: Some(size.width),
@ -484,7 +484,7 @@ impl<'a> ContainerSizeQuery<'a> {
}
)
},
ContainerType::INLINE_SIZE => {
ContainerType::InlineSize => {
if wm.is_horizontal() {
TraversalResult::Done(
ContainerSizeQueryResult {
@ -501,7 +501,7 @@ impl<'a> ContainerSizeQuery<'a> {
)
}
},
_ => TraversalResult::InProgress,
ContainerType::Normal => TraversalResult::InProgress,
}
}

View file

@ -1489,30 +1489,28 @@ pub enum ContentVisibility {
Visible,
}
bitflags! {
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToCss, Parse, ToResolvedValue, ToShmem)]
#[repr(C)]
#[allow(missing_docs)]
#[css(bitflags(single="normal", mixed="size,inline-size", overlapping_bits))]
/// https://drafts.csswg.org/css-contain-3/#container-type
///
/// TODO: block-size is on the spec but it seems it was removed? WPTs don't
/// support it, see https://github.com/w3c/csswg-drafts/issues/7179.
pub struct ContainerType: u8 {
/// The `normal` variant.
const NORMAL = 0;
/// The `inline-size` variant.
const INLINE_SIZE = 1 << 0;
/// The `size` variant, exclusive with `inline-size` (they sharing bits
/// guarantees this).
const SIZE = 1 << 1 | Self::INLINE_SIZE.bits;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToCss, Parse, ToResolvedValue, ToShmem)]
#[repr(u8)]
#[allow(missing_docs)]
/// https://drafts.csswg.org/css-contain-3/#container-type
pub enum ContainerType {
/// The `normal` variant.
Normal,
/// The `inline-size` variant.
InlineSize,
/// The `size` variant.
Size,
}
impl ContainerType {
/// Is this container-type: normal?
pub fn is_normal(self) -> bool {
self == Self::Normal
}
/// Is this type containing size in any way?
pub fn is_size_container_type(&self) -> bool {
self.intersects(ContainerType::SIZE | ContainerType::INLINE_SIZE)
pub fn is_size_container_type(self) -> bool {
!self.is_normal()
}
}