style: Tidy and sprinkle some comments.

This commit is contained in:
Emilio Cobos Álvarez 2018-01-31 22:09:53 +01:00
parent 3e27459ad3
commit 190e9b9715
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 15 additions and 6 deletions

View file

@ -243,6 +243,8 @@ impl ToCss for FontSettingTagInt {
1 => Ok(()), 1 => Ok(()),
0 => dest.write_str(" off"), 0 => dest.write_str(" off"),
x => { x => {
// FIXME(emilio): Why in the world does this serialize the space
// itself?
dest.write_char(' ')?; dest.write_char(' ')?;
x.to_css(dest) x.to_css(dest)
} }
@ -252,6 +254,7 @@ impl ToCss for FontSettingTagInt {
impl Parse for FontSettingTagInt { impl Parse for FontSettingTagInt {
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>> {
// FIXME(emilio): This doesn't handle calc properly.
if let Ok(value) = input.try(|input| input.expect_integer()) { if let Ok(value) = input.try(|input| input.expect_integer()) {
// handle integer, throw if it is negative // handle integer, throw if it is negative
if value >= 0 { if value >= 0 {
@ -272,9 +275,11 @@ impl Parse for FontSettingTagInt {
} }
} }
impl Parse for FontSettingTagFloat { impl Parse for FontSettingTagFloat {
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
// FIXME(emilio): Should handle calc() using Number::parse.
//
// Also why is this not in font.rs?
input.expect_number().map(FontSettingTagFloat).map_err(|e| e.into()) input.expect_number().map(FontSettingTagFloat).map_err(|e| e.into())
} }
} }

View file

@ -2060,6 +2060,7 @@ pub enum MozScriptLevel {
impl Parse for MozScriptLevel { impl Parse for MozScriptLevel {
fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<MozScriptLevel, ParseError<'i>> { fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<MozScriptLevel, ParseError<'i>> {
// We don't bother to handle calc here.
if let Ok(i) = input.try(|i| i.expect_integer()) { if let Ok(i) = input.try(|i| i.expect_integer()) {
return Ok(MozScriptLevel::Relative(i)) return Ok(MozScriptLevel::Relative(i))
} }

View file

@ -825,8 +825,10 @@ impl LengthOrPercentage {
/// Parse a length, treating dimensionless numbers as pixels /// Parse a length, treating dimensionless numbers as pixels
/// ///
/// <https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value> /// <https://www.w3.org/TR/SVG2/types.html#presentation-attribute-css-value>
pub fn parse_numbers_are_pixels<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) pub fn parse_numbers_are_pixels<'i, 't>(
-> Result<LengthOrPercentage, ParseError<'i>> { context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<LengthOrPercentage, ParseError<'i>> {
if let Ok(lop) = input.try(|i| Self::parse(context, i)) { if let Ok(lop) = input.try(|i| Self::parse(context, i)) {
return Ok(lop) return Ok(lop)
} }
@ -840,9 +842,10 @@ impl LengthOrPercentage {
/// Parse a non-negative length, treating dimensionless numbers as pixels /// Parse a non-negative length, treating dimensionless numbers as pixels
/// ///
/// This is nonstandard behavior used by Firefox for SVG /// This is nonstandard behavior used by Firefox for SVG
pub fn parse_numbers_are_pixels_non_negative<'i, 't>(context: &ParserContext, pub fn parse_numbers_are_pixels_non_negative<'i, 't>(
input: &mut Parser<'i, 't>) context: &ParserContext,
-> Result<LengthOrPercentage, ParseError<'i>> { input: &mut Parser<'i, 't>,
) -> Result<LengthOrPercentage, ParseError<'i>> {
if let Ok(lop) = input.try(|i| Self::parse_non_negative(context, i)) { if let Ok(lop) = input.try(|i| Self::parse_non_negative(context, i)) {
return Ok(lop) return Ok(lop)
} }