From a9296bc89cdbdb634432d46dfa15791bfd22c614 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:32:18 +1100 Subject: [PATCH] Add stylo FFI for CSSStyleRule --- components/style/binding_tools/regen.py | 3 ++- components/style/gecko/conversions.rs | 10 +++++++-- components/style/gecko_bindings/bindings.rs | 16 +++++++++++++ ports/geckolib/glue.rs | 25 ++++++++++++++++++++- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/components/style/binding_tools/regen.py b/components/style/binding_tools/regen.py index 1187e0d677e..b348cc0615b 100755 --- a/components/style/binding_tools/regen.py +++ b/components/style/binding_tools/regen.py @@ -335,7 +335,8 @@ COMPILATION_TARGETS = { "ServoComputedValues", "ServoCssRules", "RawServoStyleSheet", - "RawServoDeclarationBlock" + "RawServoDeclarationBlock", + "RawServoStyleRule", ], "servo_owned_types": [ "RawServoStyleSet", diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 25daba40daf..afca398c8b5 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -11,13 +11,14 @@ use app_units::Au; use gecko::values::{convert_rgba_to_nscolor, StyleCoordHelpers}; use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue}; -use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, ServoComputedValues, ServoCssRules}; +use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, RawServoStyleRule}; +use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules}; use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage}; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut}; use gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI}; use parking_lot::RwLock; use properties::{ComputedValues, PropertyDeclarationBlock}; -use stylesheets::{CssRule, Stylesheet}; +use stylesheets::{CssRule, Stylesheet, StyleRule}; use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto}; unsafe impl HasFFI for Stylesheet { @@ -39,6 +40,11 @@ unsafe impl HasFFI for RwLock> { } unsafe impl HasArcFFI for RwLock> {} +unsafe impl HasFFI for RwLock { + type FFIType = RawServoStyleRule; +} +unsafe impl HasArcFFI for RwLock {} + impl From for nsStyleCoord_CalcValue { fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 32d68b78b58..ef0086edde1 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -24,6 +24,11 @@ pub type RawServoDeclarationBlockBorrowedOrNull<'a> = Option<&'a RawServoDeclara pub type RawServoDeclarationBlockBorrowed<'a> = &'a RawServoDeclarationBlock; enum RawServoDeclarationBlockVoid{ } pub struct RawServoDeclarationBlock(RawServoDeclarationBlockVoid); +pub type RawServoStyleRuleStrong = ::gecko_bindings::sugar::ownership::Strong; +pub type RawServoStyleRuleBorrowedOrNull<'a> = Option<&'a RawServoStyleRule>; +pub type RawServoStyleRuleBorrowed<'a> = &'a RawServoStyleRule; +enum RawServoStyleRuleVoid{ } +pub struct RawServoStyleRule(RawServoStyleRuleVoid); pub type RawGeckoNodeBorrowed<'a> = &'a RawGeckoNode; pub type RawGeckoNodeBorrowedOrNull<'a> = Option<&'a RawGeckoNode>; pub type RawGeckoElementBorrowed<'a> = &'a RawGeckoElement; @@ -220,6 +225,12 @@ extern "C" { pub fn Servo_DeclarationBlock_Release(ptr: RawServoDeclarationBlockBorrowed); } +extern "C" { + pub fn Servo_StyleRule_AddRef(ptr: RawServoStyleRuleBorrowed); +} +extern "C" { + pub fn Servo_StyleRule_Release(ptr: RawServoStyleRuleBorrowed); +} extern "C" { pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned); } @@ -994,6 +1005,11 @@ extern "C" { pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed, result: nsTArrayBorrowed_uintptr_t); } +extern "C" { + pub fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, + index: u32) + -> RawServoStyleRuleStrong; +} extern "C" { pub fn Servo_ParseProperty(property: *const nsACString_internal, value: *const nsACString_internal, diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 007579d7f07..11ef9d7701c 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -23,6 +23,7 @@ use style::gecko::wrapper::{GeckoElement, GeckoNode}; use style::gecko::wrapper::DUMMY_BASE_URL; use style::gecko_bindings::bindings::{RawGeckoElementBorrowed, RawGeckoNodeBorrowed}; use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong}; +use style::gecko_bindings::bindings::{RawServoStyleRuleBorrowed, RawServoStyleRuleStrong}; use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; @@ -47,7 +48,7 @@ use style::properties::{apply_declarations, parse_one_declaration}; use style::selector_parser::PseudoElementCascadeType; use style::sequential; use style::string_cache::Atom; -use style::stylesheets::{CssRule, Origin, Stylesheet}; +use style::stylesheets::{CssRule, Origin, Stylesheet, StyleRule}; use style::thread_state; use style::timer::Timer; use style_traits::ToCss; @@ -290,6 +291,18 @@ pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed, result.iter_mut().zip(iter).fold((), |_, (r, v)| *r = v); } +#[no_mangle] +pub extern "C" fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, index: u32) + -> RawServoStyleRuleStrong { + let rules = RwLock::>::as_arc(&rules).read(); + match rules[index as usize] { + CssRule::Style(ref rule) => rule.clone().into_strong(), + _ => { + unreachable!("GetStyleRuleAt should only be called on a style rule"); + } + } +} + #[no_mangle] pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () { unsafe { RwLock::>::addref(rules) }; @@ -300,6 +313,16 @@ pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () { unsafe { RwLock::>::release(rules) }; } +#[no_mangle] +pub extern "C" fn Servo_StyleRule_AddRef(rule: RawServoStyleRuleBorrowed) -> () { + unsafe { RwLock::::addref(rule) }; +} + +#[no_mangle] +pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () { + unsafe { RwLock::::release(rule) }; +} + #[no_mangle] pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed) -> ServoComputedValuesStrong {