diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs index ed409804274..ac1175743bc 100644 --- a/components/style/gecko/arc_types.rs +++ b/components/style/gecko/arc_types.rs @@ -27,6 +27,7 @@ use gecko_bindings::structs::RawServoCssUrlData; use gecko_bindings::structs::RawServoDeclarationBlock; use gecko_bindings::structs::RawServoFontFaceRule; use gecko_bindings::structs::RawServoMediaList; +use gecko_bindings::structs::RawServoQuotes; use gecko_bindings::structs::RawServoStyleRule; use gecko_bindings::structs::RawServoStyleSheetContents; use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong}; @@ -41,6 +42,7 @@ use stylesheets::keyframes_rule::Keyframe; use stylesheets::{CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRule}; use stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule, NamespaceRule, PageRule}; use stylesheets::{StyleRule, StylesheetContents, SupportsRule}; +use values::computed::QuotePair; macro_rules! impl_arc_ffi { ($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => { @@ -115,6 +117,9 @@ impl_arc_ffi!(Locked => RawServoCounterStyleRule impl_arc_ffi!(CssUrlData => RawServoCssUrlData [Servo_CssUrlData_AddRef, Servo_CssUrlData_Release]); +impl_arc_ffi!(Box<[QuotePair]> => RawServoQuotes + [Servo_Quotes_AddRef, Servo_Quotes_Release]); + // RuleNode is a Arc-like type but it does not use Arc. impl StrongRuleNode { diff --git a/components/style/gecko_bindings/sugar/refptr.rs b/components/style/gecko_bindings/sugar/refptr.rs index ca37c4e576f..960f43885ac 100644 --- a/components/style/gecko_bindings/sugar/refptr.rs +++ b/components/style/gecko_bindings/sugar/refptr.rs @@ -211,6 +211,16 @@ impl structs::RefPtr { } impl structs::RefPtr { + /// Sets the contents to an `Arc`, releasing the old value in `self` if + /// necessary. + pub fn set_arc(&mut self, other: Arc) + where + U: HasArcFFI, + { + unsafe { U::release_opt(self.mRawPtr.as_ref()); } + self.set_arc_leaky(other); + } + /// Sets the contents to an Arc /// will leak existing contents pub fn set_arc_leaky(&mut self, other: Arc) @@ -277,11 +287,6 @@ impl_threadsafe_refcount!( bindings::Gecko_AddRefURLExtraDataArbitraryThread, bindings::Gecko_ReleaseURLExtraDataArbitraryThread ); -impl_threadsafe_refcount!( - structs::nsStyleQuoteValues, - bindings::Gecko_AddRefQuoteValuesArbitraryThread, - bindings::Gecko_ReleaseQuoteValuesArbitraryThread -); impl_threadsafe_refcount!( structs::nsCSSValueSharedList, bindings::Gecko_AddRefCSSValueSharedListArbitraryThread, diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index b79f08cb500..7fe1cd4d5c7 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -4180,23 +4180,11 @@ fn static_assert() { } pub fn set_quotes(&mut self, other: longhands::quotes::computed_value::T) { - use gecko_bindings::bindings::Gecko_NewStyleQuoteValues; - use gecko_bindings::sugar::refptr::UniqueRefPtr; - - let mut refptr = unsafe { - UniqueRefPtr::from_addrefed(Gecko_NewStyleQuoteValues(other.0.len() as u32)) - }; - - for (servo, gecko) in other.0.iter().zip(refptr.mQuotePairs.iter_mut()) { - gecko.first.assign_str(&servo.opening); - gecko.second.assign_str(&servo.closing); - } - - self.gecko.mQuotes.set_move(refptr.get()) + self.gecko.mQuotes.set_arc(other.0.clone()); } pub fn copy_quotes_from(&mut self, other: &Self) { - unsafe { self.gecko.mQuotes.set(&other.gecko.mQuotes); } + self.set_quotes(other.clone_quotes()); } pub fn reset_quotes(&mut self, other: &Self) { @@ -4204,17 +4192,13 @@ fn static_assert() { } pub fn clone_quotes(&self) -> longhands::quotes::computed_value::T { - unsafe { - let ref gecko_quote_values = *self.gecko.mQuotes.mRawPtr; - longhands::quotes::computed_value::T(Arc::new( - gecko_quote_values.mQuotePairs.iter().map(|gecko_pair| { - values::specified::QuotePair { - opening: gecko_pair.first.to_string().into_boxed_str(), - closing: gecko_pair.second.to_string().into_boxed_str(), - } - }).collect::>().into_boxed_slice() - )) - } + use gecko_bindings::sugar::ownership::HasArcFFI; + use values::computed::QuotePair; + + let quote_pairs = unsafe { &*self.gecko.mQuotes.mRawPtr }; + longhands::quotes::computed_value::T( + Box::<[QuotePair]>::as_arc("e_pairs).clone_arc() + ) } #[allow(non_snake_case)] diff --git a/components/style/values/computed/list.rs b/components/style/values/computed/list.rs index d7a69a18e99..32759787e77 100644 --- a/components/style/values/computed/list.rs +++ b/components/style/values/computed/list.rs @@ -9,7 +9,6 @@ pub use values::specified::list::ListStyleType; pub use values::specified::list::{QuotePair, Quotes}; use servo_arc::Arc; -use values::specified::list::QuotePair; lazy_static! { static ref INITIAL_QUOTES: Arc> = Arc::new(