Bug 1367523 Part 1: Servo-side define and call Gecko CounterStyle and FontFaceRule clone functions. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 05 Jun 2017 11:56:45 -0700
changeset 589177 7fbf5d2faf8b85de7b1681206378abab42a7ce93
parent 589111 50343dfdae0e4d45fbf4c34c55e888938e13a367
child 589178 f6f01195a4fa05847a27acbf7268b1b90640b23d
push id62267
push userbwerth@mozilla.com
push dateMon, 05 Jun 2017 19:02:20 +0000
bugs1367523
milestone55.0a1
Bug 1367523 Part 1: Servo-side define and call Gecko CounterStyle and FontFaceRule clone functions. MozReview-Commit-ID: Jj6YRD3tGfb
servo/components/style/gecko/generated/bindings.rs
servo/components/style/gecko/rules.rs
servo/components/style/stylesheets/mod.rs
--- a/servo/components/style/gecko/generated/bindings.rs
+++ b/servo/components/style/gecko/generated/bindings.rs
@@ -1367,30 +1367,38 @@ extern "C" {
     pub fn Gecko_CSSKeywordString(keyword: nsCSSKeyword, len: *mut u32)
      -> *const ::std::os::raw::c_char;
 }
 extern "C" {
     pub fn Gecko_CSSFontFaceRule_Create(line: u32, column: u32)
      -> *mut nsCSSFontFaceRule;
 }
 extern "C" {
+    pub fn Gecko_CSSFontFaceRule_Clone(rule: *const nsCSSFontFaceRule)
+     -> *mut nsCSSFontFaceRule;
+}
+extern "C" {
     pub fn Gecko_CSSFontFaceRule_GetCssText(rule: *const nsCSSFontFaceRule,
                                             result: *mut nsAString);
 }
 extern "C" {
     pub fn Gecko_CSSFontFaceRule_AddRef(aPtr: *mut nsCSSFontFaceRule);
 }
 extern "C" {
     pub fn Gecko_CSSFontFaceRule_Release(aPtr: *mut nsCSSFontFaceRule);
 }
 extern "C" {
     pub fn Gecko_CSSCounterStyle_Create(name: *mut nsIAtom)
      -> *mut nsCSSCounterStyleRule;
 }
 extern "C" {
+    pub fn Gecko_CSSCounterStyle_Clone(rule: *const nsCSSCounterStyleRule)
+     -> *mut nsCSSCounterStyleRule;
+}
+extern "C" {
     pub fn Gecko_CSSCounterStyle_GetCssText(rule:
                                                 *const nsCSSCounterStyleRule,
                                             result: *mut nsAString);
 }
 extern "C" {
     pub fn Gecko_CSSCounterStyleRule_AddRef(aPtr: *mut nsCSSCounterStyleRule);
 }
 extern "C" {
--- a/servo/components/style/gecko/rules.rs
+++ b/servo/components/style/gecko/rules.rs
@@ -145,16 +145,28 @@ impl ToNsCssValue for FontDisplay {
             FontDisplay::Block => structs::NS_FONT_DISPLAY_BLOCK,
             FontDisplay::Swap => structs::NS_FONT_DISPLAY_SWAP,
             FontDisplay::Fallback => structs::NS_FONT_DISPLAY_FALLBACK,
             FontDisplay::Optional => structs::NS_FONT_DISPLAY_OPTIONAL,
         } as i32)
     }
 }
 
+impl FontFaceRule {
+    /// Ask Gecko to deep clone the nsCSSFontFaceRule, and then construct
+    /// a FontFaceRule object from it.
+    pub fn deep_clone_from_gecko(&self) -> FontFaceRule {
+        let result = unsafe {
+            UniqueRefPtr::from_addrefed(
+                bindings::Gecko_CSSFontFaceRule_Clone(self.get()))
+        };
+        result.get()
+    }
+}
+
 impl From<FontFaceRuleData> for FontFaceRule {
     fn from(data: FontFaceRuleData) -> FontFaceRule {
         let mut result = unsafe {
             UniqueRefPtr::from_addrefed(bindings::Gecko_CSSFontFaceRule_Create(
                 data.source_location.line as u32, data.source_location.column as u32
             ))
         };
         data.set_descriptors(&mut result.mDecl.mDescriptors);
@@ -171,16 +183,28 @@ impl ToCssWithGuard for FontFaceRule {
         }
         write!(dest, "{}", css_text)
     }
 }
 
 /// A @counter-style rule
 pub type CounterStyleRule = RefPtr<nsCSSCounterStyleRule>;
 
+impl CounterStyleRule {
+    /// Ask Gecko to deep clone the nsCSSCounterStyleRule, and then construct
+    /// a CounterStyleRule object from it.
+    pub fn deep_clone_from_gecko(&self) -> CounterStyleRule {
+        let result = unsafe {
+            UniqueRefPtr::from_addrefed(
+                bindings::Gecko_CSSCounterStyle_Clone(self.get()))
+        };
+        result.get()
+    }
+}
+
 impl From<counter_style::CounterStyleRuleData> for CounterStyleRule {
     fn from(data: counter_style::CounterStyleRuleData) -> CounterStyleRule {
         let mut result = unsafe {
             UniqueRefPtr::from_addrefed(
                 bindings::Gecko_CSSCounterStyle_Create(data.name().0.as_ptr()))
         };
         data.set_descriptors(&mut result.mValues);
         result.get()
--- a/servo/components/style/stylesheets/mod.rs
+++ b/servo/components/style/stylesheets/mod.rs
@@ -283,22 +283,24 @@ impl DeepCloneWithLock for CssRule {
                     lock.wrap(rule.deep_clone_with_lock(lock, guard))))
             },
             CssRule::Media(ref arc) => {
                 let rule = arc.read_with(guard);
                 CssRule::Media(Arc::new(
                     lock.wrap(rule.deep_clone_with_lock(lock, guard))))
             },
             CssRule::FontFace(ref arc) => {
-                let rule = arc.read_with(guard);
-                CssRule::FontFace(Arc::new(lock.wrap(rule.clone())))
+                let rule = arc.read_with(&guard);
+                CssRule::FontFace(Arc::new(lock.wrap(
+                    rule.deep_clone_from_gecko())))
             },
             CssRule::CounterStyle(ref arc) => {
-                let rule = arc.read_with(guard);
-                CssRule::CounterStyle(Arc::new(lock.wrap(rule.clone())))
+                let rule = arc.read_with(&guard);
+                CssRule::CounterStyle(Arc::new(lock.wrap(
+                    rule.deep_clone_from_gecko())))
             },
             CssRule::Viewport(ref arc) => {
                 let rule = arc.read_with(guard);
                 CssRule::Viewport(Arc::new(lock.wrap(rule.clone())))
             },
             CssRule::Keyframes(ref arc) => {
                 let rule = arc.read_with(guard);
                 CssRule::Keyframes(Arc::new(