mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Removed mutation calls from sync_property_with_attrs_style method in order to avoid reparsing serialized output
This commit is contained in:
parent
f6bbeae67f
commit
8b39260793
2 changed files with 23 additions and 10 deletions
|
@ -173,13 +173,18 @@ impl Attr {
|
||||||
pub fn set_value(&self, mut value: AttrValue, owner: &Element) {
|
pub fn set_value(&self, mut value: AttrValue, owner: &Element) {
|
||||||
assert!(Some(owner) == self.owner().r());
|
assert!(Some(owner) == self.owner().r());
|
||||||
owner.will_mutate_attr();
|
owner.will_mutate_attr();
|
||||||
mem::swap(&mut *self.value.borrow_mut(), &mut value);
|
self.swap_value(&mut value);
|
||||||
if self.identifier.namespace == ns!() {
|
if self.identifier.namespace == ns!() {
|
||||||
vtable_for(owner.upcast())
|
vtable_for(owner.upcast())
|
||||||
.attribute_mutated(self, AttributeMutation::Set(Some(&value)));
|
.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 {
|
pub fn identifier(&self) -> &AttrIdentifier {
|
||||||
&self.identifier
|
&self.identifier
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,6 +698,8 @@ 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) {
|
fn sync_property_with_attrs_style(&self) {
|
||||||
let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() {
|
let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() {
|
||||||
declarations.to_css_string()
|
declarations.to_css_string()
|
||||||
|
@ -705,20 +707,26 @@ impl Element {
|
||||||
String::new()
|
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")) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.push_new_attribute(
|
// explicitly not calling the push_new_attribute convenience method
|
||||||
atom!("style"),
|
// in order to avoid triggering mutation events
|
||||||
new_style,
|
let window = window_from_node(self);
|
||||||
atom!("style"),
|
let attr = Attr::new(&window,
|
||||||
ns!(),
|
atom!("style"),
|
||||||
Some(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) {
|
pub fn remove_inline_style_property(&self, property: &str) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue