diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index f11cabd7989..d347b63b3b0 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -126,34 +126,20 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority fn GetPropertyPriority(&self, mut property: DOMString) -> DOMString { - // Step 1 - property.make_ascii_lowercase(); - let property = Atom::from(property); - - // Step 2 - if let Some(shorthand) = Shorthand::from_name(&property) { - // Step 2.1 & 2.2 & 2.3 - if shorthand.longhands().iter() - .map(|&longhand| self.GetPropertyPriority(DOMString::from(longhand))) - .all(|priority| priority == "important") { - return DOMString::from("important"); - } + let style_attribute = self.owner.style_attribute().borrow(); + let style_attribute = if let Some(ref style_attribute) = *style_attribute { + style_attribute.read() } else { - // Step 3 - return self.owner.get_inline_style_declaration(&property, |d| { - if let Some(decl) = d { - if decl.1.important() { - return DOMString::from("important"); - } - } + // No style attribute is like an empty style attribute: no matching declaration. + return DOMString::new() + }; - // Step 4 - DOMString::new() - }) + if style_attribute.property_priority(&property).important() { + DOMString::from("important") + } else { + // Step 4 + DOMString::new() } - - // Step 4 - DOMString::new() } // https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 13937bf904c..4c2ac626e7e 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -872,17 +872,6 @@ impl Element { self.sync_property_with_attrs_style(); } - pub fn get_inline_style_declaration(&self, property: &str, f: F) -> R - where F: FnOnce(Option<&(PropertyDeclaration, Importance)>) -> R { - let style_attr = self.style_attribute.borrow(); - if let Some(ref block) = *style_attr { - let block = block.read(); - f(block.get(property)) - } else { - f(None) - } - } - 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 44af1a75ef0..10f4eb42d84 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -109,6 +109,27 @@ impl PropertyDeclarationBlock { } } + /// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority + pub fn property_priority(&self, property_name: &str) -> Importance { + // Step 1 + let property = property_name.to_ascii_lowercase(); + + // Step 2 + if let Some(shorthand) = Shorthand::from_name(&property) { + // Step 2.1 & 2.2 & 2.3 + if shorthand.longhands().iter().all(|l| { + self.get(l).map_or(false, |&(_, importance)| importance.important()) + }) { + Importance::Important + } else { + Importance::Normal + } + } else { + // Step 3 + self.get(&property).map_or(Importance::Normal, |&(_, importance)| importance) + } + } + /// Take a declaration block known to contain a single property and serialize it. pub fn single_value_to_css(&self, property_name: &str, dest: &mut W) -> fmt::Result where W: fmt::Write {