Permalink
Browse files

style: Store the Rust QuotePair slice as the computed quotes value in…

… Gecko style structs.

Depends on D10651

Differential Revision: https://phabricator.services.mozilla.com/D10652
  • Loading branch information...
heycam authored and emilio committed Nov 6, 2018
1 parent acf7b65 commit de5584c1f6136d4fdc81e2dfb96ca4b8d536f298
@@ -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<CounterStyleRule> => 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 {
@@ -211,6 +211,16 @@ impl<T: RefCounted> structs::RefPtr<T> {
}
impl<T> structs::RefPtr<T> {
/// Sets the contents to an `Arc<T>`, releasing the old value in `self` if
/// necessary.
pub fn set_arc<U>(&mut self, other: Arc<U>)
where
U: HasArcFFI<FFIType = T>,
{
unsafe { U::release_opt(self.mRawPtr.as_ref()); }
self.set_arc_leaky(other);
}
/// Sets the contents to an Arc<T>
/// will leak existing contents
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>)
@@ -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,
@@ -4180,41 +4180,25 @@ 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) {
self.copy_quotes_from(other)
}
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::<Vec<_>>().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(&quote_pairs).clone_arc()
)
}
#[allow(non_snake_case)]
@@ -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<Box<[QuotePair]>> = Arc::new(

0 comments on commit de5584c

Please sign in to comment.