From c9c21e72b1793bc2d905ff9fc7c00e4f65913c4c Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Wed, 15 Mar 2017 20:27:48 +1100 Subject: [PATCH] Add bindings for namespace rule. --- components/style/gecko/arc_types.rs | 7 +++++-- components/style/gecko_bindings/bindings.rs | 18 +++++++++++++++++ ports/geckolib/glue.rs | 22 ++++++++++++++++++++- ports/geckolib/lib.rs | 2 +- tests/unit/stylo/lib.rs | 2 +- 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/components/style/gecko/arc_types.rs b/components/style/gecko/arc_types.rs index 149f70db27a..43a87f6b35f 100644 --- a/components/style/gecko/arc_types.rs +++ b/components/style/gecko/arc_types.rs @@ -8,7 +8,7 @@ #![allow(non_snake_case, missing_docs)] -use gecko_bindings::bindings::{RawServoMediaList, RawServoMediaRule}; +use gecko_bindings::bindings::{RawServoMediaList, RawServoMediaRule, RawServoNamespaceRule}; use gecko_bindings::bindings::{RawServoStyleSheet, RawServoStyleRule, RawServoImportRule}; use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules}; use gecko_bindings::structs::{RawServoAnimationValue, RawServoDeclarationBlock}; @@ -17,7 +17,7 @@ use media_queries::MediaList; use parking_lot::RwLock; use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::animated_properties::AnimationValue; -use stylesheets::{CssRules, Stylesheet, StyleRule, ImportRule, MediaRule}; +use stylesheets::{CssRules, Stylesheet, StyleRule, ImportRule, MediaRule, NamespaceRule}; macro_rules! impl_arc_ffi { ($servo_type:ty => $gecko_type:ty [$addref:ident, $release:ident]) => { @@ -64,3 +64,6 @@ impl_arc_ffi!(RwLock => RawServoMediaList impl_arc_ffi!(RwLock => RawServoMediaRule [Servo_MediaRule_AddRef, Servo_MediaRule_Release]); + +impl_arc_ffi!(RwLock => RawServoNamespaceRule + [Servo_NamespaceRule_AddRef, Servo_NamespaceRule_Release]); diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 832bd3b7ae4..ff8040f140f 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -4,6 +4,11 @@ pub use nsstring::{nsACString, nsAString, nsString}; type nsACString_internal = nsACString; type nsAString_internal = nsAString; use gecko_bindings::structs::mozilla::css::URLValue; +pub type RawServoNamespaceRuleStrong = ::gecko_bindings::sugar::ownership::Strong; +pub type RawServoNamespaceRuleBorrowedOrNull<'a> = Option<&'a RawServoNamespaceRule>; +pub type RawServoNamespaceRuleBorrowed<'a> = &'a RawServoNamespaceRule; +enum RawServoNamespaceRuleVoid{ } +pub struct RawServoNamespaceRule(RawServoNamespaceRuleVoid); use gecko_bindings::structs::RawGeckoDocument; use gecko_bindings::structs::RawGeckoElement; use gecko_bindings::structs::RawGeckoKeyframeList; @@ -1383,6 +1388,11 @@ extern "C" { index: u32) -> RawServoMediaRuleStrong; } +extern "C" { + pub fn Servo_CssRules_GetNamespaceRuleAt(rules: ServoCssRulesBorrowed, + index: u32) + -> RawServoNamespaceRuleStrong; +} extern "C" { pub fn Servo_CssRules_InsertRule(rules: ServoCssRulesBorrowed, sheet: RawServoStyleSheetBorrowed, @@ -1431,6 +1441,14 @@ extern "C" { pub fn Servo_MediaRule_GetCssText(rule: RawServoMediaRuleBorrowed, result: *mut nsAString_internal); } +extern "C" { + pub fn Servo_NamespaceRule_Debug(rule: RawServoNamespaceRuleBorrowed, + result: *mut nsACString_internal); +} +extern "C" { + pub fn Servo_NamespaceRule_GetCssText(rule: RawServoNamespaceRuleBorrowed, + 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 8e057a322b6..54b4e03d3a3 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -34,6 +34,7 @@ use style::gecko_bindings::bindings::{RawGeckoKeyframeListBorrowed, RawGeckoKeyf use style::gecko_bindings::bindings::{RawServoDeclarationBlockBorrowed, RawServoDeclarationBlockStrong}; use style::gecko_bindings::bindings::{RawServoMediaListBorrowed, RawServoMediaListStrong}; use style::gecko_bindings::bindings::{RawServoMediaRule, RawServoMediaRuleBorrowed}; +use style::gecko_bindings::bindings::{RawServoNamespaceRule, RawServoNamespaceRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleRule, RawServoStyleRuleBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; @@ -76,7 +77,8 @@ use style::restyle_hints::{self, RestyleHint}; use style::selector_parser::PseudoElementCascadeType; use style::sequential; use style::string_cache::Atom; -use style::stylesheets::{CssRule, CssRules, ImportRule, MediaRule, Origin, Stylesheet, StyleRule}; +use style::stylesheets::{CssRule, CssRules, ImportRule, MediaRule, NamespaceRule}; +use style::stylesheets::{Origin, Stylesheet, StyleRule}; use style::stylesheets::StylesheetLoader as StyleStylesheetLoader; use style::supports::parse_condition_or_declaration; use style::thread_state; @@ -580,6 +582,12 @@ impl_basic_rule_funcs! { (Media, MediaRule, RawServoMediaRule), to_css: Servo_MediaRule_GetCssText, } +impl_basic_rule_funcs! { (Namespace, NamespaceRule, RawServoNamespaceRule), + getter: Servo_CssRules_GetNamespaceRuleAt, + debug: Servo_NamespaceRule_Debug, + to_css: Servo_NamespaceRule_GetCssText, +} + #[no_mangle] pub extern "C" fn Servo_StyleRule_GetStyle(rule: RawServoStyleRuleBorrowed) -> RawServoDeclarationBlockStrong { let rule = RwLock::::as_arc(&rule); @@ -612,6 +620,18 @@ pub extern "C" fn Servo_MediaRule_GetRules(rule: RawServoMediaRuleBorrowed) -> S rule.read().rules.clone().into_strong() } +#[no_mangle] +pub extern "C" fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom { + let rule = RwLock::::as_arc(&rule); + rule.read().prefix.as_ref().unwrap_or(&atom!("")).as_ptr() +} + +#[no_mangle] +pub extern "C" fn Servo_NamespaceRule_GetURI(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom { + let rule = RwLock::::as_arc(&rule); + rule.read().url.0.as_ptr() +} + #[no_mangle] pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull, pseudo_tag: *mut nsIAtom, diff --git a/ports/geckolib/lib.rs b/ports/geckolib/lib.rs index ac04fb58757..0bdbaa12f24 100644 --- a/ports/geckolib/lib.rs +++ b/ports/geckolib/lib.rs @@ -15,7 +15,7 @@ extern crate parking_lot; extern crate rayon; extern crate selectors; extern crate servo_url; -extern crate style; +#[macro_use] extern crate style; extern crate style_traits; #[allow(non_snake_case)] diff --git a/tests/unit/stylo/lib.rs b/tests/unit/stylo/lib.rs index 8e2cf196190..bf09699f7ce 100644 --- a/tests/unit/stylo/lib.rs +++ b/tests/unit/stylo/lib.rs @@ -15,7 +15,7 @@ extern crate parking_lot; extern crate rayon; extern crate selectors; extern crate servo_url; -extern crate style; +#[macro_use] extern crate style; extern crate style_traits; mod sanity_checks;