mirror of
https://github.com/servo/servo.git
synced 2025-06-19 14:48:59 +01:00
Add overridable tree binding/unbinding behaviour.
This commit is contained in:
parent
f5d1907195
commit
6388dec996
3 changed files with 39 additions and 10 deletions
|
@ -727,4 +727,22 @@ impl VirtualMethods for JS<Element> {
|
||||||
|
|
||||||
self.notify_attribute_changed(name);
|
self.notify_attribute_changed(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bind_to_tree(&mut self) {
|
||||||
|
match self.super_type() {
|
||||||
|
Some(ref mut s) => s.bind_to_tree(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
self.bind_to_tree_impl();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unbind_from_tree(&mut self) {
|
||||||
|
match self.super_type() {
|
||||||
|
Some(ref mut s) => s.unbind_from_tree(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
self.unbind_from_tree_impl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,12 +19,12 @@ use dom::comment::Comment;
|
||||||
use dom::document::{Document, HTMLDocument, NonHTMLDocument};
|
use dom::document::{Document, HTMLDocument, NonHTMLDocument};
|
||||||
use dom::documentfragment::DocumentFragment;
|
use dom::documentfragment::DocumentFragment;
|
||||||
use dom::documenttype::DocumentType;
|
use dom::documenttype::DocumentType;
|
||||||
use dom::element::{Element, ElementTypeId, HTMLAnchorElementTypeId, IElement};
|
use dom::element::{Element, ElementTypeId, HTMLAnchorElementTypeId};
|
||||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||||
use dom::nodelist::{NodeList};
|
use dom::nodelist::{NodeList};
|
||||||
use dom::processinginstruction::ProcessingInstruction;
|
use dom::processinginstruction::ProcessingInstruction;
|
||||||
use dom::text::Text;
|
use dom::text::Text;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::{VirtualMethods, vtable_for};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use html::hubbub_html_parser::build_element_from_tag;
|
use html::hubbub_html_parser::build_element_from_tag;
|
||||||
use layout_interface::{LayoutChan, ReapLayoutDataMsg, UntrustedNodeAddress};
|
use layout_interface::{LayoutChan, ReapLayoutDataMsg, UntrustedNodeAddress};
|
||||||
|
@ -404,10 +404,7 @@ impl NodeHelpers for JS<Node> {
|
||||||
|
|
||||||
if self.is_in_doc() {
|
if self.is_in_doc() {
|
||||||
for node in self.traverse_preorder() {
|
for node in self.traverse_preorder() {
|
||||||
if node.is_element() {
|
vtable_for(&node).bind_to_tree();
|
||||||
let element: JS<Element> = ElementCast::to(&node).unwrap();
|
|
||||||
element.bind_to_tree_impl();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,10 +417,8 @@ impl NodeHelpers for JS<Node> {
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
|
|
||||||
for node in self.traverse_preorder() {
|
for node in self.traverse_preorder() {
|
||||||
if node.is_element() {
|
// XXX how about if the node wasn't in the tree in the first place?
|
||||||
let element: JS<Element> = ElementCast::to(&node).unwrap();
|
vtable_for(&node).unbind_from_tree();
|
||||||
element.unbind_from_tree_impl();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.get().content_changed();
|
document.get().content_changed();
|
||||||
|
|
|
@ -42,6 +42,22 @@ pub trait VirtualMethods {
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called when a Node is appended to a tree that is part of a Document.
|
||||||
|
fn bind_to_tree(&mut self) {
|
||||||
|
match self.super_type() {
|
||||||
|
Some(ref mut s) => s.bind_to_tree(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Called when a Node is removed from a tree that is part of a Document.
|
||||||
|
fn unbind_from_tree(&mut self) {
|
||||||
|
match self.super_type() {
|
||||||
|
Some(ref mut s) => s.unbind_from_tree(),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Obtain a VirtualMethods instance for a given Node-derived object. Any
|
/// Obtain a VirtualMethods instance for a given Node-derived object. Any
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue