mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
auto merge of #4463 : iterion/servo/get-property-priority, r=jdm
Implementation of #4432 adding `getPropertyPriority` to CSSStyleDeclaration. This is my first attempt at a Servo PR so I'm sure I've done something wrong. Let me know, and I'll fix it up. As stated in #4432 tests for this are in #4085. If there are additional tests I can write now I would love to do that, I'm just not sure where or what those would be.
This commit is contained in:
commit
7b7fe964d3
4 changed files with 68 additions and 1 deletions
|
@ -69,6 +69,7 @@ impl CSSStyleDeclaration {
|
||||||
|
|
||||||
trait PrivateCSSStyleDeclarationHelpers {
|
trait PrivateCSSStyleDeclarationHelpers {
|
||||||
fn get_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
fn get_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||||
|
fn get_important_declaration(self, property: &Atom) -> Option<PropertyDeclaration>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PrivateCSSStyleDeclarationHelpers for JSRef<'a, CSSStyleDeclaration> {
|
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);
|
let element: JSRef<Element> = ElementCast::from_ref(*owner);
|
||||||
element.get_inline_style_declaration(property).map(|decl| decl.clone())
|
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> {
|
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
|
// http://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-setproperty
|
||||||
fn SetProperty(self, property: DOMString, value: DOMString,
|
fn SetProperty(self, property: DOMString, value: DOMString,
|
||||||
priority: DOMString) -> ErrorResult {
|
priority: DOMString) -> ErrorResult {
|
||||||
|
|
|
@ -469,6 +469,7 @@ pub trait ElementHelpers<'a> {
|
||||||
fn remove_inline_style_property(self, property: DOMString);
|
fn remove_inline_style_property(self, property: DOMString);
|
||||||
fn update_inline_style(self, property_decl: style::PropertyDeclaration, important: bool);
|
fn update_inline_style(self, property_decl: style::PropertyDeclaration, important: bool);
|
||||||
fn get_inline_style_declaration(self, property: &Atom) -> Option<style::PropertyDeclaration>;
|
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> {
|
impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||||
|
@ -595,6 +596,16 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
|
||||||
.map(|decl| decl.clone())
|
.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 {
|
pub trait AttributeHandlers {
|
||||||
|
|
|
@ -14,7 +14,7 @@ interface CSSStyleDeclaration {
|
||||||
readonly attribute unsigned long length;
|
readonly attribute unsigned long length;
|
||||||
getter DOMString item(unsigned long index);
|
getter DOMString item(unsigned long index);
|
||||||
DOMString getPropertyValue(DOMString property);
|
DOMString getPropertyValue(DOMString property);
|
||||||
//DOMString getPropertyPriority(DOMString property);
|
DOMString getPropertyPriority(DOMString property);
|
||||||
[Throws]
|
[Throws]
|
||||||
void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value,
|
void setProperty(DOMString property, [TreatNullAs=EmptyString] DOMString value,
|
||||||
[TreatNullAs=EmptyString] optional DOMString priority = "");
|
[TreatNullAs=EmptyString] optional DOMString priority = "");
|
||||||
|
|
25
tests/content/test_getPropertyPriority.html
Normal file
25
tests/content/test_getPropertyPriority.html
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="harness.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="important" style='outline-color: #111 !important; outline-style: solid !important; outline-width: 1px !important; background-color: #222 !important; color: #FFF'></div>
|
||||||
|
<script>
|
||||||
|
var properties = {
|
||||||
|
'outline-color': 'important',
|
||||||
|
'outline-style': 'important',
|
||||||
|
'outline-width': 'important',
|
||||||
|
'outline': 'important',
|
||||||
|
'background-color': 'important',
|
||||||
|
'background': '',
|
||||||
|
'color': '',
|
||||||
|
};
|
||||||
|
var elem = document.getElementById('important')
|
||||||
|
for (var property in Object.keys(properties)) {
|
||||||
|
var name = Object.keys(properties)[property];
|
||||||
|
var value = properties[name];
|
||||||
|
is(elem.style.getPropertyPriority(name), value, name + ' priority');
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue