Skip to content

Commit

Permalink
Move WebCore-internal DOM notification methods from Node to Container…
Browse files Browse the repository at this point in the history
…Node where appropriate

https://bugs.webkit.org/show_bug.cgi?id=79697

Reviewed by Ryosuke Niwa.

insertedIntoTree/removedFromTree are only used by subclasses of
ContainerNode. Moreover, attempting to make use of these notifications
in a non-container Node would currently not work, because
Node::removedFromDocument/insertedIntoDocument do not dispatch to these methods.
Rather than adding useless calls to an always-empty virtual method,
this patch moves these methods to ContainerNode.

Meanwhile, childrenChanged moves to ContainerNode for an obvious reason:
non-container Nodes have no children to change.

No new tests, refactoring only.

* dom/Attr.cpp:
(WebCore::Attr::childrenChanged): Remove call to now-nonexistent Node::childrenChanged.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::removeChild): Check that the removed child is a container node before notifying it of removal.
(WebCore::ContainerNode::parserRemoveChild): ditto.
(WebCore::ContainerNode::insertedIntoTree): Remove call to now-nonexistent Node::insertedIntoTree.
(WebCore::ContainerNode::removedFromTree): Remove call to now-nonexistent Node::removedFromTree.
(WebCore::ContainerNode::childrenChanged): Remove call to now-nonexistent Node::childrenChanged.
(WebCore::notifyChildInserted): Check that the inserted child is a container node before notifying it of insertion.
* dom/ContainerNode.h:
(ContainerNode): Migrate comments from Node.h, point back at it for more notification methods.
* dom/Node.h:
(Node): Move methods, update comments to point at ContainerNode.h.

Canonical link: https://commits.webkit.org/96792@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109026 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ajklein committed Feb 27, 2012
1 parent ee38745 commit 51d50d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 27 deletions.
33 changes: 33 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,36 @@
2012-02-27 Adam Klein <adamk@chromium.org>

Move WebCore-internal DOM notification methods from Node to ContainerNode where appropriate
https://bugs.webkit.org/show_bug.cgi?id=79697

Reviewed by Ryosuke Niwa.

insertedIntoTree/removedFromTree are only used by subclasses of
ContainerNode. Moreover, attempting to make use of these notifications
in a non-container Node would currently not work, because
Node::removedFromDocument/insertedIntoDocument do not dispatch to these methods.
Rather than adding useless calls to an always-empty virtual method,
this patch moves these methods to ContainerNode.

Meanwhile, childrenChanged moves to ContainerNode for an obvious reason:
non-container Nodes have no children to change.

No new tests, refactoring only.

* dom/Attr.cpp:
(WebCore::Attr::childrenChanged): Remove call to now-nonexistent Node::childrenChanged.
* dom/ContainerNode.cpp:
(WebCore::ContainerNode::removeChild): Check that the removed child is a container node before notifying it of removal.
(WebCore::ContainerNode::parserRemoveChild): ditto.
(WebCore::ContainerNode::insertedIntoTree): Remove call to now-nonexistent Node::insertedIntoTree.
(WebCore::ContainerNode::removedFromTree): Remove call to now-nonexistent Node::removedFromTree.
(WebCore::ContainerNode::childrenChanged): Remove call to now-nonexistent Node::childrenChanged.
(WebCore::notifyChildInserted): Check that the inserted child is a container node before notifying it of insertion.
* dom/ContainerNode.h:
(ContainerNode): Migrate comments from Node.h, point back at it for more notification methods.
* dom/Node.h:
(Node): Move methods, update comments to point at ContainerNode.h.

2012-02-27 Chris Rogers <crogers@google.com>

Implement static compression curve parameters for DynamicsCompressorNode
Expand Down
2 changes: 0 additions & 2 deletions Source/WebCore/dom/Attr.cpp
Expand Up @@ -172,8 +172,6 @@ void Attr::childrenChanged(bool changedByParser, Node* beforeChange, Node* after
if (m_ignoreChildrenChanged > 0)
return;

Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);

invalidateNodeListsCacheAfterAttributeChanged(m_attribute->name());

// FIXME: We should include entity references in the value
Expand Down
25 changes: 14 additions & 11 deletions Source/WebCore/dom/ContainerNode.cpp
Expand Up @@ -463,8 +463,8 @@ bool ContainerNode::removeChild(Node* oldChild, ExceptionCode& ec)

if (child->inDocument())
child->removedFromDocument();
else
child->removedFromTree(true);
else if (child->isContainerNode())
toContainerNode(child.get())->removedFromTree(true);

dispatchSubtreeModifiedEvent();

