diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-02 04:19:59 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-02 04:19:59 -0500 |
commit | 997a3e8374092bc4bc90455c7b51b74b30a1e167 (patch) | |
tree | 34f53e05a27ec8df83f0d6a05ea826674b5fc742 /components | |
parent | f1ae547b9faf82c74f1680b1c5ff456b57d153c2 (diff) | |
parent | 53eb1bb5c63dc059719a4b390e8d85861958d0c5 (diff) | |
download | servo-997a3e8374092bc4bc90455c7b51b74b30a1e167.tar.gz servo-997a3e8374092bc4bc90455c7b51b74b30a1e167.zip |
Auto merge of #16691 - heycam:custom-prop-name, r=xidorn
style: Correctly serialize CSS Custom Property names.
From https://bugzilla.mozilla.org/show_bug.cgi?id=1361303, and reviewed by Xidorn over there.
Diffstat (limited to 'components')
-rw-r--r-- | components/style/properties/properties.mako.rs | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 00147b89879..aba24623855 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -18,7 +18,7 @@ use std::sync::Arc; use app_units::Au; #[cfg(feature = "servo")] use cssparser::{Color as CSSParserColor, RGBA}; -use cssparser::{Parser, TokenSerializationType}; +use cssparser::{Parser, TokenSerializationType, serialize_identifier}; use error_reporting::ParseErrorReporter; #[cfg(feature = "servo")] use euclid::side_offsets::SideOffsets2D; use computed_values; @@ -775,7 +775,9 @@ impl<'a> ToCss for PropertyDeclarationId<'a> { { match *self { PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()), - PropertyDeclarationId::Custom(name) => write!(dest, "--{}", name), + PropertyDeclarationId::Custom(_) => { + serialize_identifier(&self.name(), dest) + } } } } @@ -806,6 +808,19 @@ impl<'a> PropertyDeclarationId<'a> { _ => false, } } + + /// Returns the name of the property without CSS escaping. + pub fn name(&self) -> Cow<'static, str> { + 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() + } + } + } } /// Servo's representation of a CSS property, that is, either a longhand, a @@ -833,7 +848,9 @@ impl ToCss for PropertyId { match *self { PropertyId::Longhand(id) => dest.write_str(id.name()), PropertyId::Shorthand(id) => dest.write_str(id.name()), - PropertyId::Custom(ref name) => write!(dest, "--{}", name), + PropertyId::Custom(_) => { + serialize_identifier(&self.name(), dest) + } } } } @@ -935,6 +952,20 @@ impl PropertyId { PropertyId::Custom(ref name) => Err(PropertyDeclarationId::Custom(name)), } } + + /// Returns the name of the property without CSS escaping. + pub fn name(&self) -> Cow<'static, str> { + match *self { + PropertyId::Shorthand(id) => id.name().into(), + 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() + } + } + } } /// Includes shorthands before expansion |