Replace some more uses of write! in components/style

This commit is contained in:
Simon Sapin 2017-09-02 19:11:44 +02:00
parent fae2da0f59
commit 5d06c9959f
12 changed files with 33 additions and 28 deletions

View file

@ -327,7 +327,8 @@ impl ToCss for System {
System::Additive => dest.write_str("additive"), System::Additive => dest.write_str("additive"),
System::Fixed { first_symbol_value } => { System::Fixed { first_symbol_value } => {
if let Some(value) = first_symbol_value { if let Some(value) = first_symbol_value {
write!(dest, "fixed {}", value) dest.write_str("fixed ")?;
value.to_css(dest)
} else { } else {
dest.write_str("fixed") dest.write_str("fixed")
} }
@ -455,7 +456,7 @@ where W: fmt::Write {
fn bound_to_css<W>(range: Option<i32>, dest: &mut W) -> fmt::Result where W: fmt::Write { fn bound_to_css<W>(range: Option<i32>, dest: &mut W) -> fmt::Result where W: fmt::Write {
if let Some(finite) = range { if let Some(finite) = range {
write!(dest, "{}", finite) finite.to_css(dest)
} else { } else {
dest.write_str("infinite") dest.write_str("infinite")
} }

View file

@ -398,7 +398,9 @@ impl MediaExpressionValue {
dest.write_str(if v { "1" } else { "0" }) dest.write_str(if v { "1" } else { "0" })
}, },
MediaExpressionValue::IntRatio(a, b) => { MediaExpressionValue::IntRatio(a, b) => {
write!(dest, "{}/{}", a, b) a.to_css(dest)?;
dest.write_char('/')?;
b.to_css(dest)
}, },
MediaExpressionValue::Resolution(ref r) => r.to_css(dest), MediaExpressionValue::Resolution(ref r) => r.to_css(dest),
MediaExpressionValue::Ident(ref ident) => { MediaExpressionValue::Ident(ref ident) => {

View file

@ -70,7 +70,7 @@ impl ToCss for NonTSPseudoClass {
match *self { match *self {
$(NonTSPseudoClass::$name => concat!(":", $css),)* $(NonTSPseudoClass::$name => concat!(":", $css),)*
$(NonTSPseudoClass::$s_name(ref s) => { $(NonTSPseudoClass::$s_name(ref s) => {
write!(dest, ":{}(", $s_css)?; dest.write_str(concat!(":", $s_css, "("))?;
{ {
// FIXME(emilio): Avoid the extra allocation! // FIXME(emilio): Avoid the extra allocation!
let mut css = CssStringWriter::new(dest); let mut css = CssStringWriter::new(dest);
@ -84,7 +84,9 @@ impl ToCss for NonTSPseudoClass {
$(NonTSPseudoClass::$k_name(ref s) => { $(NonTSPseudoClass::$k_name(ref s) => {
// Don't include the terminating nul. // Don't include the terminating nul.
let value = String::from_utf16(&s[..s.len() - 1]).unwrap(); let value = String::from_utf16(&s[..s.len() - 1]).unwrap();
return write!(dest, ":{}({})", $k_css, value) dest.write_str(concat!(":", $k_css, "("))?;
dest.write_str(&value)?;
return dest.write_char(')')
}, )* }, )*
NonTSPseudoClass::MozAny(ref selectors) => { NonTSPseudoClass::MozAny(ref selectors) => {
dest.write_str(":-moz-any(")?; dest.write_str(":-moz-any(")?;

View file

@ -88,7 +88,7 @@ macro_rules! define_keyword_type {
impl fmt::Debug for $name { impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, $css) f.write_str($css)
} }
} }

View file

@ -96,7 +96,7 @@ impl ToCss for MediaQuery {
{ {
if let Some(qual) = self.qualifier { if let Some(qual) = self.qualifier {
qual.to_css(dest)?; qual.to_css(dest)?;
write!(dest, " ")?; dest.write_char(' ')?;
} }
match self.media_type { match self.media_type {
@ -107,7 +107,7 @@ impl ToCss for MediaQuery {
// Otherwise, we'd serialize media queries like "(min-width: // Otherwise, we'd serialize media queries like "(min-width:
// 40px)" in "all (min-width: 40px)", which is unexpected. // 40px)" in "all (min-width: 40px)", which is unexpected.
if self.qualifier.is_some() || self.expressions.is_empty() { if self.qualifier.is_some() || self.expressions.is_empty() {
write!(dest, "all")?; dest.write_str("all")?;
} }
}, },
MediaQueryType::Concrete(MediaType(ref desc)) => desc.to_css(dest)?, MediaQueryType::Concrete(MediaType(ref desc)) => desc.to_css(dest)?,
@ -118,13 +118,13 @@ impl ToCss for MediaQuery {
} }
if self.media_type != MediaQueryType::All || self.qualifier.is_some() { if self.media_type != MediaQueryType::All || self.qualifier.is_some() {
write!(dest, " and ")?; dest.write_str(" and ")?;
} }
self.expressions[0].to_css(dest)?; self.expressions[0].to_css(dest)?;
for expr in self.expressions.iter().skip(1) { for expr in self.expressions.iter().skip(1) {
write!(dest, " and ")?; dest.write_str(" and ")?;
expr.to_css(dest)?; expr.to_css(dest)?;
} }
Ok(()) Ok(())

View file

@ -273,7 +273,7 @@ macro_rules! impl_gecko_keyword_conversions {
% if product == "gecko": % if product == "gecko":
// We should treat -moz-fixed as monospace // We should treat -moz-fixed as monospace
if name == &atom!("-moz-fixed") { if name == &atom!("-moz-fixed") {
return write!(dest, "monospace"); return dest.write_str("monospace");
} }
% endif % endif

View file

@ -215,15 +215,14 @@ impl ToCss for Expression {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where W: fmt::Write, where W: fmt::Write,
{ {
write!(dest, "(")?; let (s, l) = match self.0 {
let (mm, l) = match self.0 { ExpressionKind::Width(Range::Min(ref l)) => ("(min-width: ", l),
ExpressionKind::Width(Range::Min(ref l)) => ("min-", l), ExpressionKind::Width(Range::Max(ref l)) => ("(max-width: ", l),
ExpressionKind::Width(Range::Max(ref l)) => ("max-", l), ExpressionKind::Width(Range::Eq(ref l)) => ("(width: ", l),
ExpressionKind::Width(Range::Eq(ref l)) => ("", l),
}; };
write!(dest, "{}width: ", mm)?; dest.write_str(s)?;
l.to_css(dest)?; l.to_css(dest)?;
write!(dest, ")") dest.write_char(')')
} }
} }

View file

@ -68,7 +68,7 @@ impl Parse for SingleValue {
impl ToCss for SingleValue { impl ToCss for SingleValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}", self.0) self.0.to_css(dest)
} }
} }
@ -105,9 +105,10 @@ impl Parse for PairValues {
impl ToCss for PairValues { impl ToCss for PairValues {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}", self.0)?; self.0.to_css(dest)?;
if let Some(second) = self.1 { if let Some(second) = self.1 {
write!(dest, " {}", second)?; dest.write_char(' ')?;
second.to_css(dest)?;
} }
Ok(()) Ok(())
} }
@ -158,10 +159,10 @@ impl ToCss for VectorValues {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
let first = iter.next(); let first = iter.next();
if let Some(first) = first { if let Some(first) = first {
write!(dest, "{}", first)?; first.to_css(dest)?;
for value in iter { for value in iter {
dest.write_str(" ")?; dest.write_char(' ')?;
write!(dest, "{}", value)?; value.to_css(dest)?;
} }
} }
Ok(()) Ok(())

View file

@ -155,7 +155,7 @@ impl ToCss for KeyframeSelector {
let mut iter = self.0.iter(); let mut iter = self.0.iter();
iter.next().unwrap().to_css(dest)?; iter.next().unwrap().to_css(dest)?;
for percentage in iter { for percentage in iter {
write!(dest, ", ")?; dest.write_str(", ")?;
percentage.to_css(dest)?; percentage.to_css(dest)?;
} }
Ok(()) Ok(())

View file

@ -151,7 +151,7 @@ impl ToCss for ViewportLength {
{ {
match *self { match *self {
ViewportLength::Specified(ref length) => length.to_css(dest), ViewportLength::Specified(ref length) => length.to_css(dest),
ViewportLength::ExtendToZoom => write!(dest, "extend-to-zoom"), ViewportLength::ExtendToZoom => dest.write_str("extend-to-zoom"),
} }
} }
} }

View file

@ -26524,7 +26524,7 @@
"testharness" "testharness"
], ],
"mozilla/calc.html": [ "mozilla/calc.html": [
"5b3ea33205a9f2404bd6976a2c7f6fc451be8e96", "4f65929cacf623da2d3e310a6663d6165a1b0cdc",
"testharness" "testharness"
], ],
"mozilla/canvas.initial.reset.2dstate.html": [ "mozilla/canvas.initial.reset.2dstate.html": [

View file

@ -42,7 +42,7 @@ var widthTests = [
['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'], ['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'],
// Fold absolute units // Fold absolute units
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', 'calc(155.91666666666666px)', '155.91666666666666px'], ['calc(96px + 72pt + 6pc + 1in + 2.54cm + 25.4mm)', 'calc(576px)', '576px'],
// Alphabetical order // Alphabetical order
['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)', ['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)',