diff options
author | Keith Yeung <kungfukeith11@gmail.com> | 2016-11-21 00:07:23 -0800 |
---|---|---|
committer | Keith Yeung <kungfukeith11@gmail.com> | 2016-12-17 23:03:40 -0800 |
commit | 4738ce1af5d033123b7fe057825091cc79690c30 (patch) | |
tree | d924ba91ca6698b461f1a2f85cea8395af78a680 /components/script/dom/cssstylerule.rs | |
parent | f6163c77b9ac979f8406ef6ffe90e8c8e4a054cc (diff) | |
download | servo-4738ce1af5d033123b7fe057825091cc79690c30.tar.gz servo-4738ce1af5d033123b7fe057825091cc79690c30.zip |
Implement CSSStyleRule.style
Diffstat (limited to 'components/script/dom/cssstylerule.rs')
-rw-r--r-- | components/script/dom/cssstylerule.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/components/script/dom/cssstylerule.rs b/components/script/dom/cssstylerule.rs index 091704f42d5..dce38e69bbc 100644 --- a/components/script/dom/cssstylerule.rs +++ b/components/script/dom/cssstylerule.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::CSSStyleRuleBinding; -use dom::bindings::js::Root; -use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::codegen::Bindings::CSSStyleRuleBinding::{self, CSSStyleRuleMethods}; +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 CSSStyleRule { cssrule: CSSRule, #[ignore_heap_size_of = "Arc"] stylerule: Arc<RwLock<StyleRule>>, + style_decl: MutNullableJS<CSSStyleDeclaration>, } impl CSSStyleRule { @@ -27,6 +29,7 @@ impl CSSStyleRule { CSSStyleRule { cssrule: CSSRule::new_inherited(parent_stylesheet), stylerule: stylerule, + style_decl: Default::default(), } } @@ -37,6 +40,10 @@ impl CSSStyleRule { window, CSSStyleRuleBinding::Wrap) } + + pub fn style_rule(&self) -> Arc<RwLock<StyleRule>> { + self.stylerule.clone() + } } impl SpecificCSSRule for CSSStyleRule { @@ -49,3 +56,16 @@ impl SpecificCSSRule for CSSStyleRule { self.stylerule.read().to_css_string().into() } } + +impl CSSStyleRuleMethods for CSSStyleRule { + // https://drafts.csswg.org/cssom/#dom-cssstylerule-style + fn Style(&self) -> Root<CSSStyleDeclaration> { + self.style_decl.or_init(|| { + CSSStyleDeclaration::new(self.global().as_window(), + CSSStyleOwner::CSSStyleRule(JS::from_ref(self.global().as_window()), + self.stylerule.read().block.clone()), + None, + CSSModificationAccess::ReadWrite) + }) + } +} |