servo: Merge #14712 - Implement CSSKeyframeRule.style (from KiChjang:css-keyframe-rule-style); r=Manishearth

Fixes #14636.

r? @Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: cdf14730ff4c17afdfdcc0cefbd0683a4324ba8e
This commit is contained in:
Keith Yeung 2017-01-07 22:18:11 -08:00
Родитель 3f6f95c27d
Коммит bf609ffef2
4 изменённых файлов: 29 добавлений и 13 удалений

Просмотреть файл

@ -2,11 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::Bindings::CSSKeyframeRuleBinding; use dom::bindings::codegen::Bindings::CSSKeyframeRuleBinding::{self, CSSKeyframeRuleMethods};
use dom::bindings::js::Root; use dom::bindings::js::{JS, MutNullableJS, Root};
use dom::bindings::reflector::reflect_dom_object; use dom::bindings::reflector::{DomObject, reflect_dom_object};
use dom::bindings::str::DOMString; use dom::bindings::str::DOMString;
use dom::cssrule::{CSSRule, SpecificCSSRule}; use dom::cssrule::{CSSRule, SpecificCSSRule};
use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration, CSSStyleOwner};
use dom::cssstylesheet::CSSStyleSheet; use dom::cssstylesheet::CSSStyleSheet;
use dom::window::Window; use dom::window::Window;
use parking_lot::RwLock; use parking_lot::RwLock;
@ -19,6 +20,7 @@ pub struct CSSKeyframeRule {
cssrule: CSSRule, cssrule: CSSRule,
#[ignore_heap_size_of = "Arc"] #[ignore_heap_size_of = "Arc"]
keyframerule: Arc<RwLock<Keyframe>>, keyframerule: Arc<RwLock<Keyframe>>,
style_decl: MutNullableJS<CSSStyleDeclaration>,
} }
impl CSSKeyframeRule { impl CSSKeyframeRule {
@ -27,6 +29,7 @@ impl CSSKeyframeRule {
CSSKeyframeRule { CSSKeyframeRule {
cssrule: CSSRule::new_inherited(parent_stylesheet), cssrule: CSSRule::new_inherited(parent_stylesheet),
keyframerule: keyframerule, 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 { impl SpecificCSSRule for CSSKeyframeRule {
fn ty(&self) -> u16 { fn ty(&self) -> u16 {
use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants; use dom::bindings::codegen::Bindings::CSSRuleBinding::CSSRuleConstants;

Просмотреть файл

@ -34,9 +34,9 @@ pub struct CSSStyleDeclaration {
#[must_root] #[must_root]
pub enum CSSStyleOwner { pub enum CSSStyleOwner {
Element(JS<Element>), Element(JS<Element>),
CSSStyleRule(JS<Window>, CSSRule(JS<Window>,
#[ignore_heap_size_of = "Arc"] #[ignore_heap_size_of = "Arc"]
Arc<RwLock<PropertyDeclarationBlock>>), Arc<RwLock<PropertyDeclarationBlock>>),
} }
impl CSSStyleOwner { impl CSSStyleOwner {
@ -49,7 +49,7 @@ impl CSSStyleOwner {
None None
} }
} }
CSSStyleOwner::CSSStyleRule(_, ref pdb) => { CSSStyleOwner::CSSRule(_, ref pdb) => {
Some(pdb.clone()) Some(pdb.clone())
} }
} }
@ -58,7 +58,7 @@ impl CSSStyleOwner {
fn window(&self) -> Root<Window> { fn window(&self) -> Root<Window> {
match *self { match *self {
CSSStyleOwner::Element(ref el) => window_from_node(&**el), 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 { match *self {
CSSStyleOwner::Element(ref el) => CSSStyleOwner::Element(ref el) =>
el.upcast::<Node>().dirty(NodeDamage::NodeStyleDamaged), el.upcast::<Node>().dirty(NodeDamage::NodeStyleDamaged),
CSSStyleOwner::CSSStyleRule(ref window, _) => CSSStyleOwner::CSSRule(ref window, _) =>
window.Document().invalidate_stylesheets(), window.Document().invalidate_stylesheets(),
} }
} }
@ -126,8 +126,8 @@ impl CSSStyleDeclaration {
fn get_computed_style(&self, property: PropertyId) -> DOMString { fn get_computed_style(&self, property: PropertyId) -> DOMString {
match self.owner { match self.owner {
CSSStyleOwner::CSSStyleRule(..) => CSSStyleOwner::CSSRule(..) =>
panic!("get_computed_style called on CSSStyleDeclaration with a CSSStyleRule owner"), panic!("get_computed_style called on CSSStyleDeclaration with a CSSRule owner"),
CSSStyleOwner::Element(ref el) => { CSSStyleOwner::Element(ref el) => {
let node = el.upcast::<Node>(); let node = el.upcast::<Node>();
if !node.is_in_doc() { if !node.is_in_doc() {

Просмотреть файл

@ -58,7 +58,7 @@ impl CSSStyleRuleMethods for CSSStyleRule {
fn Style(&self) -> Root<CSSStyleDeclaration> { fn Style(&self) -> Root<CSSStyleDeclaration> {
self.style_decl.or_init(|| { self.style_decl.or_init(|| {
CSSStyleDeclaration::new(self.global().as_window(), 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()), self.stylerule.read().block.clone()),
None, None,
CSSModificationAccess::ReadWrite) CSSModificationAccess::ReadWrite)

Просмотреть файл

@ -6,5 +6,5 @@
[Exposed=Window] [Exposed=Window]
interface CSSKeyframeRule : CSSRule { interface CSSKeyframeRule : CSSRule {
// attribute DOMString keyText; // attribute DOMString keyText;
// readonly attribute CSSStyleDeclaration style; readonly attribute CSSStyleDeclaration style;
}; };