mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
CounterBound::Integer made to store an Integer
This commit is contained in:
parent
8e6cfbca47
commit
307858bf69
2 changed files with 11 additions and 17 deletions
|
@ -22,6 +22,7 @@ use str::CssStringWriter;
|
||||||
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
||||||
use style_traits::{StyleParseErrorKind, ToCss};
|
use style_traits::{StyleParseErrorKind, ToCss};
|
||||||
use values::CustomIdent;
|
use values::CustomIdent;
|
||||||
|
use values::specified::Integer;
|
||||||
|
|
||||||
/// Parse a counter style name reference.
|
/// Parse a counter style name reference.
|
||||||
///
|
///
|
||||||
|
@ -450,21 +451,19 @@ pub struct Ranges(pub Vec<Range<CounterBound>>);
|
||||||
#[derive(Clone, Copy, Debug, ToCss)]
|
#[derive(Clone, Copy, Debug, ToCss)]
|
||||||
pub enum CounterBound {
|
pub enum CounterBound {
|
||||||
/// An integer bound.
|
/// An integer bound.
|
||||||
///
|
Integer(Integer),
|
||||||
/// FIXME(https://github.com/servo/servo/issues/20197)
|
|
||||||
Integer(i32),
|
|
||||||
/// The infinite bound.
|
/// The infinite bound.
|
||||||
Infinite,
|
Infinite,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for Ranges {
|
impl Parse for Ranges {
|
||||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
if input.try(|input| input.expect_ident_matching("auto")).is_ok() {
|
||||||
Ok(Ranges(Vec::new()))
|
Ok(Ranges(Vec::new()))
|
||||||
} else {
|
} else {
|
||||||
input.parse_comma_separated(|input| {
|
input.parse_comma_separated(|input| {
|
||||||
let opt_start = parse_bound(input)?;
|
let opt_start = parse_bound(context, input)?;
|
||||||
let opt_end = parse_bound(input)?;
|
let opt_end = parse_bound(context, input)?;
|
||||||
if let (CounterBound::Integer(start), CounterBound::Integer(end)) = (opt_start, opt_end) {
|
if let (CounterBound::Integer(start), CounterBound::Integer(end)) = (opt_start, opt_end) {
|
||||||
if start > end {
|
if start > end {
|
||||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||||
|
@ -477,18 +476,13 @@ impl Parse for Ranges {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bound<'i, 't>(
|
fn parse_bound<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
context: &ParserContext, input: &mut Parser<'i, 't>,
|
||||||
) -> Result<CounterBound, ParseError<'i>> {
|
) -> Result<CounterBound, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
if let Ok(integer) = input.try(|input| Integer::parse(context, input)) {
|
||||||
match *input.next()? {
|
return Ok(CounterBound::Integer(integer));
|
||||||
Token::Number { int_value: Some(v), .. } => {
|
|
||||||
Ok(CounterBound::Integer(v))
|
|
||||||
}
|
|
||||||
Token::Ident(ref ident) if ident.eq_ignore_ascii_case("infinite") => {
|
|
||||||
Ok(CounterBound::Infinite)
|
|
||||||
}
|
|
||||||
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
|
||||||
}
|
}
|
||||||
|
input.expect_ident_matching("infinite")?;
|
||||||
|
Ok(CounterBound::Infinite)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for Ranges {
|
impl ToCss for Ranges {
|
||||||
|
|
|
@ -326,7 +326,7 @@ impl ToNsCssValue for counter_style::Ranges {
|
||||||
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
|
nscssvalue.set_pair_list(self.0.into_iter().map(|range| {
|
||||||
fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) {
|
fn set_bound(bound: CounterBound, nscssvalue: &mut nsCSSValue) {
|
||||||
if let CounterBound::Integer(finite) = bound {
|
if let CounterBound::Integer(finite) = bound {
|
||||||
nscssvalue.set_integer(finite)
|
nscssvalue.set_integer(finite.value())
|
||||||
} else {
|
} else {
|
||||||
nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
|
nscssvalue.set_enum(structs::NS_STYLE_COUNTER_RANGE_INFINITE as i32)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue