servo: Merge #16691 - style: Correctly serialize CSS Custom Property names (from heycam:custom-prop-name); r=xidorn
authorCameron McCormack <cam@mcc.id.au>
Tue, 02 May 2017 04:19:59 -0500
changeset 356009 785f1ade7dc2e8cc0b82b6df2eb29d86333337c8
parent 356008 d37e0ce6c7c9c28a0b991cc9d2a34390a127d7a0
child 356010 dc77087efa2edb596be4c4bc2ce54613d426f362
push id31754
push userkwierso@gmail.com
push dateWed, 03 May 2017 00:28:51 +0000
treeherdermozilla-central@5eaf2d70eded [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #16691 - style: Correctly serialize CSS Custom Property names (from heycam:custom-prop-name); r=xidorn From https://bugzilla.mozilla.org/show_bug.cgi?id=1361303, and reviewed by Xidorn over there. Source-Repo: https://github.com/servo/servo Source-Revision: 997a3e8374092bc4bc90455c7b51b74b30a1e167
servo/components/style/properties/properties.mako.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/style/properties/properties.mako.rs
+++ b/servo/components/style/properties/properties.mako.rs
@@ -13,17 +13,17 @@
 use std::borrow::Cow;
 use std::collections::HashSet;
 use std::fmt;
 use std::ops::Deref;
 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;
 use context::QuirksMode;
 use font_metrics::FontMetricsProvider;
 #[cfg(feature = "gecko")] use gecko_bindings::bindings;
 #[cfg(feature = "gecko")] use gecko_bindings::structs::{self, nsCSSPropertyID};
 #[cfg(feature = "servo")] use logical_geometry::{LogicalMargin, PhysicalSide};
@@ -770,17 +770,19 @@ pub enum PropertyDeclarationId<'a> {
 }
 
 impl<'a> ToCss for PropertyDeclarationId<'a> {
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result
         where W: fmt::Write,
     {
         match *self {
             PropertyDeclarationId::Longhand(id) => dest.write_str(id.name()),
-            PropertyDeclarationId::Custom(name) => write!(dest, "--{}", name),
+            PropertyDeclarationId::Custom(_) => {
+                serialize_identifier(&self.name(), dest)
+            }
         }
     }
 }
 
 impl<'a> PropertyDeclarationId<'a> {
     /// Whether a given declaration id is either the same as `other`, or a
     /// longhand of it.
     pub fn is_or_is_longhand_of(&self, other: &PropertyId) -> bool {
@@ -801,16 +803,29 @@ impl<'a> PropertyDeclarationId<'a> {
     /// Whether a given declaration id is a longhand belonging to this
     /// shorthand.
     pub fn is_longhand_of(&self, shorthand: ShorthandId) -> bool {
         match *self {
             PropertyDeclarationId::Longhand(ref id) => shorthand.longhands().contains(id),
             _ => 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
 /// shorthand, or a custom property.
 #[derive(Eq, PartialEq, Clone)]
 pub enum PropertyId {
     /// A longhand property.
     Longhand(LonghandId),
@@ -828,17 +843,19 @@ impl fmt::Debug for PropertyId {
 
 impl ToCss for PropertyId {
     fn to_css<W>(&self, dest: &mut W) -> fmt::Result
         where W: fmt::Write,
     {
         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)
+            }
         }
     }
 }
 
 impl PropertyId {
     /// Returns a given property from the string `s`.
     ///
     /// Returns Err(()) for unknown non-custom properties
@@ -930,16 +947,30 @@ impl PropertyId {
     /// `PropertyDeclarationId`.
     pub fn as_shorthand(&self) -> Result<ShorthandId, PropertyDeclarationId> {
         match *self {
             PropertyId::Shorthand(id) => Ok(id),
             PropertyId::Longhand(id) => Err(PropertyDeclarationId::Longhand(id)),
             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
 pub enum ParsedDeclaration {
     % for shorthand in data.shorthands:
         % if shorthand.name == "all":
         // No need for an All(shorthands::all::Longhands) case, since we can
         // never have any values for 'all' other than the CSS-wide keywords
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -1164,17 +1164,17 @@ pub extern "C" fn Servo_DeclarationBlock
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_DeclarationBlock_GetNthProperty(declarations: RawServoDeclarationBlockBorrowed,
                                                         index: u32, result: *mut nsAString) -> bool {
     read_locked_arc(declarations, |decls: &PropertyDeclarationBlock| {
         if let Some(&(ref decl, _)) = decls.declarations().get(index as usize) {
             let result = unsafe { result.as_mut().unwrap() };
-            decl.id().to_css(result).unwrap();
+            result.assign_utf8(&decl.id().name());
             true
         } else {
             false
         }
     })
 }
 
 macro_rules! get_property_id_from_property {