Introduce VirtualMethods::children_changed()

This virtual method mimics the behaviour of mutation observers and make it more
viable than the older child_inserted(), which didn't cover removed nodes and
was called as many times as there were inserted nodes.

A few other shortcomings where remove_child() was called directly instead of
Node::remove() were also fixed while at it.
This commit is contained in:
Anthony Ramine 2015-07-18 14:45:52 +02:00
parent 389a9ff643
commit 7b40cc9fd7
7 changed files with 194 additions and 180 deletions

View file

@ -11,7 +11,8 @@ use dom::document::Document;
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::{ElementTypeId, AttributeHandlers};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node};
use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId};
use dom::node::window_from_node;
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
use layout_interface::{LayoutChan, Msg};
@ -86,11 +87,10 @@ impl<'a> VirtualMethods for &'a HTMLStyleElement {
Some(htmlelement as &VirtualMethods)
}
fn child_inserted(&self, child: &Node) {
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.child_inserted(child);
s.children_changed(mutation);
}
let node = NodeCast::from_ref(*self);
if node.is_in_doc() {
self.parse_own_css();