Expand Down Expand Up @@ -513,8 +513,8 @@ void ContainerNode::parserRemoveChild(Node* oldChild)
childrenChanged(true, prev, next, -1);
if (oldChild->inDocument())
oldChild->removedFromDocument();
else
oldChild->removedFromTree(true);
else if (oldChild->isContainerNode())
toContainerNode(oldChild)->removedFromTree(true);
}

// this differs from other remove functions because it forcibly removes all the children,
Expand Down Expand Up @@ -812,21 +812,24 @@ void ContainerNode::insertedIntoTree(bool deep)
{
if (!deep)
return;
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->insertedIntoTree(true);
for (Node* child = m_firstChild; child; child = child->nextSibling()) {
if (child->isContainerNode())
toContainerNode(child)->insertedIntoTree(true);
}
}

void ContainerNode::removedFromTree(bool deep)
{
if (!deep)
return;
for (Node* child = m_firstChild; child; child = child->nextSibling())
child->removedFromTree(true);
for (Node* child = m_firstChild; child; child = child->nextSibling()) {
if (child->isContainerNode())
toContainerNode(child)->removedFromTree(true);
}
}

void ContainerNode::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (!changedByParser && childCountDelta)
document()->updateRangesAfterChildrenChanged(this);
invalidateNodeListsCacheAfterChildrenChanged();
Expand Down Expand Up @@ -1085,8 +1088,8 @@ static void notifyChildInserted(Node* child)
Node* parentOrHostNode = c->parentOrHostNode();
if (parentOrHostNode && parentOrHostNode->inDocument())
c->insertedIntoDocument();
else
c->insertedIntoTree(true);
else if (c->isContainerNode())
toContainerNode(c.get())->insertedIntoTree(true);

document->incDOMTreeVersion();
}
Expand Down
16 changes: 13 additions & 3 deletions Source/WebCore/dom/ContainerNode.h
Expand Up @@ -79,11 +79,21 @@ class ContainerNode : public Node {
virtual void setHovered(bool = true) OVERRIDE;
virtual void insertedIntoDocument() OVERRIDE;
virtual void removedFromDocument() OVERRIDE;
virtual void insertedIntoTree(bool deep) OVERRIDE;
virtual void removedFromTree(bool deep) OVERRIDE;
virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
virtual void scheduleSetNeedsStyleRecalc(StyleChangeType = FullStyleChange) OVERRIDE;

// -----------------------------------------------------------------------------
// Notification of document structure changes (see Node.h for more notification methods)

// These functions are called whenever you are connected or disconnected from a tree. That tree may be the main
// document tree, or it could be another disconnected tree. Override these functions to do any work that depends
// on connectedness to some ancestor (e.g., an ancestor <form>).
virtual void insertedIntoTree(bool deep);
virtual void removedFromTree(bool deep);

// Notifies the node that it's list of children have changed (either by adding or removing child nodes), or a child
// node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
virtual void childrenChanged(bool createdByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);

protected:
ContainerNode(Document*, ConstructionType = CreateContainer);

Expand Down
12 changes: 1 addition & 11 deletions Source/WebCore/dom/Node.h
Expand Up @@ -510,7 +510,7 @@ class Node : public EventTarget, public ScriptWrappable, public TreeShared<Conta
RenderStyle* computedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return virtualComputedStyle(pseudoElementSpecifier); }

// -----------------------------------------------------------------------------
// Notification of document structure changes
// Notification of document structure changes (see ContainerNode.h for more notification methods)

// Notifies the node that it has been inserted into the document. This is called during document parsing, and also
// when a node is added through the DOM methods insertBefore(), appendChild() or replaceChild(). Note that this only
Expand All @@ -528,16 +528,6 @@ class Node : public EventTarget, public ScriptWrappable, public TreeShared<Conta
// dispatching, and is called _after_ the node is removed from the tree.
virtual void removedFromDocument();

// These functions are called whenever you are connected or disconnected from a tree. That tree may be the main
// document tree, or it could be another disconnected tree. Override these functions to do any work that depends
// on connectedness to some ancestor (e.g., an ancestor <form> for example).
virtual void insertedIntoTree(bool /*deep*/) { }
virtual void removedFromTree(bool /*deep*/) { }

// Notifies the node that it's list of children have changed (either by adding or removing child nodes), or a child
// node that is of the type CDATA_SECTION_NODE, TEXT_NODE or COMMENT_NODE has changed its value.
virtual void childrenChanged(bool /*changedByParser*/ = false, Node* /*beforeChange*/ = 0, Node* /*afterChange*/ = 0, int /*childCountDelta*/ = 0) { }

#ifndef NDEBUG
virtual void formatForDebugger(char* buffer, unsigned length) const;

Expand Down

0 comments on commit 51d50d1

Please sign in to comment.