Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(537)

Unified Diff: Source/core/dom/ContainerNodeAlgorithms.h

Issue 49153006: Have ContainerNodeAlgorithms deal with references instead of pointers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/ContainerNodeAlgorithms.h
diff --git a/Source/core/dom/ContainerNodeAlgorithms.h b/Source/core/dom/ContainerNodeAlgorithms.h
index a6683fd2e0a12c3b83c3bf236c687c41b8620eea..9224393aa1cd987931b2578dc771b805d022bc9f 100644
--- a/Source/core/dom/ContainerNodeAlgorithms.h
+++ b/Source/core/dom/ContainerNodeAlgorithms.h
@@ -31,52 +31,52 @@ namespace WebCore {
class ChildNodeInsertionNotifier {
public:
- explicit ChildNodeInsertionNotifier(ContainerNode* insertionPoint)
+ explicit ChildNodeInsertionNotifier(ContainerNode& insertionPoint)
: m_insertionPoint(insertionPoint)
{
}
- void notify(Node*);
+ void notify(Node&);
private:
- void notifyDescendantInsertedIntoDocument(ContainerNode*);
- void notifyDescendantInsertedIntoTree(ContainerNode*);
- void notifyNodeInsertedIntoDocument(Node*);
- void notifyNodeInsertedIntoTree(ContainerNode*);
+ void notifyDescendantInsertedIntoDocument(ContainerNode&);
+ void notifyDescendantInsertedIntoTree(ContainerNode&);
+ void notifyNodeInsertedIntoDocument(Node&);
+ void notifyNodeInsertedIntoTree(ContainerNode&);
- ContainerNode* m_insertionPoint;
+ ContainerNode& m_insertionPoint;
Vector< RefPtr<Node> > m_postInsertionNotificationTargets;
};
class ChildNodeRemovalNotifier {
public:
- explicit ChildNodeRemovalNotifier(ContainerNode* insertionPoint)
+ explicit ChildNodeRemovalNotifier(ContainerNode& insertionPoint)
: m_insertionPoint(insertionPoint)
{
}
- void notify(Node*);
+ void notify(Node&);
private:
- void notifyDescendantRemovedFromDocument(ContainerNode*);
- void notifyDescendantRemovedFromTree(ContainerNode*);
- void notifyNodeRemovedFromDocument(Node*);
- void notifyNodeRemovedFromTree(ContainerNode*);
+ void notifyDescendantRemovedFromDocument(ContainerNode&);
+ void notifyDescendantRemovedFromTree(ContainerNode&);
+ void notifyNodeRemovedFromDocument(Node&);
+ void notifyNodeRemovedFromTree(ContainerNode&);
- ContainerNode* m_insertionPoint;
+ ContainerNode& m_insertionPoint;
};
namespace Private {
template<class GenericNode, class GenericNodeContainer>
- void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer*);
+ void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer&);
}
// Helper functions for TreeShared-derived classes, which have a 'Node' style interface
// This applies to 'ContainerNode' and 'SVGElementInstance'
template<class GenericNode, class GenericNodeContainer>
-inline void removeDetachedChildrenInContainer(GenericNodeContainer* container)
+inline void removeDetachedChildrenInContainer(GenericNodeContainer& container)
{
// List of nodes to be deleted.
GenericNode* head = 0;
@@ -97,25 +97,26 @@ inline void removeDetachedChildrenInContainer(GenericNodeContainer* container)
tail = 0;
if (n->hasChildNodes())
- Private::addChildNodesToDeletionQueue<GenericNode, GenericNodeContainer>(head, tail, static_cast<GenericNodeContainer*>(n));
+ Private::addChildNodesToDeletionQueue<GenericNode, GenericNodeContainer>(head, tail, static_cast<GenericNodeContainer&>(*n));
delete n;
}
}
template<class GenericNode, class GenericNodeContainer>
-inline void appendChildToContainer(GenericNode* child, GenericNodeContainer* container)
+inline void appendChildToContainer(GenericNode& child, GenericNodeContainer& container)
{
- child->setParentOrShadowHostNode(container);
+ child.setParentOrShadowHostNode(&container);
- GenericNode* lastChild = container->lastChild();
+ GenericNode* lastChild = container.lastChild();
if (lastChild) {
- child->setPreviousSibling(lastChild);
- lastChild->setNextSibling(child);
- } else
- container->setFirstChild(child);
+ child.setPreviousSibling(lastChild);
+ lastChild->setNextSibling(&child);
+ } else {
+ container.setFirstChild(&child);
+ }
- container->setLastChild(child);
+ container.setLastChild(&child);
}
// Helper methods for removeDetachedChildrenInContainer, hidden from WebCore namespace
@@ -123,7 +124,7 @@ namespace Private {
template<class GenericNode, class GenericNodeContainer, bool dispatchRemovalNotification>
struct NodeRemovalDispatcher {
- static void dispatch(GenericNode*, GenericNodeContainer*)
+ static void dispatch(GenericNode&, GenericNodeContainer&)
{
// no-op, by default
}
@@ -131,12 +132,12 @@ namespace Private {
template<class GenericNode, class GenericNodeContainer>
struct NodeRemovalDispatcher<GenericNode, GenericNodeContainer, true> {
- static void dispatch(GenericNode* node, GenericNodeContainer* container)
+ static void dispatch(GenericNode& node, GenericNodeContainer& container)
{
// Clean up any TreeScope to a removed tree.
- if (Document* containerDocument = container->ownerDocument())
- containerDocument->adoptIfNeeded(node);
- if (node->inDocument())
+ if (Document* containerDocument = container.ownerDocument())
+ containerDocument->adoptIfNeeded(&node);
+ if (node.inDocument())
ChildNodeRemovalNotifier(container).notify(node);
}
};
@@ -152,17 +153,17 @@ namespace Private {
};
template<class GenericNode, class GenericNodeContainer>
- void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer* container)
+ void addChildNodesToDeletionQueue(GenericNode*& head, GenericNode*& tail, GenericNodeContainer& container)
{
// We have to tell all children that their parent has died.
GenericNode* next = 0;
- for (GenericNode* n = container->firstChild(); n != 0; n = next) {
+ for (GenericNode* n = container.firstChild(); n; n = next) {
ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun);
next = n->nextSibling();
n->setNextSibling(0);
n->setParentOrShadowHostNode(0);
- container->setFirstChild(next);
+ container.setFirstChild(next);
if (next)
next->setPreviousSibling(0);
@@ -180,47 +181,47 @@ namespace Private {
tail = n;
} else {
RefPtr<GenericNode> protect(n); // removedFromDocument may remove remove all references to this node.
- NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldDispatchRemovalNotification<GenericNode>::value>::dispatch(n, container);
+ NodeRemovalDispatcher<GenericNode, GenericNodeContainer, ShouldDispatchRemovalNotification<GenericNode>::value>::dispatch(*n, container);
}
}
- container->setLastChild(0);
+ container.setLastChild(0);
}
} // namespace Private
-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node* node)
+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoDocument(Node& node)
{
- ASSERT(m_insertionPoint->inDocument());
+ ASSERT(m_insertionPoint.inDocument());
RefPtr<Node> protect(node);
- if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->insertedInto(m_insertionPoint))
- m_postInsertionNotificationTargets.append(node);
- if (node->isContainerNode())
+ if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(&m_insertionPoint))
+ m_postInsertionNotificationTargets.append(&node);
+ if (node.isContainerNode())
notifyDescendantInsertedIntoDocument(toContainerNode(node));
}
-inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode* node)
+inline void ChildNodeInsertionNotifier::notifyNodeInsertedIntoTree(ContainerNode& node)
{
NoEventDispatchAssertion assertNoEventDispatch;
- ASSERT(!m_insertionPoint->inDocument());
+ ASSERT(!m_insertionPoint.inDocument());
- if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->insertedInto(m_insertionPoint))
- m_postInsertionNotificationTargets.append(node);
+ if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(&m_insertionPoint))
+ m_postInsertionNotificationTargets.append(&node);
notifyDescendantInsertedIntoTree(node);
}
-inline void ChildNodeInsertionNotifier::notify(Node* node)
+inline void ChildNodeInsertionNotifier::notify(Node& node)
{
ASSERT(!NoEventDispatchAssertion::isEventDispatchForbidden());
- InspectorInstrumentation::didInsertDOMNode(node);
+ InspectorInstrumentation::didInsertDOMNode(&node);
- RefPtr<Document> protectDocument(node->document());
+ RefPtr<Document> protectDocument(node.document());
RefPtr<Node> protectNode(node);
- if (m_insertionPoint->inDocument())
+ if (m_insertionPoint.inDocument())
notifyNodeInsertedIntoDocument(node);
- else if (node->isContainerNode())
+ else if (node.isContainerNode())
notifyNodeInsertedIntoTree(toContainerNode(node));
// Script runs in didNotifySubtreeInsertions so we should lazy attach before
@@ -228,40 +229,40 @@ inline void ChildNodeInsertionNotifier::notify(Node* node)
// were inserted.
// FIXME: We should merge the lazy attach logic into the tree traversal in
// notifyNodeInsertedIntoDocument.
- if (!node->confusingAndOftenMisusedAttached() && node->parentNode() && node->parentNode()->confusingAndOftenMisusedAttached())
- node->lazyAttach();
+ if (!node.confusingAndOftenMisusedAttached() && node.parentNode() && node.parentNode()->confusingAndOftenMisusedAttached())
+ node.lazyAttach();
for (size_t i = 0; i < m_postInsertionNotificationTargets.size(); ++i) {
- Node* node = m_postInsertionNotificationTargets[i].get();
- if (node->inDocument())
- node->didNotifySubtreeInsertionsToDocument();
+ Node* targetNode = m_postInsertionNotificationTargets[i].get();
+ if (targetNode->inDocument())
+ targetNode->didNotifySubtreeInsertionsToDocument();
}
}
-inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument(Node* node)
+inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromDocument(Node& node)
{
- ASSERT(m_insertionPoint->inDocument());
- node->removedFrom(m_insertionPoint);
+ ASSERT(m_insertionPoint.inDocument());
+ node.removedFrom(&m_insertionPoint);
- if (node->isContainerNode())
+ if (node.isContainerNode())
notifyDescendantRemovedFromDocument(toContainerNode(node));
}
-inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromTree(ContainerNode* node)
+inline void ChildNodeRemovalNotifier::notifyNodeRemovedFromTree(ContainerNode& node)
{
NoEventDispatchAssertion assertNoEventDispatch;
- ASSERT(!m_insertionPoint->inDocument());
+ ASSERT(!m_insertionPoint.inDocument());
- node->removedFrom(m_insertionPoint);
+ node.removedFrom(&m_insertionPoint);
notifyDescendantRemovedFromTree(node);
}
-inline void ChildNodeRemovalNotifier::notify(Node* node)
+inline void ChildNodeRemovalNotifier::notify(Node& node)
{
- if (node->inDocument()) {
+ if (node.inDocument()) {
notifyNodeRemovedFromDocument(node);
- node->document().notifyRemovePendingSheetIfNeeded();
- } else if (node->isContainerNode())
+ node.document().notifyRemovePendingSheetIfNeeded();
+ } else if (node.isContainerNode())
notifyNodeRemovedFromTree(toContainerNode(node));
}

Powered by Google App Engine
This is Rietveld 408576698