Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sync method to update atrr from inline style updates #9410

Closed
wants to merge 15 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Removed mutation calls from sync_property_with_attrs_style method in …

…order to avoid reparsing serialized output
  • Loading branch information
craftytrickster committed May 19, 2016
commit 870c47f74bf1f1ef0023b5561fc8df58b0d53462
@@ -174,13 +174,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
}
@@ -696,27 +696,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(DOMString::from_string(style_str));
let mut new_style = AttrValue::String(DOMString::from_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) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.