Move CSSStyleDeclaration.RemoveProperty logic to style

This commit is contained in:
Simon Sapin 2016-10-07 17:06:56 +02:00
parent fc6a536b3a
commit bd4a4c38c8
3 changed files with 55 additions and 50 deletions

View file

@ -741,8 +741,11 @@ impl Element {
} else {
String::new()
};
self.set_style_attr(style_str)
}
let mut new_style = AttrValue::String(style_str);
pub fn set_style_attr(&self, new_value: String) {
let mut new_style = AttrValue::String(new_value);
if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &atom!("style")) {
style_attr.swap_value(&mut new_style);
@ -764,32 +767,6 @@ impl Element {
self.attrs.borrow_mut().push(JS::from_ref(&attr));
}
pub fn remove_inline_style_property(&self, property: &str) {
fn remove(element: &Element, property: &str) {
let mut inline_declarations = element.style_attribute.borrow_mut();
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
let mut importance = None;
let index = declarations.read().declarations.iter().position(|&(ref decl, i)| {
let matching = decl.matches(property);
if matching {
importance = Some(i)
}
matching
});
if let Some(index) = index {
let mut declarations = declarations.write();
declarations.declarations.remove(index);
if importance.unwrap().important() {
declarations.important_count -= 1;
}
}
}
}
remove(self, property);
self.sync_property_with_attrs_style();
}
pub fn update_inline_style(&self,
declarations: Vec<PropertyDeclaration>,
importance: Importance) {