diff --git a/components/script/dom/medialist.rs b/components/script/dom/medialist.rs index 6ae318da582..449c3c19ea6 100644 --- a/components/script/dom/medialist.rs +++ b/components/script/dom/medialist.rs @@ -93,12 +93,11 @@ impl MediaListMethods for MediaList { // https://drafts.csswg.org/cssom/#dom-medialist-item fn Item(&self, index: u32) -> Option { let guard = self.shared_lock().read(); - self.media_queries.read_with(&guard).media_queries - .get(index as usize).and_then(|query| { - let mut s = String::new(); - query.to_css(&mut s).unwrap(); - Some(DOMString::from_string(s)) - }) + self.media_queries + .read_with(&guard) + .media_queries + .get(index as usize) + .map(|query| query.to_css_string().into()) } // https://drafts.csswg.org/cssom/#dom-medialist-item diff --git a/components/script/dom/mediaquerylist.rs b/components/script/dom/mediaquerylist.rs index e89e7d4d744..4c6be0091b1 100644 --- a/components/script/dom/mediaquerylist.rs +++ b/components/script/dom/mediaquerylist.rs @@ -83,9 +83,7 @@ impl MediaQueryList { impl MediaQueryListMethods for MediaQueryList { // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-media fn Media(&self) -> DOMString { - let mut s = String::new(); - self.media_query_list.to_css(&mut s).unwrap(); - DOMString::from_string(s) + self.media_query_list.to_css_string().into() } // https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-matches diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 8b1c3085523..1ad385c4bfd 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -20,7 +20,8 @@ use std::borrow::Cow; use std::fmt::{self, Write}; use std::ops::Range; use str::CssStringWriter; -use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseErrorKind, ToCss}; +use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError}; +use style_traits::{StyleParseErrorKind, ToCss}; use values::CustomIdent; /// Parse a counter style name reference. @@ -231,12 +232,12 @@ macro_rules! counter_style_descriptors { impl ToCssWithGuard for CounterStyleRuleData { fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@counter-style ")?; - self.name.to_css(dest)?; + self.name.to_css(&mut CssWriter::new(dest))?; dest.write_str(" {\n")?; $( if let Some(ref value) = self.$ident { dest.write_str(concat!(" ", $name, ": "))?; - ToCss::to_css(value, dest)?; + ToCss::to_css(value, &mut CssWriter::new(dest))?; dest.write_str(";\n")?; } )+ @@ -362,7 +363,10 @@ impl Parse for System { } impl ToCss for System { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { System::Cyclic => dest.write_str("cyclic"), System::Numeric => dest.write_str("numeric"), @@ -410,7 +414,10 @@ impl Parse for Symbol { } impl ToCss for Symbol { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { Symbol::String(ref s) => s.to_css(dest), Symbol::Ident(ref s) => serialize_identifier(s, dest), @@ -477,7 +484,10 @@ fn parse_bound<'i, 't>(input: &mut Parser<'i, 't>) -> Result, ParseE } impl ToCss for Ranges { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut iter = self.0.iter(); if let Some(first) = iter.next() { range_to_css(first, dest)?; @@ -492,14 +502,19 @@ impl ToCss for Ranges { } } -fn range_to_css(range: &Range>, dest: &mut W) -> fmt::Result -where W: fmt::Write { +fn range_to_css(range: &Range>, dest: &mut CssWriter) -> fmt::Result +where + W: Write, +{ bound_to_css(range.start, dest)?; dest.write_char(' ')?; bound_to_css(range.end, dest) } -fn bound_to_css(range: Option, dest: &mut W) -> fmt::Result where W: fmt::Write { +fn bound_to_css(range: Option, dest: &mut CssWriter) -> fmt::Result +where + W: Write, +{ if let Some(finite) = range { finite.to_css(dest) } else { @@ -556,7 +571,10 @@ impl Parse for Symbols { } impl ToCss for Symbols { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut iter = self.0.iter(); let first = iter.next().expect("expected at least one symbol"); first.to_css(dest)?; diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 86aa135a0b8..0aa43109a18 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -17,9 +17,9 @@ use smallvec::SmallVec; #[allow(unused_imports)] use std::ascii::AsciiExt; use std::borrow::{Borrow, Cow}; use std::cmp; -use std::fmt; +use std::fmt::{self, Write}; use std::hash::Hash; -use style_traits::{ToCss, StyleParseErrorKind, ParseError}; +use style_traits::{CssWriter, ToCss, StyleParseErrorKind, ParseError}; /// A custom property name is just an `Atom`. /// @@ -53,8 +53,9 @@ pub struct VariableValue { } impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { dest.write_str(&self.css) } diff --git a/components/style/font_face.rs b/components/style/font_face.rs index e74064a9625..1eae14e4a3a 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -22,7 +22,8 @@ use selectors::parser::SelectorParseErrorKind; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::{Comma, OneOrMoreSeparated, ParseError, StyleParseErrorKind, ToCss}; +use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError}; +use style_traits::{StyleParseErrorKind, ToCss}; use values::computed::font::FamilyName; use values::specified::url::SpecifiedUrl; @@ -55,8 +56,9 @@ pub struct UrlSource { } impl ToCss for UrlSource { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { self.url.to_css(dest) } @@ -278,7 +280,7 @@ macro_rules! font_face_descriptors_common { $( if let Some(ref value) = self.$ident { dest.write_str(concat!(" ", $name, ": "))?; - ToCss::to_css(value, dest)?; + ToCss::to_css(value, &mut CssWriter::new(dest))?; dest.write_str(";\n")?; } )* diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index bbecaff7905..69ad65ac70c 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -24,7 +24,7 @@ use std::fmt::{self, Write}; use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering}; use str::starts_with_ignore_ascii_case; use string_cache::Atom; -use style_traits::{CSSPixel, DevicePixel}; +use style_traits::{CSSPixel, CssWriter, DevicePixel}; use style_traits::{ToCss, ParseError, StyleParseErrorKind}; use style_traits::viewport::ViewportConstraints; use stylesheets::Origin; @@ -236,7 +236,7 @@ pub struct Expression { } impl ToCss for Expression { - fn to_css(&self, dest: &mut W) -> fmt::Result + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write, { dest.write_str("(")?; @@ -408,7 +408,7 @@ impl MediaExpressionValue { } impl MediaExpressionValue { - fn to_css(&self, dest: &mut W, for_expr: &Expression) -> fmt::Result + fn to_css(&self, dest: &mut CssWriter, for_expr: &Expression) -> fmt::Result where W: fmt::Write, { match *self { diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index cb57d9b21fb..985bd453b4c 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -16,7 +16,7 @@ use selectors::parser::{self as selector_parser, Selector, Visit, SelectorParseE use selectors::visitor::SelectorVisitor; use std::fmt; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; -use style_traits::{ParseError, StyleParseErrorKind, ToCss as ToCss_}; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss as ToCss_}; pub use gecko::pseudo_element::{PseudoElement, EAGER_PSEUDOS, EAGER_PSEUDO_COUNT, PSEUDO_COUNT}; pub use gecko::snapshot::SnapshotMap; @@ -86,12 +86,12 @@ impl ToCss for NonTSPseudoClass { }, )* NonTSPseudoClass::MozLocaleDir(ref dir) => { dest.write_str(":-moz-locale-dir(")?; - dir.to_css(dest)?; + dir.to_css(&mut CssWriter::new(dest))?; return dest.write_char(')') }, NonTSPseudoClass::Dir(ref dir) => { dest.write_str(":dir(")?; - dir.to_css(dest)?; + dir.to_css(&mut CssWriter::new(dest))?; return dest.write_char(')') }, NonTSPseudoClass::MozAny(ref selectors) => { diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index 64eda812f45..b18d00a559c 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -12,9 +12,9 @@ use gecko_bindings::sugar::refptr::RefPtr; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use parser::ParserContext; use servo_arc::{Arc, RawOffsetArc}; -use std::fmt; +use std::fmt::{self, Write}; use std::mem; -use style_traits::{ToCss, ParseError}; +use style_traits::{CssWriter, ToCss, ParseError}; /// A specified url() value for gecko. Gecko does not eagerly resolve SpecifiedUrls. #[derive(Clone, Debug, PartialEq)] @@ -136,7 +136,10 @@ impl SpecifiedUrl { } impl ToCss for SpecifiedUrl { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { dest.write_str("url(")?; self.serialization.to_css(dest)?; dest.write_str(")") diff --git a/components/style/lib.rs b/components/style/lib.rs index d4d3855a481..d789c1d3305 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -134,8 +134,8 @@ pub mod traversal_flags; #[allow(non_camel_case_types)] pub mod values; -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; #[cfg(feature = "gecko")] pub use gecko_string_cache as string_cache; #[cfg(feature = "gecko")] pub use gecko_string_cache::Atom; @@ -181,11 +181,13 @@ longhand_properties_idents!(reexport_computed_values); /// Serializes as CSS a comma-separated list of any `T` that supports being /// serialized as CSS. -pub fn serialize_comma_separated_list(dest: &mut W, - list: &[T]) - -> fmt::Result - where W: fmt::Write, - T: ToCss, +pub fn serialize_comma_separated_list( + dest: &mut CssWriter, + list: &[T], +) -> fmt::Result +where + W: Write, + T: ToCss, { if list.is_empty() { return Ok(()); diff --git a/components/style/macros.rs b/components/style/macros.rs index aa505498d3b..ac795bdb09f 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -91,8 +91,11 @@ macro_rules! define_numbered_css_keyword_enum { } } - impl ::style_traits::values::ToCss for $name { - fn to_css(&self, dest: &mut W) -> ::std::fmt::Result + impl ::style_traits::ToCss for $name { + fn to_css( + &self, + dest: &mut ::style_traits::CssWriter, + ) -> ::std::fmt::Result where W: ::std::fmt::Write, { diff --git a/components/style/media_queries.rs b/components/style/media_queries.rs index 42a72ba2d58..8941b21a30a 100644 --- a/components/style/media_queries.rs +++ b/components/style/media_queries.rs @@ -14,9 +14,9 @@ use error_reporting::{ContextualParseError, ParseErrorReporter}; use parser::{ParserContext, ParserErrorContext}; use selectors::parser::SelectorParseErrorKind; use serialize_comma_separated_list; -use std::fmt; +use std::fmt::{self, Write}; use str::string_as_ascii_lowercase; -use style_traits::{ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{CssWriter, ToCss, ParseError, StyleParseErrorKind}; use values::CustomIdent; #[cfg(feature = "servo")] @@ -33,8 +33,9 @@ pub struct MediaList { } impl ToCss for MediaList { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { serialize_comma_separated_list(dest, &self.media_queries) } @@ -86,8 +87,9 @@ impl MediaQuery { } impl ToCss for MediaQuery { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { if let Some(qual) = self.qualifier { qual.to_css(dest)?; diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 48b1eb3717d..284c8230b5d 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -16,11 +16,11 @@ use properties::animated_properties::AnimationValue; use shared_lock::Locked; use smallbitvec::{self, SmallBitVec}; use smallvec::SmallVec; -use std::fmt; +use std::fmt::{self, Write}; use std::iter::{DoubleEndedIterator, Zip}; use std::slice::Iter; use str::{CssString, CssStringBorrow, CssStringWriter}; -use style_traits::{ToCss, ParseError, ParsingMode, StyleParseErrorKind}; +use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss}; use stylesheets::{CssRuleType, Origin, UrlExtraData}; use super::*; use values::computed::Context; @@ -664,7 +664,7 @@ impl PropertyDeclarationBlock { css.append_to(dest) }, Some(AppendableValue::DeclarationsForShorthand(_, decls)) => { - shorthand.longhands_to_css(decls, dest) + shorthand.longhands_to_css(decls, &mut CssWriter::new(dest)) } _ => Ok(()) } @@ -845,7 +845,7 @@ impl PropertyDeclarationBlock { } #[cfg(feature = "gecko")] (_, Some(sys)) => { - sys.to_css(&mut v)?; + sys.to_css(&mut CssWriter::new(&mut v))?; AppendableValue::Css { css: CssStringBorrow::from(&v), with_variables: false, @@ -951,10 +951,12 @@ pub enum AppendableValue<'a, I> } /// Potentially appends whitespace after the first (property: value;) pair. -fn handle_first_serialization(dest: &mut W, - is_first_serialization: &mut bool) - -> fmt::Result - where W: fmt::Write, +fn handle_first_serialization( + dest: &mut W, + is_first_serialization: &mut bool, +) -> fmt::Result +where + W: Write, { if !*is_first_serialization { dest.write_str(" ") @@ -980,7 +982,7 @@ where decl.to_css(dest) }, AppendableValue::DeclarationsForShorthand(shorthand, decls) => { - shorthand.longhands_to_css(decls, dest) + shorthand.longhands_to_css(decls, &mut CssWriter::new(dest)) } } } @@ -999,7 +1001,7 @@ where { handle_first_serialization(dest, is_first_serialization)?; - property_name.to_css(dest)?; + property_name.to_css(&mut CssWriter::new(dest))?; dest.write_char(':')?; // for normal parsed values, add a space between key: and value diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index becef724657..4d7c1ff19ad 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -82,8 +82,8 @@ need_animatable=need_animatable, **kwargs)"> #[allow(unused_imports)] use smallvec::SmallVec; - use std::fmt; - use style_traits::{Separator, ToCss}; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, Separator, ToCss}; pub mod single_value { #[allow(unused_imports)] @@ -154,8 +154,9 @@ } impl ToCss for computed_value::T { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { let mut iter = self.0.iter(); if let Some(val) = iter.next() { @@ -180,8 +181,9 @@ pub struct SpecifiedValue(pub Vec); impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { let mut iter = self.0.iter(); if let Some(val) = iter.next() { @@ -682,11 +684,11 @@ #[allow(unused_imports)] use selectors::parser::SelectorParseErrorKind; #[allow(unused_imports)] - use std::fmt; + use std::fmt::{self, Write}; #[allow(unused_imports)] use style_traits::{ParseError, StyleParseErrorKind}; #[allow(unused_imports)] - use style_traits::ToCss; + use style_traits::{CssWriter, ToCss}; pub struct Longhands { % for sub_property in shorthand.sub_properties: @@ -806,7 +808,10 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let rect = Rect::new( % for side in ["top", "right", "bottom", "left"]: &self.${to_rust_ident(sub_property_pattern % side)}, diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index a4581f1c31e..6a76f0a84e1 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -27,9 +27,9 @@ use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; use smallvec::SmallVec; use std::cmp; -use std::fmt; +use std::fmt::{self, Write}; #[cfg(feature = "gecko")] use hash::FnvHashMap; -use style_traits::{ParseError, ToCss}; +use style_traits::{CssWriter, ParseError, ToCss}; use super::ComputedValues; use values::{CSSFloat, CustomIdent, Either}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; @@ -94,7 +94,10 @@ pub enum TransitionProperty { } impl ToCss for TransitionProperty { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { TransitionProperty::All => dest.write_str("all"), TransitionProperty::Shorthand(ref id) => dest.write_str(id.name()), diff --git a/components/style/properties/longhand/color.mako.rs b/components/style/properties/longhand/color.mako.rs index 459352fd59c..3dfc685f082 100644 --- a/components/style/properties/longhand/color.mako.rs +++ b/components/style/properties/longhand/color.mako.rs @@ -66,8 +66,8 @@ pub mod system_colors { use cssparser::Parser; use gecko_bindings::bindings::Gecko_GetLookAndFeelSystemColor; use gecko_bindings::structs::root::mozilla::LookAndFeel_ColorID; - use std::fmt; - use style_traits::ToCss; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, ToCss}; use values::computed::{Context, ToComputedValue}; pub type SystemColor = LookAndFeel_ColorID; @@ -77,7 +77,10 @@ pub mod system_colors { malloc_size_of_is_0!(SystemColor); impl ToCss for SystemColor { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let s = match *self { % for color in system_colors + extra_colors: LookAndFeel_ColorID::eColorID_${to_rust_ident(color)} => "${color}", diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index c65a5ba3239..d55e880dcc9 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -23,8 +23,8 @@ pub mod computed_value { use cssparser; - use std::fmt; - use style_traits::ToCss; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, ToCss}; #[cfg(feature = "gecko")] use values::specified::url::SpecifiedUrl; @@ -62,7 +62,10 @@ } impl ToCss for ContentItem { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { ContentItem::String(ref s) => s.to_css(dest), ContentItem::Counter(ref s, ref counter_style) => { @@ -106,7 +109,10 @@ } impl ToCss for T { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { T::Normal => dest.write_str("normal"), T::None => dest.write_str("none"), @@ -232,8 +238,8 @@ <%helpers:longhand name="counter-increment" animation_value_type="discrete" spec="https://drafts.csswg.org/css-lists/#propdef-counter-increment"> - use std::fmt; - use style_traits::ToCss; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, ToCss}; use values::CustomIdent; #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] @@ -241,16 +247,17 @@ pub struct SpecifiedValue(pub Vec<(CustomIdent, specified::Integer)>); pub mod computed_value { - use std::fmt; - use style_traits::ToCss; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, ToCss}; use values::CustomIdent; #[derive(Clone, Debug, MallocSizeOf, PartialEq)] pub struct T(pub Vec<(CustomIdent, i32)>); impl ToCss for T { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { if self.0.is_empty() { return dest.write_str("none") @@ -292,10 +299,10 @@ computed_value::T(Vec::new()) } - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { if self.0.is_empty() { return dest.write_str("none"); diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index a9ae76fe9a3..c7ad330a274 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -193,8 +193,8 @@ ${helpers.predefined_type( animation_value_type="discrete" spec="https://drafts.csswg.org/css-text-decor/#propdef-text-emphasis-style"> use computed_values::writing_mode::T as WritingMode; - use std::fmt; - use style_traits::ToCss; + use std::fmt::{self, Write}; + use style_traits::{CssWriter, ToCss}; use unicode_segmentation::UnicodeSegmentation; @@ -229,7 +229,7 @@ ${helpers.predefined_type( } impl ToCss for KeywordValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if let Some(fill) = self.fill() { if fill { dest.write_str("filled")?; @@ -246,8 +246,12 @@ ${helpers.predefined_type( Ok(()) } } + impl ToCss for computed_value::KeywordValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { if self.fill { dest.write_str("filled")?; } else { diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index a30fa6c0e0a..806efc9edae 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -16,10 +16,9 @@ use custom_properties::CustomPropertiesBuilder; use servo_arc::{Arc, UniqueArc}; use smallbitvec::SmallBitVec; use std::borrow::Cow; +use std::{mem, ops}; use std::cell::RefCell; use std::fmt::{self, Write}; -use std::mem; -use std::ops; #[cfg(feature = "servo")] use cssparser::RGBA; use cssparser::{CowRcStr, Parser, TokenSerializationType, serialize_identifier}; @@ -40,7 +39,7 @@ use selector_parser::PseudoElement; use selectors::parser::SelectorParseErrorKind; #[cfg(feature = "servo")] use servo_config::prefs::PREFS; use shared_lock::StylesheetGuards; -use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss}; use stylesheets::{CssRuleType, Origin, UrlExtraData}; #[cfg(feature = "servo")] use values::Either; use values::generics::text::LineHeight; @@ -855,9 +854,14 @@ impl ShorthandId { /// /// Returns an error if writing to the stream fails, or if the declarations /// do not map to a shorthand. - pub fn longhands_to_css<'a, W, I>(&self, declarations: I, dest: &mut W) -> fmt::Result - where W: fmt::Write, - I: Iterator, + pub fn longhands_to_css<'a, W, I>( + &self, + declarations: I, + dest: &mut CssWriter, + ) -> fmt::Result + where + W: Write, + I: Iterator, { match *self { ShorthandId::All => { @@ -1075,8 +1079,9 @@ impl UnparsedValue { } impl<'a, T: ToCss> ToCss for DeclaredValue<'a, T> { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { match *self { DeclaredValue::Value(ref inner) => inner.to_css(dest), @@ -1104,8 +1109,9 @@ pub enum PropertyDeclarationId<'a> { } impl<'a> ToCss for PropertyDeclarationId<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { match *self { PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()), @@ -1150,7 +1156,6 @@ impl<'a> PropertyDeclarationId<'a> { match *self { PropertyDeclarationId::Longhand(id) => id.name().into(), PropertyDeclarationId::Custom(name) => { - use std::fmt::Write; let mut s = String::new(); write!(&mut s, "--{}", name).unwrap(); s.into() @@ -1177,13 +1182,14 @@ pub enum PropertyId { impl fmt::Debug for PropertyId { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - self.to_css(formatter) + self.to_css(&mut CssWriter::new(formatter)) } } impl ToCss for PropertyId { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { match *self { PropertyId::Longhand(id) => dest.write_str(id.name()), @@ -1331,7 +1337,6 @@ impl PropertyId { PropertyId::LonghandAlias(id, _) | PropertyId::Longhand(id) => id.name().into(), PropertyId::Custom(ref name) => { - use std::fmt::Write; let mut s = String::new(); write!(&mut s, "--{}", name).unwrap(); s.into() @@ -1464,7 +1469,7 @@ pub enum PropertyDeclaration { impl fmt::Debug for PropertyDeclaration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - self.id().to_css(f)?; + self.id().to_css(&mut CssWriter::new(f))?; f.write_str(": ")?; // Because PropertyDeclaration::to_css requires CssStringWriter, we can't write @@ -1483,10 +1488,13 @@ impl PropertyDeclaration { pub fn to_css(&self, dest: &mut CssStringWriter) -> fmt::Result { match *self { % for property in data.longhands: - PropertyDeclaration::${property.camel_case}(ref value) => - value.to_css(dest), + PropertyDeclaration::${property.camel_case}(ref value) => { + value.to_css(&mut CssWriter::new(dest)) + } % endfor - PropertyDeclaration::CSSWideKeyword(_, keyword) => keyword.to_css(dest), + PropertyDeclaration::CSSWideKeyword(_, keyword) => { + keyword.to_css(&mut CssWriter::new(dest)) + }, PropertyDeclaration::WithVariables(_, ref with_variables) => { // https://drafts.csswg.org/css-variables/#variables-in-shorthands match with_variables.from_shorthand { @@ -1500,7 +1508,9 @@ impl PropertyDeclaration { } Ok(()) }, - PropertyDeclaration::Custom(_, ref value) => value.borrow().to_css(dest), + PropertyDeclaration::Custom(_, ref value) => { + value.borrow().to_css(&mut CssWriter::new(dest)) + }, } } } diff --git a/components/style/properties/shorthand/background.mako.rs b/components/style/properties/shorthand/background.mako.rs index 4fb5f2c10f4..8fd2101ecec 100644 --- a/components/style/properties/shorthand/background.mako.rs +++ b/components/style/properties/shorthand/background.mako.rs @@ -131,7 +131,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let len = self.background_image.0.len(); // There should be at least one declared value if len == 0 { @@ -228,7 +228,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let len = self.background_position_x.0.len(); if len == 0 || len != self.background_position_y.0.len() { return Ok(()); diff --git a/components/style/properties/shorthand/border.mako.rs b/components/style/properties/shorthand/border.mako.rs index 3d175350a90..0209ebb2376 100644 --- a/components/style/properties/shorthand/border.mako.rs +++ b/components/style/properties/shorthand/border.mako.rs @@ -34,7 +34,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style", } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { % for side in PHYSICAL_SIDES: let ${side} = &self.border_${side}_width; % endfor @@ -113,7 +113,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { super::serialize_directional_border( dest, self.border_${to_rust_ident(side)}_width, @@ -156,7 +156,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let all_equal = { % for side in PHYSICAL_SIDES: let border_${side}_width = self.border_${side}_width; @@ -215,7 +215,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let LonghandsToSerialize { border_top_left_radius: &BorderCornerRadius(ref tl), border_top_right_radius: &BorderCornerRadius(ref tr), @@ -315,7 +315,7 @@ pub fn parse_border<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.border_image_source.to_css(dest)?; dest.write_str(" ")?; self.border_image_slice.to_css(dest)?; diff --git a/components/style/properties/shorthand/box.mako.rs b/components/style/properties/shorthand/box.mako.rs index ca8523173f8..137599078ad 100644 --- a/components/style/properties/shorthand/box.mako.rs +++ b/components/style/properties/shorthand/box.mako.rs @@ -48,7 +48,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.overflow_x == self.overflow_y { self.overflow_x.to_css(dest) } else { @@ -83,7 +83,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.overflow_clip_box_block.to_css(dest)?; if self.overflow_clip_box_block != self.overflow_clip_box_inline { @@ -203,7 +203,7 @@ macro_rules! try_parse_one { } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let property_len = self.transition_property.0.len(); // There are two cases that we can do shorthand serialization: @@ -327,7 +327,7 @@ macro_rules! try_parse_one { } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let len = self.animation_name.0.len(); // There should be at least one declared value if len == 0 { @@ -376,7 +376,7 @@ macro_rules! try_parse_one { impl<'a> ToCss for LonghandsToSerialize<'a> { // Serializes into the single keyword value if both scroll-snap-type-x and scroll-snap-type-y are same. // Otherwise into an empty string. This is done to match Gecko's behaviour. - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.scroll_snap_type_x == self.scroll_snap_type_y { self.scroll_snap_type_x.to_css(dest) } else { @@ -406,7 +406,7 @@ macro_rules! try_parse_one { impl<'a> ToCss for LonghandsToSerialize<'a> { // Serializes into the single keyword value if both overscroll-behavior-x and overscroll-behavior-y are same. // Otherwise into two values separated by a space. - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.overscroll_behavior_x.to_css(dest)?; if self.overscroll_behavior_y != self.overscroll_behavior_x { dest.write_str(" ")?; diff --git a/components/style/properties/shorthand/font.mako.rs b/components/style/properties/shorthand/font.mako.rs index b40505e3c86..22bbe7d71ff 100644 --- a/components/style/properties/shorthand/font.mako.rs +++ b/components/style/properties/shorthand/font.mako.rs @@ -151,9 +151,14 @@ } impl<'a> LonghandsToSerialize<'a> { - fn to_css_for(&self, - serialize_for: SerializeFor, - dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css_for( + &self, + serialize_for: SerializeFor, + dest: &mut CssWriter, + ) -> fmt::Result + where + W: Write, + { % if product == "gecko": match self.check_system() { CheckSystemResult::AllSystem(sys) => return sys.to_css(dest), @@ -226,7 +231,7 @@ } /// Serialize the shorthand value for canvas font attribute. - pub fn to_css_for_canvas(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + pub fn to_css_for_canvas(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.to_css_for(SerializeFor::Canvas, dest) } % endif @@ -234,7 +239,7 @@ // This may be a bit off, unsure, possibly needs changes impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.to_css_for(SerializeFor::Normal, dest) } } @@ -309,7 +314,7 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { #[allow(unused_assignments)] - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let has_none_ligatures = % if product == "gecko": diff --git a/components/style/properties/shorthand/inherited_svg.mako.rs b/components/style/properties/shorthand/inherited_svg.mako.rs index 76f1c840f0e..1742ef28ed7 100644 --- a/components/style/properties/shorthand/inherited_svg.mako.rs +++ b/components/style/properties/shorthand/inherited_svg.mako.rs @@ -22,7 +22,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.marker_start == self.marker_mid && self.marker_mid == self.marker_end { self.marker_start.to_css(dest) } else { diff --git a/components/style/properties/shorthand/mask.mako.rs b/components/style/properties/shorthand/mask.mako.rs index 87feba23d16..483ce9b50f8 100644 --- a/components/style/properties/shorthand/mask.mako.rs +++ b/components/style/properties/shorthand/mask.mako.rs @@ -121,7 +121,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { use properties::longhands::mask_origin::single_value::computed_value::T as Origin; use properties::longhands::mask_clip::single_value::computed_value::T as Clip; @@ -214,7 +214,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let len = self.mask_position_x.0.len(); if len == 0 || self.mask_position_y.0.len() != len { return Ok(()); diff --git a/components/style/properties/shorthand/outline.mako.rs b/components/style/properties/shorthand/outline.mako.rs index 0fe8a11118b..95d6b0be28a 100644 --- a/components/style/properties/shorthand/outline.mako.rs +++ b/components/style/properties/shorthand/outline.mako.rs @@ -76,7 +76,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { use values::generics::border::BorderCornerRadius; let LonghandsToSerialize { diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 1bddeeb8b33..95a4c183e20 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -119,7 +119,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.grid_row_gap == self.grid_column_gap { self.grid_row_gap.to_css(dest) } else { @@ -163,7 +163,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.grid_${kind}_start.to_css(dest)?; dest.write_str(" / ")?; self.grid_${kind}_end.to_css(dest) @@ -224,7 +224,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.grid_row_start.to_css(dest)?; let values = [&self.grid_column_start, &self.grid_row_end, &self.grid_column_end]; for value in &values { @@ -362,10 +362,14 @@ } /// Serialization for `` shorthand (also used by `grid` shorthand). - pub fn serialize_grid_template(template_rows: &GridTemplateComponent, - template_columns: &GridTemplateComponent, - template_areas: &Either, - dest: &mut W) -> fmt::Result where W: fmt::Write { + pub fn serialize_grid_template( + template_rows: &GridTemplateComponent, + template_columns: &GridTemplateComponent, + template_areas: &Either, + dest: &mut CssWriter, + ) -> fmt::Result + where + W: Write { match *template_areas { Either::Second(_none) => { template_rows.to_css(dest)?; @@ -451,7 +455,7 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { #[inline] - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { serialize_grid_template(self.grid_template_rows, self.grid_template_columns, self.grid_template_areas, dest) } @@ -542,7 +546,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if *self.grid_template_areas != Either::Second(None_) || (*self.grid_template_rows != GridTemplateComponent::None && *self.grid_template_columns != GridTemplateComponent::None) || @@ -635,7 +639,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.align_content.to_css(dest)?; if self.align_content != self.justify_content { dest.write_str(" ")?; @@ -670,7 +674,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.align_self == self.justify_self { self.align_self.to_css(dest) } else { @@ -713,7 +717,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.align_items.0 == self.justify_items.0 { self.align_items.to_css(dest) } else { diff --git a/components/style/properties/shorthand/serialize.mako.rs b/components/style/properties/shorthand/serialize.mako.rs index a86704a5488..afcbe3c488b 100644 --- a/components/style/properties/shorthand/serialize.mako.rs +++ b/components/style/properties/shorthand/serialize.mako.rs @@ -2,15 +2,20 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use values::specified::{BorderStyle, Color}; -use std::fmt; +use std::fmt::{self, Write}; -fn serialize_directional_border(dest: &mut W, - width: &I, - style: &BorderStyle, - color: &Color) - -> fmt::Result where W: fmt::Write, I: ToCss { +fn serialize_directional_border( + dest: &mut CssWriter, + width: &I, + style: &BorderStyle, + color: &Color, +) -> fmt::Result +where + W: Write, + I: ToCss, +{ width.to_css(dest)?; dest.write_str(" ")?; style.to_css(dest)?; diff --git a/components/style/properties/shorthand/text.mako.rs b/components/style/properties/shorthand/text.mako.rs index 2c21d1971bf..c53f1b8b27e 100644 --- a/components/style/properties/shorthand/text.mako.rs +++ b/components/style/properties/shorthand/text.mako.rs @@ -62,7 +62,7 @@ } impl<'a> ToCss for LonghandsToSerialize<'a> { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.text_decoration_line.to_css(dest)?; % if product == "gecko": diff --git a/components/style/selector_parser.rs b/components/style/selector_parser.rs index 54978d284b7..e68aded1c9a 100644 --- a/components/style/selector_parser.rs +++ b/components/style/selector_parser.rs @@ -9,7 +9,7 @@ use cssparser::{Parser as CssParser, ParserInput}; use selectors::parser::SelectorList; use std::fmt::{self, Debug, Write}; -use style_traits::{ParseError, ToCss}; +use style_traits::{CssWriter, ParseError, ToCss}; use stylesheets::{Origin, Namespaces, UrlExtraData}; /// A convenient alias for the type that represents an attribute value used for @@ -201,7 +201,7 @@ impl Direction { } impl ToCss for Direction { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write { let dir_str = match *self { Direction::Rtl => "rtl", Direction::Ltr => "ltr", diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index ea71ee84ab0..79bc288b775 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -12,9 +12,9 @@ use media_queries::MediaType; use parser::ParserContext; use properties::ComputedValues; use selectors::parser::SelectorParseErrorKind; -use std::fmt; +use std::fmt::{self, Write}; use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering}; -use style_traits::{CSSPixel, DevicePixel, ToCss, ParseError}; +use style_traits::{CSSPixel, CssWriter, DevicePixel, ToCss, ParseError}; use style_traits::viewport::ViewportConstraints; use values::computed::{self, ToComputedValue}; use values::computed::font::FontSize; @@ -218,8 +218,9 @@ impl Expression { } impl ToCss for Expression { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { let (s, l) = match self.0 { ExpressionKind::Width(Range::Min(ref l)) => ("(min-width: ", l), diff --git a/components/style/servo/url.rs b/components/style/servo/url.rs index 6dc1d46d2aa..25a4aa5297d 100644 --- a/components/style/servo/url.rs +++ b/components/style/servo/url.rs @@ -6,12 +6,12 @@ use parser::ParserContext; use servo_url::ServoUrl; -use std::fmt; +use std::fmt::{self, Write}; // Note: We use std::sync::Arc rather than servo_arc::Arc here because the // nonzero optimization is important in keeping the size of SpecifiedUrl below // the threshold. use std::sync::Arc; -use style_traits::{ToCss, ParseError}; +use style_traits::{CssWriter, ParseError, ToCss}; use values::computed::{Context, ToComputedValue, ComputedUrl}; /// A specified url() value for servo. @@ -111,7 +111,10 @@ impl PartialEq for SpecifiedUrl { } impl ToCss for SpecifiedUrl { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let string = match self.original { Some(ref original) => &**original, None => match self.resolved { diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index ea140849be3..ab8382df069 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -15,7 +15,7 @@ use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::{ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use stylesheets::CssRules; use values::specified::url::SpecifiedUrl; @@ -43,7 +43,7 @@ impl DocumentRule { impl ToCssWithGuard for DocumentRule { fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@-moz-document ")?; - self.condition.to_css(dest)?; + self.condition.to_css(&mut CssWriter::new(dest))?; dest.write_str(" {")?; for rule in self.rules.read_with(guard).0.iter() { dest.write_str(" ")?; @@ -167,8 +167,10 @@ impl UrlMatchingFunction { } impl ToCss for UrlMatchingFunction { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { UrlMatchingFunction::Url(ref url) => { url.to_css(dest) @@ -219,8 +221,10 @@ impl DocumentCondition { } impl ToCss for DocumentCondition { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut iter = self.0.iter(); let first = iter.next() .expect("Empty DocumentCondition, should contain at least one URL matching function"); diff --git a/components/style/stylesheets/font_feature_values_rule.rs b/components/style/stylesheets/font_feature_values_rule.rs index 18cf957d466..35ac85c7469 100644 --- a/components/style/stylesheets/font_feature_values_rule.rs +++ b/components/style/stylesheets/font_feature_values_rule.rs @@ -18,7 +18,7 @@ use parser::{ParserContext, ParserErrorContext, Parse}; use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::{ParseError, StyleParseErrorKind, ToCss}; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use stylesheets::CssRuleType; use values::computed::font::FamilyName; @@ -37,7 +37,10 @@ pub struct FFVDeclaration { } impl ToCss for FFVDeclaration { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { serialize_identifier(&self.name.to_string(), dest)?; dest.write_str(": ")?; self.value.to_css(dest)?; @@ -101,7 +104,10 @@ impl Parse for PairValues { } impl ToCss for PairValues { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { self.0.to_css(dest)?; if let Some(second) = self.1 { dest.write_char(' ')?; @@ -153,7 +159,10 @@ impl Parse for VectorValues { } impl ToCss for VectorValues { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut iter = self.0.iter(); let first = iter.next(); if let Some(first) = first { @@ -280,7 +289,13 @@ macro_rules! font_feature_values_blocks { } /// Prints font family names. - pub fn font_family_to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + pub fn font_family_to_css( + &self, + dest: &mut CssWriter, + ) -> fmt::Result + where + W: Write, + { let mut iter = self.family_names.iter(); iter.next().unwrap().to_css(dest)?; for val in iter { @@ -291,7 +306,10 @@ macro_rules! font_feature_values_blocks { } /// Prints inside of `@font-feature-values` block. - pub fn value_to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + pub fn value_to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { $( if self.$ident.len() > 0 { dest.write_str(concat!("@", $name, " {\n"))?; @@ -344,9 +362,9 @@ macro_rules! font_feature_values_blocks { impl ToCssWithGuard for FontFeatureValuesRule { fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@font-feature-values ")?; - self.font_family_to_css(dest)?; + self.font_family_to_css(&mut CssWriter::new(dest))?; dest.write_str(" {\n")?; - self.value_to_css(dest)?; + self.value_to_css(&mut CssWriter::new(dest))?; dest.write_str("}") } } diff --git a/components/style/stylesheets/import_rule.rs b/components/style/stylesheets/import_rule.rs index c9fcd8d2c8a..c72800b4517 100644 --- a/components/style/stylesheets/import_rule.rs +++ b/components/style/stylesheets/import_rule.rs @@ -11,7 +11,7 @@ use media_queries::MediaList; use shared_lock::{DeepCloneWithLock, DeepCloneParams, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use stylesheets::{StylesheetContents, StylesheetInDocument}; use values::specified::url::SpecifiedUrl; @@ -110,12 +110,12 @@ impl DeepCloneWithLock for ImportRule { impl ToCssWithGuard for ImportRule { fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@import ")?; - self.url.to_css(dest)?; + self.url.to_css(&mut CssWriter::new(dest))?; match self.stylesheet.media(guard) { Some(media) if !media.is_empty() => { dest.write_str(" ")?; - media.to_css(dest)?; + media.to_css(&mut CssWriter::new(dest))?; } _ => {}, }; diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index b7f28704b1a..fe52edd60be 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -16,7 +16,7 @@ use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, Locked, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::{ParsingMode, ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{CssWriter, ParseError, ParsingMode, StyleParseErrorKind, ToCss}; use stylesheets::{CssRuleType, StylesheetContents}; use stylesheets::rule_parser::VendorPrefix; use values::{KeyframesName, serialize_percentage}; @@ -40,7 +40,7 @@ impl ToCssWithGuard for KeyframesRule { // Serialization of KeyframesRule is not specced. fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@keyframes ")?; - self.name.to_css(dest)?; + self.name.to_css(&mut CssWriter::new(dest))?; dest.write_str(" {")?; let iter = self.keyframes.iter(); for lock in iter { @@ -109,7 +109,10 @@ impl ::std::cmp::Ord for KeyframePercentage { impl ::std::cmp::Eq for KeyframePercentage { } impl ToCss for KeyframePercentage { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { serialize_percentage(self.0, dest) } } @@ -146,7 +149,10 @@ impl KeyframePercentage { pub struct KeyframeSelector(Vec); impl ToCss for KeyframeSelector { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut iter = self.0.iter(); iter.next().unwrap().to_css(dest)?; for percentage in iter { @@ -194,7 +200,7 @@ pub struct Keyframe { impl ToCssWithGuard for Keyframe { fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { - self.selector.to_css(dest)?; + self.selector.to_css(&mut CssWriter::new(dest))?; dest.write_str(" { ")?; self.block.read_with(guard).to_css(dest)?; dest.write_str(" }")?; diff --git a/components/style/stylesheets/media_rule.rs b/components/style/stylesheets/media_rule.rs index d9c8e72ffb9..20aa4329693 100644 --- a/components/style/stylesheets/media_rule.rs +++ b/components/style/stylesheets/media_rule.rs @@ -14,7 +14,7 @@ use servo_arc::Arc; use shared_lock::{DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use std::fmt::{self, Write}; use str::CssStringWriter; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use stylesheets::CssRules; /// An [`@media`][media] urle. @@ -45,7 +45,7 @@ impl ToCssWithGuard for MediaRule { // https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSMediaRule fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@media ")?; - self.media_queries.read_with(guard).to_css(dest)?; + self.media_queries.read_with(guard).to_css(&mut CssWriter::new(dest))?; self.rules.read_with(guard).to_css_block(guard, dest) } } diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index 641fc5f5603..3780c18ede1 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -18,7 +18,7 @@ use std::ffi::{CStr, CString}; use std::fmt::{self, Write}; use std::str; use str::CssStringWriter; -use style_traits::{ToCss, ParseError}; +use style_traits::{CssWriter, ParseError, ToCss}; use stylesheets::{CssRuleType, CssRules}; /// An [`@supports`][supports] rule. @@ -49,7 +49,7 @@ impl SupportsRule { impl ToCssWithGuard for SupportsRule { fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@supports ")?; - self.condition.to_css(dest)?; + self.condition.to_css(&mut CssWriter::new(dest))?; self.rules.read_with(guard).to_css_block(guard, dest) } } @@ -219,8 +219,9 @@ pub fn parse_condition_or_declaration<'i, 't>(input: &mut Parser<'i, 't>) } impl ToCss for SupportsCondition { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { match *self { SupportsCondition::Not(ref cond) => { @@ -276,7 +277,10 @@ impl ToCss for SupportsCondition { pub struct Declaration(pub String); impl ToCss for Declaration { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { dest.write_str(&self.0) } } diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index 1b8b9fd2f8b..e50d9f1720b 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -27,7 +27,7 @@ use std::fmt::{self, Write}; use std::iter::Enumerate; use std::str::Chars; use str::CssStringWriter; -use style_traits::{PinchZoomFactor, ToCss, ParseError, StyleParseErrorKind}; +use style_traits::{CssWriter, ParseError, PinchZoomFactor, StyleParseErrorKind, ToCss}; use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom}; use stylesheets::{StylesheetInDocument, Origin}; use values::computed::{Context, ToComputedValue}; @@ -101,7 +101,10 @@ macro_rules! declare_viewport_descriptor_inner { } impl ToCss for ViewportDescriptor { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { $( ViewportDescriptor::$assigned_variant(ref val) => { @@ -149,8 +152,9 @@ pub enum ViewportLength { } impl ToCss for ViewportLength { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { match *self { ViewportLength::Specified(ref length) => length.to_css(dest), @@ -255,7 +259,10 @@ impl ViewportDescriptorDeclaration { } impl ToCss for ViewportDescriptorDeclaration { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { self.descriptor.to_css(dest)?; if self.important { dest.write_str(" !important")?; @@ -524,10 +531,10 @@ impl ToCssWithGuard for ViewportRule { fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result { dest.write_str("@viewport { ")?; let mut iter = self.declarations.iter(); - iter.next().unwrap().to_css(dest)?; + iter.next().unwrap().to_css(&mut CssWriter::new(dest))?; for declaration in iter { dest.write_str(" ")?; - declaration.to_css(dest)?; + declaration.to_css(&mut CssWriter::new(dest))?; } dest.write_str(" }") } diff --git a/components/style/values/computed/align.rs b/components/style/values/computed/align.rs index f3caade67a5..85f8f70cb25 100644 --- a/components/style/values/computed/align.rs +++ b/components/style/values/computed/align.rs @@ -7,7 +7,7 @@ //! https://drafts.csswg.org/css-align/ use std::fmt; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use values::computed::{Context, ToComputedValue}; use values::specified; @@ -26,7 +26,7 @@ pub struct JustifyItems { } impl ToCss for JustifyItems { - fn to_css(&self, dest: &mut W) -> fmt::Result + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write, { self.computed.to_css(dest) diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index e71f208c984..7b7f7c4991b 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -6,8 +6,8 @@ use properties::animated_properties::RepeatableListAnimatable; use properties::longhands::background_size::computed_value::T as BackgroundSizeList; -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::{Context, ToComputedValue}; use values::computed::length::LengthOrPercentageOrAuto; @@ -96,9 +96,9 @@ impl BackgroundRepeat { } impl ToCss for BackgroundRepeat { - fn to_css(&self, dest: &mut W) -> fmt::Result + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where - W: fmt::Write, + W: Write, { match (self.0, self.1) { (RepeatKeyword::Repeat, RepeatKeyword::NoRepeat) => dest.write_str("repeat-x"), diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index 20dcffec9c6..17c39741c81 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -7,8 +7,8 @@ //! //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::computed::{LengthOrPercentage, ComputedUrl, Image}; use values::generics::basic_shape::{BasicShape as GenericBasicShape}; use values::generics::basic_shape::{Circle as GenericCircle, ClippingShape as GenericClippingShape}; @@ -37,7 +37,10 @@ pub type Ellipse = GenericEllipse; impl ToCss for Circle { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { dest.write_str("circle(")?; self.radius.to_css(dest)?; dest.write_str(" at ")?; @@ -47,7 +50,10 @@ impl ToCss for Circle { } impl ToCss for Ellipse { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { dest.write_str("ellipse(")?; if (self.semiaxis_x, self.semiaxis_y) != Default::default() { self.semiaxis_x.to_css(dest)?; diff --git a/components/style/values/computed/color.rs b/components/style/values/computed/color.rs index 6327e734626..314c4bed266 100644 --- a/components/style/values/computed/color.rs +++ b/components/style/values/computed/color.rs @@ -6,7 +6,7 @@ use cssparser::{Color as CSSParserColor, RGBA}; use std::fmt; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use values::animated::ToAnimatedValue; use values::animated::color::{Color as AnimatedColor, RGBA as AnimatedRGBA}; @@ -138,7 +138,7 @@ impl From for Color { } impl ToCss for Color { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { if self.is_numeric() { self.color.to_css(dest) } else if self.is_currentcolor() { diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 407be16c203..20a41154ec9 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -19,7 +19,7 @@ use std::fmt::{self, Write}; use std::hash::{Hash, Hasher}; #[cfg(feature = "servo")] use std::slice; -use style_traits::{ToCss, ParseError}; +use style_traits::{CssWriter, ParseError, ToCss}; use values::CSSFloat; use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::{Context, NonNegativeLength, ToComputedValue}; @@ -201,7 +201,7 @@ impl FontSize { } impl ToCss for FontSize { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { self.size.to_css(dest) } } @@ -257,7 +257,7 @@ impl MallocSizeOf for FontFamily { } impl ToCss for FontFamily { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { let mut iter = self.0.iter(); iter.next().unwrap().to_css(dest)?; for family in iter { @@ -279,7 +279,7 @@ pub struct FamilyName { } impl ToCss for FamilyName { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { match self.syntax { FamilyNameSyntax::Quoted => { dest.write_char('"')?; @@ -488,7 +488,7 @@ impl SingleFontFamily { } impl ToCss for SingleFontFamily { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { match *self { SingleFontFamily::FamilyName(ref name) => name.to_css(dest), @@ -731,7 +731,7 @@ impl FontLanguageOverride { } impl ToCss for FontLanguageOverride { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { use std::str; if self.0 == 0 { diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 8972774aa77..93fa627a41d 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -9,8 +9,8 @@ use cssparser::RGBA; use std::f32::consts::PI; -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::{Either, None_}; use values::computed::{Angle, ComputedUrl, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue}; #[cfg(feature = "gecko")] @@ -99,8 +99,13 @@ impl GenericLineDirection for LineDirection { } } - fn to_css(&self, dest: &mut W, compat_mode: CompatMode) -> fmt::Result - where W: fmt::Write + fn to_css( + &self, + dest: &mut CssWriter, + compat_mode: CompatMode, + ) -> fmt::Result + where + W: Write, { match *self { LineDirection::Angle(ref angle) => angle.to_css(dest), diff --git a/components/style/values/computed/inherited_box.rs b/components/style/values/computed/inherited_box.rs index 2fa4dd819a5..f6fe6ad7bf9 100644 --- a/components/style/values/computed/inherited_box.rs +++ b/components/style/values/computed/inherited_box.rs @@ -4,8 +4,8 @@ //! Computed values for inherited box -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::specified::Angle; /// An angle rounded and normalized per https://drafts.csswg.org/css-images/#propdef-image-orientation @@ -31,7 +31,10 @@ impl Orientation { } impl ToCss for Orientation { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { // Should agree with Angle::to_css. match *self { Orientation::Angle0 => dest.write_str("0deg"), @@ -60,7 +63,10 @@ impl ImageOrientation { } impl ToCss for ImageOrientation { - fn to_css(&self, dest: &mut W) -> fmt::Result { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { match *self { ImageOrientation::FromImage => dest.write_str("from-image"), ImageOrientation::AngleWithFlipped(angle, flipped) => { diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index a0a92c713c2..49db7201a39 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -6,9 +6,9 @@ use app_units::Au; use ordered_float::NotNaN; -use std::fmt; +use std::fmt::{self, Write}; use std::ops::{Add, Neg}; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use style_traits::values::specified::AllowedNumericType; use super::{Number, ToComputedValue, Context, Percentage}; use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified}; @@ -203,7 +203,10 @@ impl From for Option { } impl ToCss for CalcLengthOrPercentage { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { use num_traits::Zero; let (length, percentage) = match (self.length, self.percentage) { @@ -738,7 +741,10 @@ impl CSSPixelLength { impl ToCss for CSSPixelLength { #[inline] - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { self.0.to_css(dest)?; dest.write_str("px") } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 20bcefc655b..a559f4fbe87 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -15,11 +15,12 @@ use properties::{ComputedValues, LonghandId, StyleBuilder}; use rule_cache::RuleCacheConditions; #[cfg(feature = "servo")] use servo_url::ServoUrl; -use std::{f32, fmt}; use std::cell::RefCell; +use std::f32; +use std::fmt::{self, Write}; #[cfg(feature = "servo")] use std::sync::Arc; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use style_traits::cursor::CursorKind; use super::{CSSFloat, CSSInteger}; use super::generics::{GreaterThanOrEqualToOne, NonNegative}; @@ -531,7 +532,10 @@ pub struct ClipRect { } impl ToCss for ClipRect { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { dest.write_str("rect(")?; if let Some(top) = self.top { top.to_css(dest)?; @@ -627,7 +631,10 @@ impl ComputedUrl { #[cfg(feature = "servo")] impl ToCss for ComputedUrl { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let string = match *self { ComputedUrl::Valid(ref url) => url.as_str(), ComputedUrl::Invalid(ref invalid_string) => invalid_string, diff --git a/components/style/values/computed/percentage.rs b/components/style/values/computed/percentage.rs index 1bc28a13488..842019f03c8 100644 --- a/components/style/values/computed/percentage.rs +++ b/components/style/values/computed/percentage.rs @@ -5,7 +5,7 @@ //! Computed percentages. use std::fmt; -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; use values::{CSSFloat, serialize_percentage}; /// A computed percentage. @@ -35,7 +35,7 @@ impl Percentage { } impl ToCss for Percentage { - fn to_css(&self, dest: &mut W) -> fmt::Result + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write, { diff --git a/components/style/values/computed/pointing.rs b/components/style/values/computed/pointing.rs index 9b108dbcfc2..b14f22dec9c 100644 --- a/components/style/values/computed/pointing.rs +++ b/components/style/values/computed/pointing.rs @@ -10,10 +10,10 @@ use cssparser::Parser; use parser::{Parse, ParserContext}; use selectors::parser::SelectorParseErrorKind; #[cfg(feature = "gecko")] -use std::fmt; -use style_traits::ParseError; +use std::fmt::{self, Write}; #[cfg(feature = "gecko")] -use style_traits::ToCss; +use style_traits::{CssWriter, ToCss}; +use style_traits::ParseError; use style_traits::cursor::CursorKind; /// The computed value for the `cursor` property. @@ -80,8 +80,9 @@ impl Parse for Cursor { #[cfg(feature = "gecko")] impl ToCss for Cursor { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { for url in &*self.images { url.to_css(dest)?; @@ -123,8 +124,9 @@ impl CursorImage { #[cfg(feature = "gecko")] impl ToCss for CursorImage { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, { self.url.to_css(dest)?; if let Some((x, y)) = self.hotspot { diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index ed6a308151f..abd3522382d 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -7,8 +7,8 @@ //! //! [position]: https://drafts.csswg.org/css-backgrounds-3/#position -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::computed::{LengthOrPercentage, Percentage}; use values::generics::position::Position as GenericPosition; pub use values::specified::position::{GridAutoFlow, GridTemplateAreas}; @@ -40,7 +40,10 @@ impl Position { } impl ToCss for Position { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { self.horizontal.to_css(dest)?; dest.write_str(" ")?; self.vertical.to_css(dest) diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 27c198a46a5..123f735d513 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -6,8 +6,8 @@ #[cfg(feature = "servo")] use properties::StyleBuilder; -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::{CSSInteger, CSSFloat}; use values::animated::ToAnimatedZero; use values::computed::{NonNegativeLength, NonNegativeNumber}; @@ -66,7 +66,10 @@ impl TextOverflow { } impl ToCss for TextOverflow { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { if self.sides_are_logical { debug_assert!(self.first == TextOverflowSide::Clip); self.second.to_css(dest)?; @@ -80,7 +83,10 @@ impl ToCss for TextOverflow { } impl ToCss for TextDecorationLine { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { let mut has_any = false; macro_rules! write_value { diff --git a/components/style/values/computed/time.rs b/components/style/values/computed/time.rs index a90a0935a8e..cef128af4a8 100644 --- a/components/style/values/computed/time.rs +++ b/components/style/values/computed/time.rs @@ -4,8 +4,8 @@ //! Computed time values. -use std::fmt; -use style_traits::ToCss; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; use values::CSSFloat; /// A computed `