style: [css-lists-3] Make 'none' invalid as a <counter-style> in counter()/counters().

CSSWG resolution:
https://github.com/w3c/csswg-drafts/issues/4163#issuecomment-521331100

Spec:
https://drafts.csswg.org/css-lists-3/#counter-functions

Differential Revision: https://phabricator.services.mozilla.com/D43893
This commit is contained in:
Mats Palmgren 2019-08-30 00:15:37 +00:00 committed by Emilio Cobos Álvarez
parent 1406ae7f39
commit f7a87c49b1
7 changed files with 63 additions and 63 deletions

View file

@ -7,7 +7,7 @@
#[cfg(feature = "servo")]
use crate::computed_values::list_style_type::T as ListStyleType;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyleOrNone;
use crate::values::generics::CounterStyle;
#[cfg(feature = "gecko")]
use crate::values::specified::Attr;
use crate::values::CustomIdent;
@ -127,7 +127,7 @@ impl<I> Counters<I> {
type CounterStyleType = ListStyleType;
#[cfg(feature = "gecko")]
type CounterStyleType = CounterStyleOrNone;
type CounterStyleType = CounterStyle;
#[cfg(feature = "servo")]
#[inline]
@ -138,7 +138,7 @@ fn is_decimal(counter_type: &CounterStyleType) -> bool {
#[cfg(feature = "gecko")]
#[inline]
fn is_decimal(counter_type: &CounterStyleType) -> bool {
*counter_type == CounterStyleOrNone::decimal()
*counter_type == CounterStyle::decimal()
}
/// The specified value for the `content` property.

View file

@ -92,13 +92,10 @@ impl SymbolsType {
/// <https://drafts.csswg.org/css-counter-styles/#typedef-counter-style>
///
/// Since wherever <counter-style> is used, 'none' is a valid value as
/// well, we combine them into one type to make code simpler.
/// Note that 'none' is not a valid name.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Debug, Eq, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem)]
pub enum CounterStyleOrNone {
/// `none`
None,
pub enum CounterStyle {
/// `<counter-style-name>`
Name(CustomIdent),
/// `symbols()`
@ -111,28 +108,25 @@ fn is_symbolic(symbols_type: &SymbolsType) -> bool {
*symbols_type == SymbolsType::Symbolic
}
impl CounterStyleOrNone {
impl CounterStyle {
/// disc value
pub fn disc() -> Self {
CounterStyleOrNone::Name(CustomIdent(atom!("disc")))
CounterStyle::Name(CustomIdent(atom!("disc")))
}
/// decimal value
pub fn decimal() -> Self {
CounterStyleOrNone::Name(CustomIdent(atom!("decimal")))
CounterStyle::Name(CustomIdent(atom!("decimal")))
}
}
impl Parse for CounterStyleOrNone {
impl Parse for CounterStyle {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(name) = input.try(|i| parse_counter_style_name(i)) {
return Ok(CounterStyleOrNone::Name(name));
}
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(CounterStyleOrNone::None);
return Ok(CounterStyle::Name(name));
}
input.expect_function_matching("symbols")?;
input.parse_nested_block(|input| {
@ -151,12 +145,12 @@ impl Parse for CounterStyleOrNone {
if symbols.0.iter().any(|sym| !sym.is_allowed_in_symbols()) {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(CounterStyleOrNone::Symbols(symbols_type, symbols))
Ok(CounterStyle::Symbols(symbols_type, symbols))
})
}
}
impl SpecifiedValueInfo for CounterStyleOrNone {
impl SpecifiedValueInfo for CounterStyle {
fn collect_completion_keywords(f: KeywordsCollectFn) {
// XXX The best approach for implementing this is probably
// having a CounterStyleName type wrapping CustomIdent, and
@ -165,7 +159,7 @@ impl SpecifiedValueInfo for CounterStyleOrNone {
// approach here.
macro_rules! predefined {
($($name:expr,)+) => {
f(&["none", "symbols", $($name,)+]);
f(&["symbols", $($name,)+]);
}
}
include!("../../counter_style/predefined.rs");

View file

@ -12,7 +12,7 @@ use crate::values::generics::counters::CounterIncrement as GenericCounterIncreme
use crate::values::generics::counters::CounterPair;
use crate::values::generics::counters::CounterSetOrReset as GenericCounterSetOrReset;
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyleOrNone;
use crate::values::generics::CounterStyle;
use crate::values::specified::url::SpecifiedImageUrl;
#[cfg(feature = "gecko")]
use crate::values::specified::Attr;
@ -98,13 +98,13 @@ impl Content {
}
#[cfg(feature = "gecko")]
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyleOrNone {
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyle {
input
.try(|input| {
input.expect_comma()?;
CounterStyleOrNone::parse(context, input)
CounterStyle::parse(context, input)
})
.unwrap_or(CounterStyleOrNone::decimal())
.unwrap_or(CounterStyle::decimal())
}
}

View file

@ -6,7 +6,7 @@
use crate::parser::{Parse, ParserContext};
#[cfg(feature = "gecko")]
use crate::values::generics::CounterStyleOrNone;
use crate::values::generics::CounterStyle;
#[cfg(feature = "gecko")]
use crate::values::CustomIdent;
use cssparser::{Parser, Token};
@ -27,8 +27,10 @@ use style_traits::{ParseError, StyleParseErrorKind};
ToShmem,
)]
pub enum ListStyleType {
/// <counter-style> | none
CounterStyle(CounterStyleOrNone),
/// `none`
None,
/// <counter-style>
CounterStyle(CounterStyle),
/// <string>
String(String),
}
@ -38,7 +40,7 @@ impl ListStyleType {
/// Initial specified value for `list-style-type`.
#[inline]
pub fn disc() -> Self {
ListStyleType::CounterStyle(CounterStyleOrNone::disc())
ListStyleType::CounterStyle(CounterStyle::disc())
}
/// Convert from gecko keyword to list-style-type.
@ -50,10 +52,10 @@ impl ListStyleType {
use crate::gecko_bindings::structs;
if value == structs::NS_STYLE_LIST_STYLE_NONE {
return ListStyleType::CounterStyle(CounterStyleOrNone::None);
return ListStyleType::None;
}
ListStyleType::CounterStyle(CounterStyleOrNone::Name(CustomIdent(match value {
ListStyleType::CounterStyle(CounterStyle::Name(CustomIdent(match value {
structs::NS_STYLE_LIST_STYLE_DISC => atom!("disc"),
structs::NS_STYLE_LIST_STYLE_CIRCLE => atom!("circle"),
structs::NS_STYLE_LIST_STYLE_SQUARE => atom!("square"),
@ -73,10 +75,12 @@ impl Parse for ListStyleType {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(style) = input.try(|i| CounterStyleOrNone::parse(context, i)) {
if let Ok(style) = input.try(|i| CounterStyle::parse(context, i)) {
return Ok(ListStyleType::CounterStyle(style));
}
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
return Ok(ListStyleType::None);
}
Ok(ListStyleType::String(
input.expect_string()?.as_ref().to_owned(),
))