diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-09 05:00:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-09 05:00:45 -0700 |
commit | 1555f0fc413415d5c8f7c5a5f3fec2eecfce640e (patch) | |
tree | cd9478601deb35ab7637f296ed54edfebdb41a7d | |
parent | 969047bb7cab0f5e8c235017b7e9f7a170c9b7e4 (diff) | |
parent | d55d726a2145b9e95ec839363b8a83fa21ce3845 (diff) | |
download | servo-1555f0fc413415d5c8f7c5a5f3fec2eecfce640e.tar.gz servo-1555f0fc413415d5c8f7c5a5f3fec2eecfce640e.zip |
Auto merge of #17215 - servo:derive-all-the-things, r=emilio
Derive more ToCss impls
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17215)
<!-- Reviewable:end -->
-rw-r--r-- | components/layout/display_list_builder.rs | 4 | ||||
-rw-r--r-- | components/style/counter_style/mod.rs | 6 | ||||
-rw-r--r-- | components/style/properties/gecko.mako.rs | 4 | ||||
-rw-r--r-- | components/style/properties/longhand/counters.mako.rs | 8 | ||||
-rw-r--r-- | components/style/properties/longhand/font.mako.rs | 7 | ||||
-rw-r--r-- | components/style/properties/longhand/inherited_text.mako.rs | 23 | ||||
-rw-r--r-- | components/style/properties/longhand/list.mako.rs | 14 | ||||
-rw-r--r-- | components/style/properties/longhand/pointing.mako.rs | 27 | ||||
-rw-r--r-- | components/style/properties/longhand/position.mako.rs | 3 | ||||
-rw-r--r-- | components/style/properties/longhand/text.mako.rs | 15 | ||||
-rw-r--r-- | components/style/properties/shorthand/position.mako.rs | 3 | ||||
-rw-r--r-- | components/style/stylesheets/document_rule.rs | 8 | ||||
-rw-r--r-- | components/style/values/generics/mod.rs | 3 | ||||
-rw-r--r-- | components/style/values/mod.rs | 4 | ||||
-rw-r--r-- | components/style_traits/values.rs | 21 |
15 files changed, 54 insertions, 96 deletions
diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 4a7f2814cbf..b97aeb4c1fa 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -2853,8 +2853,8 @@ impl ServoComputedValuesCursorUtility for ServoComputedValues { fn get_cursor(&self, default_cursor: Cursor) -> Option<Cursor> { match (self.get_pointing().pointer_events, self.get_pointing().cursor) { (pointer_events::T::none, _) => None, - (pointer_events::T::auto, cursor::Keyword::AutoCursor) => Some(default_cursor), - (pointer_events::T::auto, cursor::Keyword::SpecifiedCursor(cursor)) => Some(cursor), + (pointer_events::T::auto, cursor::Keyword::Auto) => Some(default_cursor), + (pointer_events::T::auto, cursor::Keyword::Cursor(cursor)) => Some(cursor), } } } diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index a018f9b8286..55d1010259c 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -7,8 +7,8 @@ //! [counter-style]: https://drafts.csswg.org/css-counter-styles/ use Atom; -use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, Token}; -use cssparser::{serialize_string, serialize_identifier}; +use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser}; +use cssparser::{Parser, Token, serialize_identifier}; #[cfg(feature = "gecko")] use gecko::rules::CounterStyleDescriptors; #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSCounterDesc; use parser::{ParserContext, log_css_error, Parse}; @@ -361,7 +361,7 @@ impl Parse for Symbol { impl ToCss for Symbol { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - Symbol::String(ref s) => serialize_string(s, dest), + Symbol::String(ref s) => s.to_css(dest), Symbol::Ident(ref s) => serialize_identifier(s, dest), } } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 3905400ce8d..5b87bdc853d 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4241,8 +4241,8 @@ clip-path use style_traits::cursor::Cursor; self.gecko.mCursor = match v.keyword { - Keyword::AutoCursor => structs::NS_STYLE_CURSOR_AUTO, - Keyword::SpecifiedCursor(cursor) => match cursor { + Keyword::Auto => structs::NS_STYLE_CURSOR_AUTO, + Keyword::Cursor(cursor) => match cursor { Cursor::None => structs::NS_STYLE_CURSOR_NONE, Cursor::Default => structs::NS_STYLE_CURSOR_DEFAULT, Cursor::Pointer => structs::NS_STYLE_CURSOR_POINTER, diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index e71d80c42af..55d054e8a27 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -70,9 +70,7 @@ impl ToCss for ContentItem { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { - ContentItem::String(ref s) => { - cssparser::serialize_string(&**s, dest) - } + ContentItem::String(ref s) => s.to_css(dest), ContentItem::Counter(ref s, ref counter_style) => { try!(dest.write_str("counter(")); try!(cssparser::serialize_identifier(&**s, dest)); @@ -84,9 +82,9 @@ try!(dest.write_str("counters(")); try!(cssparser::serialize_identifier(&**s, dest)); try!(dest.write_str(", ")); - try!(cssparser::serialize_string(&**separator, dest)); + separator.to_css(dest)?; try!(dest.write_str(", ")); - try!(counter_style.to_css(dest)); + counter_style.to_css(dest)?; dest.write_str(")") } ContentItem::OpenQuote => dest.write_str("open-quote"), diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index 825577b1e60..127a1856e3e 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -1894,11 +1894,9 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- impl ToCss for SpecifiedValue { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - use cssparser; match *self { SpecifiedValue::Normal => dest.write_str("normal"), - SpecifiedValue::Override(ref lang) => - cssparser::serialize_string(lang, dest), + SpecifiedValue::Override(ref lang) => lang.to_css(dest), SpecifiedValue::System(_) => Ok(()) } } @@ -1921,7 +1919,6 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- use std::{fmt, str}; use style_traits::ToCss; use byteorder::{BigEndian, ByteOrder}; - use cssparser; impl ToCss for T { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { @@ -1936,7 +1933,7 @@ https://drafts.csswg.org/css-fonts-4/#low-level-font-variation-settings-control- } else { unsafe { str::from_utf8_unchecked(&buf) } }; - cssparser::serialize_string(slice.trim_right(), dest) + slice.trim_right().to_css(dest) } } diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index f78059017b5..c5301e31378 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -427,8 +427,8 @@ ${helpers.predefined_type("word-spacing", no_viewport_percentage!(SpecifiedValue); pub mod computed_value { - #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Debug, PartialEq, ToCss)] pub enum T { Keyword(KeywordValue), None, @@ -443,33 +443,14 @@ ${helpers.predefined_type("word-spacing", } } - #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Debug, PartialEq, ToCss)] pub enum SpecifiedValue { Keyword(KeywordValue), None, String(String), } - impl ToCss for computed_value::T { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - computed_value::T::Keyword(ref keyword) => keyword.to_css(dest), - computed_value::T::None => dest.write_str("none"), - computed_value::T::String(ref string) => write!(dest, "\"{}\"", string), - } - } - } - impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::Keyword(ref keyword) => keyword.to_css(dest), - SpecifiedValue::None => dest.write_str("none"), - SpecifiedValue::String(ref string) => write!(dest, "\"{}\"", string), - } - } - } - #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub enum KeywordValue { diff --git a/components/style/properties/longhand/list.mako.rs b/components/style/properties/longhand/list.mako.rs index 620695f3eba..649b04c3eaf 100644 --- a/components/style/properties/longhand/list.mako.rs +++ b/components/style/properties/longhand/list.mako.rs @@ -33,9 +33,6 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu % else: <%helpers:longhand name="list-style-type" animation_value_type="none" boxed="True" spec="https://drafts.csswg.org/css-lists/#propdef-list-style-type"> - use cssparser; - use std::fmt; - use style_traits::ToCss; use values::CustomIdent; use values::computed::ComputedValueAsSpecified; use values::generics::CounterStyleOrNone; @@ -46,7 +43,7 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu use values::generics::CounterStyleOrNone; /// <counter-style> | <string> | none - #[derive(Debug, Clone, PartialEq, Eq)] + #[derive(Debug, Clone, Eq, PartialEq, ToCss)] pub enum T { CounterStyle(CounterStyleOrNone), String(String), @@ -56,15 +53,6 @@ ${helpers.single_keyword("list-style-position", "outside inside", animation_valu impl ComputedValueAsSpecified for SpecifiedValue {} no_viewport_percentage!(SpecifiedValue); - impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - SpecifiedValue::CounterStyle(ref s) => s.to_css(dest), - SpecifiedValue::String(ref s) => cssparser::serialize_string(s, dest) - } - } - } - #[cfg(feature = "gecko")] impl SpecifiedValue { /// Convert from gecko keyword to list-style-type. diff --git a/components/style/properties/longhand/pointing.mako.rs b/components/style/properties/longhand/pointing.mako.rs index bba9b160638..05f014a07da 100644 --- a/components/style/properties/longhand/pointing.mako.rs +++ b/components/style/properties/longhand/pointing.mako.rs @@ -17,17 +17,19 @@ no_viewport_percentage!(SpecifiedValue); pub mod computed_value { + #[cfg(feature = "gecko")] use std::fmt; - use style_traits::cursor::Cursor; + #[cfg(feature = "gecko")] use style_traits::ToCss; + use style_traits::cursor::Cursor; #[cfg(feature = "gecko")] use values::specified::url::SpecifiedUrl; - #[derive(Clone, PartialEq, Copy, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Copy, Debug, PartialEq, ToCss)] pub enum Keyword { - AutoCursor, - SpecifiedCursor(Cursor), + Auto, + Cursor(Cursor), } #[cfg(not(feature = "gecko"))] @@ -47,15 +49,6 @@ pub keyword: Keyword, } - impl ToCss for Keyword { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - Keyword::AutoCursor => dest.write_str("auto"), - Keyword::SpecifiedCursor(c) => c.to_css(dest), - } - } - } - #[cfg(feature = "gecko")] impl ToCss for Image { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { @@ -85,7 +78,7 @@ #[cfg(not(feature = "gecko"))] #[inline] pub fn get_initial_value() -> computed_value::T { - computed_value::Keyword::AutoCursor + computed_value::Keyword::Auto } #[cfg(feature = "gecko")] @@ -93,7 +86,7 @@ pub fn get_initial_value() -> computed_value::T { computed_value::T { images: vec![], - keyword: computed_value::Keyword::AutoCursor + keyword: computed_value::Keyword::Auto } } @@ -103,9 +96,9 @@ use style_traits::cursor::Cursor; let ident = try!(input.expect_ident()); if ident.eq_ignore_ascii_case("auto") { - Ok(computed_value::Keyword::AutoCursor) + Ok(computed_value::Keyword::Auto) } else { - Cursor::from_css_keyword(&ident).map(computed_value::Keyword::SpecifiedCursor) + Cursor::from_css_keyword(&ident).map(computed_value::Keyword::Cursor) } } } diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index ebf4265cd0d..748f8a4ae81 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -354,7 +354,6 @@ ${helpers.predefined_type("object-position", animation_value_type="none" disable_when_testing="True" boxed="True"> - use cssparser::serialize_string; use std::collections::HashMap; use std::fmt; use std::ops::Range; @@ -486,7 +485,7 @@ ${helpers.predefined_type("object-position", if i != 0 { dest.write_str(" ")?; } - serialize_string(string, dest)?; + string.to_css(dest)?; } Ok(()) } diff --git a/components/style/properties/longhand/text.mako.rs b/components/style/properties/longhand/text.mako.rs index 08113b228f2..6ebf1e9d277 100644 --- a/components/style/properties/longhand/text.mako.rs +++ b/components/style/properties/longhand/text.mako.rs @@ -16,12 +16,11 @@ spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow"> use std::fmt; use style_traits::ToCss; - use cssparser; no_viewport_percentage!(SpecifiedValue); - #[derive(PartialEq, Eq, Clone, Debug)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + #[derive(Clone, Debug, Eq, PartialEq, ToCss)] pub enum Side { Clip, Ellipsis, @@ -127,18 +126,6 @@ } } - impl ToCss for Side { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - match *self { - Side::Clip => dest.write_str("clip"), - Side::Ellipsis => dest.write_str("ellipsis"), - Side::String(ref s) => { - cssparser::serialize_string(s, dest) - } - } - } - } - impl ToCss for SpecifiedValue { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { try!(self.first.to_css(dest)); diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 65586ab1ec2..6627edd92bf 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -250,7 +250,6 @@ spec="https://drafts.csswg.org/css-grid/#propdef-grid-template" disable_when_testing="True" products="gecko"> - use cssparser::serialize_string; use parser::Parse; use properties::longhands::grid_template_rows; use properties::longhands::grid_template_areas::TemplateAreas; @@ -370,7 +369,7 @@ concat_serialize_idents("[", "] ", names, " ", dest)?; } - serialize_string(string, dest)?; + string.to_css(dest)?; dest.write_str(" ")?; size.to_css(dest)?; } diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 0c79b0bfd8e..f921eeb7631 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -6,7 +6,7 @@ //! initially in CSS Conditional Rules Module Level 3, @document has been postponed to the level 4. //! We implement the prefixed `@-moz-document`. -use cssparser::{Parser, Token, SourceLocation, serialize_string}; +use cssparser::{Parser, Token, SourceLocation}; use media_queries::Device; use parser::{Parse, ParserContext}; use shared_lock::{DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; @@ -160,17 +160,17 @@ impl ToCss for UrlMatchingFunction { }, UrlMatchingFunction::UrlPrefix(ref url_prefix) => { dest.write_str("url-prefix(")?; - serialize_string(url_prefix, dest)?; + url_prefix.to_css(dest)?; dest.write_str(")") }, UrlMatchingFunction::Domain(ref domain) => { dest.write_str("domain(")?; - serialize_string(domain, dest)?; + domain.to_css(dest)?; dest.write_str(")") }, UrlMatchingFunction::RegExp(ref regex) => { dest.write_str("regexp(")?; - serialize_string(regex, dest)?; + regex.to_css(dest)?; dest.write_str(")") }, } diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 40d3f4e46df..da0ba4a4301 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -143,12 +143,11 @@ impl<T> OneOrMoreCommaSeparated for FontSettingTag<T> {} impl<T: ToCss> ToCss for FontSettingTag<T> { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { use byteorder::{BigEndian, ByteOrder}; - use cssparser::serialize_string; use std::str; let mut raw = [0u8; 4]; BigEndian::write_u32(&mut raw, self.tag); - serialize_string(str::from_utf8(&raw).unwrap_or_default(), dest)?; + str::from_utf8(&raw).unwrap_or_default().to_css(dest)?; self.value.to_css(dest) } diff --git a/components/style/values/mod.rs b/components/style/values/mod.rs index 506584c1e76..32b7df063c9 100644 --- a/components/style/values/mod.rs +++ b/components/style/values/mod.rs @@ -9,7 +9,7 @@ #![deny(missing_docs)] use Atom; -pub use cssparser::{RGBA, Token, Parser, serialize_identifier, serialize_string}; +pub use cssparser::{RGBA, Token, Parser, serialize_identifier}; use parser::{Parse, ParserContext}; use std::ascii::AsciiExt; use std::borrow::Cow; @@ -166,7 +166,7 @@ impl ToCss for KeyframesName { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match *self { KeyframesName::Ident(ref ident) => ident.to_css(dest), - KeyframesName::QuotedString(ref atom) => serialize_string(&atom.to_string(), dest), + KeyframesName::QuotedString(ref atom) => atom.to_string().to_css(dest), } } } diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 7c73f7bd4cf..406df824e37 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -5,11 +5,14 @@ //! Helper types and traits for the handling of CSS values. use app_units::Au; -use cssparser::UnicodeRange; +use cssparser::{UnicodeRange, serialize_string}; use std::fmt; /// Serialises a value according to its CSS representation. /// +/// This trait is implemented for `str` and its friends, serialising the string +/// contents as a CSS quoted string. +/// /// This trait is derivable with `#[derive(ToCss)]`, with the following behaviour: /// * unit variants get serialised as the `snake-case` representation /// of their name; @@ -38,6 +41,20 @@ impl<'a, T> ToCss for &'a T where T: ToCss + ?Sized { } } +impl ToCss for str { + #[inline] + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + serialize_string(self, dest) + } +} + +impl ToCss for String { + #[inline] + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + serialize_string(self, dest) + } +} + /// Marker trait to automatically implement ToCss for Vec<T>. pub trait OneOrMoreCommaSeparated {} @@ -55,7 +72,7 @@ impl<T> ToCss for Vec<T> where T: ToCss + OneOrMoreCommaSeparated { } } -impl<T: ToCss> ToCss for Box<T> { +impl<T> ToCss for Box<T> where T: ?Sized + ToCss { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write, { |