Make CSSRule always keep a pointer to its parent stylesheet

even when the parentStylesheet IDL attribute returns null.
This commit is contained in:
Simon Sapin 2016-11-28 16:33:47 +01:00
parent 0714e2291c
commit f1d49d3773
11 changed files with 84 additions and 69 deletions

View file

@ -22,17 +22,18 @@ pub struct CSSFontFaceRule {
} }
impl CSSFontFaceRule { impl CSSFontFaceRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, fontfacerule: Arc<RwLock<FontFaceRule>>) -> CSSFontFaceRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, fontfacerule: Arc<RwLock<FontFaceRule>>)
-> CSSFontFaceRule {
CSSFontFaceRule { CSSFontFaceRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
fontfacerule: fontfacerule, fontfacerule: fontfacerule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
fontfacerule: Arc<RwLock<FontFaceRule>>) -> Root<CSSFontFaceRule> { fontfacerule: Arc<RwLock<FontFaceRule>>) -> Root<CSSFontFaceRule> {
reflect_dom_object(box CSSFontFaceRule::new_inherited(parent, fontfacerule), reflect_dom_object(box CSSFontFaceRule::new_inherited(parent_stylesheet, fontfacerule),
window, window,
CSSFontFaceRuleBinding::Wrap) CSSFontFaceRuleBinding::Wrap)
} }

View file

@ -4,7 +4,6 @@
use dom::bindings::codegen::Bindings::CSSGroupingRuleBinding; use dom::bindings::codegen::Bindings::CSSGroupingRuleBinding;
use dom::bindings::codegen::Bindings::CSSGroupingRuleBinding::CSSGroupingRuleMethods; use dom::bindings::codegen::Bindings::CSSGroupingRuleBinding::CSSGroupingRuleMethods;
use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleBinding::CSSRuleMethods;
use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::{ErrorResult, Fallible};
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, MutNullableHeap, Root};
@ -25,27 +24,26 @@ pub struct CSSGroupingRule {
} }
impl CSSGroupingRule { impl CSSGroupingRule {
pub fn new_inherited(parent: Option<&CSSStyleSheet>, pub fn new_inherited(parent_stylesheet: &CSSStyleSheet,
rules: StyleCssRules) -> CSSGroupingRule { rules: StyleCssRules) -> CSSGroupingRule {
CSSGroupingRule { CSSGroupingRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
rules: rules, rules: rules,
rulelist: MutNullableHeap::new(None), rulelist: MutNullableHeap::new(None),
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, rules: StyleCssRules) -> Root<CSSGroupingRule> { pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet, rules: StyleCssRules) -> Root<CSSGroupingRule> {
reflect_dom_object(box CSSGroupingRule::new_inherited(parent, rules), reflect_dom_object(box CSSGroupingRule::new_inherited(parent_stylesheet, rules),
window, window,
CSSGroupingRuleBinding::Wrap) CSSGroupingRuleBinding::Wrap)
} }
fn rulelist(&self) -> Root<CSSRuleList> { fn rulelist(&self) -> Root<CSSRuleList> {
let sheet = self.upcast::<CSSRule>().GetParentStyleSheet(); let parent_stylesheet = self.upcast::<CSSRule>().parent_stylesheet();
let sheet = sheet.as_ref().map(|s| &**s);
self.rulelist.or_init(|| CSSRuleList::new(self.global().as_window(), self.rulelist.or_init(|| CSSRuleList::new(self.global().as_window(),
sheet, parent_stylesheet,
RulesSource::Rules(self.rules.clone()))) RulesSource::Rules(self.rules.clone())))
} }
} }

View file

@ -22,17 +22,18 @@ pub struct CSSKeyframeRule {
} }
impl CSSKeyframeRule { impl CSSKeyframeRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, keyframerule: Arc<RwLock<Keyframe>>) -> CSSKeyframeRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, keyframerule: Arc<RwLock<Keyframe>>)
-> CSSKeyframeRule {
CSSKeyframeRule { CSSKeyframeRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
keyframerule: keyframerule, keyframerule: keyframerule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
keyframerule: Arc<RwLock<Keyframe>>) -> Root<CSSKeyframeRule> { keyframerule: Arc<RwLock<Keyframe>>) -> Root<CSSKeyframeRule> {
reflect_dom_object(box CSSKeyframeRule::new_inherited(parent, keyframerule), reflect_dom_object(box CSSKeyframeRule::new_inherited(parent_stylesheet, keyframerule),
window, window,
CSSKeyframeRuleBinding::Wrap) CSSKeyframeRuleBinding::Wrap)
} }

