diff options
author | Xidorn Quan <me@upsuper.org> | 2016-11-23 10:32:18 +1100 |
---|---|---|
committer | Xidorn Quan <me@upsuper.org> | 2016-11-24 10:28:38 +1100 |
commit | a9296bc89cdbdb634432d46dfa15791bfd22c614 (patch) | |
tree | c0ef0d28bc133352b057838a5872c10ac217c757 | |
parent | 9d4ab0d3e9545419fc9f6ab8cee406aed1e54757 (diff) | |
download | servo-a9296bc89cdbdb634432d46dfa15791bfd22c614.tar.gz servo-a9296bc89cdbdb634432d46dfa15791bfd22c614.zip |
Add stylo FFI for CSSStyleRule
-rwxr-xr-x | components/style/binding_tools/regen.py | 3 | ||||
-rw-r--r-- | components/style/gecko/conversions.rs | 10 | ||||
-rw-r--r-- | components/style/gecko_bindings/bindings.rs | 16 | ||||
-rw-r--r-- | 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<Vec<CssRule>> { } unsafe impl HasArcFFI for RwLock<Vec<CssRule>> {} +unsafe impl HasFFI for RwLock<StyleRule> { + type FFIType = RawServoStyleRule; +} +unsafe impl HasArcFFI for RwLock<StyleRule> {} + impl From<CalcLengthOrPercentage> 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<RawServoStyleRule>; +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; @@ -221,6 +226,12 @@ extern "C" { 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); } extern "C" { @@ -995,6 +1006,11 @@ extern "C" { 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, base_url: *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; @@ -291,6 +292,18 @@ pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed, } #[no_mangle] +pub extern "C" fn Servo_CssRules_GetStyleRuleAt(rules: ServoCssRulesBorrowed, index: u32) + -> RawServoStyleRuleStrong { + let rules = RwLock::<Vec<CssRule>>::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::<Vec<CssRule>>::addref(rules) }; } @@ -301,6 +314,16 @@ pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () { } #[no_mangle] +pub extern "C" fn Servo_StyleRule_AddRef(rule: RawServoStyleRuleBorrowed) -> () { + unsafe { RwLock::<StyleRule>::addref(rule) }; +} + +#[no_mangle] +pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () { + unsafe { RwLock::<StyleRule>::release(rule) }; +} + +#[no_mangle] pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed) -> ServoComputedValuesStrong { let node = GeckoNode(node); |