diff options
author | yvt <i@yvt.jp> | 2021-07-10 17:24:27 +0900 |
---|---|---|
committer | yvt <i@yvt.jp> | 2021-07-10 17:55:42 +0900 |
commit | 01a7de50ab1843d85295f9dccad7f4c099e7208c (patch) | |
tree | ee53fb6e8889deb7b880ee969e6c662e6128d210 /components/script/dom/cssrule.rs | |
parent | ff8d2cdbbfc7a9dc7f38b7dd47cb350fde39388f (diff) | |
parent | 94b613fbdaa2b98f2179fc0bbda13c64e6fa0d38 (diff) | |
download | servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.tar.gz servo-01a7de50ab1843d85295f9dccad7f4c099e7208c.zip |
Merge remote-tracking branch 'upstream/master' into feat-cow-infra
`tests/wpt/web-platform-tests/html/browsers/origin/cross-origin-objects/cross-origin-objects.html`
was reverted to the upstream version.
Diffstat (limited to 'components/script/dom/cssrule.rs')
-rw-r--r-- | components/script/dom/cssrule.rs | 107 |
1 files changed, 64 insertions, 43 deletions
diff --git a/components/script/dom/cssrule.rs b/components/script/dom/cssrule.rs index 1a24d5839bf..a541ee411c7 100644 --- a/components/script/dom/cssrule.rs +++ b/components/script/dom/cssrule.rs @@ -1,33 +1,32 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods; -use dom::bindings::inheritance::Castable; -use dom::bindings::js::{JS, Root}; -use dom::bindings::reflector::Reflector; -use dom::bindings::str::DOMString; -use dom::cssfontfacerule::CSSFontFaceRule; -use dom::cssimportrule::CSSImportRule; -use dom::csskeyframerule::CSSKeyframeRule; -use dom::csskeyframesrule::CSSKeyframesRule; -use dom::cssmediarule::CSSMediaRule; -use dom::cssnamespacerule::CSSNamespaceRule; -use dom::cssstylerule::CSSStyleRule; -use dom::cssstylesheet::CSSStyleSheet; -use dom::csssupportsrule::CSSSupportsRule; -use dom::cssviewportrule::CSSViewportRule; -use dom::window::Window; + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +use crate::dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleMethods; +use crate::dom::bindings::inheritance::Castable; +use crate::dom::bindings::reflector::Reflector; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::str::DOMString; +use crate::dom::cssfontfacerule::CSSFontFaceRule; +use crate::dom::cssimportrule::CSSImportRule; +use crate::dom::csskeyframerule::CSSKeyframeRule; +use crate::dom::csskeyframesrule::CSSKeyframesRule; +use crate::dom::cssmediarule::CSSMediaRule; +use crate::dom::cssnamespacerule::CSSNamespaceRule; +use crate::dom::cssstylerule::CSSStyleRule; +use crate::dom::cssstylesheet::CSSStyleSheet; +use crate::dom::csssupportsrule::CSSSupportsRule; +use crate::dom::cssviewportrule::CSSViewportRule; +use crate::dom::window::Window; use dom_struct::dom_struct; use std::cell::Cell; use style::shared_lock::SharedRwLock; use style::stylesheets::CssRule as StyleCssRule; - #[dom_struct] pub struct CSSRule { reflector_: Reflector, - parent_stylesheet: JS<CSSStyleSheet>, + parent_stylesheet: Dom<CSSStyleSheet>, /// Whether the parentStyleSheet attribute should return null. /// We keep parent_stylesheet in that case because insertRule needs it @@ -40,30 +39,30 @@ impl CSSRule { pub fn new_inherited(parent_stylesheet: &CSSStyleSheet) -> CSSRule { CSSRule { reflector_: Reflector::new(), - parent_stylesheet: JS::from_ref(parent_stylesheet), + parent_stylesheet: Dom::from_ref(parent_stylesheet), parent_stylesheet_removed: Cell::new(false), } } - pub fn as_specific(&self) -> &SpecificCSSRule { + pub fn as_specific(&self) -> &dyn SpecificCSSRule { if let Some(rule) = self.downcast::<CSSStyleRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSFontFaceRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSKeyframesRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSMediaRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSNamespaceRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSViewportRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSKeyframeRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSImportRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else if let Some(rule) = self.downcast::<CSSSupportsRule>() { - rule as &SpecificCSSRule + rule as &dyn SpecificCSSRule } else { unreachable!() } @@ -71,19 +70,41 @@ impl CSSRule { // Given a StyleCssRule, create a new instance of a derived class of // CSSRule based on which rule it is - pub fn new_specific(window: &Window, parent_stylesheet: &CSSStyleSheet, - rule: StyleCssRule) -> Root<CSSRule> { + pub fn new_specific( + window: &Window, + parent_stylesheet: &CSSStyleSheet, + rule: StyleCssRule, + ) -> DomRoot<CSSRule> { // be sure to update the match in as_specific when this is updated match rule { - StyleCssRule::Import(s) => Root::upcast(CSSImportRule::new(window, parent_stylesheet, s)), - StyleCssRule::Style(s) => Root::upcast(CSSStyleRule::new(window, parent_stylesheet, s)), - StyleCssRule::FontFace(s) => Root::upcast(CSSFontFaceRule::new(window, parent_stylesheet, s)), - StyleCssRule::Keyframes(s) => Root::upcast(CSSKeyframesRule::new(window, parent_stylesheet, s)), - StyleCssRule::Media(s) => Root::upcast(CSSMediaRule::new(window, parent_stylesheet, s)), - StyleCssRule::Namespace(s) => Root::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)), - StyleCssRule::Viewport(s) => Root::upcast(CSSViewportRule::new(window, parent_stylesheet, s)), - StyleCssRule::Supports(s) => Root::upcast(CSSSupportsRule::new(window, parent_stylesheet, s)), + StyleCssRule::Import(s) => { + DomRoot::upcast(CSSImportRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::Style(s) => { + DomRoot::upcast(CSSStyleRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::FontFace(s) => { + DomRoot::upcast(CSSFontFaceRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::FontFeatureValues(_) => unimplemented!(), + StyleCssRule::CounterStyle(_) => unimplemented!(), + StyleCssRule::Keyframes(s) => { + DomRoot::upcast(CSSKeyframesRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::Media(s) => { + DomRoot::upcast(CSSMediaRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::Namespace(s) => { + DomRoot::upcast(CSSNamespaceRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::Viewport(s) => { + DomRoot::upcast(CSSViewportRule::new(window, parent_stylesheet, s)) + }, + StyleCssRule::Supports(s) => { + DomRoot::upcast(CSSSupportsRule::new(window, parent_stylesheet, s)) + }, StyleCssRule::Page(_) => unreachable!(), + StyleCssRule::Document(_) => unimplemented!(), // TODO } } @@ -118,11 +139,11 @@ impl CSSRuleMethods for CSSRule { } // https://drafts.csswg.org/cssom/#dom-cssrule-parentstylesheet - fn GetParentStyleSheet(&self) -> Option<Root<CSSStyleSheet>> { + fn GetParentStyleSheet(&self) -> Option<DomRoot<CSSStyleSheet>> { if self.parent_stylesheet_removed.get() { None } else { - Some(Root::from_ref(&*self.parent_stylesheet)) + Some(DomRoot::from_ref(&*self.parent_stylesheet)) } } |