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

Stop calling children change notification on text elements #16676

Closed
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -1353,6 +1353,16 @@ pub enum CloneChildrenFlag {

fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t }

// Checks if parent element only cares about text nodes
fn accepts_only_text_nodes(node: &Node, parent: &Node) -> bool {
let isTextNode = node.children_count() == 0;
match parent.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadingElement)) |

This comment has been minimized.

@zimio

zimio May 1, 2017

Author Contributor

There should be more elements here, like the B element. But I don't know how to make the comparison for those type of elements.

NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)) => isTextNode,
_ => false
}
}

impl Node {
pub fn reflect_node<N>(
node: Box<N>,
@@ -1564,6 +1574,8 @@ impl Node {
debug_assert!(&*node.owner_doc() == &*parent.owner_doc());
debug_assert!(child.map_or(true, |child| Some(parent) == child.GetParentNode().r()));

let text_only = accepts_only_text_nodes(node, parent);

// Step 1.
let count = if node.is::<DocumentFragment>() {
node.children_count()
@@ -1587,7 +1599,9 @@ impl Node {
for kid in new_nodes.r() {
Node::remove(*kid, node, SuppressObserver::Suppressed);
}
vtable_for(&node).children_changed(&ChildrenMutation::replace_all(new_nodes.r(), &[]));
if !text_only {
vtable_for(&node).children_changed(&ChildrenMutation::replace_all(new_nodes.r(), &[]));
}
new_nodes.r()
} else {
// Step 3.
@@ -1610,8 +1624,10 @@ impl Node {
// Step 7.2: insertion steps.
}
if let SuppressObserver::Unsuppressed = suppress_observers {
vtable_for(&parent).children_changed(
&ChildrenMutation::insert(previous_sibling.r(), new_nodes, child));
if !text_only {
vtable_for(&parent).children_changed(
&ChildrenMutation::insert(previous_sibling.r(), new_nodes, child));
}
}
}

@@ -1644,8 +1660,10 @@ impl Node {
Node::insert(node, parent, None, SuppressObserver::Suppressed);
}
// Step 6: mutation observers.
vtable_for(&parent).children_changed(
&ChildrenMutation::replace_all(removed_nodes.r(), added_nodes));
if !accepts_only_text_nodes(node.unwrap(), parent) {
vtable_for(&parent).children_changed(
&ChildrenMutation::replace_all(removed_nodes.r(), added_nodes));
}
}

// https://dom.spec.whatwg.org/#concept-node-pre-remove
@@ -1692,10 +1710,12 @@ impl Node {
// Step 11. transient registered observers
// Step 12.
if let SuppressObserver::Unsuppressed = suppress_observers {
vtable_for(&parent).children_changed(
&ChildrenMutation::replace(old_previous_sibling.r(),
&Some(&node), &[],
old_next_sibling.r()));
if !accepts_only_text_nodes(node, parent) {
vtable_for(&parent).children_changed(
&ChildrenMutation::replace(old_previous_sibling.r(),
&Some(&node), &[],
old_next_sibling.r()));
}
}
}

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