mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Implements Stylesheet.ownerNode
This commit is contained in:
parent
406d15974f
commit
e7199c029f
14 changed files with 72 additions and 39 deletions
|
@ -5,7 +5,6 @@
|
|||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::CSSRuleListBinding::CSSRuleListMethods;
|
||||
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use crate::dom::csskeyframerule::CSSKeyframeRule;
|
||||
|
@ -13,6 +12,7 @@ use crate::dom::cssrule::CSSRule;
|
|||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::window::Window;
|
||||
use crate::style::stylesheets::StylesheetLoader as StyleStylesheetLoader;
|
||||
use crate::stylesheet_loader::StylesheetLoader;
|
||||
use dom_struct::dom_struct;
|
||||
use servo_arc::Arc;
|
||||
|
@ -107,9 +107,11 @@ impl CSSRuleList {
|
|||
let owner = self
|
||||
.parent_stylesheet
|
||||
.get_owner()
|
||||
.downcast::<HTMLElement>()
|
||||
.unwrap();
|
||||
let loader = StylesheetLoader::for_element(owner);
|
||||
.map(DomRoot::downcast::<HTMLElement>)
|
||||
.flatten();
|
||||
let loader = owner
|
||||
.as_ref()
|
||||
.map(|element| StylesheetLoader::for_element(&**element));
|
||||
let new_rule = css_rules.with_raw_offset_arc(|arc| {
|
||||
arc.insert_rule(
|
||||
&parent_stylesheet.shared_lock,
|
||||
|
@ -117,7 +119,7 @@ impl CSSRuleList {
|
|||
&parent_stylesheet.contents,
|
||||
index,
|
||||
nested,
|
||||
Some(&loader),
|
||||
loader.as_ref().map(|l| l as &dyn StyleStylesheetLoader),
|
||||
AllowImportRules::Yes,
|
||||
)
|
||||
})?;
|
||||
|
|
|
@ -113,8 +113,10 @@ impl CSSStyleOwner {
|
|||
if changed {
|
||||
// If this is changed, see also
|
||||
// CSSStyleRule::SetSelectorText, which does the same thing.
|
||||
stylesheets_owner_from_node(rule.parent_stylesheet().owner().upcast::<Node>())
|
||||
.invalidate_stylesheets();
|
||||
if let Some(owner) = rule.parent_stylesheet().get_owner() {
|
||||
stylesheets_owner_from_node(owner.upcast::<Node>())
|
||||
.invalidate_stylesheets();
|
||||
}
|
||||
}
|
||||
result
|
||||
},
|
||||
|
|
|
@ -117,8 +117,9 @@ impl CSSStyleRuleMethods for CSSStyleRule {
|
|||
let mut guard = self.cssrule.shared_lock().write();
|
||||
let stylerule = self.stylerule.write_with(&mut guard);
|
||||
mem::swap(&mut stylerule.selectors, &mut s);
|
||||
stylesheets_owner_from_node(self.cssrule.parent_stylesheet().owner().upcast::<Node>())
|
||||
.invalidate_stylesheets();
|
||||
if let Some(owner) = self.cssrule.parent_stylesheet().get_owner() {
|
||||
stylesheets_owner_from_node(owner.upcast::<Node>()).invalidate_stylesheets();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::dom::bindings::codegen::Bindings::CSSStyleSheetBinding::CSSStyleSheet
|
|||
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::cssrulelist::{CSSRuleList, RulesSource};
|
||||
use crate::dom::element::Element;
|
||||
|
@ -22,7 +22,7 @@ use style::stylesheets::Stylesheet as StyleStyleSheet;
|
|||
#[dom_struct]
|
||||
pub struct CSSStyleSheet {
|
||||
stylesheet: StyleSheet,
|
||||
owner: Dom<Element>,
|
||||
owner: MutNullableDom<Element>,
|
||||
rulelist: MutNullableDom<CSSRuleList>,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
style_stylesheet: Arc<StyleStyleSheet>,
|
||||
|
@ -39,7 +39,7 @@ impl CSSStyleSheet {
|
|||
) -> CSSStyleSheet {
|
||||
CSSStyleSheet {
|
||||
stylesheet: StyleSheet::new_inherited(type_, href, title),
|
||||
owner: Dom::from_ref(owner),
|
||||
owner: MutNullableDom::new(Some(owner)),
|
||||
rulelist: MutNullableDom::new(None),
|
||||
style_stylesheet: stylesheet,
|
||||
origin_clean: Cell::new(true),
|
||||
|
@ -63,10 +63,6 @@ impl CSSStyleSheet {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn owner(&self) -> DomRoot<Element> {
|
||||
DomRoot::from_ref(&*self.owner)
|
||||
}
|
||||
|
||||
fn rulelist(&self) -> DomRoot<CSSRuleList> {
|
||||
self.rulelist.or_init(|| {
|
||||
let rules = self.style_stylesheet.contents.rules.clone();
|
||||
|
@ -78,16 +74,21 @@ impl CSSStyleSheet {
|
|||
self.style_stylesheet.disabled()
|
||||
}
|
||||
|
||||
pub fn get_owner(&self) -> &Element {
|
||||
&*self.owner
|
||||
pub fn get_owner(&self) -> Option<DomRoot<Element>> {
|
||||
self.owner.get()
|
||||
}
|
||||
|
||||
pub fn set_disabled(&self, disabled: bool) {
|
||||
if self.style_stylesheet.set_disabled(disabled) {
|
||||
stylesheets_owner_from_node(self.owner().upcast::<Node>()).invalidate_stylesheets();
|
||||
if self.style_stylesheet.set_disabled(disabled) && self.get_owner().is_some() {
|
||||
stylesheets_owner_from_node(self.get_owner().unwrap().upcast::<Node>())
|
||||
.invalidate_stylesheets();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_owner(&self, value: Option<&Element>) {
|
||||
self.owner.set(value);
|
||||
}
|
||||
|
||||
pub fn shared_lock(&self) -> &SharedRwLock {
|
||||
&self.style_stylesheet.shared_lock
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ impl HTMLLinkElement {
|
|||
stylesheets_owner.remove_stylesheet(self.upcast(), s)
|
||||
}
|
||||
*self.stylesheet.borrow_mut() = Some(s.clone());
|
||||
self.cssom_stylesheet.set(None);
|
||||
self.clean_stylesheet_ownership();
|
||||
stylesheets_owner.add_stylesheet(self.upcast(), s);
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,13 @@ impl HTMLLinkElement {
|
|||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn clean_stylesheet_ownership(&self) {
|
||||
if let Some(cssom_stylesheet) = self.cssom_stylesheet.get() {
|
||||
cssom_stylesheet.set_owner(None);
|
||||
}
|
||||
self.cssom_stylesheet.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_attr(element: &Element, local_name: &LocalName) -> Option<String> {
|
||||
|
@ -255,6 +262,7 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
}
|
||||
|
||||
if let Some(s) = self.stylesheet.borrow_mut().take() {
|
||||
self.clean_stylesheet_ownership();
|
||||
stylesheets_owner_from_node(self).remove_stylesheet(self.upcast(), &s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ impl HTMLStyleElement {
|
|||
stylesheets_owner.remove_stylesheet(self.upcast(), s)
|
||||
}
|
||||
*self.stylesheet.borrow_mut() = Some(s.clone());
|
||||
self.cssom_stylesheet.set(None);
|
||||
self.clean_stylesheet_ownership();
|
||||
stylesheets_owner.add_stylesheet(self.upcast(), s);
|
||||
}
|
||||
|
||||
|
@ -166,6 +166,13 @@ impl HTMLStyleElement {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn clean_stylesheet_ownership(&self) {
|
||||
if let Some(cssom_stylesheet) = self.cssom_stylesheet.get() {
|
||||
cssom_stylesheet.set_owner(None);
|
||||
}
|
||||
self.cssom_stylesheet.set(None);
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLStyleElement {
|
||||
|
@ -217,6 +224,7 @@ impl VirtualMethods for HTMLStyleElement {
|
|||
|
||||
if context.tree_connected {
|
||||
if let Some(s) = self.stylesheet.borrow_mut().take() {
|
||||
self.clean_stylesheet_ownership();
|
||||
stylesheets_owner_from_node(self).remove_stylesheet(self.upcast(), &s)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,10 @@
|
|||
use crate::dom::bindings::codegen::Bindings::StyleSheetBinding::StyleSheetMethods;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::reflector::Reflector;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::element::Element;
|
||||
use dom_struct::dom_struct;
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -44,6 +46,11 @@ impl StyleSheetMethods for StyleSheet {
|
|||
self.href.clone()
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-stylesheet-ownernode
|
||||
fn GetOwnerNode(&self) -> Option<DomRoot<Element>> {
|
||||
self.downcast::<CSSStyleSheet>().and_then(|s| s.get_owner())
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom/#dom-stylesheet-title
|
||||
fn GetTitle(&self) -> Option<DOMString> {
|
||||
self.title.clone()
|
||||
|
|
|
@ -8,7 +8,7 @@ interface StyleSheet {
|
|||
readonly attribute DOMString type_;
|
||||
readonly attribute DOMString? href;
|
||||
|
||||
// readonly attribute (Element or ProcessingInstruction)? ownerNode;
|
||||
readonly attribute Element? ownerNode;
|
||||
// readonly attribute StyleSheet? parentStyleSheet;
|
||||
readonly attribute DOMString? title;
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
[MediaList2.xhtml]
|
||||
[MediaList]
|
||||
[MediaList.mediaText]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList.length]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList getter]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList.item]
|
||||
expected: FAIL
|
||||
|
|
|
@ -35,9 +35,6 @@
|
|||
[CSSStyleDeclaration interface: calling getPropertyPriority(CSSOMString) on sheet.cssRules[2\].cssRules[0\].style with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute ownerNode]
|
||||
expected: FAIL
|
||||
|
||||
[CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "STYLE_RULE" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -338,9 +335,6 @@
|
|||
[StyleSheet interface: sheet must inherit property "type" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: sheet must inherit property "ownerNode" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[CSSStyleDeclaration interface: sheet.cssRules[2\].cssRules[0\].style must inherit property "cssText" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[ttwf-cssom-doc-ext-load-count.html]
|
||||
[stylesheet.css should be unloaded and styleSheets.length === 0]
|
||||
[stylesheet-1.css should be loaded and styleSheets.length === 1]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
[MediaList2.xhtml]
|
||||
[MediaList]
|
||||
[MediaList.mediaText]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList.length]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList getter]
|
||||
expected: FAIL
|
||||
|
||||
[MediaList.item]
|
||||
expected: FAIL
|
||||
|
|
|
@ -38,9 +38,6 @@
|
|||
[CSSStyleDeclaration interface: calling getPropertyPriority(CSSOMString) on sheet.cssRules[2\].cssRules[0\].style with too few arguments must throw TypeError]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: attribute ownerNode]
|
||||
expected: FAIL
|
||||
|
||||
[CSSRule interface: sheet.cssRules[2\].cssRules[0\] must inherit property "STYLE_RULE" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -350,9 +347,6 @@
|
|||
[StyleSheet interface: sheet must inherit property "type" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[StyleSheet interface: sheet must inherit property "ownerNode" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[CSSStyleDeclaration interface: sheet.cssRules[2\].cssRules[0\].style must inherit property "cssText" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[ttwf-cssom-doc-ext-load-count.html]
|
||||
type: testharness
|
||||
[stylesheet.css should be unloaded and styleSheets.length === 0]
|
||||
[stylesheet-1.css should be loaded and styleSheets.length === 1]
|
||||
expected: FAIL
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue