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

Introduce VirtualMethods::children_changed() #6660

Merged
merged 2 commits into from Jul 25, 2015
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

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.
  • Loading branch information
nox committed Jul 25, 2015
commit 7b40cc9fd7ea4dcc3816be0cb1ad6543bb5c88e0
@@ -27,7 +27,8 @@ use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node, CloneChildrenFlag};
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeHelpers};
use dom::node::{NodeTypeId, document_from_node, window_from_node};
use dom::servohtmlparser::ServoHTMLParserHelpers;
use dom::virtualmethods::VirtualMethods;
use dom::window::{WindowHelpers, ScriptHelpers};
@@ -564,9 +565,9 @@ impl<'a> VirtualMethods for &'a HTMLScriptElement {
}
}

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 !self.parser_inserted.get() && node.is_in_doc() {
@@ -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();
@@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaEl
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLFieldSetElementDerived};
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, TextDerived};
use dom::bindings::codegen::InheritTypes::KeyboardEventCast;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{LayoutJS, Root};
use dom::bindings::refcounted::Trusted;
@@ -23,8 +23,8 @@ use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlformelement::FormControl;
use dom::keyboardevent::KeyboardEvent;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId};
use dom::node::{document_from_node, window_from_node};
use dom::node::{ChildrenMutation, DisabledStateHelpers, Node, NodeDamage};
use dom::node::{NodeHelpers, NodeTypeId, document_from_node, window_from_node};
use textinput::{TextInput, Lines, KeyReaction};
use dom::virtualmethods::VirtualMethods;
use dom::window::WindowHelpers;
@@ -330,12 +330,11 @@ impl<'a> VirtualMethods for &'a HTMLTextAreaElement {
}
}

fn child_inserted(&self, child: &Node) {
if let Some(s) = self.super_type() {
s.child_inserted(child);
fn children_changed(&self, mutation: &ChildrenMutation) {
if let Some(ref s) = self.super_type() {
s.children_changed(mutation);
}

if child.is_text() && !self.value_changed.get() {
if !self.value_changed.get() {
self.reset();
}
}
@@ -13,7 +13,7 @@ use dom::document::{Document, DocumentHelpers};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::element::ElementTypeId;
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeHelpers, NodeTypeId};
use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId};
use dom::text::Text;
use dom::virtualmethods::VirtualMethods;
use util::str::DOMString;
@@ -75,15 +75,13 @@ impl<'a> VirtualMethods for &'a HTMLTitleElement {
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() {
let document = node.owner_doc();
document.r().title_changed();
node.owner_doc().title_changed();
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.