Skip to content

Commit

Permalink
Removed mutation calls from sync_property_with_attrs_style method in …
Browse files Browse the repository at this point in the history
…order to avoid reparsing serialized output
  • Loading branch information
craftytrickster authored and SimonSapin committed May 25, 2016
1 parent f6bbeae commit 8b39260
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
7 changes: 6 additions & 1 deletion components/script/dom/attr.rs
Expand Up @@ -173,13 +173,18 @@ impl Attr {
pub fn set_value(&self, mut value: AttrValue, owner: &Element) {
assert!(Some(owner) == self.owner().r());
owner.will_mutate_attr();
mem::swap(&mut *self.value.borrow_mut(), &mut value);
self.swap_value(&mut value);
if self.identifier.namespace == ns!() {
vtable_for(owner.upcast())
.attribute_mutated(self, AttributeMutation::Set(Some(&value)));
}
}

/// Used to swap the attribute's value without triggering mutation events
pub fn swap_value(&self, value: &mut AttrValue) {
mem::swap(&mut *self.value.borrow_mut(), value);
}

pub fn identifier(&self) -> &AttrIdentifier {
&self.identifier
}
Expand Down
26 changes: 17 additions & 9 deletions components/script/dom/element.rs
Expand Up @@ -698,27 +698,35 @@ impl Element {
}
}

// this sync method is called upon modification of the style_attribute property,
// therefore, it should not trigger subsequent mutation events
fn sync_property_with_attrs_style(&self) {
let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() {
declarations.to_css_string()
} else {
String::new()
};

let new_style = AttrValue::String(style_str);
let mut new_style = AttrValue::String(style_str);

if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &atom!("style")) {
style_attr.set_value(new_style, self);
style_attr.swap_value(&mut new_style);
return;
}

self.push_new_attribute(
atom!("style"),
new_style,
atom!("style"),
ns!(),
Some(atom!("style"))
);
// explicitly not calling the push_new_attribute convenience method
// in order to avoid triggering mutation events
let window = window_from_node(self);
let attr = Attr::new(&window,
atom!("style"),
new_style,
atom!("style"),
ns!(),
Some(atom!("style")),
Some(self));

assert!(attr.GetOwnerElement().r() == Some(self));
self.attrs.borrow_mut().push(JS::from_ref(&attr));
}

pub fn remove_inline_style_property(&self, property: &str) {
Expand Down

0 comments on commit 8b39260

Please sign in to comment.