diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index abd6d207dd1..37ff6e7a3bf 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -242,24 +242,26 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { } // Step 4 - let priority = match &*priority { + let importance = match &*priority { "" => Importance::Normal, p if p.eq_ignore_ascii_case("important") => Importance::Important, _ => return Ok(()), }; - let element = self.owner.upcast::(); + let style_attribute = self.owner.style_attribute().borrow(); + if let Some(ref lock) = *style_attribute { + let mut style_attribute = lock.write(); - // Step 5 & 6 - match Shorthand::from_name(&property) { - Some(shorthand) => { - element.set_inline_style_property_priority(shorthand.longhands(), priority) + // Step 5 & 6 + match Shorthand::from_name(&property) { + Some(shorthand) => style_attribute.set_importance(shorthand.longhands(), importance), + None => style_attribute.set_importance(&[&*property], importance), } - None => element.set_inline_style_property_priority(&[&*property], priority), - } - let node = element.upcast::(); - node.dirty(NodeDamage::NodeStyleDamaged); + self.owner.set_style_attr(style_attribute.to_css_string()); + let node = self.owner.upcast::(); + node.dirty(NodeDamage::NodeStyleDamaged); + } Ok(()) } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 67e0b549d56..621faa912aa 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -5,7 +5,7 @@ //! Element nodes. use app_units::Au; -use cssparser::{Color, ToCss}; +use cssparser::Color; use devtools_traits::AttrInfo; use dom::activation::Activatable; use dom::attr::{Attr, AttrHelpersForLayout}; @@ -735,15 +735,6 @@ impl Element { // this sync method is called upon modification of the style_attribute property, // therefore, it should not trigger subsequent mutation events - pub fn sync_property_with_attrs_style(&self) { - let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() { - declarations.read().to_css_string() - } else { - String::new() - }; - self.set_style_attr(style_str) - } - pub fn set_style_attr(&self, new_value: String) { let mut new_style = AttrValue::String(new_value); @@ -767,35 +758,6 @@ impl Element { self.attrs.borrow_mut().push(JS::from_ref(&attr)); } - pub fn set_inline_style_property_priority(&self, - properties: &[&str], - new_importance: Importance) { - { - let mut inline_declarations = self.style_attribute().borrow_mut(); - if let &mut Some(ref mut block) = &mut *inline_declarations { - let mut block = block.write(); - let block = &mut *block; - let declarations = &mut block.declarations; - for &mut (ref declaration, ref mut importance) in declarations { - if properties.iter().any(|p| declaration.name() == **p) { - match (*importance, new_importance) { - (Importance::Normal, Importance::Important) => { - block.important_count += 1; - } - (Importance::Important, Importance::Normal) => { - block.important_count -= 1; - } - _ => {} - } - *importance = new_importance; - } - } - } - } - - self.sync_property_with_attrs_style(); - } - pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible { let mut writer = vec![]; match serialize(&mut writer, diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 2300634b559..25d48a1cb55 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -154,6 +154,23 @@ impl PropertyDeclarationBlock { } } + pub fn set_importance(&mut self, property_names: &[&str], new_importance: Importance) { + for &mut (ref declaration, ref mut importance) in &mut self.declarations { + if property_names.iter().any(|p| declaration.matches(p)) { + match (*importance, new_importance) { + (Importance::Normal, Importance::Important) => { + self.important_count += 1; + } + (Importance::Important, Importance::Normal) => { + self.important_count -= 1; + } + _ => {} + } + *importance = new_importance; + } + } + } + /// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty pub fn remove_property(&mut self, property_name: &str) { // Step 2