Auto merge of #16642 - upsuper:bug1355394, r=heycam

stylo: Implement access to CSSSupportsRule

Servo side change of [bug 1355394](https://bugzilla.mozilla.org/show_bug.cgi?id=1355394).

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16642)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-28 05:11:04 -05:00 committed by GitHub
commit 22747e2763
3 changed files with 78 additions and 15 deletions

View file

@ -9,7 +9,7 @@
#![allow(non_snake_case, missing_docs)] #![allow(non_snake_case, missing_docs)]
use gecko_bindings::bindings::{RawServoMediaList, RawServoMediaRule, RawServoNamespaceRule, RawServoPageRule}; use gecko_bindings::bindings::{RawServoMediaList, RawServoMediaRule, RawServoNamespaceRule, RawServoPageRule};
use gecko_bindings::bindings::{RawServoStyleSheet, RawServoImportRule}; use gecko_bindings::bindings::{RawServoStyleSheet, RawServoImportRule, RawServoSupportsRule};
use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules}; use gecko_bindings::bindings::{ServoComputedValues, ServoCssRules};
use gecko_bindings::structs::{RawServoAnimationValue, RawServoAnimationValueMap}; use gecko_bindings::structs::{RawServoAnimationValue, RawServoAnimationValueMap};
use gecko_bindings::structs::{RawServoDeclarationBlock, RawServoStyleRule}; use gecko_bindings::structs::{RawServoDeclarationBlock, RawServoStyleRule};
@ -19,7 +19,8 @@ use parking_lot::RwLock;
use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::{ComputedValues, PropertyDeclarationBlock};
use properties::animated_properties::{AnimationValue, AnimationValueMap}; use properties::animated_properties::{AnimationValue, AnimationValueMap};
use shared_lock::Locked; use shared_lock::Locked;
use stylesheets::{CssRules, Stylesheet, StyleRule, ImportRule, MediaRule, NamespaceRule, PageRule}; use stylesheets::{CssRules, Stylesheet, StyleRule, ImportRule, MediaRule};
use stylesheets::{NamespaceRule, PageRule, SupportsRule};
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]) => {
@ -75,3 +76,6 @@ impl_arc_ffi!(Locked<NamespaceRule> => RawServoNamespaceRule
impl_arc_ffi!(Locked<PageRule> => RawServoPageRule impl_arc_ffi!(Locked<PageRule> => RawServoPageRule
[Servo_PageRule_AddRef, Servo_PageRule_Release]); [Servo_PageRule_AddRef, Servo_PageRule_Release]);
impl_arc_ffi!(Locked<SupportsRule> => RawServoSupportsRule
[Servo_SupportsRule_AddRef, Servo_SupportsRule_Release]);

View file

@ -244,6 +244,11 @@ pub type RawServoPageRuleBorrowed<'a> = &'a RawServoPageRule;
pub type RawServoPageRuleBorrowedOrNull<'a> = Option<&'a RawServoPageRule>; pub type RawServoPageRuleBorrowedOrNull<'a> = Option<&'a RawServoPageRule>;
enum RawServoPageRuleVoid { } enum RawServoPageRuleVoid { }
pub struct RawServoPageRule(RawServoPageRuleVoid); pub struct RawServoPageRule(RawServoPageRuleVoid);
pub type RawServoSupportsRuleStrong = ::gecko_bindings::sugar::ownership::Strong<RawServoSupportsRule>;
pub type RawServoSupportsRuleBorrowed<'a> = &'a RawServoSupportsRule;
pub type RawServoSupportsRuleBorrowedOrNull<'a> = Option<&'a RawServoSupportsRule>;
enum RawServoSupportsRuleVoid { }
pub struct RawServoSupportsRule(RawServoSupportsRuleVoid);
pub type RawServoStyleSetOwned = ::gecko_bindings::sugar::ownership::Owned<RawServoStyleSet>; pub type RawServoStyleSetOwned = ::gecko_bindings::sugar::ownership::Owned<RawServoStyleSet>;
pub type RawServoStyleSetOwnedOrNull = ::gecko_bindings::sugar::ownership::OwnedOrNull<RawServoStyleSet>; pub type RawServoStyleSetOwnedOrNull = ::gecko_bindings::sugar::ownership::OwnedOrNull<RawServoStyleSet>;
pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet; pub type RawServoStyleSetBorrowed<'a> = &'a RawServoStyleSet;
@ -399,6 +404,12 @@ extern "C" {
extern "C" { extern "C" {
pub fn Servo_PageRule_Release(ptr: RawServoPageRuleBorrowed); pub fn Servo_PageRule_Release(ptr: RawServoPageRuleBorrowed);
} }
extern "C" {
pub fn Servo_SupportsRule_AddRef(ptr: RawServoSupportsRuleBorrowed);
}
extern "C" {
pub fn Servo_SupportsRule_Release(ptr: RawServoSupportsRuleBorrowed);
}
extern "C" { extern "C" {
pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned); pub fn Servo_StyleSet_Drop(ptr: RawServoStyleSetOwned);
} }
@ -1665,6 +1676,10 @@ extern "C" {
pub fn Servo_MediaRule_GetCssText(rule: RawServoMediaRuleBorrowed, pub fn Servo_MediaRule_GetCssText(rule: RawServoMediaRuleBorrowed,
result: *mut nsAString); result: *mut nsAString);
} }
extern "C" {
pub fn Servo_MediaRule_GetRules(rule: RawServoMediaRuleBorrowed)
-> ServoCssRulesStrong;
}
extern "C" { extern "C" {
pub fn Servo_CssRules_GetNamespaceRuleAt(rules: ServoCssRulesBorrowed, pub fn Servo_CssRules_GetNamespaceRuleAt(rules: ServoCssRulesBorrowed,
index: u32) index: u32)
@ -1690,6 +1705,23 @@ extern "C" {
pub fn Servo_PageRule_GetCssText(rule: RawServoPageRuleBorrowed, pub fn Servo_PageRule_GetCssText(rule: RawServoPageRuleBorrowed,
result: *mut nsAString); result: *mut nsAString);
} }
extern "C" {
pub fn Servo_CssRules_GetSupportsRuleAt(rules: ServoCssRulesBorrowed,
index: u32)
-> RawServoSupportsRuleStrong;
}
extern "C" {
pub fn Servo_SupportsRule_Debug(rule: RawServoSupportsRuleBorrowed,
result: *mut nsACString);
}
extern "C" {
pub fn Servo_SupportsRule_GetCssText(rule: RawServoSupportsRuleBorrowed,
result: *mut nsAString);
}
extern "C" {
pub fn Servo_SupportsRule_GetRules(rule: RawServoSupportsRuleBorrowed)
-> ServoCssRulesStrong;
}
extern "C" { extern "C" {
pub fn Servo_CssRules_GetFontFaceRuleAt(rules: ServoCssRulesBorrowed, pub fn Servo_CssRules_GetFontFaceRuleAt(rules: ServoCssRulesBorrowed,
index: u32) index: u32)
@ -1712,10 +1744,6 @@ extern "C" {
pub fn Servo_MediaRule_GetMedia(rule: RawServoMediaRuleBorrowed) pub fn Servo_MediaRule_GetMedia(rule: RawServoMediaRuleBorrowed)
-> RawServoMediaListStrong; -> RawServoMediaListStrong;
} }
extern "C" {
pub fn Servo_MediaRule_GetRules(rule: RawServoMediaRuleBorrowed)
-> ServoCssRulesStrong;
}
extern "C" { extern "C" {
pub fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed) pub fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed)
-> *mut nsIAtom; -> *mut nsIAtom;
@ -1733,6 +1761,11 @@ extern "C" {
declarations: declarations:
RawServoDeclarationBlockBorrowed); RawServoDeclarationBlockBorrowed);
} }
extern "C" {
pub fn Servo_SupportsRule_GetConditionText(rule:
RawServoSupportsRuleBorrowed,
result: *mut nsAString);
}
extern "C" { extern "C" {
pub fn Servo_ParseProperty(property: nsCSSPropertyID, pub fn Servo_ParseProperty(property: nsCSSPropertyID,
value: *const nsACString, value: *const nsACString,

View file

@ -36,6 +36,7 @@ use style::gecko_bindings::bindings::{RawServoPageRule, RawServoPageRuleBorrowed
use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned}; use style::gecko_bindings::bindings::{RawServoStyleSetBorrowed, RawServoStyleSetOwned};
use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed}; use style::gecko_bindings::bindings::{RawServoStyleSheetBorrowed, ServoComputedValuesBorrowed};
use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong}; use style::gecko_bindings::bindings::{RawServoStyleSheetStrong, ServoComputedValuesStrong};
use style::gecko_bindings::bindings::{RawServoSupportsRule, RawServoSupportsRuleBorrowed};
use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong}; use style::gecko_bindings::bindings::{ServoCssRulesBorrowed, ServoCssRulesStrong};
use style::gecko_bindings::bindings::{nsACString, nsAString}; use style::gecko_bindings::bindings::{nsACString, nsAString};
use style::gecko_bindings::bindings::Gecko_AnimationAppendKeyframe; use style::gecko_bindings::bindings::Gecko_AnimationAppendKeyframe;
@ -84,7 +85,7 @@ use style::shared_lock::{SharedRwLock, SharedRwLockReadGuard, StylesheetGuards,
use style::string_cache::Atom; use style::string_cache::Atom;
use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers}; use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers};
use style::stylesheets::{ImportRule, MediaRule, NamespaceRule, Origin}; use style::stylesheets::{ImportRule, MediaRule, NamespaceRule, Origin};
use style::stylesheets::{PageRule, Stylesheet, StyleRule}; use style::stylesheets::{PageRule, Stylesheet, StyleRule, SupportsRule};
use style::stylesheets::StylesheetLoader as StyleStylesheetLoader; use style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
use style::supports::parse_condition_or_declaration; use style::supports::parse_condition_or_declaration;
use style::thread_state; use style::thread_state;
@ -780,13 +781,30 @@ macro_rules! impl_basic_rule_funcs {
} }
} }
macro_rules! impl_group_rule_funcs {
{ ($name:ident, $rule_type:ty, $raw_type:ty),
get_rules: $get_rules:ident,
$($basic:tt)+
} => {
impl_basic_rule_funcs! { ($name, $rule_type, $raw_type), $($basic)+ }
#[no_mangle]
pub extern "C" fn $get_rules(rule: &$raw_type) -> ServoCssRulesStrong {
read_locked_arc(rule, |rule: &$rule_type| {
rule.rules.clone().into_strong()
})
}
}
}
impl_basic_rule_funcs! { (Style, StyleRule, RawServoStyleRule), impl_basic_rule_funcs! { (Style, StyleRule, RawServoStyleRule),
getter: Servo_CssRules_GetStyleRuleAt, getter: Servo_CssRules_GetStyleRuleAt,
debug: Servo_StyleRule_Debug, debug: Servo_StyleRule_Debug,
to_css: Servo_StyleRule_GetCssText, to_css: Servo_StyleRule_GetCssText,
} }
impl_basic_rule_funcs! { (Media, MediaRule, RawServoMediaRule), impl_group_rule_funcs! { (Media, MediaRule, RawServoMediaRule),
get_rules: Servo_MediaRule_GetRules,
getter: Servo_CssRules_GetMediaRuleAt, getter: Servo_CssRules_GetMediaRuleAt,
debug: Servo_MediaRule_Debug, debug: Servo_MediaRule_Debug,
to_css: Servo_MediaRule_GetCssText, to_css: Servo_MediaRule_GetCssText,
@ -804,6 +822,13 @@ impl_basic_rule_funcs! { (Page, PageRule, RawServoPageRule),
to_css: Servo_PageRule_GetCssText, to_css: Servo_PageRule_GetCssText,
} }
impl_group_rule_funcs! { (Supports, SupportsRule, RawServoSupportsRule),
get_rules: Servo_SupportsRule_GetRules,
getter: Servo_CssRules_GetSupportsRuleAt,
debug: Servo_SupportsRule_Debug,
to_css: Servo_SupportsRule_GetCssText,
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_CssRules_GetFontFaceRuleAt(rules: ServoCssRulesBorrowed, index: u32) pub extern "C" fn Servo_CssRules_GetFontFaceRuleAt(rules: ServoCssRulesBorrowed, index: u32)
-> *mut nsCSSFontFaceRule -> *mut nsCSSFontFaceRule
@ -847,13 +872,6 @@ pub extern "C" fn Servo_MediaRule_GetMedia(rule: RawServoMediaRuleBorrowed) -> R
}) })
} }
#[no_mangle]
pub extern "C" fn Servo_MediaRule_GetRules(rule: RawServoMediaRuleBorrowed) -> ServoCssRulesStrong {
read_locked_arc(rule, |rule: &MediaRule| {
rule.rules.clone().into_strong()
})
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom { pub extern "C" fn Servo_NamespaceRule_GetPrefix(rule: RawServoNamespaceRuleBorrowed) -> *mut nsIAtom {
read_locked_arc(rule, |rule: &NamespaceRule| { read_locked_arc(rule, |rule: &NamespaceRule| {
@ -882,6 +900,14 @@ pub extern "C" fn Servo_PageRule_SetStyle(rule: RawServoPageRuleBorrowed,
}) })
} }
#[no_mangle]
pub extern "C" fn Servo_SupportsRule_GetConditionText(rule: RawServoSupportsRuleBorrowed,
result: *mut nsAString) {
read_locked_arc(rule, |rule: &SupportsRule| {
rule.condition.to_css(unsafe { result.as_mut().unwrap() }).unwrap();
})
}
#[no_mangle] #[no_mangle]
pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull, pub extern "C" fn Servo_ComputedValues_GetForAnonymousBox(parent_style_or_null: ServoComputedValuesBorrowedOrNull,
pseudo_tag: *mut nsIAtom, pseudo_tag: *mut nsIAtom,