mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Add GetPropertyPriority to CSSStyleDeclaration
Tweak getPropertyPriority to match recommendations Adding Tests for Style Priority Use else if Adding Content Test for GetPropertyPriority Revert "Adding Tests for Style Priority" This reverts commit 8666a37f833b06c3e43f27acd8a9678e94425e55.
This commit is contained in:
parent
49f2c6974d
commit
674fe910c1
4 changed files with 68 additions and 1 deletions
|
@ -69,6 +69,7 @@ impl CSSStyleDeclaration {
|
|||
|
||||
trait PrivateCSSStyleDeclarationHelpers {
|
||||
fn get_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
fn get_important_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||
}
|
||||
|
||||
impl<'a> PrivateCSSStyleDeclarationHelpers for JSRef<'a, CSSStyleDeclaration> {
|
||||
|
@ -77,6 +78,12 @@ impl<'a> PrivateCSSStyleDeclarationHelpers for JSRef<'a, CSSStyleDeclaration> {
|
|||
let element: JSRef<Element> = ElementCast::from_ref(*owner);
|
||||
element.get_inline_style_declaration(property).map(|decl| decl.clone())
|
||||
}
|
||||
|
||||
fn get_important_declaration(self, property: &Atom) -> Option<PropertyDeclaration> {
|
||||
let owner = self.owner.root();
|
||||
let element: JSRef<Element> = 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 {
|
||||
|
|
|
@ -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<style::PropertyDeclaration>;
|
||||
fn get_important_inline_style_declaration(self, property: &Atom) -> Option<style::PropertyDeclaration>;
|
||||
}
|
||||
|
||||
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<style::PropertyDeclaration> {
|
||||
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 {
|
||||
|
|
|
@ -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 = "");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue