servo: Merge #20304 - CounterBound::Integer made to store an Integer (from nupurbaghel:counterbound); r=emilio

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #20197

<!-- Either: -->
- [x] These changes do not require tests because they involve datatype change of already existing enum CounterBound

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 6d06d1bbcc99af5195c538b339bf4e92beaa412f

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : 7a8a001f7cc1dca6043148e6fc99445e005f3c6e
This commit is contained in:
Nupur Baghel 2018-03-19 04:25:56 -04:00
Родитель 14a179db40
Коммит b6bc5523fc
2 изменённых файлов: 11 добавлений и 17 удалений

Просмотреть файл

@ -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)
} }