#[cfg(feature = "gecko")]
use crate::counter_style::{CounterStyle, CounterStyleParsingFlags};
use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use crate::properties::longhands::list_style_type::SpecifiedValue as ListStyleType;
use cssparser::{Parser, Token};
use style_traits::{ParseError, StyleParseErrorKind};
#[cfg(feature = "gecko")]
#[derive(
Clone,
Debug,
Eq,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct ListStyleType(pub CounterStyle);
#[cfg(feature = "gecko")]
impl ListStyleType {
#[inline]
pub fn disc() -> Self {
Self(CounterStyle::disc())
}
#[inline]
pub fn none() -> Self {
Self(CounterStyle::None)
}
pub fn from_gecko_keyword(value: u32) -> Self {
use crate::gecko_bindings::structs;
use crate::values::CustomIdent;
let v8 = value as u8;
if v8 == structs::ListStyle_None {
return Self::none();
}
Self(CounterStyle::Name(CustomIdent(match v8 {
structs::ListStyle_Disc => atom!("disc"),
structs::ListStyle_Circle => atom!("circle"),
structs::ListStyle_Square => atom!("square"),
structs::ListStyle_Decimal => atom!("decimal"),
structs::ListStyle_LowerRoman => atom!("lower-roman"),
structs::ListStyle_UpperRoman => atom!("upper-roman"),
structs::ListStyle_LowerAlpha => atom!("lower-alpha"),
structs::ListStyle_UpperAlpha => atom!("upper-alpha"),
_ => unreachable!("Unknown counter style keyword value"),
})))
}
#[inline]
pub fn is_bullet(&self) -> bool {
self.0.is_bullet()
}
}
#[cfg(feature = "gecko")]
impl Parse for ListStyleType {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let flags = CounterStyleParsingFlags::ALLOW_NONE | CounterStyleParsingFlags::ALLOW_STRING;
Ok(Self(CounterStyle::parse(context, input, flags)?))
}
}
#[cfg(feature = "servo")]
impl ListStyleType {
#[inline]
pub fn disc() -> Self {
Self::Disc
}
#[inline]
pub fn none() -> Self {
Self::None
}
}
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct QuotePair {
pub opening: crate::OwnedStr,
pub closing: crate::OwnedStr,
}
#[derive(
Clone,
Debug,
Default,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct QuoteList(
#[css(iterable, if_empty = "none")]
#[ignore_malloc_size_of = "Arc"]
pub crate::ArcSlice<QuotePair>,
);
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub enum Quotes {
QuoteList(QuoteList),
Auto,
}
impl Parse for Quotes {
fn parse<'i, 't>(
_: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Quotes, ParseError<'i>> {
if input
.try_parse(|input| input.expect_ident_matching("auto"))
.is_ok()
{
return Ok(Quotes::Auto);
}
if input
.try_parse(|input| input.expect_ident_matching("none"))
.is_ok()
{
return Ok(Quotes::QuoteList(QuoteList::default()));
}
let mut quotes = Vec::new();
loop {
let location = input.current_source_location();
let opening = match input.next() {
Ok(&Token::QuotedString(ref value)) => value.as_ref().to_owned().into(),
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
Err(_) => break,
};
let closing = input.expect_string()?.as_ref().to_owned().into();
quotes.push(QuotePair { opening, closing });
}
if !quotes.is_empty() {
Ok(Quotes::QuoteList(QuoteList(crate::ArcSlice::from_iter(
quotes.into_iter(),
))))
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}