script: Propagate the attribute into the document's element_attr_will_change method.

This commit is contained in:
Emilio Cobos Álvarez 2017-01-26 23:05:29 +01:00
parent 7a9cdbb857
commit d37e6f8c66
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 7 additions and 7 deletions

View file

@ -170,7 +170,7 @@ impl AttrMethods for Attr {
impl Attr { 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(self);
self.swap_value(&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())

View file

@ -2157,7 +2157,7 @@ impl Document {
} }
} }
pub fn element_attr_will_change(&self, el: &Element) { pub fn element_attr_will_change(&self, el: &Element, _attr: &Attr) {
let mut snapshot = self.ensure_snapshot(el); let mut snapshot = self.ensure_snapshot(el);
if snapshot.attrs.is_none() { if snapshot.attrs.is_none() {
let attrs = el.attrs() let attrs = el.attrs()

View file

@ -962,7 +962,7 @@ impl Element {
pub fn push_attribute(&self, attr: &Attr) { pub fn push_attribute(&self, attr: &Attr) {
assert!(attr.GetOwnerElement().r() == Some(self)); assert!(attr.GetOwnerElement().r() == Some(self));
self.will_mutate_attr(); self.will_mutate_attr(attr);
self.attrs.borrow_mut().push(JS::from_ref(attr)); self.attrs.borrow_mut().push(JS::from_ref(attr));
if attr.namespace() == &ns!() { if attr.namespace() == &ns!() {
vtable_for(self.upcast()).attribute_mutated(attr, AttributeMutation::Set(None)); vtable_for(self.upcast()).attribute_mutated(attr, AttributeMutation::Set(None));
@ -1088,8 +1088,8 @@ impl Element {
let idx = self.attrs.borrow().iter().position(|attr| find(&attr)); let idx = self.attrs.borrow().iter().position(|attr| find(&attr));
idx.map(|idx| { idx.map(|idx| {
self.will_mutate_attr();
let attr = Root::from_ref(&*(*self.attrs.borrow())[idx]); let attr = Root::from_ref(&*(*self.attrs.borrow())[idx]);
self.will_mutate_attr(&attr);
self.attrs.borrow_mut().remove(idx); self.attrs.borrow_mut().remove(idx);
attr.set_owner(None); attr.set_owner(None);
if attr.namespace() == &ns!() { if attr.namespace() == &ns!() {
@ -1227,9 +1227,9 @@ impl Element {
self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value)); self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
} }
pub fn will_mutate_attr(&self) { pub fn will_mutate_attr(&self, attr: &Attr) {
let node = self.upcast::<Node>(); let node = self.upcast::<Node>();
node.owner_doc().element_attr_will_change(self); node.owner_doc().element_attr_will_change(self, attr);
} }
// https://dom.spec.whatwg.org/#insert-adjacent // https://dom.spec.whatwg.org/#insert-adjacent
@ -1502,7 +1502,7 @@ impl ElementMethods for Element {
} }
// Step 4. // Step 4.
self.will_mutate_attr(); self.will_mutate_attr(attr);
attr.set_owner(Some(self)); attr.set_owner(Some(self));
self.attrs.borrow_mut()[position] = JS::from_ref(attr); self.attrs.borrow_mut()[position] = JS::from_ref(attr);
old_attr.set_owner(None); old_attr.set_owner(None);