View file

@ -5,7 +5,6 @@
use cssparser::Parser; use cssparser::Parser;
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding; use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding;
use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods; use dom::bindings::codegen::Bindings::CSSKeyframesRuleBinding::CSSKeyframesRuleMethods;
use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, MutNullableHeap, Root};
@ -32,28 +31,28 @@ pub struct CSSKeyframesRule {
} }
impl CSSKeyframesRule { impl CSSKeyframesRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, keyframesrule: Arc<RwLock<KeyframesRule>>) -> CSSKeyframesRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, keyframesrule: Arc<RwLock<KeyframesRule>>)
-> CSSKeyframesRule {
CSSKeyframesRule { CSSKeyframesRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
keyframesrule: keyframesrule, keyframesrule: keyframesrule,
rulelist: MutNullableHeap::new(None), rulelist: MutNullableHeap::new(None),
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
keyframesrule: Arc<RwLock<KeyframesRule>>) -> Root<CSSKeyframesRule> { keyframesrule: Arc<RwLock<KeyframesRule>>) -> Root<CSSKeyframesRule> {
reflect_dom_object(box CSSKeyframesRule::new_inherited(parent, keyframesrule), reflect_dom_object(box CSSKeyframesRule::new_inherited(parent_stylesheet, keyframesrule),
window, window,
CSSKeyframesRuleBinding::Wrap) CSSKeyframesRuleBinding::Wrap)
} }
fn rulelist(&self) -> Root<CSSRuleList> { fn rulelist(&self) -> Root<CSSRuleList> {
self.rulelist.or_init(|| { self.rulelist.or_init(|| {
let sheet = self.upcast::<CSSRule>().GetParentStyleSheet(); let parent_stylesheet = &self.upcast::<CSSRule>().parent_stylesheet();
let sheet = sheet.as_ref().map(|s| &**s);
CSSRuleList::new(self.global().as_window(), CSSRuleList::new(self.global().as_window(),
sheet, parent_stylesheet,
RulesSource::Keyframes(self.keyframesrule.clone())) RulesSource::Keyframes(self.keyframesrule.clone()))
}) })
} }

View file

