#[cfg(feature = "servo")]
use crate::computed_values::list_style_type::T as ListStyleType;
#[cfg(feature = "gecko")]
use crate::counter_style::CounterStyle;
use crate::values::specified::Attr;
use crate::values::CustomIdent;
use std::fmt::{self, Write};
use std::ops::Deref;
use style_traits::{CssWriter, ToCss};
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct GenericCounterPair<Integer> {
pub name: CustomIdent,
pub value: Integer,
pub is_reversed: bool,
}
pub use self::GenericCounterPair as CounterPair;
impl<Integer> ToCss for CounterPair<Integer>
where
Integer: ToCss + PartialEq<i32>,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
if self.is_reversed {
dest.write_str("reversed(")?;
}
self.name.to_css(dest)?;
if self.is_reversed {
dest.write_char(')')?;
if self.value == i32::min_value() {
return Ok(());
}
}
dest.write_char(' ')?;
self.value.to_css(dest)
}
}
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct GenericCounterIncrement<I>(#[css(field_bound)] pub GenericCounters<I>);
pub use self::GenericCounterIncrement as CounterIncrement;
impl<I> CounterIncrement<I> {
#[inline]
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
CounterIncrement(Counters(counters.into()))
}
}
impl<I> Deref for CounterIncrement<I> {
type Target = [CounterPair<I>];
#[inline]
fn deref(&self) -> &Self::Target {
&(self.0).0
}
}
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct GenericCounterSet<I>(#[css(field_bound)] pub GenericCounters<I>);
pub use self::GenericCounterSet as CounterSet;
impl<I> CounterSet<I> {
#[inline]
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
CounterSet(Counters(counters.into()))
}
}
impl<I> Deref for CounterSet<I> {
type Target = [CounterPair<I>];
#[inline]
fn deref(&self) -> &Self::Target {
&(self.0).0
}
}
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct GenericCounterReset<I>(#[css(field_bound)] pub GenericCounters<I>);
pub use self::GenericCounterReset as CounterReset;
impl<I> CounterReset<I> {
#[inline]
pub fn new(counters: Vec<CounterPair<I>>) -> Self {
CounterReset(Counters(counters.into()))
}
}
impl<I> Deref for CounterReset<I> {
type Target = [CounterPair<I>];
#[inline]
fn deref(&self) -> &Self::Target {
&(self.0).0
}
}
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct GenericCounters<I>(
#[css(field_bound)]
#[css(iterable, if_empty = "none")]
crate::OwnedSlice<GenericCounterPair<I>>,
);
pub use self::GenericCounters as Counters;
#[cfg(feature = "servo")]
type CounterStyleType = ListStyleType;
#[cfg(feature = "gecko")]
type CounterStyleType = CounterStyle;
#[cfg(feature = "servo")]
#[inline]
fn is_decimal(counter_type: &CounterStyleType) -> bool {
*counter_type == ListStyleType::Decimal
}
#[cfg(feature = "gecko")]
#[inline]
fn is_decimal(counter_type: &CounterStyleType) -> bool {
*counter_type == CounterStyle::decimal()
}
#[derive(
Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToShmem,
)]
#[repr(C)]
pub struct GenericContentItems<Image> {
pub items: thin_vec::ThinVec<GenericContentItem<Image>>,
pub alt_start: usize,
}
impl<Image> ToCss for GenericContentItems<Image>
where
Image: ToCss,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
for (i, item) in self.items.iter().enumerate() {
if i == self.alt_start {
dest.write_str(" /")?;
}
if i != 0 {
dest.write_str(" ")?;
}
item.to_css(dest)?;
}
Ok(())
}
}
#[derive(
Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToShmem,
)]
#[repr(u8)]
pub enum GenericContent<Image> {
Normal,
None,
Items(GenericContentItems<Image>),
}
pub use self::GenericContent as Content;
impl<Image> Content<Image> {
#[inline]
pub fn is_items(&self) -> bool {
matches!(*self, Self::Items(..))
}
#[inline]
pub fn normal() -> Self {
Content::Normal
}
}
#[derive(
Clone,
Debug,
Eq,
MallocSizeOf,
PartialEq,
ToComputedValue,
SpecifiedValueInfo,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(u8)]
pub enum GenericContentItem<I> {
String(crate::OwnedStr),
#[css(comma, function)]
Counter(CustomIdent, #[css(skip_if = "is_decimal")] CounterStyleType),
#[css(comma, function)]
Counters(
CustomIdent,
crate::OwnedStr,
#[css(skip_if = "is_decimal")] CounterStyleType,
),
OpenQuote,
CloseQuote,
NoOpenQuote,
NoCloseQuote,
#[cfg(feature = "gecko")]
MozAltContent,
#[cfg(feature = "gecko")]
MozLabelContent,
Attr(Attr),
Image(I),
}
pub use self::GenericContentItem as ContentItem;