return nullptr;
}
- // nothing to do
+ // Nothing to do.
if (refChild->previousSibling() == newChild || refChild == newChild)
return newChild;
InspectorInstrumentation::willInsertDOMNode(this);
ChildListMutationScope mutation(*this);
- for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
- ASSERT(*it);
- Node& child = **it;
+ for (const auto& targetNode : targets) {
+ ASSERT(targetNode);
+ Node& child = *targetNode;
// Due to arbitrary code running in response to a DOM mutation event it's
// possible that "next" is no longer a child of "this".
RefPtrWillBeRawPtr<Node> protect(this);
- if (oldChild == newChild) // nothing to do
+ if (oldChild == newChild) // Nothing to do.
return oldChild;
if (!oldChild) {
RefPtrWillBeRawPtr<Node> child = oldChild;
- // Make sure replacing the old child with the new is ok
+ // Make sure replacing the old child with the new is OK.
if (!checkAcceptChild(newChild.get(), child.get(), exceptionState)) {
if (exceptionState.hadException())
return nullptr;
RefPtrWillBeRawPtr<Node> next = child->nextSibling();
- // Remove the node we're replacing
+ // Remove the node we're replacing.
removeChild(child, exceptionState);
if (exceptionState.hadException())
return nullptr;
InspectorInstrumentation::willInsertDOMNode(this);
- // Add the new child(ren)
- for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
- ASSERT(*it);
- Node& child = **it;
+ // Add the new child(ren).
+ for (const auto& targetNode : targets) {
+ ASSERT(targetNode);
+ Node& child = *targetNode;
// Due to arbitrary code running in response to a DOM mutation event it's
// possible that "next" is no longer a child of "this".
getChildNodes(*this, children);
ChildListMutationScope mutation(*this);
- for (NodeVector::const_iterator it = children.begin(); it != children.end(); ++it) {
- ASSERT(*it);
- Node& child = **it;
+ for (const auto& node : children) {
+ ASSERT(node);
+ Node& child = *node;
mutation.willRemoveChild(child);
child.notifyMutationObserversNodeWillDetach();
dispatchChildRemovalEvents(child);
void ContainerNode::removeDetachedChildrenInContainer(ContainerNode& container)
{
// List of nodes to be deleted.
- Node* head = 0;
- Node* tail = 0;
+ Node* head = nullptr;
+ Node* tail = nullptr;
addChildNodesToDeletionQueue(head, tail, container);
Node* n;
Node* next;
- while ((n = head) != 0) {
+ while (head) {
+ n = head;
ASSERT_WITH_SECURITY_IMPLICATION(n->m_deletionHasBegun);
next = n->nextSibling();
- n->setNextSibling(0);
+ n->setNextSibling(nullptr);
head = next;
- if (next == 0)
- tail = 0;
+ if (!next)
+ tail = nullptr;
if (n->hasChildren())
addChildNodesToDeletionQueue(head, tail, toContainerNode(*n));
void ContainerNode::addChildNodesToDeletionQueue(Node*& head, Node*& tail, ContainerNode& container)
{
// We have to tell all children that their parent has died.
- Node* next = 0;
+ Node* next = nullptr;
for (Node* n = container.firstChild(); n; n = next) {
ASSERT_WITH_SECURITY_IMPLICATION(!n->m_deletionHasBegun);
next = n->nextSibling();
- n->setNextSibling(0);
- n->setParentOrShadowHostNode(0);
+ n->setNextSibling(nullptr);
+ n->setParentOrShadowHostNode(nullptr);
container.setFirstChild(next);
if (next)
- next->setPreviousSibling(0);
+ next->setPreviousSibling(nullptr);
if (!n->refCount()) {
#if ENABLE(SECURITY_ASSERT)
}
}
- container.setLastChild(0);
+ container.setLastChild(nullptr);
}
#endif
if (m_lastChild == &oldChild)
m_lastChild = previousChild;
- oldChild.setPreviousSibling(0);
- oldChild.setNextSibling(0);
- oldChild.setParentOrShadowHostNode(0);
+ oldChild.setPreviousSibling(nullptr);
+ oldChild.setNextSibling(nullptr);
+ oldChild.setParentOrShadowHostNode(nullptr);
document().adoptIfNeeded(oldChild);
}
childrenChanged(ChildrenChange::forRemoval(oldChild, prev, next, ChildrenChangeSourceParser));
}
-// this differs from other remove functions because it forcibly removes all the children,
+// This differs from other remove functions because it forcibly removes all the children,
// regardless of read-only status or event exceptions, e.g.
void ContainerNode::removeChildren()
{
InspectorInstrumentation::willInsertDOMNode(this);
- // Now actually add the child(ren)
+ // Now actually add the child(ren).
ChildListMutationScope mutation(*this);
- for (NodeVector::const_iterator it = targets.begin(); it != targets.end(); ++it) {
- ASSERT(*it);
- Node& child = **it;
+ for (const auto& targetNode : targets) {
+ ASSERT(targetNode);
+ Node& child = *targetNode;
// If the child has a parent again, just stop what we're doing, because
// that means someone is doing something with DOM mutation -- can't re-parent
childrenChanged(ChildrenChange::forInsertion(root, source));
- for (size_t i = 0; i < postInsertionNotificationTargets.size(); ++i) {
- Node* targetNode = postInsertionNotificationTargets[i].get();
+ for (const auto& targetNode : postInsertionNotificationTargets) {
if (targetNode->inDocument())
targetNode->didNotifySubtreeInsertionsToDocument();
}
EventDispatchForbiddenScope assertNoEventDispatch;
ScriptForbiddenScope forbidScript;
- for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
+ for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) {
// As an optimization we don't notify leaf nodes when when inserting
// into detached subtrees.
- if (!inDocument() && !node->isContainerNode())
+ if (!inDocument() && !node.isContainerNode())
continue;
- if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node->insertedInto(this))
- postInsertionNotificationTargets.append(node);
- for (ShadowRoot* shadowRoot = node->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot())
+ if (Node::InsertionShouldCallDidNotifySubtreeInsertions == node.insertedInto(this))
+ postInsertionNotificationTargets.append(&node);
+ for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot())
notifyNodeInsertedInternal(*shadowRoot, postInsertionNotificationTargets);
}
}
EventDispatchForbiddenScope assertNoEventDispatch;
Document& document = root.document();
- for (Node* node = &root; node; node = NodeTraversal::next(*node, &root)) {
+ for (Node& node : NodeTraversal::inclusiveDescendantsOf(root)) {
// As an optimization we skip notifying Text nodes and other leaf nodes
// of removal when they're not in the Document tree since the virtual
// call to removedFrom is not needed.
- if (!node->inDocument() && !node->isContainerNode())
+ if (!node.inDocument() && !node.isContainerNode())
continue;
if (document.cssTarget() == node)
document.setCSSTarget(nullptr);
- node->removedFrom(this);
- for (ShadowRoot* shadowRoot = node->youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot())
+ node.removedFrom(this);
+ for (ShadowRoot* shadowRoot = node.youngestShadowRoot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot())
notifyNodeRemoved(*shadowRoot);
}
}
{
if (!renderer())
return false;
- // What is this code really trying to do?
- RenderObject* o = renderer();
+ // FIXME: What is this code really trying to do?
+ RenderObject* o = renderer();
if (!o->isInline() || o->isReplaced()) {
point = o->localToAbsolute(FloatPoint(), UseTransforms);
return true;
}
- // find the next text/image child, to get a position
+ // Find the next text/image child, to get a position.
while (o) {
RenderObject* p = o;
if (RenderObject* oFirstChild = o->slowFirstChild()) {
} else if (o->nextSibling()) {
o = o->nextSibling();
} else {
- RenderObject* next = 0;
+ RenderObject* next = nullptr;
while (!next && o->parent()) {
o = o->parent();
next = o->nextSibling();
}
if (p->node() && p->node() == this && o->isText() && !o->isBR() && !toRenderText(o)->firstTextBox()) {
- // do nothing - skip unrendered whitespace that is a child or next sibling of the anchor
+ // Do nothing - skip unrendered whitespace that is a child or next sibling of the anchor.
} else if ((o->isText() && !o->isBR()) || o->isReplaced()) {
point = FloatPoint();
if (o->isText() && toRenderText(o)->firstTextBox()) {
return true;
}
- // find the last text/image child, to get a position
+ // Find the last text/image child, to get a position.
while (o) {
if (RenderObject* oLastChild = o->slowLastChild()) {
o = oLastChild;
} else if (o->previousSibling()) {
o = o->previousSibling();
} else {
- RenderObject* prev = 0;
- while (!prev) {
- o = o->parent();
- if (!o)
- return false;
- prev = o->previousSibling();
- }
- o = prev;
+ RenderObject* prev = nullptr;
+ while (!prev) {
+ o = o->parent();
+ if (!o)
+ return false;
+ prev = o->previousSibling();
+ }
+ o = prev;
}
ASSERT(o);
if (o->isText() || o->isReplaced()) {
if (styleChangeType() < SubtreeStyleChange) {
if (renderStyle()->affectedByFocus() && renderStyle()->hasPseudoStyle(FIRST_LETTER))
- setNeedsStyleRecalc(SubtreeStyleChange);
+ setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
else if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByFocus())
document().ensureStyleResolver().ensureUpdatedRuleFeatureSet().scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoFocus, *toElement(this));
else if (renderStyle()->affectedByFocus())
- setNeedsStyleRecalc(LocalStyleChange);
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
}
if (renderer() && renderer()->style()->hasAppearance())
if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByFocus() && styleChangeType() < SubtreeStyleChange)
document().ensureStyleResolver().ensureUpdatedRuleFeatureSet().scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoFocus, *toElement(this));
else
- setNeedsStyleRecalc(LocalStyleChange);
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Focus));
}
void ContainerNode::setActive(bool down)
if (renderer()) {
if (styleChangeType() < SubtreeStyleChange) {
if (renderStyle()->affectedByActive() && renderStyle()->hasPseudoStyle(FIRST_LETTER))
- setNeedsStyleRecalc(SubtreeStyleChange);
+ setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Active));
else if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByActive())
document().ensureStyleResolver().ensureUpdatedRuleFeatureSet().scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoActive, *toElement(this));
else if (renderStyle()->affectedByActive())
- setNeedsStyleRecalc(LocalStyleChange);
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Active));
}
if (renderStyle()->hasAppearance())
if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByHover() && styleChangeType() < SubtreeStyleChange)
document().ensureStyleResolver().ensureUpdatedRuleFeatureSet().scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoHover, *toElement(this));
else
- setNeedsStyleRecalc(LocalStyleChange);
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Hover));
return;
}
if (styleChangeType() < SubtreeStyleChange) {
if (renderStyle()->affectedByHover() && renderStyle()->hasPseudoStyle(FIRST_LETTER))
- setNeedsStyleRecalc(SubtreeStyleChange);
+ setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Hover));
else if (isElementNode() && toElement(this)->childrenOrSiblingsAffectedByHover())
document().ensureStyleResolver().ensureUpdatedRuleFeatureSet().scheduleStyleInvalidationForPseudoChange(CSSSelector::PseudoHover, *toElement(this));
else if (renderStyle()->affectedByHover())
- setNeedsStyleRecalc(LocalStyleChange);
+ setNeedsStyleRecalc(LocalStyleChange, StyleChangeReasonForTracing::createWithExtraData(StyleChangeReason::PseudoClass, StyleChangeExtraData::Hover));
}
if (renderer()->style()->hasAppearance())
RefPtrWillBeRawPtr<Node> c(child);
RefPtrWillBeRawPtr<Document> document(child.document());
- // dispatch pre-removal mutation events
+ // Dispatch pre-removal mutation events.
if (c->parentNode() && document->hasListenerType(Document::DOMNODEREMOVED_LISTENER)) {
NodeChildRemovalTracker scope(child);
c->dispatchScopedEvent(MutationEvent::create(EventTypeNames::DOMNodeRemoved, true, c->parentNode()));
}
- // dispatch the DOMNodeRemovedFromDocument event to all descendants
+ // Dispatch the DOMNodeRemovedFromDocument event to all descendants.
if (c->inDocument() && document->hasListenerType(Document::DOMNODEREMOVEDFROMDOCUMENT_LISTENER)) {
NodeChildRemovalTracker scope(child);
for (; c; c = NodeTraversal::next(*c, &child))
// child and work our way back means in the common case, we'll find the insertion point in O(1) time.
// See crbug.com/288225
StyleResolver& styleResolver = document().ensureStyleResolver();
- Text* lastTextNode = 0;
+ Text* lastTextNode = nullptr;
for (Node* child = lastChild(); child; child = child->previousSibling()) {
if (child->isTextNode()) {
toText(child)->recalcTextStyle(change, lastTextNode);
else if (element->supportsStyleSharing())
styleResolver.addToStyleSharingList(*element);
if (element->renderer())
- lastTextNode = 0;
+ lastTextNode = nullptr;
}
}
}
bool childRulesChanged = child->needsStyleRecalc() && child->styleChangeType() >= SubtreeStyleChange;
if (forceCheckOfNextElementCount || forceCheckOfAnyElementSibling)
- child->setNeedsStyleRecalc(SubtreeStyleChange);
+ child->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
if (childRulesChanged && hasDirectAdjacentRules)
forceCheckOfNextElementCount = document.styleEngine()->maxDirectAdjacentSelectors();
// here. recalcStyle will then force a walk of the children when it sees that this has happened.
if (((childrenAffectedByForwardPositionalRules() || childrenAffectedByIndirectAdjacentRules()) && nodeAfterChange)
|| (childrenAffectedByBackwardPositionalRules() && nodeBeforeChange)) {
- setNeedsStyleRecalc(SubtreeStyleChange);
+ setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
return;
}
ASSERT(changeType != FinishedParsingChildren);
// Find our new first child element.
Element* firstChildElement = ElementTraversal::firstChild(*this);
- RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElement->renderStyle() : 0;
+ RenderStyle* firstChildElementStyle = firstChildElement ? firstChildElement->renderStyle() : nullptr;
// Find the first element after the change.
Element* elementAfterChange = nodeAfterChange->isElementNode() ? toElement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange);
- RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfterChange->renderStyle() : 0;
+ RenderStyle* elementAfterChangeStyle = elementAfterChange ? elementAfterChange->renderStyle() : nullptr;
// This is the element insertion as first child element case.
if (firstChildElement != elementAfterChange && elementAfterChangeStyle && elementAfterChangeStyle->firstChildState()) {
ASSERT(changeType == SiblingElementInserted);
- elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange);
+ elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
}
// This is the first child element removal case.
if (changeType == SiblingElementRemoved && firstChildElement == elementAfterChange && firstChildElement && (!firstChildElementStyle || !firstChildElementStyle->firstChildState()))
- firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange);
+ firstChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
}
// :last-child. In the parser callback case, we don't have to check anything, since we were right the first time.
if (childrenAffectedByLastChildRules() && nodeBeforeChange) {
// Find our new last child element.
Element* lastChildElement = ElementTraversal::lastChild(*this);
- RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement->renderStyle() : 0;
+ RenderStyle* lastChildElementStyle = lastChildElement ? lastChildElement->renderStyle() : nullptr;
// Find the last element before the change.
Element* elementBeforeChange = nodeBeforeChange->isElementNode() ? toElement(nodeBeforeChange) : ElementTraversal::previousSibling(*nodeBeforeChange);
- RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBeforeChange->renderStyle() : 0;
+ RenderStyle* elementBeforeChangeStyle = elementBeforeChange ? elementBeforeChange->renderStyle() : nullptr;
// This is the element insertion as last child element case.
if (lastChildElement != elementBeforeChange && elementBeforeChangeStyle && elementBeforeChangeStyle->lastChildState()) {
ASSERT(SiblingElementInserted);
- elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange);
+ elementBeforeChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
}
// This is the last child element removal case. The parser callback case is similar to node removal as well in that we need to change the last child
// to match now.
if ((changeType == SiblingElementRemoved || changeType == FinishedParsingChildren) && lastChildElement == elementBeforeChange && lastChildElement && (!lastChildElementStyle || !lastChildElementStyle->lastChildState()))
- lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange);
+ lastChildElement->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
}
// The + selector. We need to invalidate the first element following the change. It is the only possible element
// that could be affected by this DOM change.
if (childrenAffectedByDirectAdjacentRules() && nodeAfterChange) {
if (Element* elementAfterChange = nodeAfterChange->isElementNode() ? toElement(nodeAfterChange) : ElementTraversal::nextSibling(*nodeAfterChange))
- elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange);
+ elementAfterChange->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::SiblingSelector));
}
}
// and check if the matching element is in our subtree.
Element* element = treeScope().getElementById(id);
if (!element)
- return 0;
+ return nullptr;
if (element->isDescendantOf(this))
return element;
}
// Fall back to traversing our subtree. In case of duplicate ids, the first element found will be returned.
- for (Element* element = ElementTraversal::firstWithin(*this); element; element = ElementTraversal::next(*element, this)) {
- if (element->getIdAttribute() == id)
- return element;
+ for (Element& element : ElementTraversal::descendantsOf(*this)) {
+ if (element.getIdAttribute() == id)
+ return &element;
}
- return 0;
+ return nullptr;
}
NodeListsNodeData& ContainerNode::ensureNodeLists()