From 18567ce7a88aad4ce315f5c277d29d32c702d899 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Fri, 23 Dec 2016 11:58:29 -0800 Subject: [PATCH] Implement CSSKeyframeRule.style --- components/script/dom/csskeyframerule.rs | 22 ++++++++-- components/script/dom/cssstyledeclaration.rs | 16 +++---- components/script/dom/cssstylerule.rs | 2 +- .../script/dom/webidls/CSSKeyframeRule.webidl | 2 +- tests/wpt/metadata/MANIFEST.json | 6 +++ .../cssom/CSSKeyframeRule.html | 44 +++++++++++++++++++ 6 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 tests/wpt/web-platform-tests/cssom/CSSKeyframeRule.html diff --git a/components/script/dom/csskeyframerule.rs b/components/script/dom/csskeyframerule.rs index 78916d339ab..9d245d98343 100644 --- a/components/script/dom/csskeyframerule.rs +++ b/components/script/dom/csskeyframerule.rs @@ -2,11 +2,12 @@ * 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::CSSKeyframeRuleBinding; -use dom::bindings::js::Root; -use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::codegen::Bindings::CSSKeyframeRuleBinding::{self, CSSKeyframeRuleMethods}; +use dom::bindings::js::{JS, MutNullableJS, Root}; +use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::str::DOMString; use dom::cssrule::{CSSRule, SpecificCSSRule}; +use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner}; use dom::cssstylesheet::CSSStyleSheet; use dom::window::Window; use parking_lot::RwLock; @@ -19,6 +20,7 @@ pub struct CSSKeyframeRule { cssrule: CSSRule, #[ignore_heap_size_of = "Arc"] keyframerule: Arc>, + style_decl: MutNullableJS, } impl CSSKeyframeRule { @@ -27,6 +29,7 @@ impl CSSKeyframeRule { CSSKeyframeRule { cssrule: CSSRule::new_inherited(parent_stylesheet), keyframerule: keyframerule, + style_decl: Default::default(), } } @@ -39,6 +42,19 @@ impl CSSKeyframeRule { } } +impl CSSKeyframeRuleMethods for CSSKeyframeRule { + // https://drafts.csswg.org/css-animations/#dom-csskeyframerule-style + fn Style(&self) -> Root { + self.style_decl.or_init(|| { + CSSStyleDeclaration::new(self.global().as_window(), + CSSStyleOwner::CSSRule(JS::from_ref(self.global().as_window()), + self.keyframerule.read().block.clone()), + None, + CSSModificationAccess::ReadWrite) + }) + } +} + impl SpecificCSSRule for CSSKeyframeRule { fn ty(&self) -> u16 { use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 7cd63aa12b0..7595fe4bfd5 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -34,9 +34,9 @@ pub struct CSSStyleDeclaration { #[must_root] pub enum CSSStyleOwner { Element(JS), - CSSStyleRule(JS, - #[ignore_heap_size_of = "Arc"] - Arc>), + CSSRule(JS, + #[ignore_heap_size_of = "Arc"] + Arc>), } impl CSSStyleOwner { @@ -49,7 +49,7 @@ impl CSSStyleOwner { None } } - CSSStyleOwner::CSSStyleRule(_, ref pdb) => { + CSSStyleOwner::CSSRule(_, ref pdb) => { Some(pdb.clone()) } } @@ -58,7 +58,7 @@ impl CSSStyleOwner { fn window(&self) -> Root { match *self { CSSStyleOwner::Element(ref el) => window_from_node(&**el), - CSSStyleOwner::CSSStyleRule(ref window, _) => Root::from_ref(&**window), + CSSStyleOwner::CSSRule(ref window, _) => Root::from_ref(&**window), } } @@ -72,7 +72,7 @@ impl CSSStyleOwner { match *self { CSSStyleOwner::Element(ref el) => el.upcast::().dirty(NodeDamage::NodeStyleDamaged), - CSSStyleOwner::CSSStyleRule(ref window, _) => + CSSStyleOwner::CSSRule(ref window, _) => window.Document().invalidate_stylesheets(), } } @@ -126,8 +126,8 @@ impl CSSStyleDeclaration { fn get_computed_style(&self, property: PropertyId) -> DOMString { match self.owner { - CSSStyleOwner::CSSStyleRule(..) => - panic!("get_computed_style called on CSSStyleDeclaration with a CSSStyleRule owner"), + CSSStyleOwner::CSSRule(..) => + panic!("get_computed_style called on CSSStyleDeclaration with a CSSRule owner"), CSSStyleOwner::Element(ref el) => { let node = el.upcast::(); if !node.is_in_doc() { diff --git a/components/script/dom/cssstylerule.rs b/components/script/dom/cssstylerule.rs index 3e23864ae61..1eb6e74df8b 100644 --- a/components/script/dom/cssstylerule.rs +++ b/components/script/dom/cssstylerule.rs @@ -58,7 +58,7 @@ impl CSSStyleRuleMethods for CSSStyleRule { fn Style(&self) -> Root { self.style_decl.or_init(|| { CSSStyleDeclaration::new(self.global().as_window(), - CSSStyleOwner::CSSStyleRule(JS::from_ref(self.global().as_window()), + CSSStyleOwner::CSSRule(JS::from_ref(self.global().as_window()), self.stylerule.read().block.clone()), None, CSSModificationAccess::ReadWrite) diff --git a/components/script/dom/webidls/CSSKeyframeRule.webidl b/components/script/dom/webidls/CSSKeyframeRule.webidl index 5458440be6d..079b88ef231 100644 --- a/components/script/dom/webidls/CSSKeyframeRule.webidl +++ b/components/script/dom/webidls/CSSKeyframeRule.webidl @@ -6,5 +6,5 @@ [Exposed=Window] interface CSSKeyframeRule : CSSRule { // attribute DOMString keyText; - // readonly attribute CSSStyleDeclaration style; + readonly attribute CSSStyleDeclaration style; }; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index f7d01004cf1..46a4e70d852 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -45847,6 +45847,12 @@ "deleted_reftests": {}, "items": { "testharness": { + "cssom/CSSKeyframeRule.html": [ + { + "path": "cssom/CSSKeyframeRule.html", + "url": "/cssom/CSSKeyframeRule.html" + } + ], "cssom/overflow-serialization.html": [ { "path": "cssom/overflow-serialization.html", diff --git a/tests/wpt/web-platform-tests/cssom/CSSKeyframeRule.html b/tests/wpt/web-platform-tests/cssom/CSSKeyframeRule.html new file mode 100644 index 00000000000..20067f95cd2 --- /dev/null +++ b/tests/wpt/web-platform-tests/cssom/CSSKeyframeRule.html @@ -0,0 +1,44 @@ + + + + + + +