style: Support image-set in the content property

Differential Revision: https://phabricator.services.mozilla.com/D107397
This commit is contained in:
Oriol Brufau 2023-05-16 08:03:48 +02:00
parent 5c3be71f25
commit 4cee8cf937
3 changed files with 32 additions and 16 deletions

View file

@ -4,7 +4,7 @@
//! Computed values for counter properties
use crate::values::computed::url::ComputedImageUrl;
use crate::values::computed::image::Image;
use crate::values::generics::counters as generics;
use crate::values::generics::counters::CounterIncrement as GenericCounterIncrement;
use crate::values::generics::counters::CounterSetOrReset as GenericCounterSetOrReset;
@ -16,7 +16,7 @@ pub type CounterIncrement = GenericCounterIncrement<i32>;
pub type CounterSetOrReset = GenericCounterSetOrReset<i32>;
/// A computed value for the `content` property.
pub type Content = generics::GenericContent<ComputedImageUrl>;
pub type Content = generics::GenericContent<Image>;
/// A computed content item.
pub type ContentItem = generics::GenericContentItem<ComputedImageUrl>;
pub type ContentItem = generics::GenericContentItem<Image>;

View file

@ -148,18 +148,18 @@ fn is_decimal(counter_type: &CounterStyleType) -> bool {
Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToShmem,
)]
#[repr(u8)]
pub enum GenericContent<ImageUrl> {
pub enum GenericContent<Image> {
/// `normal` reserved keyword.
Normal,
/// `none` reserved keyword.
None,
/// Content items.
Items(#[css(iterable)] crate::OwnedSlice<GenericContentItem<ImageUrl>>),
Items(#[css(iterable)] crate::OwnedSlice<GenericContentItem<Image>>),
}
pub use self::GenericContent as Content;
impl<ImageUrl> Content<ImageUrl> {
impl<Image> Content<Image> {
/// Whether `self` represents list of items.
#[inline]
pub fn is_items(&self) -> bool {
@ -180,14 +180,13 @@ impl<ImageUrl> Content<ImageUrl> {
Eq,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
pub enum GenericContentItem<ImageUrl> {
pub enum GenericContentItem<I> {
/// Literal string content.
String(crate::OwnedStr),
/// `counter(name, style)`.
@ -220,8 +219,8 @@ pub enum GenericContentItem<ImageUrl> {
/// `attr([namespace? `|`]? ident)`
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
Attr(Attr),
/// `url(url)`
Url(ImageUrl),
/// image-set(url) | url(url)
Image(I),
}
pub use self::GenericContentItem as ContentItem;

View file

@ -11,7 +11,7 @@ use crate::values::generics::counters as generics;
use crate::values::generics::counters::CounterPair;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyle;
use crate::values::specified::url::SpecifiedImageUrl;
use crate::values::specified::image::Image;
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
use crate::values::specified::Attr;
use crate::values::specified::Integer;
@ -19,7 +19,7 @@ use crate::values::CustomIdent;
use cssparser::{Parser, Token};
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
use selectors::parser::SelectorParseErrorKind;
use style_traits::{ParseError, StyleParseErrorKind};
use style_traits::{KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind};
/// A specified value for the `counter-increment` property.
pub type CounterIncrement = generics::GenericCounterIncrement<Integer>;
@ -83,10 +83,10 @@ fn parse_counters<'i, 't>(
}
/// The specified value for the `content` property.
pub type Content = generics::GenericContent<SpecifiedImageUrl>;
pub type Content = generics::GenericContent<Image>;
/// The specified value for a content item in the `content` property.
pub type ContentItem = generics::GenericContentItem<SpecifiedImageUrl>;
pub type ContentItem = generics::GenericContentItem<Image>;
impl Content {
#[cfg(feature = "servo-layout-2013")]
@ -137,8 +137,8 @@ impl Parse for Content {
loop {
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
{
if let Ok(url) = input.try_parse(|i| SpecifiedImageUrl::parse(context, i)) {
content.push(generics::ContentItem::Url(url));
if let Ok(image) = input.try_parse(|i| Image::parse_only_url(context, i)) {
content.push(generics::ContentItem::Image(image));
continue;
}
}
@ -214,3 +214,20 @@ impl Parse for Content {
Ok(generics::Content::Items(content.into()))
}
}
impl<Image> SpecifiedValueInfo for generics::GenericContentItem<Image> {
fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&[
"url",
"image-set",
"counter",
"counters",
"attr",
"open-quote",
"close-quote",
"no-open-quote",
"no-close-quote",
"-moz-alt-content",
]);
}
}