@ -23,18 +23,19 @@ pub struct CSSMediaRule {
} }
impl CSSMediaRule { impl CSSMediaRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, mediarule: Arc<RwLock<MediaRule>>) -> CSSMediaRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, mediarule: Arc<RwLock<MediaRule>>)
-> CSSMediaRule {
let list = mediarule.read().rules.clone(); let list = mediarule.read().rules.clone();
CSSMediaRule { CSSMediaRule {
cssrule: CSSGroupingRule::new_inherited(parent, list), cssrule: CSSGroupingRule::new_inherited(parent_stylesheet, list),
mediarule: mediarule, mediarule: mediarule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
mediarule: Arc<RwLock<MediaRule>>) -> Root<CSSMediaRule> { mediarule: Arc<RwLock<MediaRule>>) -> Root<CSSMediaRule> {
reflect_dom_object(box CSSMediaRule::new_inherited(parent, mediarule), reflect_dom_object(box CSSMediaRule::new_inherited(parent_stylesheet, mediarule),
window, window,
CSSMediaRuleBinding::Wrap) CSSMediaRuleBinding::Wrap)
} }

View file

@ -23,17 +23,18 @@ pub struct CSSNamespaceRule {
} }
impl CSSNamespaceRule { impl CSSNamespaceRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, namespacerule: Arc<RwLock<NamespaceRule>>) -> CSSNamespaceRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, namespacerule: Arc<RwLock<NamespaceRule>>)
-> CSSNamespaceRule {
CSSNamespaceRule { CSSNamespaceRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
namespacerule: namespacerule, namespacerule: namespacerule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
namespacerule: Arc<RwLock<NamespaceRule>>) -> Root<CSSNamespaceRule> { namespacerule: Arc<RwLock<NamespaceRule>>) -> Root<CSSNamespaceRule> {
reflect_dom_object(box CSSNamespaceRule::new_inherited(parent, namespacerule), reflect_dom_object(box CSSNamespaceRule::new_inherited(parent_stylesheet, namespacerule),
window, window,
CSSNamespaceRuleBinding::Wrap) CSSNamespaceRuleBinding::Wrap)
} }

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::Bindings::CSSRuleBinding; use dom::bindings::codegen::Bindings::CSSRuleBinding;
use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods; use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods;
use dom::bindings::inheritance::Castable; use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::cssfontfacerule::CSSFontFaceRule; use dom::cssfontfacerule::CSSFontFaceRule;
@ -17,27 +17,34 @@ use dom::cssstylerule::CSSStyleRule;
use dom::cssstylesheet::CSSStyleSheet; use dom::cssstylesheet::CSSStyleSheet;
use dom::cssviewportrule::CSSViewportRule; use dom::cssviewportrule::CSSViewportRule;
use dom::window::Window; use dom::window::Window;
use std::cell::Cell;
use style::stylesheets::CssRule as StyleCssRule; use style::stylesheets::CssRule as StyleCssRule;
#[dom_struct] #[dom_struct]
pub struct CSSRule { pub struct CSSRule {
reflector_: Reflector, reflector_: Reflector,
parent: MutNullableHeap<JS<CSSStyleSheet>>, parent_stylesheet: JS<CSSStyleSheet>,
/// Whether the parentStyleSheet attribute should return null.
/// We keep parent_stylesheet in that case because insertRule needs it
/// for the stylesheets base URL and namespace prefixes.
parent_stylesheet_removed: Cell<bool>,
} }
impl CSSRule { impl CSSRule {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new_inherited(parent: Option<&CSSStyleSheet>) -> CSSRule { pub fn new_inherited(parent_stylesheet: &CSSStyleSheet) -> CSSRule {
CSSRule { CSSRule {
reflector_: Reflector::new(), reflector_: Reflector::new(),
parent: MutNullableHeap::new(parent), parent_stylesheet: JS::from_ref(parent_stylesheet),
parent_stylesheet_removed: Cell::new(false),
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>) -> Root<CSSRule> { pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet) -> Root<CSSRule> {
reflect_dom_object(box CSSRule::new_inherited(parent), reflect_dom_object(box CSSRule::new_inherited(parent_stylesheet),
window, window,
CSSRuleBinding::Wrap) CSSRuleBinding::Wrap)
} }
@ -64,16 +71,16 @@ impl CSSRule {
// Given a StyleCssRule, create a new instance of a derived class of // Given a StyleCssRule, create a new instance of a derived class of
// CSSRule based on which rule it is // CSSRule based on which rule it is
pub fn new_specific(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new_specific(window: &Window, parent_stylesheet: &CSSStyleSheet,
rule: StyleCssRule) -> Root<CSSRule> { rule: StyleCssRule) -> Root<CSSRule> {
// be sure to update the match in as_specific when this is updated // be sure to update the match in as_specific when this is updated
match rule { match rule {
StyleCssRule::Style(s) => Root::upcast(CSSStyleRule::new(window, parent, s)), StyleCssRule::Style(s) => Root::upcast(CSSStyleRule::new(window, parent_stylesheet, s)),
StyleCssRule::FontFace(s) => Root::upcast(CSSFontFaceRule::new(window, parent, s)), StyleCssRule::FontFace(s) => Root::upcast(CSSFontFaceRule::new(window, parent_stylesheet, s)),
StyleCssRule::Keyframes(s) => Root::upcast(CSSKeyframesRule::new(window, parent, s)), StyleCssRule::Keyframes(s) => Root::upcast(CSSKeyframesRule::new(window, parent_stylesheet, s)),
StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent, s)), StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent_stylesheet, s)),
StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent, s)), StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)),
StyleCssRule::Viewport(s) => Root::upcast(CSSViewportRule::new(window, parent, s)), StyleCssRule::Viewport(s) => Root::upcast(CSSViewportRule::new(window, parent_stylesheet, s)),
} }
} }
@ -85,12 +92,16 @@ impl CSSRule {
/// Sets owner sheet to null (and does the same for all children) /// Sets owner sheet to null (and does the same for all children)
pub fn deparent(&self) { pub fn deparent(&self) {
self.parent.set(None); self.parent_stylesheet_removed.set(true);
// https://github.com/w3c/csswg-drafts/issues/722 // https://github.com/w3c/csswg-drafts/issues/722
// Spec doesn't ask us to do this, but it makes sense // Spec doesn't ask us to do this, but it makes sense
// and browsers implement this behavior // and browsers implement this behavior
self.as_specific().deparent_children(); self.as_specific().deparent_children();
} }
pub fn parent_stylesheet(&self) -> &CSSStyleSheet {
&self.parent_stylesheet
}
} }
impl CSSRuleMethods for CSSRule { impl CSSRuleMethods for CSSRule {
@ -101,7 +112,11 @@ impl CSSRuleMethods for CSSRule {
// https://drafts.csswg.org/cssom/#dom-cssrule-parentstylesheet // https://drafts.csswg.org/cssom/#dom-cssrule-parentstylesheet
fn GetParentStyleSheet(&self) -> Option<Root<CSSStyleSheet>> { fn GetParentStyleSheet(&self) -> Option<Root<CSSStyleSheet>> {
self.parent.get() if self.parent_stylesheet_removed.get() {
None
} else {
Some(Root::from_ref(&*self.parent_stylesheet))
}
} }
// https://drafts.csswg.org/cssom/#dom-cssrule-csstext // https://drafts.csswg.org/cssom/#dom-cssrule-csstext
@ -118,7 +133,7 @@ impl CSSRuleMethods for CSSRule {
pub trait SpecificCSSRule { pub trait SpecificCSSRule {
fn ty(&self) -> u16; fn ty(&self) -> u16;
fn get_css(&self) -> DOMString; fn get_css(&self) -> DOMString;
/// Remove CSSStyleSheet parent from all transitive children /// Remove parentStylesheet from all transitive children
fn deparent_children(&self) { fn deparent_children(&self) {
// most CSSRules do nothing here // most CSSRules do nothing here
} }

View file

@ -34,7 +34,7 @@ impl From<RulesMutateError> for Error {
#[dom_struct] #[dom_struct]
pub struct CSSRuleList { pub struct CSSRuleList {
reflector_: Reflector, reflector_: Reflector,
sheet: MutNullableHeap<JS<CSSStyleSheet>>, parent_stylesheet: JS<CSSStyleSheet>,
#[ignore_heap_size_of = "Arc"] #[ignore_heap_size_of = "Arc"]
rules: RulesSource, rules: RulesSource,
dom_rules: DOMRefCell<Vec<MutNullableHeap<JS<CSSRule>>>> dom_rules: DOMRefCell<Vec<MutNullableHeap<JS<CSSRule>>>>
@ -47,7 +47,7 @@ pub enum RulesSource {
impl CSSRuleList { impl CSSRuleList {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new_inherited(sheet: Option<&CSSStyleSheet>, rules: RulesSource) -> CSSRuleList { pub fn new_inherited(parent_stylesheet: &CSSStyleSheet, rules: RulesSource) -> CSSRuleList {
let dom_rules = match rules { let dom_rules = match rules {
RulesSource::Rules(ref rules) => { RulesSource::Rules(ref rules) => {
rules.0.read().iter().map(|_| MutNullableHeap::new(None)).collect() rules.0.read().iter().map(|_| MutNullableHeap::new(None)).collect()
@ -59,16 +59,16 @@ impl CSSRuleList {
CSSRuleList { CSSRuleList {
reflector_: Reflector::new(), reflector_: Reflector::new(),
sheet: MutNullableHeap::new(sheet), parent_stylesheet: JS::from_ref(parent_stylesheet),
rules: rules, rules: rules,
dom_rules: DOMRefCell::new(dom_rules), dom_rules: DOMRefCell::new(dom_rules),
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, sheet: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
rules: RulesSource) -> Root<CSSRuleList> { rules: RulesSource) -> Root<CSSRuleList> {
reflect_dom_object(box CSSRuleList::new_inherited(sheet, rules), reflect_dom_object(box CSSRuleList::new_inherited(parent_stylesheet, rules),
window, window,
CSSRuleListBinding::Wrap) CSSRuleListBinding::Wrap)
} }
@ -89,9 +89,8 @@ impl CSSRuleList {
let new_rule = css_rules.insert_rule(rule, doc.url().clone(), index, nested)?; let new_rule = css_rules.insert_rule(rule, doc.url().clone(), index, nested)?;
let sheet = self.sheet.get(); let parent_stylesheet = &*self.parent_stylesheet;
let sheet = sheet.as_ref().map(|sheet| &**sheet); let dom_rule = CSSRule::new_specific(&window, parent_stylesheet, new_rule);
let dom_rule = CSSRule::new_specific(&window, sheet, new_rule);
self.dom_rules.borrow_mut().insert(index, MutNullableHeap::new(Some(&*dom_rule))); self.dom_rules.borrow_mut().insert(index, MutNullableHeap::new(Some(&*dom_rule)));
Ok((idx)) Ok((idx))
} }
@ -129,17 +128,16 @@ impl CSSRuleList {
pub fn item(&self, idx: u32) -> Option<Root<CSSRule>> { pub fn item(&self, idx: u32) -> Option<Root<CSSRule>> {
self.dom_rules.borrow().get(idx as usize).map(|rule| { self.dom_rules.borrow().get(idx as usize).map(|rule| {
rule.or_init(|| { rule.or_init(|| {
let sheet = self.sheet.get(); let parent_stylesheet = &self.parent_stylesheet;
let sheet = sheet.as_ref().map(|sheet| &**sheet);
match self.rules { match self.rules {
RulesSource::Rules(ref rules) => { RulesSource::Rules(ref rules) => {
CSSRule::new_specific(self.global().as_window(), CSSRule::new_specific(self.global().as_window(),
sheet, parent_stylesheet,
rules.0.read()[idx as usize].clone()) rules.0.read()[idx as usize].clone())
} }
RulesSource::Keyframes(ref rules) => { RulesSource::Keyframes(ref rules) => {
Root::upcast(CSSKeyframeRule::new(self.global().as_window(), Root::upcast(CSSKeyframeRule::new(self.global().as_window(),
sheet, parent_stylesheet,
rules.read() rules.read()
.keyframes[idx as usize] .keyframes[idx as usize]
.clone())) .clone()))

View file

@ -22,17 +22,18 @@ pub struct CSSStyleRule {
} }
impl CSSStyleRule { impl CSSStyleRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, stylerule: Arc<RwLock<StyleRule>>) -> CSSStyleRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, stylerule: Arc<RwLock<StyleRule>>)
-> CSSStyleRule {
CSSStyleRule { CSSStyleRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
stylerule: stylerule, stylerule: stylerule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
stylerule: Arc<RwLock<StyleRule>>) -> Root<CSSStyleRule> { stylerule: Arc<RwLock<StyleRule>>) -> Root<CSSStyleRule> {
reflect_dom_object(box CSSStyleRule::new_inherited(parent, stylerule), reflect_dom_object(box CSSStyleRule::new_inherited(parent_stylesheet, stylerule),
window, window,
CSSStyleRuleBinding::Wrap) CSSStyleRuleBinding::Wrap)
} }

View file

@ -53,7 +53,7 @@ impl CSSStyleSheet {
fn rulelist(&self) -> Root<CSSRuleList> { fn rulelist(&self) -> Root<CSSRuleList> {
self.rulelist.or_init(|| CSSRuleList::new(self.global().as_window(), self.rulelist.or_init(|| CSSRuleList::new(self.global().as_window(),
Some(self), self,
RulesSource::Rules(self.style_stylesheet RulesSource::Rules(self.style_stylesheet
.rules.clone()))) .rules.clone())))
} }

View file

@ -22,17 +22,17 @@ pub struct CSSViewportRule {
} }
impl CSSViewportRule { impl CSSViewportRule {
fn new_inherited(parent: Option<&CSSStyleSheet>, viewportrule: Arc<RwLock<ViewportRule>>) -> CSSViewportRule { fn new_inherited(parent_stylesheet: &CSSStyleSheet, viewportrule: Arc<RwLock<ViewportRule>>) -> CSSViewportRule {
CSSViewportRule { CSSViewportRule {
cssrule: CSSRule::new_inherited(parent), cssrule: CSSRule::new_inherited(parent_stylesheet),
viewportrule: viewportrule, viewportrule: viewportrule,
} }
} }
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
pub fn new(window: &Window, parent: Option<&CSSStyleSheet>, pub fn new(window: &Window, parent_stylesheet: &CSSStyleSheet,
viewportrule: Arc<RwLock<ViewportRule>>) -> Root<CSSViewportRule> { viewportrule: Arc<RwLock<ViewportRule>>) -> Root<CSSViewportRule> {
reflect_dom_object(box CSSViewportRule::new_inherited(parent, viewportrule), reflect_dom_object(box CSSViewportRule::new_inherited(parent_stylesheet, viewportrule),
window, window,
CSSViewportRuleBinding::Wrap) CSSViewportRuleBinding::Wrap)
} }