From 9d4ab0d3e9545419fc9f6ab8cee406aed1e54757 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:30:48 +1100 Subject: [PATCH 1/5] Add stylo FFI for CSSRuleList --- components/style/binding_tools/regen.py | 15 ++++++++- components/style/gecko/conversions.rs | 9 ++++-- components/style/gecko_bindings/bindings.rs | 20 ++++++++++++ components/style/stylesheets.rs | 35 +++++++++++++++++++++ ports/geckolib/glue.rs | 30 +++++++++++++++++- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/components/style/binding_tools/regen.py b/components/style/binding_tools/regen.py index 4e0ef4b0e9b..1187e0d677e 100755 --- a/components/style/binding_tools/regen.py +++ b/components/style/binding_tools/regen.py @@ -328,8 +328,13 @@ COMPILATION_TARGETS = { "nsStyleVisibility", "nsStyleXUL", ], + "array_types": { + "uintptr_t": "usize", + }, "servo_nullable_arc_types": [ - "ServoComputedValues", "RawServoStyleSheet", + "ServoComputedValues", + "ServoCssRules", + "RawServoStyleSheet", "RawServoDeclarationBlock" ], "servo_owned_types": [ @@ -535,6 +540,14 @@ def build(objdir, target_name, debug, debugger, kind_name=None, flags.append("--opaque-type") flags.append(ty) + if "array_types" in current_target: + for cpp_type, rust_type in current_target["array_types"].items(): + flags.append("--blacklist-type") + flags.append("nsTArrayBorrowed_{}".format(cpp_type)) + flags.append("--raw-line") + flags.append("pub type nsTArrayBorrowed_{0}<'a> = &'a mut ::gecko_bindings::structs::nsTArray<{1}>;" + .format(cpp_type, rust_type)) + if "blacklist_types" in current_target: for ty in current_target["blacklist_types"]: flags.append("--blacklist-type") diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 950003a2249..25daba40daf 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -11,13 +11,13 @@ 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}; +use gecko_bindings::bindings::{RawServoStyleSheet, RawServoDeclarationBlock, 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::Stylesheet; +use stylesheets::{CssRule, Stylesheet}; use values::computed::{CalcLengthOrPercentage, Gradient, Image, LengthOrPercentage, LengthOrPercentageOrAuto}; unsafe impl HasFFI for Stylesheet { @@ -34,6 +34,11 @@ unsafe impl HasFFI for RwLock { } unsafe impl HasArcFFI for RwLock {} +unsafe impl HasFFI for RwLock> { + type FFIType = ServoCssRules; +} +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 dcd961263c6..32d68b78b58 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -3,11 +3,17 @@ pub use nsstring::{nsACString, nsAString}; type nsACString_internal = nsACString; type nsAString_internal = nsAString; +pub type nsTArrayBorrowed_uintptr_t<'a> = &'a mut ::gecko_bindings::structs::nsTArray; pub type ServoComputedValuesStrong = ::gecko_bindings::sugar::ownership::Strong; pub type ServoComputedValuesBorrowedOrNull<'a> = Option<&'a ServoComputedValues>; pub type ServoComputedValuesBorrowed<'a> = &'a ServoComputedValues; enum ServoComputedValuesVoid{ } pub struct ServoComputedValues(ServoComputedValuesVoid); +pub type ServoCssRulesStrong = ::gecko_bindings::sugar::ownership::Strong; +pub type ServoCssRulesBorrowedOrNull<'a> = Option<&'a ServoCssRules>; +pub type ServoCssRulesBorrowed<'a> = &'a ServoCssRules; +enum ServoCssRulesVoid{ } +pub struct ServoCssRules(ServoCssRulesVoid); pub type RawServoStyleSheetStrong = ::gecko_bindings::sugar::ownership::Strong; pub type RawServoStyleSheetBorrowedOrNull<'a> = Option<&'a RawServoStyleSheet>; pub type RawServoStyleSheetBorrowed<'a> = &'a RawServoStyleSheet; @@ -188,6 +194,12 @@ unsafe impl Sync for nsStyleXUL {} pub type RawGeckoNode = nsINode; pub type RawGeckoElement = Element; pub type RawGeckoDocument = nsIDocument; +extern "C" { + pub fn Servo_CssRules_AddRef(ptr: ServoCssRulesBorrowed); +} +extern "C" { + pub fn Servo_CssRules_Release(ptr: ServoCssRulesBorrowed); +} extern "C" { pub fn Servo_StyleSheet_AddRef(ptr: RawServoStyleSheetBorrowed); } @@ -950,6 +962,10 @@ extern "C" { pub fn Servo_StyleSheet_HasRules(sheet: RawServoStyleSheetBorrowed) -> bool; } +extern "C" { + pub fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed) + -> ServoCssRulesStrong; +} extern "C" { pub fn Servo_StyleSet_Init() -> RawServoStyleSetOwned; } @@ -974,6 +990,10 @@ extern "C" { reference: RawServoStyleSheetBorrowed); } +extern "C" { + pub fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed, + result: nsTArrayBorrowed_uintptr_t); +} extern "C" { pub fn Servo_ParseProperty(property: *const nsACString_internal, value: *const nsACString_internal, diff --git a/components/style/stylesheets.rs b/components/style/stylesheets.rs index 6e057e26f37..12ca0423cfa 100644 --- a/components/style/stylesheets.rs +++ b/components/style/stylesheets.rs @@ -136,6 +136,30 @@ pub enum CssRule { Keyframes(Arc>), } +pub enum CssRuleType { + // https://drafts.csswg.org/cssom/#the-cssrule-interface + Style = 1, + Charset = 2, + Import = 3, + Media = 4, + FontFace = 5, + Page = 6, + // https://drafts.csswg.org/css-animations-1/#interface-cssrule-idl + Keyframes = 7, + Keyframe = 8, + // https://drafts.csswg.org/cssom/#the-cssrule-interface + Margin = 9, + Namespace = 10, + // https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface + CounterStyle = 11, + // https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface + Supports = 12, + // https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues + FontFeatureValues = 14, + // https://drafts.csswg.org/css-device-adapt/#css-rule-interface + Viewport = 15, +} + /// Error reporter which silently forgets errors pub struct MemoryHoleReporter; @@ -157,6 +181,17 @@ pub enum SingleRuleParseError { } impl CssRule { + pub fn rule_type(&self) -> CssRuleType { + match *self { + CssRule::Style(_) => CssRuleType::Style, + CssRule::Media(_) => CssRuleType::Media, + CssRule::FontFace(_) => CssRuleType::FontFace, + CssRule::Keyframes(_) => CssRuleType::Keyframes, + CssRule::Namespace(_) => CssRuleType::Namespace, + CssRule::Viewport(_) => CssRuleType::Viewport, + } + } + /// Call `f` with the slice of rules directly contained inside this rule. /// /// Note that only some types of rules can contain rules. An empty slice is used for others. diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index cf6d2a9a006..007579d7f07 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -26,10 +26,12 @@ use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServo use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; +use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong}; use style::gecko_bindings::bindings::{ThreadSafePrincipalHolder, ThreadSafeURIHolder}; use style::gecko_bindings::bindings::{nsACString, nsAString}; use style::gecko_bindings::bindings::Gecko_Utf8SliceToString; use style::gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull; +use style::gecko_bindings::bindings::nsTArrayBorrowed_uintptr_t; use style::gecko_bindings::structs::{SheetParsingMode, nsIAtom}; use style::gecko_bindings::structs::ServoElementSnapshot; use style::gecko_bindings::structs::nsRestyleHint; @@ -45,7 +47,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::{Origin, Stylesheet}; +use style::stylesheets::{CssRule, Origin, Stylesheet}; use style::thread_state; use style::timer::Timer; use style_traits::ToCss; @@ -262,6 +264,11 @@ pub extern "C" fn Servo_StyleSheet_HasRules(raw_sheet: RawServoStyleSheetBorrowe !Stylesheet::as_arc(&raw_sheet).rules.0.read().is_empty() } +#[no_mangle] +pub extern "C" fn Servo_StyleSheet_GetRules(sheet: RawServoStyleSheetBorrowed) -> ServoCssRulesStrong { + Stylesheet::as_arc(&sheet).rules.0.clone().into_strong() +} + #[no_mangle] pub extern "C" fn Servo_StyleSheet_AddRef(sheet: RawServoStyleSheetBorrowed) -> () { unsafe { Stylesheet::addref(sheet) }; @@ -272,6 +279,27 @@ pub extern "C" fn Servo_StyleSheet_Release(sheet: RawServoStyleSheetBorrowed) -> unsafe { Stylesheet::release(sheet) }; } +#[no_mangle] +pub extern "C" fn Servo_CssRules_ListTypes(rules: ServoCssRulesBorrowed, + result: nsTArrayBorrowed_uintptr_t) -> () { + let rules = RwLock::>::as_arc(&rules).read(); + let iter = rules.iter().map(|rule| rule.rule_type() as usize); + let (size, upper) = iter.size_hint(); + debug_assert_eq!(size, upper.unwrap()); + unsafe { result.set_len(size as u32) }; + result.iter_mut().zip(iter).fold((), |_, (r, v)| *r = v); +} + +#[no_mangle] +pub extern "C" fn Servo_CssRules_AddRef(rules: ServoCssRulesBorrowed) -> () { + unsafe { RwLock::>::addref(rules) }; +} + +#[no_mangle] +pub extern "C" fn Servo_CssRules_Release(rules: ServoCssRulesBorrowed) -> () { + unsafe { RwLock::>::release(rules) }; +} + #[no_mangle] pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed) -> ServoComputedValuesStrong { From a9296bc89cdbdb634432d46dfa15791bfd22c614 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:32:18 +1100 Subject: [PATCH 2/5] 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 { From 66669e48effa1e3d099c7a94fbf6a98f07c0de21 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:33:16 +1100 Subject: [PATCH 3/5] Add stylo FFI for cssText getters of CSSStyleRule --- components/style/gecko_bindings/bindings.rs | 8 ++++++++ ports/geckolib/glue.rs | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index ef0086edde1..0513cc695ac 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1010,6 +1010,14 @@ extern "C" { index: u32) -> RawServoStyleRuleStrong; } +extern "C" { + pub fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, + result: *mut nsAString_internal); +} +extern "C" { + pub fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed, + result: *mut nsAString_internal); +} 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 11ef9d7701c..8fed9eb8a66 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -4,6 +4,7 @@ use app_units::Au; use cssparser::Parser; +use cssparser::ToCss as ParserToCss; use env_logger; use euclid::Size2D; use parking_lot::RwLock; @@ -323,6 +324,18 @@ pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () unsafe { RwLock::::release(rule) }; } +#[no_mangle] +pub extern "C" fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) -> () { + let rule = RwLock::::as_arc(&rule); + rule.read().to_css(unsafe { result.as_mut().unwrap() }).unwrap(); +} + +#[no_mangle] +pub extern "C" fn Servo_StyleRule_GetSelectorText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) -> () { + let rule = RwLock::::as_arc(&rule); + rule.read().selectors.to_css(unsafe { result.as_mut().unwrap() }).unwrap(); +} + #[no_mangle] pub extern "C" fn Servo_ComputedValues_Get(node: RawGeckoNodeBorrowed) -> ServoComputedValuesStrong { From 9ee2ec5a35784bc90415212f21253de396f661a6 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:34:25 +1100 Subject: [PATCH 4/5] Add stylo FFI for CSSStyleRule.style --- components/style/gecko_bindings/bindings.rs | 9 +++++++++ ports/geckolib/glue.rs | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 0513cc695ac..348f27fc878 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1010,6 +1010,15 @@ extern "C" { index: u32) -> RawServoStyleRuleStrong; } +extern "C" { + pub fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) + -> RawServoDeclarationBlockStrong; +} +extern "C" { + pub fn Servo_StyleRule_SetStyle(rule: RawServoStyleRuleBorrowed, + declarations: + RawServoDeclarationBlockBorrowed); +} extern "C" { pub fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString_internal); diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 8fed9eb8a66..103f680507c 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -324,6 +324,20 @@ pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () unsafe { RwLock::::release(rule) }; } +#[no_mangle] +pub extern "C" fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) -> RawServoDeclarationBlockStrong { + let rule = RwLock::::as_arc(&rule); + rule.read().block.clone().into_strong() +} + +#[no_mangle] +pub extern "C" fn Servo_StyleRule_SetStyle(rule: RawServoStyleRuleBorrowed, + declarations: RawServoDeclarationBlockBorrowed) -> () { + let rule = RwLock::::as_arc(&rule); + let declarations = RwLock::::as_arc(&declarations); + rule.write().block = declarations.clone(); +} + #[no_mangle] pub extern "C" fn Servo_StyleRule_GetCssText(rule: RawServoStyleRuleBorrowed, result: *mut nsAString) -> () { let rule = RwLock::::as_arc(&rule); From 3c5871f83a66df709ae8f583f6f4fdb30e8cd911 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 23 Nov 2016 10:35:00 +1100 Subject: [PATCH 5/5] Add FFI for debug info of CSSStyleRule --- components/style/gecko_bindings/bindings.rs | 4 ++++ ports/geckolib/glue.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 348f27fc878..c00e7149da6 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1010,6 +1010,10 @@ extern "C" { index: u32) -> RawServoStyleRuleStrong; } +extern "C" { + pub fn Servo_StyleRule_Debug(rule: RawServoStyleRuleBorrowed, + result: *mut nsACString_internal); +} extern "C" { pub fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) -> RawServoDeclarationBlockStrong; diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 103f680507c..e65c8cbd5bd 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -324,6 +324,13 @@ pub extern "C" fn Servo_StyleRule_Release(rule: RawServoStyleRuleBorrowed) -> () unsafe { RwLock::::release(rule) }; } +#[no_mangle] +pub extern "C" fn Servo_StyleRule_Debug(rule: RawServoStyleRuleBorrowed, result: *mut nsACString) -> () { + let rule = RwLock::::as_arc(&rule); + let result = unsafe { result.as_mut().unwrap() }; + write!(result, "{:?}", *rule.read()).unwrap(); +} + #[no_mangle] pub extern "C" fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) -> RawServoDeclarationBlockStrong { let rule = RwLock::::as_arc(&rule);