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
This commit is contained in:
Cameron McCormack 2018-11-06 23:03:24 +00:00 committed by Emilio Cobos Álvarez
parent acf7b65f36
commit de5584c1f6
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 24 additions and 31 deletions

View file

@ -27,6 +27,7 @@ use gecko_bindings::structs::RawServoCssUrlData;
use gecko_bindings::structs::RawServoDeclarationBlock; use gecko_bindings::structs::RawServoDeclarationBlock;
use gecko_bindings::structs::RawServoFontFaceRule; use gecko_bindings::structs::RawServoFontFaceRule;
use gecko_bindings::structs::RawServoMediaList; use gecko_bindings::structs::RawServoMediaList;
use gecko_bindings::structs::RawServoQuotes;
use gecko_bindings::structs::RawServoStyleRule; use gecko_bindings::structs::RawServoStyleRule;
use gecko_bindings::structs::RawServoStyleSheetContents; use gecko_bindings::structs::RawServoStyleSheetContents;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong}; 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::{CounterStyleRule, CssRules, FontFaceRule, FontFeatureValuesRule};
use stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule, NamespaceRule, PageRule}; use stylesheets::{DocumentRule, ImportRule, KeyframesRule, MediaRule, NamespaceRule, PageRule};
use stylesheets::{StyleRule, StylesheetContents, SupportsRule}; use stylesheets::{StyleRule, StylesheetContents, SupportsRule};
use values::computed::QuotePair;
macro_rules! impl_arc_ffi { macro_rules! impl_arc_ffi {
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => { ($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 impl_arc_ffi!(CssUrlData => RawServoCssUrlData
[Servo_CssUrlData_AddRef, Servo_CssUrlData_Release]); [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. // RuleNode is a Arc-like type but it does not use Arc.
impl StrongRuleNode { impl StrongRuleNode {

View file

@ -211,6 +211,16 @@ impl<T: RefCounted> structs::RefPtr<T> {
} }
impl<T> 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> /// Sets the contents to an Arc<T>
/// will leak existing contents /// will leak existing contents
pub fn set_arc_leaky<U>(&mut self, other: Arc<U>) pub fn set_arc_leaky<U>(&mut self, other: Arc<U>)
@ -277,11 +287,6 @@ impl_threadsafe_refcount!(
bindings::Gecko_AddRefURLExtraDataArbitraryThread, bindings::Gecko_AddRefURLExtraDataArbitraryThread,
bindings::Gecko_ReleaseURLExtraDataArbitraryThread bindings::Gecko_ReleaseURLExtraDataArbitraryThread
); );
impl_threadsafe_refcount!(
structs::nsStyleQuoteValues,
bindings::Gecko_AddRefQuoteValuesArbitraryThread,
bindings::Gecko_ReleaseQuoteValuesArbitraryThread
);
impl_threadsafe_refcount!( impl_threadsafe_refcount!(
structs::nsCSSValueSharedList, structs::nsCSSValueSharedList,
bindings::Gecko_AddRefCSSValueSharedListArbitraryThread, bindings::Gecko_AddRefCSSValueSharedListArbitraryThread,

View file

@ -4180,23 +4180,11 @@ fn static_assert() {
} }
pub fn set_quotes(&mut self, other: longhands::quotes::computed_value::T) { pub fn set_quotes(&mut self, other: longhands::quotes::computed_value::T) {
use gecko_bindings::bindings::Gecko_NewStyleQuoteValues; self.gecko.mQuotes.set_arc(other.0.clone());
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())
} }
pub fn copy_quotes_from(&mut self, other: &Self) { 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) { 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 { pub fn clone_quotes(&self) -> longhands::quotes::computed_value::T {
unsafe { use gecko_bindings::sugar::ownership::HasArcFFI;
let ref gecko_quote_values = *self.gecko.mQuotes.mRawPtr; use values::computed::QuotePair;
longhands::quotes::computed_value::T(Arc::new(
gecko_quote_values.mQuotePairs.iter().map(|gecko_pair| { let quote_pairs = unsafe { &*self.gecko.mQuotes.mRawPtr };
values::specified::QuotePair { longhands::quotes::computed_value::T(
opening: gecko_pair.first.to_string().into_boxed_str(), Box::<[QuotePair]>::as_arc(&quote_pairs).clone_arc()
closing: gecko_pair.second.to_string().into_boxed_str(), )
}
}).collect::<Vec<_>>().into_boxed_slice()
))
}
} }
#[allow(non_snake_case)] #[allow(non_snake_case)]

View file

@ -9,7 +9,6 @@ pub use values::specified::list::ListStyleType;
pub use values::specified::list::{QuotePair, Quotes}; pub use values::specified::list::{QuotePair, Quotes};
use servo_arc::Arc; use servo_arc::Arc;
use values::specified::list::QuotePair;
lazy_static! { lazy_static! {
static ref INITIAL_QUOTES: Arc<Box<[QuotePair]>> = Arc::new( static ref INITIAL_QUOTES: Arc<Box<[QuotePair]>> = Arc::new(