mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
style: Support image-set in the content property
Differential Revision: https://phabricator.services.mozilla.com/D107397
This commit is contained in:
parent
5c3be71f25
commit
4cee8cf937
3 changed files with 32 additions and 16 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
//! Computed values for counter properties
|
//! 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 as generics;
|
||||||
use crate::values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
use crate::values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
||||||
use crate::values::generics::counters::CounterSetOrReset as GenericCounterSetOrReset;
|
use crate::values::generics::counters::CounterSetOrReset as GenericCounterSetOrReset;
|
||||||
|
@ -16,7 +16,7 @@ pub type CounterIncrement = GenericCounterIncrement<i32>;
|
||||||
pub type CounterSetOrReset = GenericCounterSetOrReset<i32>;
|
pub type CounterSetOrReset = GenericCounterSetOrReset<i32>;
|
||||||
|
|
||||||
/// A computed value for the `content` property.
|
/// A computed value for the `content` property.
|
||||||
pub type Content = generics::GenericContent<ComputedImageUrl>;
|
pub type Content = generics::GenericContent<Image>;
|
||||||
|
|
||||||
/// A computed content item.
|
/// A computed content item.
|
||||||
pub type ContentItem = generics::GenericContentItem<ComputedImageUrl>;
|
pub type ContentItem = generics::GenericContentItem<Image>;
|
||||||
|
|
|
@ -148,18 +148,18 @@ fn is_decimal(counter_type: &CounterStyleType) -> bool {
|
||||||
Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToShmem,
|
Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToShmem,
|
||||||
)]
|
)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum GenericContent<ImageUrl> {
|
pub enum GenericContent<Image> {
|
||||||
/// `normal` reserved keyword.
|
/// `normal` reserved keyword.
|
||||||
Normal,
|
Normal,
|
||||||
/// `none` reserved keyword.
|
/// `none` reserved keyword.
|
||||||
None,
|
None,
|
||||||
/// Content items.
|
/// Content items.
|
||||||
Items(#[css(iterable)] crate::OwnedSlice<GenericContentItem<ImageUrl>>),
|
Items(#[css(iterable)] crate::OwnedSlice<GenericContentItem<Image>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::GenericContent as Content;
|
pub use self::GenericContent as Content;
|
||||||
|
|
||||||
impl<ImageUrl> Content<ImageUrl> {
|
impl<Image> Content<Image> {
|
||||||
/// Whether `self` represents list of items.
|
/// Whether `self` represents list of items.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_items(&self) -> bool {
|
pub fn is_items(&self) -> bool {
|
||||||
|
@ -180,14 +180,13 @@ impl<ImageUrl> Content<ImageUrl> {
|
||||||
Eq,
|
Eq,
|
||||||
MallocSizeOf,
|
MallocSizeOf,
|
||||||
PartialEq,
|
PartialEq,
|
||||||
SpecifiedValueInfo,
|
|
||||||
ToComputedValue,
|
ToComputedValue,
|
||||||
ToCss,
|
ToCss,
|
||||||
ToResolvedValue,
|
ToResolvedValue,
|
||||||
ToShmem,
|
ToShmem,
|
||||||
)]
|
)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum GenericContentItem<ImageUrl> {
|
pub enum GenericContentItem<I> {
|
||||||
/// Literal string content.
|
/// Literal string content.
|
||||||
String(crate::OwnedStr),
|
String(crate::OwnedStr),
|
||||||
/// `counter(name, style)`.
|
/// `counter(name, style)`.
|
||||||
|
@ -220,8 +219,8 @@ pub enum GenericContentItem<ImageUrl> {
|
||||||
/// `attr([namespace? `|`]? ident)`
|
/// `attr([namespace? `|`]? ident)`
|
||||||
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
||||||
Attr(Attr),
|
Attr(Attr),
|
||||||
/// `url(url)`
|
/// image-set(url) | url(url)
|
||||||
Url(ImageUrl),
|
Image(I),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::GenericContentItem as ContentItem;
|
pub use self::GenericContentItem as ContentItem;
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::values::generics::counters as generics;
|
||||||
use crate::values::generics::counters::CounterPair;
|
use crate::values::generics::counters::CounterPair;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use crate::values::generics::CounterStyle;
|
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"))]
|
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
||||||
use crate::values::specified::Attr;
|
use crate::values::specified::Attr;
|
||||||
use crate::values::specified::Integer;
|
use crate::values::specified::Integer;
|
||||||
|
@ -19,7 +19,7 @@ use crate::values::CustomIdent;
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
|
#[cfg(any(feature = "gecko", feature = "servo-layout-2013"))]
|
||||||
use selectors::parser::SelectorParseErrorKind;
|
use selectors::parser::SelectorParseErrorKind;
|
||||||
use style_traits::{ParseError, StyleParseErrorKind};
|
use style_traits::{KeywordsCollectFn, ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
||||||
|
|
||||||
/// A specified value for the `counter-increment` property.
|
/// A specified value for the `counter-increment` property.
|
||||||
pub type CounterIncrement = generics::GenericCounterIncrement<Integer>;
|
pub type CounterIncrement = generics::GenericCounterIncrement<Integer>;
|
||||||
|
@ -83,10 +83,10 @@ fn parse_counters<'i, 't>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The specified value for the `content` property.
|
/// 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.
|
/// 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 {
|
impl Content {
|
||||||
#[cfg(feature = "servo-layout-2013")]
|
#[cfg(feature = "servo-layout-2013")]
|
||||||
|
@ -137,8 +137,8 @@ impl Parse for Content {
|
||||||
loop {
|
loop {
|
||||||
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
||||||
{
|
{
|
||||||
if let Ok(url) = input.try_parse(|i| SpecifiedImageUrl::parse(context, i)) {
|
if let Ok(image) = input.try_parse(|i| Image::parse_only_url(context, i)) {
|
||||||
content.push(generics::ContentItem::Url(url));
|
content.push(generics::ContentItem::Image(image));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,3 +214,20 @@ impl Parse for Content {
|
||||||
Ok(generics::Content::Items(content.into()))
|
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",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue