зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #4463 - Add GetPropertyPriority to CSSStyleDeclaration (from iterion: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. Source-Repo: https://github.com/servo/servo Source-Revision: 7b7fe964d328362126a8a56ff463d48f3285391f
This commit is contained in:
Родитель
4401f47c66
Коммит
8d4f1a4c72
|
@ -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 = "");
|
||||
|
|
|
@ -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>
|
Загрузка…
Ссылка в новой задаче