diff options
Diffstat (limited to 'components/script/dom/cssstyledeclaration.rs')
-rw-r--r-- | components/script/dom/cssstyledeclaration.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 4da0b1a019c..101ac3ef252 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -2,6 +2,7 @@ * 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 cssparser::ToCss; use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::{self, CSSStyleDeclarationMethods}; use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; @@ -18,7 +19,7 @@ use std::slice; use string_cache::Atom; use style::parser::ParserContextExtraData; use style::properties::{PropertyDeclaration, Shorthand}; -use style::properties::{is_supported_property, parse_one_declaration}; +use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute}; use style::selector_impl::PseudoElement; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface @@ -339,6 +340,42 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { rval } - // https://drafts.csswg.org/cssom/#cssstyledeclaration + // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext + fn CssText(&self) -> DOMString { + let elem = self.owner.upcast::<Element>(); + let style_attribute = elem.style_attribute().borrow(); + + if let Some(declarations) = style_attribute.as_ref() { + DOMString::from(declarations.to_css_string()) + } else { + DOMString::new() + } + } + + // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext + fn SetCssText(&self, value: DOMString) -> ErrorResult { + let window = window_from_node(self.owner.upcast::<Node>()); + let element = self.owner.upcast::<Element>(); + + // Step 1 + if self.readonly { + return Err(Error::NoModificationAllowed); + } + + // Step 3 + let decl_block = parse_style_attribute(&value, &window.get_url(), window.css_error_reporter(), + ParserContextExtraData::default()); + *element.style_attribute().borrow_mut() = if decl_block.normal.is_empty() && decl_block.important.is_empty() { + None // Step 2 + } else { + Some(decl_block) + }; + element.sync_property_with_attrs_style(); + let node = element.upcast::<Node>(); + node.dirty(NodeDamage::NodeStyleDamaged); + Ok(()) + } + + // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-_camel_cased_attribute css_properties_accessors!(css_properties); } |