diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index df3c492d9da..cacb5afb1a7 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -69,6 +69,7 @@ impl CSSStyleDeclaration { trait PrivateCSSStyleDeclarationHelpers { fn get_declaration(self, property: &Atom) -> Option; + fn get_important_declaration(self, property: &Atom) -> Option; } impl<'a> PrivateCSSStyleDeclarationHelpers for JSRef<'a, CSSStyleDeclaration> { @@ -77,6 +78,12 @@ impl<'a> PrivateCSSStyleDeclarationHelpers for JSRef<'a, CSSStyleDeclaration> { let element: JSRef = ElementCast::from_ref(*owner); element.get_inline_style_declaration(property).map(|decl| decl.clone()) } + + fn get_important_declaration(self, property: &Atom) -> Option { + let owner = self.owner.root(); + let element: JSRef = ElementCast::from_ref(*owner); + element.get_important_inline_style_declaration(property).map(|decl| decl.clone()) + } } impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { @@ -144,6 +151,30 @@ impl<'a> CSSStyleDeclarationMethods for JSRef<'a, CSSStyleDeclaration> { } } + // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertypriority + fn GetPropertyPriority(self, property: DOMString) -> DOMString { + // Step 1 + let property = Atom::from_slice(property.as_slice().to_ascii_lower().as_slice()); + + // Step 2 + let longhand_properties = longhands_from_shorthand(property.as_slice()); + if let Some(longhand_properties) = longhand_properties { + // Step 2.1 & 2.2 & 2.3 + if longhand_properties.iter() + .map(|longhand| self.GetPropertyPriority(longhand.clone())) + .all(|priority| priority.as_slice() == "important") { + + return "important".to_string(); + } + // Step 3 + } else if self.get_important_declaration(&property).is_some() { + return "important".to_string(); + } + + // Step 4 + "".to_string() + } + // http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty fn SetProperty(self, property: DOMString, value: DOMString, priority: DOMString) -> ErrorResult { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 00f481dcd32..b1d85ef8c74 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -469,6 +469,7 @@ pub trait ElementHelpers<'a> { fn remove_inline_style_property(self, property: DOMString); fn update_inline_style(self, property_decl: style::PropertyDeclaration, important: bool); fn get_inline_style_declaration(self, property: &Atom) -> Option; + fn get_important_inline_style_declaration(self, property: &Atom) -> Option; } impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { @@ -595,6 +596,16 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { .map(|decl| decl.clone()) }) } + + fn get_important_inline_style_declaration(self, property: &Atom) -> Option { + let inline_declarations = self.style_attribute.borrow(); + inline_declarations.as_ref().and_then(|declarations| { + declarations.important + .iter() + .find(|decl| decl.matches(property.as_slice())) + .map(|decl| decl.clone()) + }) + } } pub trait AttributeHandlers { diff --git a/components/script/dom/webidls/CSSStyleDeclaration.webidl b/components/script/dom/webidls/CSSStyleDeclaration.webidl index 7b0e2213956..38f20af8d4e 100644 --- a/components/script/dom/webidls/CSSStyleDeclaration.webidl +++ b/components/script/dom/webidls/CSSStyleDeclaration.webidl @@ -14,7 +14,7 @@ interface CSSStyleDeclaration { readonly attribute unsigned long length; getter DOMString item(unsigned long index); DOMString getPropertyValue(DOMString property); - //DOMString getPropertyPriority(DOMString property); + DOMString getPropertyPriority(DOMString property); [Throws] void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value, [TreatNullAs=EmptyString] optional DOMString priority = ""); diff --git a/tests/content/test_getPropertyPriority.html b/tests/content/test_getPropertyPriority.html new file mode 100644 index 00000000000..85bcde77238 --- /dev/null +++ b/tests/content/test_getPropertyPriority.html @@ -0,0 +1,25 @@ + + + + + +
+ + +