Implement CSSKeyframeRule.style

This commit is contained in:
Keith Yeung 2016-12-23 11:58:29 -08:00
parent 6d4ccab2b7
commit 18567ce7a8
6 changed files with 79 additions and 13 deletions

View file

@ -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<RwLock<Keyframe>>,
style_decl: MutNullableJS<CSSStyleDeclaration>,
}
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<CSSStyleDeclaration> {
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;